답안 #573520

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
573520 2022-06-06T18:48:12 Z Hussein3602 Zamjena (COCI18_zamjena) C++14
0 / 70
34 ms 4052 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,a;
    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) ;
        if(var[s]==0)
        {
            var[s]=-1;
        }
    }
    for(ll i=0;i<n;i++)
    {
        string s;
        cin >> s ;
        b.push_back(s) ;
    }
    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;
                }
                else
                {
                    if(mp[b[i]]!=num)
                        ok=false ;
                }
            }
        }
        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
            {
                b[i]=rep[a[i]];
            }
        }
    }
    if(ok)cout<<"DA"<<endl;
    else cout<<"NE"<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Incorrect 3 ms 432 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 2000 KB Output is correct
2 Incorrect 34 ms 4052 KB Output isn't correct
3 Halted 0 ms 0 KB -