Submission #151413

# Submission time Handle Problem Language Result Execution time Memory
151413 2019-09-02T19:04:25 Z phillip Zamjena (COCI18_zamjena) C++14
70 / 70
230 ms 17900 KB
#include <bits/stdc++.h>

using namespace std;
vector<string>s;
map<string,int>name;
int val[100009],vis[100009];
vector<int>v[100009];
void dfs(int x)
{
    if(vis[x])return;
    vis[x]=1;
    for(int i=0;i<v[x].size();i++)
    {
        int y=v[x][i];
        if(val[x]!=val[y]&&val[y]!=-1)
        {
            cout<<"NE";
            exit(0);
        }
        val[y]=val[x];
        dfs(y);
    }
}
int mapit(string s)
{
    if(s.size()<=3)
    {
        int x=0,ml=1;
        for(int i=s.size()-1;i>=0;i--)
        {
            if(s[i]-'0'>9)
            {
                return -1;
            }
            x+=(s[i]-'0')*ml;
            ml*=10;
        }
        return x;
    }
    return -1;
}
int n;
string a1[100090],a2[100009];
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a1[i];
        s.push_back(a1[i]);
    }
    for(int i=0;i<n;i++)
    {
        cin>>a2[i];
        s.push_back(a2[i]);
    }
    int nn;
    for(int i=0,j=0;i<s.size();i++)
    {
        if(name[s[i]])continue;
        name[s[i]]=j;
        val[j]=mapit(s[i]);
        j++;
        nn=j;
    }
    for(int i=0;i<n;i++)
    {
        int x=name[a1[i]],y=name[a2[i]];
        v[x].push_back(y);
        v[y].push_back(x);
    }
    for(int i=0;i<nn;i++)
    {
        if(val[i]==-1)continue;
        dfs(i);
    }
    cout<<"DA";
}

Compilation message

zamjena.cpp: In function 'void dfs(int)':
zamjena.cpp:12:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<v[x].size();i++)
                 ~^~~~~~~~~~~~
zamjena.cpp: In function 'int main()':
zamjena.cpp:58:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0,j=0;i<s.size();i++)
                     ~^~~~~~~~~
zamjena.cpp:57:9: warning: 'nn' may be used uninitialized in this function [-Wmaybe-uninitialized]
     int nn;
         ^~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8952 KB Output is correct
2 Correct 10 ms 8952 KB Output is correct
3 Correct 11 ms 9080 KB Output is correct
4 Correct 9 ms 8952 KB Output is correct
5 Correct 10 ms 8952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8952 KB Output is correct
2 Correct 10 ms 8952 KB Output is correct
3 Correct 10 ms 8956 KB Output is correct
4 Correct 9 ms 8952 KB Output is correct
5 Correct 10 ms 8952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8952 KB Output is correct
2 Correct 9 ms 8952 KB Output is correct
3 Correct 9 ms 8952 KB Output is correct
4 Correct 9 ms 8952 KB Output is correct
5 Correct 9 ms 8928 KB Output is correct
6 Correct 9 ms 8952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 9080 KB Output is correct
2 Correct 11 ms 9052 KB Output is correct
3 Correct 16 ms 9460 KB Output is correct
4 Correct 16 ms 9460 KB Output is correct
5 Correct 17 ms 9468 KB Output is correct
6 Correct 17 ms 9464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 10348 KB Output is correct
2 Correct 62 ms 12004 KB Output is correct
3 Correct 100 ms 13924 KB Output is correct
4 Correct 126 ms 15068 KB Output is correct
5 Correct 230 ms 17900 KB Output is correct
6 Correct 142 ms 15304 KB Output is correct