Submission #990625

# Submission time Handle Problem Language Result Execution time Memory
990625 2024-05-30T18:14:41 Z alexdd Dijamant (COI16_dijament) C++17
100 / 100
65 ms 644 KB
#include<bits/stdc++.h>
using namespace std;
int n;
unordered_map<string,int> id;
bool cmp(int x, int y)
{
    return x>y;
}
bool visited[1005];
int cnt[1005];
vector<int> con[1005];
void dfs(int nod)
{
    visited[nod]=1;
    for(auto x:con[nod])
        if(!visited[x])
            dfs(x);
}
vector<int> nodes;
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        string nume,aux;
        cin>>nume>>aux;
        bool rau=0;
        if(id[nume]) rau=1;
        vector<int> v;
        while(cin>>aux)
        {
            if(aux==";")
                break;
            if(id[nume])
                continue;
            if(!id[aux] || aux==nume) rau=1;
            v.push_back(id[aux]);
        }
        if(rau)
        {
            cout<<"greska\n";
            continue;
        }
        for(int j=1;j<=n;j++)
        {
            visited[j]=0;
            cnt[j]=0;
        }
        sort(v.begin(),v.end(),cmp);
        for(auto x:v)
        {
            if(!visited[x])
            {
                dfs(x);
                con[i].push_back(x);
            }
        }
        for(auto x:nodes)
            if(visited[x])
                for(auto y:con[x])
                    cnt[y]++;
        for(auto x:nodes)
        {
            if(cnt[x]>=2)
            {
                rau=1;
                break;
            }
        }
        if(rau)
        {
            cout<<"greska\n";
            continue;
        }
        nodes.push_back(i);
        id[nume]=i;
        cout<<"ok\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 600 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 596 KB Output is correct
2 Correct 65 ms 592 KB Output is correct
3 Correct 56 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 5 ms 604 KB Output is correct
8 Correct 8 ms 644 KB Output is correct
9 Correct 9 ms 604 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 52 ms 572 KB Output is correct