답안 #283436

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
283436 2020-08-25T18:44:01 Z kshitij_sodani DEL13 (info1cup18_del13) C++14
15 / 100
11 ms 4600 KB
//#pragma GCC optimize("Ofast,unroll-loops")//
//#pragma GCC target("fma,avx")//,avx2,fma")
//#pragma GCC optimization ("O3")


/*#pragma GCC optimization ("unroll-loops")
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first 
#define b second


llo t;

llo vis[200001];
llo dp[200001][3];
llo back[200001][3];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>t;
	while(t--){
		llo n,q;
		cin>>n>>q;
		if(q==0){
			cout<<-1<<endl;
			continue;
		}
		for(llo i=0;i<n;i++){
			vis[i]=0;
		}
		//vector<llo> aa;
		set<llo> ac;
		for(llo i=0;i<q;i++){
			llo bb;
			cin>>bb;
			bb--;
			vis[bb]=1;
			//aa.pb(bb);
			ac.insert(bb);
		}
		if(q==n){
			cout<<0<<endl;
			cout<<endl;
			continue;
		}
		vector<vector<deque<llo>>> ss;
		llo cot=0;
		llo stt=0;
		for(llo i=0;i<n;i++){
			if(vis[i]==0){
			//	cout<<i<<"::"<<endl;

				if(cot>=2 or stt==0){
					deque<llo> tt;
					tt.pb(i);
					ss.pb({tt});
				}
				else if(cot==0){
					ss[ss.size()-1][ss[ss.size()-1].size()-1].pb(i);
				}
				else{
					deque<llo> tt;
					tt.pb(i);
					ss[ss.size()-1].pb(tt);
				}
				stt=1;
				cot=0;
			}
			else{
				cot+=1;
			}
		}
		vector<llo> ans;
		llo ye=0;
	
		for(llo i=0;i<ss.size();i++){
			for(llo j=0;j<ss[i].size();j++){
				//cout<<j<<":";
				while(ss[i][j].size()>4){
					llo aa=ss[i][j].back();
					ss[i][j].pop_back();
					llo bb=ss[i][j].back();
					ss[i][j].pop_back();
					llo cc=ss[i][j].back();
					ss[i][j].pop_back();
					ans.pb(bb);
					ss[i][j].pb(bb);
				}
			}
			//cout<<",,"<<endl;
			if(ss[i].size()==1){
				ye=1;
				break;
			}
			for(llo j=0;j<ss[i].size();j++){
				dp[j][0]=0;
				dp[j][1]=0;
				dp[j][2]=0;

			}
			for(llo j=1;j<=2;j++){
				if(ss[i][1].size()>=j and ss[i][0].size()>=j and ss[i][0].size()%2==j%2){
					dp[1][j]=1;
					back[1][j]=j;
				//	cout<<j<<"<"<<'\n';
				}
			}
			for(llo j=2;j<ss[i].size();j++){
				for(llo jj=0;jj<=ss[i][j].size();jj++){
					for(llo ii=0;ii<=2;ii++){
						if((ss[i][j-1].size()-ii-jj)>=0){
							if((ss[i][j-1].size()-ii-jj)%2==0){
								if(dp[j-1][ii]==1){
									dp[j][jj]|=dp[j-1][ii];
									back[j][jj]=ii;
								}
							}
						}
					}
				}
			}
			ye=1;

			for(llo ko=ss[i].back().size();ko>0;ko-=2){
				if(dp[ss[i].size()-1][ko]){
					ye=0;
				//	cout<<ko<<"//"<<endl;
					vector<llo> jj;
					jj.pb(ko);
					for(llo ii=ss[i].size()-1;ii>0;ii--){
						jj.pb(back[ii][jj.back()]);	
					}
					reverse(jj.begin(),jj.end());
					/*for(auto jo:jj){
						cout<<ko<<".";
					}
					cout<<endl;*/
					for(llo j=0;j<ss[i].size();j++){
						llo le=ss[i][j].size()-jj[j];
						if(j>0){
							if(j<ss[i].size()-1){
								le-=jj[j+1];
							}
						}
					//	cout<<le<<"///"<<endl;
						for(llo jo=0;jo<le/2;jo++){
							llo aa=ss[i][j].back();
							ss[i][j].pop_back();
							llo bb=ss[i][j].back();
							ss[i][j].pop_back();
							llo cc=ss[i][j].back();
							ss[i][j].pop_back();
							ans.pb(bb);
							ss[i][j].pb(bb);
						}
					//	cout<<11<<endl;
					}
					//cout<<endl;
					for(llo j=0;j<ss[i].size()-1;j++){
						for(llo pp=0;pp<jj[j];pp++){
							llo aa=ss[i][j].back();
							ss[i][j].pop_back();
							llo bb=ss[i][j+1].front();
							ss[i][j+1].pop_front();

							llo x=*ac.lower_bound(aa);
							ans.pb(x);
						}
					}
					break;
				}
			}
			if(ye){
				break;
			}


		}

		if(ye){
			cout<<-1<<'\n';
			continue;
		}
		cout<<ans.size()<<'\n';
		for(auto j:ans){
			cout<<j+1<<" ";
		}
		cout<<'\n';

		










	}


	return 0;
}


Compilation message

del13.cpp: In function 'int main()':
del13.cpp:84:16: warning: comparison of integer expressions of different signedness: 'llo' {aka 'long long int'} and 'std::vector<std::vector<std::deque<long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |   for(llo i=0;i<ss.size();i++){
      |               ~^~~~~~~~~~
del13.cpp:85:17: warning: comparison of integer expressions of different signedness: 'llo' {aka 'long long int'} and 'std::vector<std::deque<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |    for(llo j=0;j<ss[i].size();j++){
      |                ~^~~~~~~~~~~~~
del13.cpp:88:10: warning: unused variable 'aa' [-Wunused-variable]
   88 |      llo aa=ss[i][j].back();
      |          ^~
del13.cpp:92:10: warning: unused variable 'cc' [-Wunused-variable]
   92 |      llo cc=ss[i][j].back();
      |          ^~
del13.cpp:103:17: warning: comparison of integer expressions of different signedness: 'llo' {aka 'long long int'} and 'std::vector<std::deque<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  103 |    for(llo j=0;j<ss[i].size();j++){
      |                ~^~~~~~~~~~~~~
del13.cpp:110:23: warning: comparison of integer expressions of different signedness: 'std::deque<long long int>::size_type' {aka 'long unsigned int'} and 'llo' {aka 'long long int'} [-Wsign-compare]
  110 |     if(ss[i][1].size()>=j and ss[i][0].size()>=j and ss[i][0].size()%2==j%2){
      |        ~~~~~~~~~~~~~~~^~~
del13.cpp:110:46: warning: comparison of integer expressions of different signedness: 'std::deque<long long int>::size_type' {aka 'long unsigned int'} and 'llo' {aka 'long long int'} [-Wsign-compare]
  110 |     if(ss[i][1].size()>=j and ss[i][0].size()>=j and ss[i][0].size()%2==j%2){
      |                               ~~~~~~~~~~~~~~~^~~
del13.cpp:110:71: warning: comparison of integer expressions of different signedness: 'std::deque<long long int>::size_type' {aka 'long unsigned int'} and 'llo' {aka 'long long int'} [-Wsign-compare]
  110 |     if(ss[i][1].size()>=j and ss[i][0].size()>=j and ss[i][0].size()%2==j%2){
      |                                                      ~~~~~~~~~~~~~~~~~^~~~~
del13.cpp:116:17: warning: comparison of integer expressions of different signedness: 'llo' {aka 'long long int'} and 'std::vector<std::deque<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  116 |    for(llo j=2;j<ss[i].size();j++){
      |                ~^~~~~~~~~~~~~
del13.cpp:117:20: warning: comparison of integer expressions of different signedness: 'llo' {aka 'long long int'} and 'std::deque<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  117 |     for(llo jj=0;jj<=ss[i][j].size();jj++){
      |                  ~~^~~~~~~~~~~~~~~~~
del13.cpp:146:19: warning: comparison of integer expressions of different signedness: 'llo' {aka 'long long int'} and 'std::vector<std::deque<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  146 |      for(llo j=0;j<ss[i].size();j++){
      |                  ~^~~~~~~~~~~~~
del13.cpp:149:12: warning: comparison of integer expressions of different signedness: 'llo' {aka 'long long int'} and 'std::vector<std::deque<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  149 |        if(j<ss[i].size()-1){
      |           ~^~~~~~~~~~~~~~~
del13.cpp:155:12: warning: unused variable 'aa' [-Wunused-variable]
  155 |        llo aa=ss[i][j].back();
      |            ^~
del13.cpp:159:12: warning: unused variable 'cc' [-Wunused-variable]
  159 |        llo cc=ss[i][j].back();
      |            ^~
del13.cpp:167:19: warning: comparison of integer expressions of different signedness: 'llo' {aka 'long long int'} and 'std::vector<std::deque<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  167 |      for(llo j=0;j<ss[i].size()-1;j++){
      |                  ~^~~~~~~~~~~~~~~
del13.cpp:171:12: warning: unused variable 'bb' [-Wunused-variable]
  171 |        llo bb=ss[i][j+1].front();
      |            ^~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 640 KB Execution killed with signal 11
2 Incorrect 2 ms 384 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 640 KB Execution killed with signal 11
2 Incorrect 2 ms 384 KB Output isn't correct
3 Runtime error 3 ms 512 KB Execution killed with signal 11
4 Runtime error 2 ms 640 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 768 KB Output is correct
2 Correct 7 ms 2628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 640 KB Execution killed with signal 11
2 Incorrect 2 ms 384 KB Output isn't correct
3 Runtime error 3 ms 512 KB Execution killed with signal 11
4 Runtime error 2 ms 640 KB Execution killed with signal 11
5 Runtime error 2 ms 512 KB Execution killed with signal 11
6 Correct 2 ms 384 KB Output is partially correct
7 Runtime error 4 ms 512 KB Execution killed with signal 11
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 640 KB Execution killed with signal 11
2 Incorrect 2 ms 384 KB Output isn't correct
3 Runtime error 3 ms 512 KB Execution killed with signal 11
4 Runtime error 2 ms 640 KB Execution killed with signal 11
5 Runtime error 2 ms 512 KB Execution killed with signal 11
6 Correct 2 ms 384 KB Output is partially correct
7 Runtime error 4 ms 512 KB Execution killed with signal 11
8 Runtime error 7 ms 4096 KB Execution killed with signal 11
9 Runtime error 1 ms 512 KB Execution killed with signal 11
10 Runtime error 8 ms 4600 KB Execution killed with signal 11
11 Runtime error 2 ms 640 KB Execution killed with signal 11