답안 #1104749

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1104749 2024-10-24T10:12:45 Z ezzzay 게임판 (CEOI13_board) C++14
40 / 100
200 ms 262144 KB
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
map<vector<int>,int >dist;
string a,b;
vector<int> has (vector<int> v){
    int n=v.size();
   
    for(int i=n-1;i>=0;i--){
        if(v[i]){
            v[i]=0;
            for(int j=i+1;j<n;j++){
                v[j]=1;
            }
           
            break;
        }
    }
    
    return v;
}
vector<int> nem (vector<int> v){
    int n=v.size();
     bool u=1;
    for(int i=n-1;i>=0;i--){
        if(v[i]==0){
            v[i]=1;
            u=0;
            for(int j=i+1;j<n;j++){
                v[j]=0;
            }
            
            break;
        }
    }
    if(u){
        v.clear();
        v.pb(1);
        for(int i=0;i<n;i++){
            v.pb(0);
        }
    }
    return v;
}
int fun(vector<int>a, vector<int>b){
    if(a.size()!=b.size()){
        if(max(a.size(),b.size())>30)return 1e17;
    }
    reverse(a.begin(),a.end());
    reverse(b.begin(),b.end());
    int x=0;
    for(int i=0;i<a.size();i++){
        if(a[i]){
            x+=(1<<i);
        }
    }
    int y=0;
    for(int i=0;i<b.size();i++){
        if(b[i]){
            y+=(1<<i);
        }
    }
    return abs(x-y);
}
signed main(){
    cin>>a;
    vector<int>x={1},y={1};
   
    
    int lvl=1;
    dist[{1}]=1;
    for(auto c:a){
        if(c=='1'){
            x.pb(0);
            lvl++;
        }
        else if(c=='2'){
            x.pb(1);
            lvl++;
        }
        else if(c=='U'){
            x.pop_back();
            lvl--;
        }
        else if(c=='L'){
            x=has(x);
        }
        else{
           
            x=nem(x);
            
        }
        
        
        dist[x]=lvl;
    }
    lvl=1;
    cin>>a;
    for(auto c:a){
        if(c=='1'){
            y.pb(0);
            lvl++;
        }
        else if(c=='2'){
            y.pb(1);
            lvl++;
        }
        else if(c=='U'){
            y.pop_back();
            lvl--;
        }
        else if(c=='L'){
            y=has(y);
        }
        else{
            y=nem(y);
        }
        dist[y]=lvl;
    }
    if(dist[y]>dist[x]){
        swap(y,x);
    }
    int k=0;
    int p=dist[x];
    while(dist[x]>dist[y]){
        x.pop_back();
        dist[x]= --p;
        k++;
    }
    int ans=k+fun(x,y);
    p=dist[x];
    while(p>1){
        x.pop_back();
        y.pop_back();
        p--;
        k+=2;
        // cout<<k+fun(x,y)<<endl;
        ans=min(ans,k+fun(x,y));
    }
    cout<<ans;
}

Compilation message

board.cpp: In function 'long long int fun(std::vector<long long int>, std::vector<long long int>)':
board.cpp:55:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for(int i=0;i<a.size();i++){
      |                 ~^~~~~~~~~
board.cpp:61:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for(int i=0;i<b.size();i++){
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 848 KB Output is correct
2 Correct 5 ms 592 KB Output is correct
3 Correct 23 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 3472 KB Output is correct
2 Correct 140 ms 12680 KB Output is correct
3 Correct 84 ms 5704 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 848 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Incorrect 2 ms 860 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 22384 KB Output is correct
2 Correct 162 ms 34632 KB Output is correct
3 Incorrect 2 ms 1016 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 580 ms 72680 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 603 ms 262144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 610 ms 262144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 650 ms 262144 KB Time limit exceeded
2 Halted 0 ms 0 KB -