This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
a++;
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 (stderr)
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;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |