Submission #223216

# Submission time Handle Problem Language Result Execution time Memory
223216 2020-04-15T05:24:21 Z spacewalker Remittance (JOI19_remittance) C++14
15 / 100
14 ms 5376 KB
#include <bits/stdc++.h>

using namespace std;

int encode(vector<int> &pos) {
	int ans = 0;
	for (int i = (int)pos.size() - 1; i >= 0; --i) ans = ans * 8 + pos[i];
	return 8 * ans + pos.size();
}

vector<int> decode(int encoded) {
	vector<int> ans(encoded % 8);
	encoded /= 8;
	for (int i = 0; i < ans.size(); ++i) {
		ans[i] = encoded % 8;
		encoded /= 8;
	}
	return ans;
}

vector<int> nextStates(int curState) {
	vector<int> status = decode(curState);
	int n = status.size();
	vector<int> ans;
	for (int i = 0; i < status.size(); ++i) {
		if (status[i] >= 2) {
			status[i] -= 2; status[(i + 1) % n]++;
			ans.push_back(encode(status));
			status[i] += 2; status[(i + 1) % n]--;
		}
	}
	return ans;
}

int main() {
	int n; scanf("%d", &n);
	vector<int> before(n), after(n);
	for (int i = 0; i < n; ++i) scanf("%d %d", &before[i], &after[i]);
	vector<bool> visited(20000000);
	int start = encode(before);
	int end = encode(after);
	visited[start] = true;
	queue<int> q;
	q.push(start);
	while (!q.empty()) {
		int cur = q.front(); q.pop();
//		printf("state reached:\n");
//		vector<int> cslist = decode(cur);
//		for (int x : cslist) printf("%d ", x);
//		printf("\n");
		vector<int> pnext = nextStates(cur);
		for (int x : pnext) {
			if (!visited[x]) {
				visited[x] = true;
				q.push(x);
			}
		}
	}
	if (visited[end]) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Compilation message

remittance.cpp: In function 'std::vector<int> decode(int)':
remittance.cpp:14:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < ans.size(); ++i) {
                  ~~^~~~~~~~~~~~
remittance.cpp: In function 'std::vector<int> nextStates(int)':
remittance.cpp:25:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < status.size(); ++i) {
                  ~~^~~~~~~~~~~~~~~
remittance.cpp: In function 'int main()':
remittance.cpp:36:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int n; scanf("%d", &n);
         ~~~~~^~~~~~~~~~
remittance.cpp:38:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 0; i < n; ++i) scanf("%d %d", &before[i], &after[i]);
                              ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2816 KB Output is correct
2 Correct 6 ms 2816 KB Output is correct
3 Correct 6 ms 2816 KB Output is correct
4 Correct 6 ms 2816 KB Output is correct
5 Correct 6 ms 2816 KB Output is correct
6 Correct 6 ms 2816 KB Output is correct
7 Correct 7 ms 2816 KB Output is correct
8 Correct 7 ms 2816 KB Output is correct
9 Correct 7 ms 2816 KB Output is correct
10 Correct 6 ms 2816 KB Output is correct
11 Correct 6 ms 2816 KB Output is correct
12 Correct 7 ms 2816 KB Output is correct
13 Correct 7 ms 2804 KB Output is correct
14 Correct 7 ms 2816 KB Output is correct
15 Correct 6 ms 2688 KB Output is correct
16 Correct 6 ms 2816 KB Output is correct
17 Correct 7 ms 2816 KB Output is correct
18 Correct 6 ms 2816 KB Output is correct
19 Correct 6 ms 2816 KB Output is correct
20 Correct 6 ms 2816 KB Output is correct
21 Correct 6 ms 2816 KB Output is correct
22 Correct 6 ms 2816 KB Output is correct
23 Correct 6 ms 2816 KB Output is correct
24 Correct 7 ms 2816 KB Output is correct
25 Correct 7 ms 2816 KB Output is correct
26 Correct 7 ms 2792 KB Output is correct
27 Correct 6 ms 2816 KB Output is correct
28 Correct 6 ms 2816 KB Output is correct
29 Correct 12 ms 2816 KB Output is correct
30 Correct 11 ms 2816 KB Output is correct
31 Correct 11 ms 2816 KB Output is correct
32 Correct 14 ms 2816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2816 KB Output is correct
2 Correct 6 ms 2816 KB Output is correct
3 Correct 6 ms 2816 KB Output is correct
4 Correct 6 ms 2816 KB Output is correct
5 Correct 6 ms 2816 KB Output is correct
6 Correct 6 ms 2816 KB Output is correct
7 Correct 7 ms 2816 KB Output is correct
8 Correct 7 ms 2816 KB Output is correct
9 Correct 7 ms 2816 KB Output is correct
10 Correct 6 ms 2816 KB Output is correct
11 Correct 6 ms 2816 KB Output is correct
12 Correct 7 ms 2816 KB Output is correct
13 Correct 7 ms 2804 KB Output is correct
14 Correct 7 ms 2816 KB Output is correct
15 Correct 6 ms 2688 KB Output is correct
16 Correct 6 ms 2816 KB Output is correct
17 Correct 7 ms 2816 KB Output is correct
18 Correct 6 ms 2816 KB Output is correct
19 Correct 6 ms 2816 KB Output is correct
20 Correct 6 ms 2816 KB Output is correct
21 Correct 6 ms 2816 KB Output is correct
22 Correct 6 ms 2816 KB Output is correct
23 Correct 6 ms 2816 KB Output is correct
24 Correct 7 ms 2816 KB Output is correct
25 Correct 7 ms 2816 KB Output is correct
26 Correct 7 ms 2792 KB Output is correct
27 Correct 6 ms 2816 KB Output is correct
28 Correct 6 ms 2816 KB Output is correct
29 Correct 12 ms 2816 KB Output is correct
30 Correct 11 ms 2816 KB Output is correct
31 Correct 11 ms 2816 KB Output is correct
32 Correct 14 ms 2816 KB Output is correct
33 Runtime error 11 ms 5376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 2816 KB Output is correct
2 Correct 6 ms 2816 KB Output is correct
3 Correct 6 ms 2816 KB Output is correct
4 Correct 6 ms 2816 KB Output is correct
5 Correct 6 ms 2816 KB Output is correct
6 Correct 6 ms 2816 KB Output is correct
7 Correct 7 ms 2816 KB Output is correct
8 Correct 7 ms 2816 KB Output is correct
9 Correct 7 ms 2816 KB Output is correct
10 Correct 6 ms 2816 KB Output is correct
11 Correct 6 ms 2816 KB Output is correct
12 Correct 7 ms 2816 KB Output is correct
13 Correct 7 ms 2804 KB Output is correct
14 Correct 7 ms 2816 KB Output is correct
15 Correct 6 ms 2688 KB Output is correct
16 Correct 6 ms 2816 KB Output is correct
17 Correct 7 ms 2816 KB Output is correct
18 Correct 6 ms 2816 KB Output is correct
19 Correct 6 ms 2816 KB Output is correct
20 Correct 6 ms 2816 KB Output is correct
21 Correct 6 ms 2816 KB Output is correct
22 Correct 6 ms 2816 KB Output is correct
23 Correct 6 ms 2816 KB Output is correct
24 Correct 7 ms 2816 KB Output is correct
25 Correct 7 ms 2816 KB Output is correct
26 Correct 7 ms 2792 KB Output is correct
27 Correct 6 ms 2816 KB Output is correct
28 Correct 6 ms 2816 KB Output is correct
29 Correct 12 ms 2816 KB Output is correct
30 Correct 11 ms 2816 KB Output is correct
31 Correct 11 ms 2816 KB Output is correct
32 Correct 14 ms 2816 KB Output is correct
33 Runtime error 11 ms 5376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
34 Halted 0 ms 0 KB -