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>
using namespace std;
#define REP(i, j, k) for (int i = j; i < k; i++)
#define RREP(i, j, k) for (int i = j; i >= k; i--)
template <class T>
bool inline mnto(T &a, const T b) {return a > b ? a = b, 1 : 0;}
template <class T>
bool inline mxto(T &a, const T b) {return a < b ? a = b, 1 : 0;}
typedef long long ll;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int) x.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef tuple<int, int, int> iii;
#ifndef DEBUG
#define cerr if (0) cerr
#endif
const int MAXN = 100;
const int INF = 1000000005;
const ll LINF = 1000000000000000005;
inline bool isop(char c) {
return c == '[' || c == '<';
}
inline int getno(char c) {
if (c == '[' || c == ']') {
return 1;
} else {
return 2;
}
}
inline vi itov(int m) {
vi res(4, 0);
res[0] = m % MAXN;
m /= MAXN;
res[1] = m % MAXN;
m /= MAXN;
res[2] = m % MAXN;
m /= MAXN;
res[3] = m;
return res;
}
inline int vtoi(vi v) {
int res = 0;
RREP (i, 3, 0) {
res *= MAXN;
res += v[i];
}
return res;
}
int Memory(int n, int m) {
vi cur = itov(m);
if (cur[0] >= n || cur[1] >= n || cur[2] >= n || cur[3] >= 3) {
return -2;
}
char c = Get(cur[1] + 1);
cerr << cur[0] << ' ' << cur[1] << ' ' << cur[2] << ' ' << cur[3] << ' ' << c << '\n';
if (cur[2] == cur[0] && isop(c)) {
if (cur[3] != 0) {
return -2;
}
cur[3] = getno(c);
} else if (cur[2] - 1 == cur[0] && !isop(c)) {
if (cur[3] != getno(c)) {
return -2;
}
cur[3] = 0;
}
cur[2] += isop(c) ? 1 : -1;
if (cur[2] < 0) {
return -2;
}
if (cur[1] < n - 1) {
cur[1]++;
} else {
if (cur[2] != 0) {
return -2;
}
if (cur[0] == n - 1) {
return -1;
}
cur[0]++;
cur[1] = 0;
cur[2] = 0;
cur[3] = 0;
}
assert(cur[0] <= n - 1);
cerr << cur[0] << ' ' << cur[1] << ' ' << cur[2] << ' ' << cur[3] << '\n';
cerr << vtoi(cur) << '\n';
return vtoi(cur);
}
# | 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... |