QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#469336#7232. Odd GrammarpropaneWA 15ms3824kbC++202.7kb2024-07-09 17:59:552024-07-09 17:59:56

Judging History

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

  • [2024-07-09 17:59:56]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:3824kb
  • [2024-07-09 17:59:55]
  • 提交

answer

#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<array>
using namespace std;
using LL = long long;

int main(){

#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int n, m;
    while(cin >> n >> m and (n != 0 or m != 0)){
        vector<int> d(m), from(m);
        vector<array<int, 2> > f(n + 1), state(m, {1, 0});
        queue<pair<int, int> > q;
        vector<vector<int> > g(n + 1);
        vector<bool> ed(n + 1);
        for(int i = 0; i < m; i++){
            int x, k;
            cin >> x >> k;
            from[i] = x;
            d[i] = k;
            for(int j = 0; j < k; j++){
                string s;
                cin >> s;
                if (isalpha(s[0])){
                    swap(state[i][0], state[i][1]);
                    d[i] -= 1;
                }
                else{
                    int t = stoi(s);
                    g[t].push_back(i);
                }
            }
            if (d[i] == 0){
                ed[from[i]] = true;
                for(auto k : {0, 1}){
                    if (state[i][k]){
                        f[from[i]][k] = 1;
                        q.push({from[i], k});
                    }
                }
            }
        }
        while(!q.empty()){
            auto [x, y] = q.front();
            q.pop();
            for(auto j : g[x]){
                if (ed[j]){
                    for(auto k : {0, 1}){
                        if (state[j][k] == 0){
                            state[j][k] = 1;
                            if (!f[from[j]][k]){
                                f[from[j]][k] = 1;
                                q.push({from[j], k});
                            }
                        }
                    }
                }
                else{
                    if (f[x][y ^ 1]){
                        state[j][0] = state[j][1] = 1;
                    }
                    else{
                        if (y == 1) swap(state[j][0], state[j][1]);
                        if (--d[j] == 0){
                            ed[j] = true;
                            for(auto k : {0, 1}){
                                if (state[j][k] == 1 and f[from[j]][k] == 0){
                                    f[from[j]][k] = 1;
                                    q.push({from[j], k});
                                }
                            }
                        }
                    }
                }
            }
        }
        cout << (f[1][1] ? "YES" : "NO") << '\n';
    }

}

詳細信息

Test #1:

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

input:

2 2
1 2 a 2
2 1 b
2 2
1 2 b 2
2 2 a a
2 2
1 2 b 2
2 3 a a 1
0 0

output:

NO
YES
NO

result:

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

Test #2:

score: 0
Accepted
time: 0ms
memory: 3604kb

input:

1 1
1 0
1 1
1 1 a
1 1
1 1 b
1 1
1 1 1
1 2
1 2 1 a
1 1 b
2 4
1 2 2 a
1 0
2 2 1 b
2 0
2 4
1 2 2 b
1 0
2 2 1 a
2 0
0 0

output:

NO
YES
YES
NO
YES
YES
YES

result:

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

Test #3:

score: 0
Accepted
time: 0ms
memory: 3528kb

input:

5 6
1 1 2
2 1 3
3 1 4
4 1 5
5 2 a 1
5 10 b b b b b b b b b b
3 3
1 1 b
2 1 a
2 2 2 a
0 0

output:

YES
YES

result:

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

Test #4:

score: 0
Accepted
time: 14ms
memory: 3768kb

input:

1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

ok 50000 token(s): yes count is 0, no count is 50000

Test #5:

score: 0
Accepted
time: 15ms
memory: 3824kb

input:

1 1
1 0
1 1
1 1 b
1 1
1 1 1
1 1
1 0
1 1
1 0
1 1
1 1 b
1 1
1 0
1 1
1 1 b
1 1
1 1 b
1 1
1 0
1 1
1 1 a
1 1
1 1 1
1 1
1 0
1 1
1 1 b
1 1
1 0
1 1
1 1 b
1 1
1 1 1
1 1
1 1 1
1 1
1 1 1
1 1
1 0
1 1
1 0
1 1
1 1 1
1 1
1 1 a
1 1
1 0
1 1
1 1 b
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 0
1 1
1 1 b
1 1
1 0
1 1
1 0
1 1
1 0
1 1
...

output:

NO
YES
NO
NO
NO
YES
NO
YES
YES
NO
YES
NO
NO
YES
NO
YES
NO
NO
NO
NO
NO
NO
YES
NO
YES
NO
NO
NO
NO
YES
NO
NO
NO
NO
YES
NO
YES
NO
NO
NO
YES
NO
NO
NO
YES
NO
YES
NO
NO
NO
YES
YES
NO
YES
NO
NO
NO
NO
NO
YES
YES
NO
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
NO
YES
YES
NO
YES
YES
NO
YES
YES
YES
N...

result:

ok 50000 token(s): yes count is 16576, no count is 33424

Test #6:

score: -100
Wrong Answer
time: 12ms
memory: 3624kb

input:

2 1
2 1 2
2 1
2 0
2 2
2 0
1 0
2 2
2 0
2 0
2 1
1 0
1 1
1 1 a
2 1
1 0
2 1
1 0
2 2
1 0
1 0
2 2
2 0
1 0
2 1
2 1 a
2 1
1 1 b
1 1
1 1 b
1 2
1 0
1 0
1 2
1 0
1 1 1
1 1
1 1 b
2 2
1 1 b
1 1 a
2 2
2 0
2 0
2 1
1 1 1
1 2
1 1 b
1 0
2 1
2 0
1 2
1 0
1 1 1
1 1
1 0
1 1
1 1 1
1 2
1 1 a
1 1 b
1 1
1 1 1
2 2
1 1 2
2 1 b
...

output:

NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
YES
YES
NO
YES
YES
YES
NO
NO
YES
NO
YES
NO
NO
YES
NO
YES
YES
YES
NO
YES
NO
YES
NO
YES
NO
YES
YES
NO
NO
NO
YES
YES
YES
YES
NO
YES
NO
YES
YES
NO
NO
NO
NO
NO
NO
NO
YES
YES
NO
NO
NO
YES
NO
YES
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
YES
YES
NO
NO
NO
YES
YES...

result:

wrong answer expected NO, found YES [15th token]