답안 #1037142

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1037142 2024-07-28T08:47:58 Z beaconmc 기억 압축 (JOI15_memory) C++14
0 / 100
0 ms 348 KB
#include "Memory_lib.h"
#include <bits/stdc++.h>
 
typedef long long 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){
    return a + b*(1<<7) + c*(1<<14) + d*(1<<21);
}
vector<int> decode(int k){
    ll a,b,c,d;
    a = k%(1<<7);
    b = (k>>7)%(1<<7);
    c = (k>>14)%(1<<7);
    d = (k>>21);
    return {a,b,c,d};
}


int Memory(int N, int M) {
    vector<int> sus = decode(M);
    ll a,b,c,d;

    a = sus[0];b=sus[1];c=sus[2];d=sus[3];
    //cout << a << " " << b << " " << c << " " << d << endl;

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

Compilation message

memory.cpp: In function 'std::vector<int> decode(int)':
memory.cpp:19:13: warning: narrowing conversion of 'a' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   19 |     return {a,b,c,d};
      |             ^
memory.cpp:19:13: warning: narrowing conversion of 'a' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
memory.cpp:19:15: warning: narrowing conversion of 'b' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   19 |     return {a,b,c,d};
      |               ^
memory.cpp:19:15: warning: narrowing conversion of 'b' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
memory.cpp:19:17: warning: narrowing conversion of 'c' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   19 |     return {a,b,c,d};
      |                 ^
memory.cpp:19:17: warning: narrowing conversion of 'c' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
memory.cpp:19:19: warning: narrowing conversion of 'd' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
   19 |     return {a,b,c,d};
      |                   ^
memory.cpp:19:19: warning: narrowing conversion of 'd' from 'll' {aka 'long long int'} to 'int' [-Wnarrowing]
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Wrong Answer [3]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Wrong Answer [3]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Wrong Answer [3]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Wrong Answer [3]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Wrong Answer [3]
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Wrong Answer [3]
2 Halted 0 ms 0 KB -