답안 #1037156

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1037156 2024-07-28T09:25:55 Z beaconmc 기억 압축 (JOI15_memory) C++14
0 / 100
1657 ms 284176 KB
#include "Memory_lib.h"
#include <bits/stdc++.h>
 
typedef int ll;
#define FOR(i,x,y) for(ll i=x; i<y; i++)
#define FORNEG(i,x,y) for(ll i=x; i>y; i--)
 
using namespace std;

int encode(int a, int b, int c, int d, int e){
    return a + b*(1<<7) + c*(1<<14) + d*(1<<20) + e*(1<<21);
}
vector<int> decode(int k){
    ll a,b,c,d,e;
    a = k%(1<<7);
    b = (k>>7)%(1<<7);
    c = (k>>14)%(1<<6);
    d = (k>>20)%(1<<1);
    e = (k>>21);
    return {a,b,c,d,e};
}


int Memory(int N, int M) {
    vector<int> sus = decode(M);
    ll a,b,c,d,e;
    ll A,B,C,D,E;
    a = sus[0];b=sus[1];c=sus[2];d=sus[3],e=sus[4];
    if (c>60) return -2;
    //cout << a << " " << b << " " << c << " " << d << " " << e << endl;
    if (e==0){
        if (a==N){
            if (b!=c) return -2;
            else return encode(0,0,0,0,1);
        }
        else{
            if (!(1<= a+1 && a+1<= N)) return -2;
            char temp = Get(a+1);
            c++;
            if (temp == '<' || temp == '[') b++;
            else c++;
        }

        return encode(a,b,c,d,e);
    }else{
        if (a==b){
            if (b+1 > N){
                if (d==1) return -1;
                return -2;
            }
            if (!(1<= b+1 && b+1<= N)) return -2;
            char temp = Get(b+1);
            if (temp == '>'){
                d = 0;
                b += 1;
            }else if (temp == ']'){
                d = 1;
                b += 1;
            }else{
                a = b+1;
                b = b+1;
                d = 0;
            }
        }else{
            if (!(1<= a && a<= N)) return -2;
            char temp = Get(a);
            if (temp == ']' || temp == '>'){
                c += 1;
                a-=1;
            }
            else{
                if (c==0){
                    if (temp == '<' && d==0){
                        a = b;
                        b = b;
                        d = 1;
                    }
                    else if (temp == '[' && d==1){
                        a = b;
                        b = b;
                        d = 1;
                    }
                    else return -2;
                }else{
                    c-=1;
                    a-=1;
                }
            }
        }
        
        if (a<=0) return -2;
        if (a==b && a==N+1) return -1;

        if (!(1<=encode(a,b,c,d,e) && encode(a,b,c,d,e) <= (1<<22))){
            cout << a << " " << b << " " << c << " " << d << " " << e << endl;
            cout << A << " "<<B<<" "<<C<<" "<<D<<" "<<E<<endl;
        }
        return encode(a,b,c,d,e);
    }
}

Compilation message

memory.cpp: In function 'int Memory(int, int)':
memory.cpp:96:26: warning: 'A' may be used uninitialized in this function [-Wmaybe-uninitialized]
   96 |             cout << A << " "<<B<<" "<<C<<" "<<D<<" "<<E<<endl;
      |                          ^~~
memory.cpp:96:34: warning: 'B' may be used uninitialized in this function [-Wmaybe-uninitialized]
   96 |             cout << A << " "<<B<<" "<<C<<" "<<D<<" "<<E<<endl;
      |                                  ^~~
memory.cpp:96:42: warning: 'C' may be used uninitialized in this function [-Wmaybe-uninitialized]
   96 |             cout << A << " "<<B<<" "<<C<<" "<<D<<" "<<E<<endl;
      |                                          ^~~
memory.cpp:96:50: warning: 'D' may be used uninitialized in this function [-Wmaybe-uninitialized]
   96 |             cout << A << " "<<B<<" "<<C<<" "<<D<<" "<<E<<endl;
      |                                                  ^~~
memory.cpp:96:55: warning: 'E' may be used uninitialized in this function [-Wmaybe-uninitialized]
   96 |             cout << A << " "<<B<<" "<<C<<" "<<D<<" "<<E<<endl;
      |                                                       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1562 ms 283984 KB Output is correct
2 Incorrect 1517 ms 284176 KB Wrong Answer [6]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1562 ms 283984 KB Output is correct
2 Incorrect 1517 ms 284176 KB Wrong Answer [6]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1562 ms 283984 KB Output is correct
2 Incorrect 1517 ms 284176 KB Wrong Answer [6]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1562 ms 283984 KB Output is correct
2 Incorrect 1517 ms 284176 KB Wrong Answer [6]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1657 ms 284012 KB Wrong Answer [6]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1562 ms 283984 KB Output is correct
2 Incorrect 1517 ms 284176 KB Wrong Answer [6]
3 Halted 0 ms 0 KB -