Submission #67295

# Submission time Handle Problem Language Result Execution time Memory
67295 2018-08-13T19:42:03 Z hamzqq9 DEL13 (info1cup18_del13) C++14
100 / 100
83 ms 5644 KB
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<int,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 2000000000
#define MOD 1000000007
#define N 100005
#define MAX 10000006
#define LOG 22
using namespace std;

int t,n,k;
int total[N],a[N];
bool dp[N][3],vis[N][3];
vector<int> rng,ans;

bool dfs(int now,int bef_dec) {

	if(now>k) return dp[now][bef_dec]=((rng[now-1]-bef_dec)%2==0 && rng[now-1]>=bef_dec && (rng[now-1]-bef_dec==0 || bef_dec>0));

	if(vis[now][bef_dec]) return dp[now][bef_dec];

	bool& r=dp[now][bef_dec];

	vis[now][bef_dec]=true;

	for(int i=0;i<3;i++) {

		int rem=rng[now-1]-bef_dec-i;

		if(rem%2 || (rem>0 && i==0 && bef_dec==0) || rem<0) continue ;

		r|=dfs(now+1,i);

	}

	return r;

}

void print() {

	if(!dp[1][0]) {

		printf("-1\n");

		return ;

	}

	printf("%d\n",sz(ans));

	for(int i:ans) printf("%d ",i);

	puts("");

}

void down() {

	if(!dp[1][0]) return ;

	for(int i=0;i<=k;i++) {

		int s=total[i];
		int e=total[i+1];

		int sz=a[i+1]-a[i]-1;

		int start=a[i]+2;

		while(sz>s+e) {

			sz-=2;

			ans.pb(start);

			start+=2;

		}


	}
    
	for(int i=1;i<=k;i++) {

		for(int j=1;j<=total[i];j++) ans.pb(a[i]);

	}

}

void find_path(int now,int bef_dec) {

	if(now>k) return ;

	for(int i=0;i<3;i++) {

		int rem=rng[now-1]-bef_dec-i;

		if(rem%2 || (rem>0 && i==0 && bef_dec==0) || !dp[now+1][i] || rem<0) continue ;

		total[now]=i;

		find_path(now+1,i);

		return ;

	}	

}

void solve() {

	memset(dp,false,sizeof(dp));
	memset(vis,false,sizeof(vis));

	dfs(1,0);

}

int main() {
 
	//freopen("input.txt","r",stdin);
 	
 	scanf("%d",&t);

 	while(t--) {

 		scanf("%d %d",&n,&k);

 		for(int i=1;i<=k;i++) {

 			scanf("%d",&a[i]);

 		}

 		bool increasing=true;

 		a[0]=0;a[k+1]=n+1;

 		for(int i=1;i<=k+1;i++) {

 			if(a[i]<a[i-1]) increasing=false;

 			rng.pb(a[i]-a[i-1]-1);

 		}

 		if(!increasing) {

 			printf("-1\n");

 			continue ;

 		}

 		solve();

 		find_path(1,0);

 		down();

 		print();

 		rng.clear();

 		ans.clear();

 	}

} 	

Compilation message

del13.cpp: In function 'int main()':
del13.cpp:138:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&t);
   ~~~~~^~~~~~~~~
del13.cpp:142:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d %d",&n,&k);
    ~~~~~^~~~~~~~~~~~~~~
del13.cpp:146:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&a[i]);
     ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 18 ms 888 KB Output is correct
2 Correct 21 ms 996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 888 KB Output is correct
2 Correct 21 ms 996 KB Output is correct
3 Correct 81 ms 996 KB Output is correct
4 Correct 83 ms 996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 1192 KB Output is correct
2 Correct 10 ms 1192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 888 KB Output is correct
2 Correct 21 ms 996 KB Output is correct
3 Correct 81 ms 996 KB Output is correct
4 Correct 83 ms 996 KB Output is correct
5 Correct 6 ms 1192 KB Output is correct
6 Correct 6 ms 1192 KB Output is correct
7 Correct 6 ms 1192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 888 KB Output is correct
2 Correct 21 ms 996 KB Output is correct
3 Correct 81 ms 996 KB Output is correct
4 Correct 83 ms 996 KB Output is correct
5 Correct 6 ms 1192 KB Output is correct
6 Correct 6 ms 1192 KB Output is correct
7 Correct 6 ms 1192 KB Output is correct
8 Correct 16 ms 1764 KB Output is correct
9 Correct 17 ms 3072 KB Output is correct
10 Correct 16 ms 3204 KB Output is correct
11 Correct 24 ms 5644 KB Output is correct