Submission #555930

# Submission time Handle Problem Language Result Execution time Memory
555930 2022-05-01T20:12:54 Z rainboy None (JOI15_memory) C
100 / 100
2237 ms 284100 KB
#include "Memory_lib.h"

#define N	101

int min(int a, int b) { return a < b ? a : b; }

int code(char c) {
	if (c == '<')
		return 0;
	if (c == '>')
		return 1;
	if (c == '[')
		return 2;
	return 3;
}

int Memory(int n, int x) {
	int i, c, c_, d_, d, a, a_;

	if (x == 0)
		return ((0 * N + 0) * N + 0) * 4 + 1;
	c_ = x / 4 / N / N, i = x / 4 / N % N, d_ = x / 4 % N, a_ = x % 4;
	if (c_ >= N || i >= n)
		return -2;
	a = code(Get(i + 1)), d = d_ + ((a & 1) == 0 ? 1 : -1);
	if (d < 0)
		return -2;
	c = min(d_, d), d_ = d;
	if (c == c_) {
		if ((a_ & 1) != 0 && (a & 1) != 0 || (a_ & 1) == 0 && (a ^ a_) != 1)
			return -2;
		a_ = a;
	}
	if (i + 1 < n)
		return ((c_ * N + (i + 1)) * N + d_) * 4 + a_;
	else {
		if (d != 0 || (a_ & 1) == 0)
			return -2;
		if (c_ + 1 == N)
			return -1;
		return (((c_ + 1) * N + 0) * N + 0) * 4 + 1;
	}
}

Compilation message

memory.c: In function 'Memory':
memory.c:30:21: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   30 |   if ((a_ & 1) != 0 && (a & 1) != 0 || (a_ & 1) == 0 && (a ^ a_) != 1)
      |       ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2237 ms 284076 KB Output is correct
2 Correct 1992 ms 284100 KB Output is correct
3 Correct 1953 ms 283948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2237 ms 284076 KB Output is correct
2 Correct 1992 ms 284100 KB Output is correct
3 Correct 1953 ms 283948 KB Output is correct
4 Correct 2029 ms 284048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2237 ms 284076 KB Output is correct
2 Correct 1992 ms 284100 KB Output is correct
3 Correct 1953 ms 283948 KB Output is correct
4 Correct 2029 ms 284048 KB Output is correct
5 Correct 2083 ms 283976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2237 ms 284076 KB Output is correct
2 Correct 1992 ms 284100 KB Output is correct
3 Correct 1953 ms 283948 KB Output is correct
4 Correct 2029 ms 284048 KB Output is correct
5 Correct 2083 ms 283976 KB Output is correct
6 Correct 1967 ms 284004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2032 ms 283968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2237 ms 284076 KB Output is correct
2 Correct 1992 ms 284100 KB Output is correct
3 Correct 1953 ms 283948 KB Output is correct
4 Correct 2029 ms 284048 KB Output is correct
5 Correct 2083 ms 283976 KB Output is correct
6 Correct 1967 ms 284004 KB Output is correct
7 Correct 2032 ms 283968 KB Output is correct
8 Correct 2045 ms 283948 KB Output is correct
9 Correct 2088 ms 283992 KB Output is correct