#include "Memory_lib.h"
int concat(int l,int r,int op,int mode) {
return mode + (op << 2) + (r << 8) + (l << 15);
}
int Memory(int N, int M) {
if (N & 1) return -2;
int sq6 = 64;
int sq7 = 128;
int mode = M & 3; M >>= 2;
int op = M & (sq6 - 1); M >>= 6;
int r = M & (sq7 - 1); // i
int l = M >> 7; //j
//printf("%d,%d,%d,%d\n",l,r,op,mode);
if (r == N)
return op ? -2 : -1;
if (l >= N) return -2;
char c = Get(l + 1);
if (l == r) {
++l;
if (c == ']' || c == '>') {
if (--op < 0) return -2;
return concat(l,++r,op,mode);
}
else {
mode = (c == '[') + 1;
op = 1;
return concat(l, r, op, mode);
}
}
else {
switch (c) {
case '<':case '[':
++op;
break;
case '>':
--op;
if (op < 0) return -2;
if (l > r && op == 0) {
if (mode != 1) return -2;
return concat(0, ++r, op, 0);
}
break;
case ']':
--op;
if (op < 0) return -2;
if (l > r && op == 0) {
if (mode != 2) return -2;
return concat(0, ++r, op, 0);
}
break;
}
++l;
}
//op>50 chk
if (op > (N >> 1)) return -2;
return concat(l,r,op,mode);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2043 ms |
276612 KB |
Output is correct |
2 |
Correct |
1998 ms |
276752 KB |
Output is correct |
3 |
Correct |
1989 ms |
276776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2043 ms |
276612 KB |
Output is correct |
2 |
Correct |
1998 ms |
276752 KB |
Output is correct |
3 |
Correct |
1989 ms |
276776 KB |
Output is correct |
4 |
Correct |
2029 ms |
276548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2043 ms |
276612 KB |
Output is correct |
2 |
Correct |
1998 ms |
276752 KB |
Output is correct |
3 |
Correct |
1989 ms |
276776 KB |
Output is correct |
4 |
Correct |
2029 ms |
276548 KB |
Output is correct |
5 |
Correct |
2114 ms |
276888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2043 ms |
276612 KB |
Output is correct |
2 |
Correct |
1998 ms |
276752 KB |
Output is correct |
3 |
Correct |
1989 ms |
276776 KB |
Output is correct |
4 |
Correct |
2029 ms |
276548 KB |
Output is correct |
5 |
Correct |
2114 ms |
276888 KB |
Output is correct |
6 |
Correct |
2062 ms |
276964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2235 ms |
276720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2043 ms |
276612 KB |
Output is correct |
2 |
Correct |
1998 ms |
276752 KB |
Output is correct |
3 |
Correct |
1989 ms |
276776 KB |
Output is correct |
4 |
Correct |
2029 ms |
276548 KB |
Output is correct |
5 |
Correct |
2114 ms |
276888 KB |
Output is correct |
6 |
Correct |
2062 ms |
276964 KB |
Output is correct |
7 |
Correct |
2235 ms |
276720 KB |
Output is correct |
8 |
Correct |
1966 ms |
276616 KB |
Output is correct |
9 |
Correct |
2150 ms |
276568 KB |
Output is correct |