Submission #743661

# Submission time Handle Problem Language Result Execution time Memory
743661 2023-05-17T15:59:38 Z lukadupli Dijamant (COI16_dijament) C++14
100 / 100
382 ms 26428 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1005;

int n, cnt = 0, depth[MAXN];
map<string, int> mapa;
set<int> orgs[MAXN];

bool add(string& klasa, vector<string>& dads){
    if(mapa.find(klasa) != mapa.end()) return 0;

    vector<int> ds;
    for(string& d : dads){
        if(mapa.find(d) == mapa.end()) return 0;
        ds.push_back(mapa[d]);
    }

    sort(ds.begin(), ds.end(), [](int a, int b){return depth[a] > depth[b]; });

    set<int> s;
    int maxi = -1;
    for(int d : ds){
        if(s.find(d) != s.end()) continue;

        for(int e : orgs[d]){
            if(s.find(e) != s.end()) return 0;
            s.insert(e);
        }
        s.insert(d);

        maxi = max(maxi, depth[d]);
    }

    mapa[klasa] = ++cnt;
    orgs[cnt] = s;
    depth[cnt] = maxi + 1;

    return 1;
}

vector<string> dads;

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++){
        string k;
        cin >> k;

        char c;
        cin >> c;

        dads.clear();
        string in = "";
        while(in != ";"){
            cin >> in;
            dads.push_back(in);
        }
        dads.pop_back();

        if(add(k, dads)) cout << "ok\n";
        else cout << "greska\n";
    }

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 356 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 356 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 4 ms 616 KB Output is correct
7 Correct 3 ms 368 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 352 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 356 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 4 ms 616 KB Output is correct
7 Correct 3 ms 368 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 352 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 352 KB Output is correct
12 Correct 1 ms 356 KB Output is correct
13 Correct 1 ms 340 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 340 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 352 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 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 342 ms 23648 KB Output is correct
2 Correct 382 ms 26428 KB Output is correct
3 Correct 148 ms 2868 KB Output is correct
4 Correct 3 ms 468 KB Output is correct
5 Correct 4 ms 724 KB Output is correct
6 Correct 10 ms 620 KB Output is correct
7 Correct 18 ms 752 KB Output is correct
8 Correct 26 ms 852 KB Output is correct
9 Correct 27 ms 852 KB Output is correct
10 Correct 8 ms 596 KB Output is correct
11 Correct 7 ms 620 KB Output is correct
12 Correct 323 ms 22772 KB Output is correct