Submission #585802

# Submission time Handle Problem Language Result Execution time Memory
585802 2022-06-29T11:02:25 Z FatihSolak Dijamant (COI16_dijament) C++17
100 / 100
299 ms 4624 KB
#include <bits/stdc++.h>
#define N 1005
using namespace std;
int par[N];
vector<int> adj[N];
bool ok;
void dfs(int v){
    for(auto u:adj[v]){
        if(!ok)return;
        if(par[u]){
            if(par[u] != v)
                ok = 0;
        }
        else{
            par[u] = v;
            dfs(u);
        }
    }
}
void solve(){
    int n,q;
    n = 0;
    cin >> q;
    map<string,int> mp;
    while(q--){
        string s;
        cin >> s;
        char c;
        cin >> c;
        vector<string> v;
        while(1){
            string t;
            cin >> t;
            if(t == ";")break;
            v.push_back(t);
        }
        ok = 1;
        if(mp[s]){
            ok = 0;
        }
        for(auto u:v){
            if(!mp[u]){
                ok = 0;
            }
        }
        for(int i = 1;i<n;i++){
            par[i] = 0;
        }
        for(auto u:v){
            dfs(mp[u]);
        }
        if(ok){
            mp[s] = ++n;
            cout << "ok" << endl;
            for(auto u:v){
                if(par[mp[u]] == 0){
                    adj[n].push_back(mp[u]);
                }
            }
        }
        else cout << "greska" << endl;
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifdef Local
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    #ifdef Local
        cout << endl << fixed << setprecision(2) << 1000.0*clock()/CLOCKS_PER_SEC << " milliseconds.";
    #endif
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 408 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 408 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 352 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 225 ms 4308 KB Output is correct
2 Correct 299 ms 4624 KB Output is correct
3 Correct 199 ms 4568 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 3 ms 368 KB Output is correct
6 Correct 8 ms 524 KB Output is correct
7 Correct 12 ms 596 KB Output is correct
8 Correct 19 ms 800 KB Output is correct
9 Correct 20 ms 744 KB Output is correct
10 Correct 7 ms 468 KB Output is correct
11 Correct 8 ms 488 KB Output is correct
12 Correct 210 ms 3844 KB Output is correct