답안 #199708

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
199708 2020-02-03T00:01:07 Z mdn2002 Klasika (COCI20_klasika) C++14
0 / 110
786 ms 12792 KB
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int n,a[200005],k,trie[1000006][4];
string ans;
string to(int x)
{
    string s;
    while(x)
    {
        s.push_back('0'+(x%2));
        x/=2;
    }
    while(s.size()!=32)s.push_back('0');
    reverse(s.begin(),s.end());
    return s;
}
int too(string s)
{
    int x=0;
    for(int i=0;i<s.size();i++)
    {
        x*=2;
        if(s[i]=='1')x++;
    }
    return x;
}
void ad(string s)
{
    int nod=0;
    for(int i=0;i<s.size();i++)
    {
        int x=s[i]-'0';
        if(trie[nod][x]==0)trie[nod][x]=++k;
        nod=trie[nod][x];
    }
}
void dfs(int x,int nod,string s)
{
    if(s[x]=='0')
    {
        if(trie[nod][1])
        {
            dfs(x+1,trie[nod][1],s);
            ans[x]='1';
        }
        else if(trie[nod][0])
        {
            dfs(x+1,trie[nod][0],s);
        }
    }
    if(s[x]=='1')
    {
        if(trie[nod][0])
        {
            dfs(x+1,trie[nod][0],s);
        }
        else if(trie[nod][1])
        {
            dfs(x+1,trie[nod][1],s);
            ans[x]='0';
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("gpsduel.in","r",stdin);
    //freopen("gpsduel.out","w",stdout);
    cin>>n;
    for(int i=0;i<n;i++)
    {
        string s;
        int x,y;
        cin>>s>>x>>y;
        if(s=="Add")
        {
            a[i+2]=a[x]^y;
            string st=to(a[i+2]);
            ad(st);
        }
        else
        {
            int b=a[x]^a[y];
            ans=to(b);
            dfs(0,0,ans);
            cout<<too(ans)<<endl;
        }
    }
}

Compilation message

klasika.cpp: In function 'int too(std::__cxx11::string)':
klasika.cpp:21:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<s.size();i++)
                 ~^~~~~~~~~
klasika.cpp: In function 'void ad(std::__cxx11::string)':
klasika.cpp:31:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<s.size();i++)
                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 786 ms 12792 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -