답안 #317236

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
317236 2020-10-29T07:31:17 Z Seanliu DEL13 (info1cup18_del13) C++14
15 / 100
500 ms 27520 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int maxN = 20;
int T, N, M, l2[1 << maxN], fromst[1 << maxN], del[1 << maxN];
bool pos[1 << maxN];

void solve(){
	cin >> N >> M;
	vector<int> has, wok;
	has.resize(M);
	fill(pos, pos + (1 << N), false);
	for(int i = 0; i < M; i++){
		cin >> has[i];
		has[i]--;
	}
	pos[(1 << N) - 1] = true;
	for(int i = (1 << N) - 1; i; i--){
		//cout << "i = " << i << endl;
		if(!pos[i]) continue;
		vector<int>().swap(wok);	
		int x = i;
		while(x){
			wok.push_back(l2[(x & -x)]);
			x -= (x & -x);
		}
		//for(int x : wok) cout << x << " ";
		//cout << endl;

		if(wok.size() >= 3){
			for(int j = 1; j < wok.size() - 1; j++){
				pos[i ^ (1 << wok[j - 1]) ^ (1 << wok[j + 1])] = true;
				fromst[i ^ (1 << wok[j - 1]) ^ (1 << wok[j + 1])] = i;
				del[i ^ (1 << wok[j - 1]) ^ (1 << wok[j + 1])] = wok[j];
			}
		}
	}
	int curst = 0;
	for(int x : has) curst ^= (1 << x);
	//cout << "curst = " << curst << endl;
	if(!pos[curst]){
		cout << -1 << endl;
		return;
	}
	vector<int> ans;
	vector<int>().swap(ans);
	while(curst != ((1 << N) - 1)){
		ans.push_back(del[curst]);
		curst = fromst[curst];
	}
	reverse(ans.begin(), ans.end());
	cout << ans.size() << endl;
	for(int x : ans) cout << x + 1 << " ";
	cout << endl;
}

int main(){
	for(int i = 0; i < maxN; i++) l2[1 << i] = i;
	cin >> T;
	while(T--){
		solve();
	}
}

Compilation message

del13.cpp: In function 'void solve()':
del13.cpp:33:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |    for(int j = 1; j < wok.size() - 1; j++){
      |                   ~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Execution timed out 1055 ms 1272 KB Time limit exceeded
4 Execution timed out 1069 ms 1784 KB Time limit exceeded
# 결과 실행 시간 메모리 Grader output
1 Runtime error 32 ms 27392 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Runtime error 32 ms 27520 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Execution timed out 1055 ms 1272 KB Time limit exceeded
4 Execution timed out 1069 ms 1784 KB Time limit exceeded
5 Runtime error 2 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 2 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 42 ms 14200 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 384 KB Output is correct
2 Correct 6 ms 384 KB Output is correct
3 Execution timed out 1055 ms 1272 KB Time limit exceeded
4 Execution timed out 1069 ms 1784 KB Time limit exceeded
5 Runtime error 2 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 2 ms 512 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 42 ms 14200 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 20 ms 17152 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 33 ms 27520 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 2 ms 640 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Runtime error 5 ms 2048 KB Execution killed with signal 11 (could be triggered by violating memory limits)