编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#25760 #2065. 数字华容道 Accepted 100 671 ms 23952 K C++ 17 / 1.1 K admin 2025-03-11 20:44:25
显示原始代码
#include <bits/stdc++.h>
#define int long long

using namespace std;
const int N = 1010;
int n, m;
int a[N][N];
int b[N * N], lb;
int c[N * N];
int hb(int l, int r) {
    if (l == r)
        return 0;
    int mid = (l + r) >> 1;
    int tot = hb(l, mid) + hb(mid + 1, r);
    int ln = l, rn = mid + 1, nn = l;
    while (ln <= mid and rn <= r) {
        if (b[ln] <= b[rn]) {
            c[nn] = b[ln];
            nn++;
            ln++;
        } else {
            tot += mid - ln + 1;
            c[nn] = b[rn];
            nn++;
            rn++;
        }
    }
    while (ln <= mid) {
        c[nn] = b[ln];
        nn++;
        ln++;
    }
    while (rn <= r) {
        c[nn] = b[rn];
        nn++;
        rn++;
    }
    for (int i = l; i <= r; i++) b[i] = c[i];
    return tot;
}
int zh() {
    int zhx = 0;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            if (a[i][j] != 0)
                zhx += abs(i - (a[i][j] - 1) / m - 1);
    return zhx;
}
signed main() {
    std::ios::sync_with_stdio(false);
    cin.tie();
    cout.tie();
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cin >> a[i][j];
            if (a[i][j] != 0) {
                lb++;
                b[lb] = a[i][j];
            }
        }
    }
    int ju1 = hb(1, lb), ju2 = zh();
    if (m % 2 == 1) {
        if (ju1 & 1)
            cout << "NO";
        else
            cout << "YES";
    } else {
        if ((ju1 ^ ju2) & 1)
            cout << "NO";
        else
            cout << "YES";
    }
}
子任务 #1
Accepted
得分:100
测试点 #1
Accepted
得分:100
用时:3 ms
内存:412 KiB

输入文件(test1.in

3 3
1 2 6 
7 3 8 
0 4 5 

答案文件(test1.out

YES

用户输出

YES

系统信息

Exited with return code 0
测试点 #2
Accepted
得分:100
用时:3 ms
内存:456 KiB

输入文件(test2.in

3 3
7 1 5 
6 0 2 
3 4 8 

答案文件(test2.out

YES

用户输出

YES

系统信息

Exited with return code 0
测试点 #3
Accepted
得分:100
用时:3 ms
内存:412 KiB

输入文件(test3.in

4 4
13 11 1 9 
15 2 14 7 
0 10 3 8 
4 5 6 12 

答案文件(test3.out

YES

用户输出

YES

系统信息

Exited with return code 0
测试点 #4
Accepted
得分:100
用时:3 ms
内存:344 KiB

输入文件(test4.in

4 4
14 3 9 8 
4 15 5 0 
1 2 6 7 
10 11 12 13 

答案文件(test4.out

NO

用户输出

NO

系统信息

Exited with return code 0
测试点 #5
Accepted
得分:100
用时:3 ms
内存:412 KiB

输入文件(test5.in

4 4
9 13 2 5 
1 14 12 0 
3 4 10 7 
8 6 11 15 

答案文件(test5.out

NO

用户输出

NO

系统信息

Exited with return code 0
测试点 #6
Accepted
得分:100
用时:5 ms
内存:1048 KiB

输入文件(test6.in

100 100
7690 5682 2677 2004 5559 6119 4307 2035 8893 7862 9155 2640 4139 6211 1754 6042 8035 8694 1
<48999 bytes omitted>

答案文件(test6.out

YES

用户输出

YES

系统信息

Exited with return code 0
测试点 #7
Accepted
得分:100
用时:6 ms
内存:1008 KiB

输入文件(test7.in

100 100
7131 5702 6393 2569 6232 2219 5826 1730 3120 8643 4870 8412 4828 9339 2366 738 5908 5688 52
<48999 bytes omitted>

答案文件(test7.out

NO

用户输出

NO

系统信息

Exited with return code 0
测试点 #8
Accepted
得分:100
用时:255 ms
内存:23952 KiB

输入文件(test8.in

1000 1000
852093 582459 126709 111945 392720 997041 498864 532066 280215 433547 734819 780448 18612
<6890801 bytes omitted>

答案文件(test8.out

YES

用户输出

YES

系统信息

Exited with return code 0
测试点 #9
Accepted
得分:100
用时:256 ms
内存:23884 KiB

输入文件(test9.in

1000 1000
425610 18558 726158 634073 689595 11109 521599 44245 742153 819901 371590 568407 886681 3
<6890801 bytes omitted>

答案文件(test9.out

YES

用户输出

YES

系统信息

Exited with return code 0
测试点 #10
Accepted
得分:100
用时:134 ms
内存:13584 KiB

输入文件(test10.in

587 931
402769 239103 45894 99675 444353 214471 33158 331145 254043 429952 47540 544790 544051 3134
<3715452 bytes omitted>

答案文件(test10.out

YES

用户输出

YES

系统信息

Exited with return code 0