QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#623569#6723. Grid with Arrowsproven#AC ✓113ms15744kbC++203.1kb2024-10-09 13:10:552024-10-09 13:10:57

Judging History

你现在查看的是最新测评结果

  • [2024-10-09 13:10:57]
  • 评测
  • 测评结果:AC
  • 用时:113ms
  • 内存:15744kb
  • [2024-10-09 13:10:55]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
#define endl '\n'
#define int long long

void solve() {
    int n, m;
    cin >> n >> m;
    vector<string> v(n + 1);
    for(int i = 1;i <= n;i++) cin >> v[i];
    for(int i = 1;i <= n;i++) v[i] = ' ' + v[i];
    vector<vector<int> > a(n + 1, vector<int> (m + 1));
    for(int i = 1;i <= n;i++) {
        for(int j = 1;j <= m;j++) cin >> a[i][j];
    }
    auto calc = [&] (int x, int y) {
        return (x - 1) * m + y;
    };
    vector<vector<int> > e(n * m + 1);
    vector<int> deg(n * m + 1), deg2(n * m + 1);
    auto check = [&] (int x, int y) {
        return (x >= 1 && x <= n && y >= 1 && y <= m);
    };
    vector<int> f(n * m + 1);
    iota(f.begin(), f.end(), 0);
    function<int(int)> find = [&] (int x) {
        return x == f[x] ? f[x] : f[x] = find(f[x]);
    };
    for(int i = 1;i <= n;i++) {
        for(int j = 1;j <= m;j++) {
            char c = v[i][j];
            int x = a[i][j];
            if(c == 'u') {
                int xx = i - x, yy = j;
                if(check(xx, yy)) {
                    deg[calc(i, j)]++;
                    deg2[calc(xx, yy)]++;
                    f[find(calc(i, j))] = f[find(calc(xx, yy))];
                    e[calc(i, j)].push_back(calc(xx, yy));
                }
            }
            else if(c == 'd') {
                int xx = i + x, yy = j;
                if(check(xx, yy)) {
                    deg[calc(i, j)]++;
                    deg2[calc(xx, yy)]++;
                    f[find(calc(i, j))] = f[find(calc(xx, yy))];
                    e[calc(i, j)].push_back(calc(xx, yy));
                }
            }
            else if(c == 'l') {
                int xx = i, yy = j - x;
                if(check(xx, yy)) {
                    deg[calc(i, j)]++;
                    deg2[calc(xx, yy)]++;
                    f[find(calc(i, j))] = f[find(calc(xx, yy))];
                    e[calc(i, j)].push_back(calc(xx, yy));
                }
            }
            else {
                int xx = i, yy = j + x;
                if(check(xx, yy)) {
                    deg[calc(i, j)]++;
                    deg2[calc(xx, yy)]++;
                    f[find(calc(i, j))] = f[find(calc(xx, yy))];
                    e[calc(i, j)].push_back(calc(xx, yy));
                }
            }
        }
    }
    bool fg = true;
    map<int, int> mp;
    for(int i = 1;i <= n * m;i++) mp[find(i)]++;
    if(mp.size() != 1 || mp.begin()->second != n * m) {
        cout << "No" << endl;
        return;
    }
    int x = 0, y = 0;
    for(int i = 1;i <= n * m;i++) {
        if(deg[i] == deg2[i]) continue;
        if(abs(deg[i] - deg2[i]) == 1) {
            if(deg[i] > deg2[i]) x++;
            else y++;
        }
        else fg = false;
    }
    if(!fg) cout << "No" << endl;
    else {
        if(max(x, y) > 1) {
            cout << "No" << endl;
        }
        else cout << "Yes" << endl;
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }

    return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3444kb

input:

2
2 3
rdd
url
2 1 1
1 1 2
2 2
rr
rr
1 1
1 1

output:

Yes
No

result:

ok 2 token(s): yes count is 1, no count is 1

Test #2:

score: 0
Accepted
time: 113ms
memory: 15744kb

input:

1109
5 8
rddddldl
drruludl
rrldrurd
urrrlluu
uurrulrl
4 4 1 2 4 3 1 6
1 3 5 1 1 1 3 6
2 4 1 1 2 1 1 1
2 3 4 2 4 3 3 3
4 1 1 2 2 5 1 5
7 9
rdrddrdll
urrdruldl
ruullrulu
drrlrlddl
rrrdddlll
ruulururl
ruurrlluu
7 1 1 1 2 1 2 3 6
1 7 3 1 3 1 2 1 8
2 2 1 2 4 3 1 2 2
2 2 4 1 1 5 3 3 1
3 4 6 1 2 1 2 7 7
6 ...

output:

Yes
No
No
No
Yes
No
Yes
Yes
Yes
Yes
No
No
No
Yes
Yes
No
Yes
No
Yes
No
No
No
Yes
Yes
No
Yes
Yes
No
Yes
No
No
Yes
No
No
Yes
Yes
Yes
No
No
Yes
Yes
Yes
No
Yes
No
Yes
No
Yes
Yes
No
Yes
No
Yes
No
Yes
Yes
No
No
Yes
No
Yes
Yes
Yes
Yes
No
Yes
Yes
No
Yes
Yes
No
No
Yes
Yes
No
No
Yes
Yes
No
No
Yes
Yes
Yes
Yes
Y...

result:

ok 1109 token(s): yes count is 602, no count is 507