Submission #312674

# Submission time Handle Problem Language Result Execution time Memory
312674 2020-10-14T03:37:43 Z colazcy Slagalica (COCI19_slagalica2) C++17
20 / 70
1000 ms 11256 KB
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn = 1e5 + 100;
inline int read(){
	int x = 0;char c = getchar();
	while(!isdigit(c))c = getchar();
	while(isdigit(c))x = x * 10 + c - '0',c = getchar();
	return x;
}
vector<int> G[16],vec[16];
int n,beg,end,cnt[16],pos[16],nxt[maxn][4];
inline int get(int x){
	return pos[x] == vec[x].size() ? 0x7fffffff : vec[x][pos[x]];
}
inline void msort(int id){
	if(get(nxt[id][1]) < get(nxt[id][0]))swap(nxt[id][1],nxt[id][0]);
	if(get(nxt[id][2]) < get(nxt[id][0]))swap(nxt[id][2],nxt[id][0]);
	if(get(nxt[id][2]) < get(nxt[id][1]))swap(nxt[id][1],nxt[id][2]);
} 
inline void add(int u,int v){G[u].push_back(v);}
inline void init(){
	add(1,3);add(1,4);add(1,8);
	add(2,1);add(2,2);add(2,7);
	add(3,3);add(3,4);add(3,8);
	add(4,1);add(4,2);add(4,7);
	add(5,3);add(5,4);add(5,8);
	add(6,1);add(6,2);add(6,7);
}
int ans[maxn];
inline void dfs(int step,int lst){
	if(step == n){
		for(int i = 1;i <= n;i++)printf("%d ",ans[i]);
		puts("");
		exit(0);
	}
	for(int i = 0;i < G[lst].size();i++)nxt[step][i] = G[lst][i]; 
	msort(step);
	for(int i = 0;i < G[lst].size();i++){
		int v = nxt[step][i];
		if(!cnt[v])continue;
		ans[step + 1] = vec[v][pos[v]];
		pos[v]++;
		cnt[v]--;
		dfs(step + 1,v);
		pos[v]--;
		cnt[v]++;
	}
}
int main(){
//	freopen("slagalica.in","r",stdin);
//	freopen("slagalica.out","w",stdout);
	n = read();
	for(int x,i = 1;i <= n;i++){
		int a = read(),b = read();
		cnt[a]++;
		vec[a].push_back(b); 
	}
	for(int i = 1;i <= 8;i++)sort(vec[i].begin(),vec[i].end());
	init();
	if(cnt[5])ans[1] = vec[5][0],dfs(1,5);
	else if(cnt[6])ans[1] = vec[6][0],dfs(1,6);
	puts("-1");
	fclose(stdin);
	fclose(stdout);
	return 0;
}
 

Compilation message

slagalica.cpp: In function 'int get(int)':
slagalica.cpp:16:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |  return pos[x] == vec[x].size() ? 0x7fffffff : vec[x][pos[x]];
      |         ~~~~~~~^~~~~~~~~~~~~~~~
slagalica.cpp: In function 'void dfs(int, int)':
slagalica.cpp:39:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |  for(int i = 0;i < G[lst].size();i++)nxt[step][i] = G[lst][i];
      |                ~~^~~~~~~~~~~~~~~
slagalica.cpp:41:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |  for(int i = 0;i < G[lst].size();i++){
      |                ~~^~~~~~~~~~~~~~~
slagalica.cpp: In function 'int main()':
slagalica.cpp:56:10: warning: unused variable 'x' [-Wunused-variable]
   56 |  for(int x,i = 1;i <= n;i++){
      |          ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 9888 KB Output is correct
2 Correct 29 ms 9660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 9524 KB Output is correct
2 Correct 27 ms 9076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 6132 KB Output is correct
2 Execution timed out 1096 ms 8812 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 24 ms 5260 KB Output is correct
2 Correct 36 ms 9328 KB Output is correct
3 Execution timed out 1084 ms 7964 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1098 ms 6004 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 36 ms 9456 KB Output is correct
2 Correct 25 ms 5748 KB Output is correct
3 Execution timed out 1093 ms 8052 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Execution timed out 1091 ms 8824 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 42 ms 11256 KB Output is correct
2 Execution timed out 1091 ms 8824 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 35 ms 9336 KB Output is correct
2 Execution timed out 1089 ms 9088 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 41 ms 10956 KB Output is correct
2 Execution timed out 1097 ms 9728 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 36 ms 9472 KB Output is correct
2 Execution timed out 1094 ms 9080 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 35 ms 9420 KB Output is correct
2 Execution timed out 1087 ms 9464 KB Time limit exceeded