#include "Memory_lib.h"
#include<bits/stdc++.h>
using namespace std;
int Memory(int N, int M);
#define MAX_N 100
#define FORMAT_S "%101s"
#define LENGTH_S 102
#define LIMIT_M 2000 // 2^22
#define MAX_NUM_DAYS 15000
int n, m, s1, s2, s4, s3, sf, k, s5, s6, mx, s7, s8, s9, mx2, res, dem2 = 0, dem = 0, s33, dem3, dem4, mid, l2, r2, center;
int i, s10, s12,k1,k2,k3,s11,lim,w,l,r,dem5,dem6,dem7,dem9;
int kk;
int t;
int el = 19;/*
static int N, Q;
static char S[LENGTH_S];
static void Wrong(int message)
{
printf("Wrong Answer [%d]\n", message);
exit(0);
}
static int c_index;
static int get_called;
static int get_I;
char Get(int I)
{
/// cout<<I<<"\n";
if (get_called)
{
Wrong(2);
}
get_called = 1;
get_I = I;
if (!(1 <= I && I <= N))
{
Wrong(3);
}
return "<>[]"[c_index];
}*/
int f(int x,int y,int z,int c)
{
return ((x*(n+2)+y)*(n+2)+z)*(n+2)+c;
}
int Memory(int N,int M)
{
n=N;
m=M;
if(n%2==1) return -2;
if(m==0)
{
return f(0,0,1,1);
}
int kk=m;
int pos=m%(n+2);
m/=(n+2);
int id=m%(n+2);
m/=(n+2);
int val=m%(n+2);
m/=(n+2);
int col=m%(n+2);
if(id==0||pos==0) return 0;
if(pos==n+1) return -1;
if(col==0)
{
char x=Get(pos);
if(x=='<'||x=='[')val++;
else val--;
if(val<0)return -2;
if(val>n/2)return -2;
if(pos==n)
{
if(val==0)return f(1,0,1,1);
return -2;
}
return f(0,val,pos+1,pos+1);
}
else
{
if(id<pos)
{
char x=Get(id);
if(x=='<'||x=='[')val--;
else val++;
if(val==0)
{
if(x=='<'&&col==1)return f(1,0,pos+1,pos+1);
if(x=='['&&col==2)return f(1,0,pos+1,pos+1);
return -2;
}
return f(col,val,id-1,pos);
}
else if(id==pos)
{
char x=Get(pos);
if(x=='<'||x=='[') return f(1,0,pos+1,pos+1);
if(x=='>')return f(1,1,pos-1,pos);
return f(2,1,pos-1,pos);
}
}
}/*
static int contestant_i[LIMIT_M];
static int contestant_m[LIMIT_M][4];
int main(void)
{
freopen("test.inp","r",stdin);
freopen("test.out","w",stdout);
int M;
int test_index;
int num_days;
int result;
if (scanf("%d%d", &N, &Q) != 2)
{
fprintf(stderr, "error: cannot read N, Q\n");
exit(1);
}
if (!(1 <= N && N <= MAX_N))
{
fprintf(stderr, "error: N is out of bounds\n");
exit(1);
}
if (Q < 0)
{
fprintf(stderr, "error: Q is out of bounds\n");
exit(1);
}
for (M = 0; M < LIMIT_M; ++M)
{
for (c_index = 0; c_index < 4; ++c_index)
{
get_called = 0;
get_I = 0;
result = Memory(N, M);
if (!((0 <= result && result < LIMIT_M) ||
result == -1 || result == -2))
{
Wrong(1);
}
if (c_index == 0)
{
contestant_i[M] = get_I;
}
else
{
if (contestant_i[M] != get_I)
{
Wrong(4);
}
if (contestant_i[M] == 0)
{
if (contestant_m[M][0] != result)
{
Wrong(4);
}
}
}
contestant_m[M][c_index] = result;
}
if (contestant_i[M] == 0)
{
contestant_i[M] = 1;
}
}
for (test_index = 0; test_index < Q; ++test_index)
{
if (scanf(FORMAT_S, S) != 1)
{
fprintf(stderr, "error: cannot read S\n");
exit(1);
}
if (N != (int)strlen(S))
{
fprintf(stderr, "error: the length of S is not N\n");
exit(1);
}
num_days = 0;
M = 0;
for (; ; )
{
switch (S[contestant_i[M] - 1])
{
case '<':
c_index = 0;
break;
case '>':
c_index = 1;
break;
case '[':
c_index = 2;
break;
case ']':
c_index = 3;
break;
default:
fprintf(stderr, "error: S contains an invalid character\n");
exit(1);
}
M = contestant_m[M][c_index];
cout<<M<<"\n";
if (M == -1 || M == -2)
{
break;
}
if (++num_days >= MAX_NUM_DAYS)
{
Wrong(5);
}
}
printf("%d\n", M);
}
return 0;
}
*/
Compilation message (stderr)
memory.cpp: In function 'int Memory(int, int)':
memory.cpp:104:1: warning: control reaches end of non-void function [-Wreturn-type]
104 | }/*
| ^
# | 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... |