Submission #312852

# Submission time Handle Problem Language Result Execution time Memory
312852 2020-10-14T13:18:31 Z colazcy Slagalica (COCI19_slagalica2) C++17
10 / 70
23 ms 2176 KB
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <vector>
#include <ctime>
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];
clock_t begt;
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((clock() - begt) * 1000 / CLOCKS_PER_SEC){
		puts("-1");
		exit(0); 
	}
	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);
	begt = clock();
	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:18:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  return pos[x] == vec[x].size() ? 0x7fffffff : vec[x][pos[x]];
      |         ~~~~~~~^~~~~~~~~~~~~~~~
slagalica.cpp: In function 'void dfs(int, int)':
slagalica.cpp:45:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |  for(int i = 0;i < G[lst].size();i++)nxt[step][i] = G[lst][i];
      |                ~~^~~~~~~~~~~~~~~
slagalica.cpp:47:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |  for(int i = 0;i < G[lst].size();i++){
      |                ~~^~~~~~~~~~~~~~~
slagalica.cpp: In function 'int main()':
slagalica.cpp:63:10: warning: unused variable 'x' [-Wunused-variable]
   63 |  for(int x,i = 1;i <= n;i++){
      |          ^
# Verdict Execution time Memory Grader output
1 Correct 0 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 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 1860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 1856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 23 ms 2044 KB Output is correct
2 Incorrect 20 ms 1916 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1920 KB Output is correct
2 Incorrect 20 ms 1916 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 1916 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 1916 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 1920 KB Output is correct
2 Incorrect 21 ms 1792 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 2176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 1792 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 2004 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 19 ms 1920 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 1748 KB Output isn't correct
2 Halted 0 ms 0 KB -