Submission #81708

# Submission time Handle Problem Language Result Execution time Memory
81708 2018-10-26T09:19:07 Z Mouhanad_Hafez Zamjena (COCI18_zamjena) C++11
14 / 70
27 ms 2964 KB
#include<bits/stdc++.h>
using namespace std;
bool ch(string s)
{
    for (int i=0; i<s.size(); i++)
    {
        if (s[i]-'a'>=0&&s[i]-'a'<=25)return 0;
    }
    return 1;
}
int toint(string s)
{
    int re=0;
    int p=1;
    for (int i=s.size()-1; i>=0; i--)
    {
        re+=((s[i]-'0')*p);
        p*=10;
    }
    return re;
}
map<string,int>mp,mp1;
vector<pair<string,string>>v;
int main()
{
    int n;
    cin>>n;
    string arr1[n+6],arr2[n+6];
    for (int i=0; i<n; i++)cin>>arr1[i];

    for (int i=0; i<n; i++)cin>>arr2[i];

    for (int i=0; i<n; i++)
    {
        string s1,s2;
        s1=arr1[i];
        s2=arr2[i];
        if (ch(s1)==1&&ch(s2)==1&&s1!=s2)
        {
            cout<<"NE";
            return 0;
        }
        if (s1==s2)continue;
        if (ch(s1)==0&&ch(s2)==0)
        {
            int x1=mp[s1],x2=mp[s2];
            int y1=mp1[s1],y2=mp1[s2];
            //if (x1==x2)continue;
            if (x1!=x2&&y1==1&&y2==1)
            {
                cout<<"NE";
                return 0;
            }
            if (x1!=x2&&y1==0&&y2==1)
            {
                mp[s1]=mp[s2];
                mp1[s1]=1;
                mp1[s2]=1;
                continue;
            }
            if (x1!=x2&&y1==1&&y2==0)
            {
                mp[s2]=mp[s1];
                mp1[s1]=1;
                mp1[s2]=1;
                continue;
            }
            if (y1==0&&y2==0)
            {
                v.push_back({s1,s2});
                continue;
            }
        }
        if (ch(s1)==1&&ch(s2)==0)
        {
            if (mp1[s2]==1)
            {
                cout<<"NE";
                return 0;
            }
            mp[s2]=toint(s1);
            mp1[s2]=1;
        }
        if (ch(s1)==0&&ch(s2)==1)
        {
            if (mp1[s1]==1)
            {
                cout<<"NE";
                return 0;
            }
            mp[s1]=toint(s2);
            mp1[s1]=1;
        }
    }
    for (int i=0; i<v.size(); i++)
    {
        if (mp[v[i].first]!=mp[v[i].second])
        {
            cout<<"NE";
            return 0;
        }
    }
    cout<<"DA";
    return 0;
}

Compilation message

zamjena.cpp: In function 'bool ch(std::__cxx11::string)':
zamjena.cpp:5:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0; i<s.size(); i++)
                   ~^~~~~~~~~
zamjena.cpp: In function 'int main()':
zamjena.cpp:95:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0; i<v.size(); i++)
                   ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 480 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 2964 KB Output is correct
2 Incorrect 13 ms 2964 KB Output isn't correct
3 Halted 0 ms 0 KB -