Submission #573560

# Submission time Handle Problem Language Result Execution time Memory
573560 2022-06-06T19:57:10 Z Hussein3602 Zamjena (COCI18_zamjena) C++14
42 / 70
1000 ms 6348 KB
#include<bits/stdc++.h>
#include<sstream>
using namespace std ;
typedef long long ll ;
int main()
{
    ll n ;
    bool ok=true;
    map<string,ll>var,mp;
    map<string,string>rep ;
    vector<string>b,b1,a,a1;
    cin >> n ;
    for(ll i=1;i<=1000;i++)
    {
        ostringstream s;
        s<<i;
        string s1=s.str();
        var[s1]++;
    }
    for(ll i=0;i<n;i++)
    {
        string s;
        cin >> s ;
        a.push_back(s) ;
        a1.push_back(s) ;
        rep[s]=s;
    }
    for(ll i=0;i<n;i++)
    {
        string s;
        cin >> s ;
        b.push_back(s) ;
        b1.push_back(s) ;
        rep[s]=s;
    }
    for(ll h=0;h<70;h++)
    {
        for(ll i=0;i<n;i++)
    {
        if(var[a[i]]>0)
        {
            if(var[b[i]]>0)
            {
                // to be a[i] and b[i] is integer
                if(a[i]!=b[i])
                    ok=false ;
            }
            else
            {
                // to be a[i] is an integer and b[i] is a variable
                b[i]=rep[b[i]] ;// if there is a variable that must be equal to him
                ll num=0,pw=1;
                for(ll j=a[i].size()-1;j>=0;j--)
                {
                    num+=int(a[i][j]-'0')*pw;
                    pw*=10;
                }
                if(mp[b[i]]==0)
                {
                    mp[b[i]]=num;
                    //cout<<num<<endl;
                }
                else
                {
                    if(mp[b[i]]!=num)
                        ok=false ;
                    //cout<<num<<" "<<mp[b[i]]<<endl;
                }
            }
        }
        else
        {
            if(var[b[i]]>0)
            {
                a[i]=rep[a[i]] ;
                ll num=0,pw=1;
                for(ll j=b[i].size()-1;j>=0;j--)
                {
                    num+=int(b[i][j]-'0')*pw;
                    pw*=10;
                }
                if(mp[a[i]]==0)
                {
                    mp[a[i]]=num;
                }
                else
                {
                    if(mp[a[i]]!=num)
                        ok=false ;
                }
            }
            else //both of them are variable
            {
                string s1=a[i],s2=b[i];
                b[i]=rep[b[i]] ;
                a[i]=rep[a[i]] ;
                if(mp[a[i]]==0&&mp[b[i]]!=0)
                    {
                        rep[a[i]]=b[i] ;
                        rep[s1]=b[i];
                    }
                else if(mp[b[i]]==0&&mp[a[i]]!=0)
                    {
                        rep[b[i]]=a[i] ;
                        rep[s2]=a[i] ;
                    }
                else if(mp[b[i]]==0&&mp[a[i]]==0)
                    {
                        rep[b[i]]=a[i] ;
                        rep[s2]=a[i] ;
                    }
                else if(mp[b[i]]!=mp[a[i]])ok=false;

            }
        }
    }
    }
    /*for(ll i=0;i<n;i++)
    {
        if(var[a1[i]]==0)
        {
            cout<<rep[a1[i]]<<" ";
        }
        else  cout<<a1[i]<<" ";
    }
    cout<<endl;
    for(ll i=0;i<n;i++)
    {
        if(var[b1[i]]==0)
        {
            cout<<rep[b1[i]]<<" ";
        }
        else  cout<<b1[i]<<" ";
    }
    */
    if(ok)cout<<"DA"<<endl;
    else cout<<"NE"<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 340 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 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
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Incorrect 2 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 39 ms 596 KB Output is correct
2 Correct 65 ms 624 KB Output is correct
3 Correct 252 ms 1328 KB Output is correct
4 Correct 201 ms 1500 KB Output is correct
5 Correct 262 ms 1436 KB Output is correct
6 Correct 268 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 636 ms 3200 KB Output is correct
2 Execution timed out 1048 ms 6348 KB Time limit exceeded
3 Halted 0 ms 0 KB -