Submission #67139

# Submission time Handle Problem Language Result Execution time Memory
67139 2018-08-13T11:31:51 Z tempytemptemp DEL13 (info1cup18_del13) C++14
12 / 100
23 ms 3156 KB
/*
  Let the good times roll
*/
#include	<iostream>
#include	<cstdio>
#include	<vector>
#include 	<set>
#include	<map>
#include	<queue>
#include	<stack>
#include	<algorithm>
#include	<cstring>
#include	<cfloat>
#include	<cmath>
#include	<cassert>
#include	<locale>
#include	<string>
#include	<bitset>
#include	<functional>
#include	<climits>
#include	<iomanip>
using namespace std;

#define read(x)     freopen(x,"r",stdin)
#define write(x)    freopen(x,"w",stdout)
#define cl(a,b)	    memset(a,b,sizeof(a))
#define all(x)      x.begin(),x.end()
#define rall(x)     x.rbegin(),x.rend()
#define ll          long long
#define ld          long double
#define vec         vector
#define vi          vec<int>
#define heap        priority_queue
#define res         reserve
#define pb          push_back
#define f(x,y,z)    for(int x=(y); x<(z); x++)
#define fd(x,y,z)   for(int x=(y); x>=(z); x--)
#define fit(x,y)    for(auto x: y)
#define srt(x)      sort(all(x))
#define rsrt(x)     sort(rall(x))
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define pii         pair<int,ll>
#define ppi         pair<pii,int>
#define pip         pair<int,pii>
#define mp          make_pair
#define f1          first
#define s2          second
#define cdbg(x)     cerr<<#x<<" = "<<x<<",\t";
#define cdbl        cerr<<"\n----------\n";
#define pow2(x)     ((x)*(x))
#define edist(x1, y1, x2, y2) (sqrt((pow2(x1-x2)+pow2(y1-y2))))
#define mdist(x1, y1, x2, y2) (abs((x1)-(x2))+abs((y1)-(y2)))
#define y1          FullSensei
#define mid         ((ss+se)>>1)
#define left        (si<<1)
#define right       ((si<<1)+1)
#define pi          3.141592653589793
#define popcount    __builtin_popcount
#define spc			' '
#define endl		'\n'
bool checkbit(int x,int y){return (x&(1<<y));}
int setbit(int x,int y){return (x^(1<<y));}
const int dirs[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int mod=1e9+7;
const int p1=805306457;
const int p2=1610612741;
const int INF=1e9;
const int N=18+2;

bool vis[1<<N];
pii dp[1<<N];
int n;

void dpf(int mask){
	if(vis[mask])
		return;
	vis[mask]=1;
	vi list;
	f(i,0,n)	if(checkbit(mask,i))	list.pb(i);
	if(list.size()<3)
		return;
	f(i,0,list.size()-2){
		int mask2=setbit(setbit(mask,list[i+2]),list[i]);
		if(vis[mask2]==0){
			dp[mask2]={mask,list[i+1]};
			dpf(mask2);
		}
	}
}

void pre(){
	cl(vis,0);
	int mask=(1<<(n))-1;
	dpf(mask);
}

int main(){
	//read("in2.in");
	int tc;
	cin>>tc;
	f(tci,0,tc){
		int r;
		cin>>n>>r;
		if(n>N)	return -1;
		
		if(tci==0)
			pre();
		vi v;
		f(i,0,r){
			int temp;
			cin>>temp;
			v.pb(temp);
		}
		int mask=0;
		fit(x,v){
			mask=setbit(mask,x-1);
		}
		if(!vis[mask]){
			cout<<-1<<endl;
		}
		else{
			stack<int> way;
			for(int currmask=mask; currmask!=(1<<n)-1; currmask=dp[currmask].f1){
				way.push(dp[currmask].s2);
			}
			cout<<way.size()<<endl;
			while(!way.empty()){
				cout<<way.top();
				way.pop();
				if(!way.empty())
					cout<<spc;
				else
					cout<<endl;
			}
		}
	}
	return 0;
}

Compilation message

del13.cpp: In function 'void dpf(int)':
del13.cpp:36:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define f(x,y,z)    for(int x=(y); x<(z); x++)
                                     ^
del13.cpp:82:2: note: in expansion of macro 'f'
  f(i,0,list.size()-2){
  ^
# Verdict Execution time Memory Grader output
1 Partially correct 5 ms 1276 KB Output is partially correct
2 Partially correct 6 ms 1380 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Partially correct 5 ms 1276 KB Output is partially correct
2 Partially correct 6 ms 1380 KB Output is partially correct
3 Partially correct 19 ms 2440 KB Output is partially correct
4 Partially correct 23 ms 3156 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 3156 KB Execution failed because the return code was nonzero
2 Runtime error 2 ms 3156 KB Execution failed because the return code was nonzero
# Verdict Execution time Memory Grader output
1 Partially correct 5 ms 1276 KB Output is partially correct
2 Partially correct 6 ms 1380 KB Output is partially correct
3 Partially correct 19 ms 2440 KB Output is partially correct
4 Partially correct 23 ms 3156 KB Output is partially correct
5 Runtime error 2 ms 3156 KB Execution failed because the return code was nonzero
6 Runtime error 3 ms 3156 KB Execution failed because the return code was nonzero
7 Runtime error 2 ms 3156 KB Execution failed because the return code was nonzero
# Verdict Execution time Memory Grader output
1 Partially correct 5 ms 1276 KB Output is partially correct
2 Partially correct 6 ms 1380 KB Output is partially correct
3 Partially correct 19 ms 2440 KB Output is partially correct
4 Partially correct 23 ms 3156 KB Output is partially correct
5 Runtime error 2 ms 3156 KB Execution failed because the return code was nonzero
6 Runtime error 3 ms 3156 KB Execution failed because the return code was nonzero
7 Runtime error 2 ms 3156 KB Execution failed because the return code was nonzero
8 Runtime error 2 ms 3156 KB Execution failed because the return code was nonzero
9 Runtime error 3 ms 3156 KB Execution failed because the return code was nonzero
10 Runtime error 2 ms 3156 KB Execution failed because the return code was nonzero
11 Runtime error 2 ms 3156 KB Execution failed because the return code was nonzero