#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
int n, p;
map<string, int> mp;
bitset<1005> prec[1005], gph[1005], rev[1005];
bool solve(int x, bitset<1005> &v){
for(int i=1; i<=p; i++){
if(!v[i]) continue;
auto t = prec[i] & ~gph[i];
if((t & v).any()){
return 0;
}
}
return 1;
}
int main(){
cin >> n;
for(int i=1; i<=n; i++){
string t, b;
cin >> t >> b;
if(mp.find(t) != mp.end()){
puts("greska");
while(1){
cin >> b;
if(b == ";") break;
}
continue;
}
bitset<1005> v;
bool bad = 0;
while(1){
string x;
cin >> x;
if(x == ";") break;
if(mp.find(x) == mp.end()){
bad = 1;
}
else{
v[mp[x]] = true;
}
}
if(bad || solve(p+1, v) == false){
puts("greska");
}
else{
puts("ok");
p++;
mp[t] = p;
for(int i=1; i<p; i++){
if(v[i]){
v |= gph[i];
}
}
for(int i=1; i<p; i++){
if(v[i]){
prec[p] |= rev[i];
}
}
for(int i=1; i<p; i++){
if(v[i]){
rev[i][p] = true;
}
}
gph[p] = v;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2404 KB |
Output is correct |
2 |
Correct |
0 ms |
2404 KB |
Output is correct |
3 |
Correct |
0 ms |
2404 KB |
Output is correct |
4 |
Correct |
0 ms |
2404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2404 KB |
Output is correct |
2 |
Correct |
0 ms |
2404 KB |
Output is correct |
3 |
Correct |
0 ms |
2404 KB |
Output is correct |
4 |
Correct |
0 ms |
2404 KB |
Output is correct |
5 |
Correct |
0 ms |
2404 KB |
Output is correct |
6 |
Correct |
3 ms |
2404 KB |
Output is correct |
7 |
Correct |
3 ms |
2404 KB |
Output is correct |
8 |
Correct |
0 ms |
2404 KB |
Output is correct |
9 |
Correct |
3 ms |
2404 KB |
Output is correct |
10 |
Correct |
0 ms |
2404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2404 KB |
Output is correct |
2 |
Correct |
0 ms |
2404 KB |
Output is correct |
3 |
Correct |
0 ms |
2404 KB |
Output is correct |
4 |
Correct |
0 ms |
2404 KB |
Output is correct |
5 |
Correct |
0 ms |
2404 KB |
Output is correct |
6 |
Correct |
3 ms |
2404 KB |
Output is correct |
7 |
Correct |
3 ms |
2404 KB |
Output is correct |
8 |
Correct |
0 ms |
2404 KB |
Output is correct |
9 |
Correct |
3 ms |
2404 KB |
Output is correct |
10 |
Correct |
0 ms |
2404 KB |
Output is correct |
11 |
Correct |
0 ms |
2404 KB |
Output is correct |
12 |
Correct |
0 ms |
2404 KB |
Output is correct |
13 |
Correct |
3 ms |
2404 KB |
Output is correct |
14 |
Correct |
3 ms |
2404 KB |
Output is correct |
15 |
Correct |
3 ms |
2404 KB |
Output is correct |
16 |
Correct |
0 ms |
2404 KB |
Output is correct |
17 |
Correct |
0 ms |
2404 KB |
Output is correct |
18 |
Correct |
0 ms |
2404 KB |
Output is correct |
19 |
Correct |
0 ms |
2404 KB |
Output is correct |
20 |
Correct |
0 ms |
2404 KB |
Output is correct |
21 |
Correct |
3 ms |
2404 KB |
Output is correct |
22 |
Correct |
0 ms |
2404 KB |
Output is correct |
23 |
Correct |
0 ms |
2404 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
509 ms |
2536 KB |
Output is correct |
2 |
Correct |
556 ms |
2536 KB |
Output is correct |
3 |
Correct |
276 ms |
2404 KB |
Output is correct |
4 |
Correct |
6 ms |
2404 KB |
Output is correct |
5 |
Correct |
9 ms |
2404 KB |
Output is correct |
6 |
Correct |
9 ms |
2404 KB |
Output is correct |
7 |
Correct |
19 ms |
2404 KB |
Output is correct |
8 |
Correct |
36 ms |
2404 KB |
Output is correct |
9 |
Correct |
36 ms |
2404 KB |
Output is correct |
10 |
Correct |
9 ms |
2404 KB |
Output is correct |
11 |
Correct |
16 ms |
2404 KB |
Output is correct |
12 |
Correct |
516 ms |
2536 KB |
Output is correct |