Submission #381809


Source Code Expand

//UTPC2014K 乱数調整
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
lint baby[(1<<18)+10],giant[(1<<18)+10];
map<lint,vector<vector<int> > > me;
map<lint,int> mi;
vector<int> cl(36,0);
vector<vector<int> > cal(lint a){
	if(me.count(a)>0) return me[a];
	vector<vector<int> > mae=cal(a/2),ato=cal(a-a/2),ret(36,cl);
	rep(i,36) rep(j,36) rep(k,36){
		ret[i][j]^=(mae[i][k]&ato[k][j]);
	}
	return me[a]=ret;
}
int main()
{
	lint A,B,X,now;int T=(1<<18);
	cin>>A>>B>>X;now=A;
	rep(i,(1<<18)+10){
		if(now==X){
			cout<<i<<endl;return 0;
		}
		//if(i==(1<<18)) cerr<<now<<endl;
		now=((now/2)^((now%2)*B));
	}
	baby[0]=X;giant[0]=A;mi[X]=0;
	rep(i,(1<<18)){
		baby[i+1]=baby[i]/2;
		if(baby[i]%2>0) baby[i+1]^=B;
		mi[baby[i+1]]=i+1;
	}
	vector<vector<int> > one(36,cl);
	rep(i,35) one[i][i+1]=1;
	rep(i,36){
		if(((1LL<<i)&B)) one[i][0]=1;
	}
	me[1]=one;
	vector<vector<int> > gi=cal((1<<18));
	rep(i,(1<<18)){
		giant[i+1]=0;
		rep(j,36){
			lint t=0;
			rep(k,36){
				if(((1LL<<k)&giant[i]) && gi[j][k]>0) t^=1;
			}
			giant[i+1]+=t<<j;
		}
	}
	//cerr<<giant[1]<<endl;
	lint ret=1145141919810893LL;
	REP(i,1,(1<<18)+1){
		if(mi.count(giant[i])<1) continue;
		lint t=i;t=(t<<18)-mi[giant[i]];
		ret=min(ret,t);
		//cout<<t<<endl;return 0;
	}
	if(ret>(1LL<<37)){cout<<-1<<endl;return 0;}
	now=giant[ret/T];
	rep(i,ret%T) now=((now/2)^((now%2)*B));
	if(now==X) cout<<ret<<endl;
	else cout<<-1<<endl;
}

Submission Info

Submission Time
Task K - 乱数調整
User sky58
Language C++ (GCC 4.9.2)
Score 300
Code Size 2110 Byte
Status AC
Exec Time 1308 ms
Memory 21720 KB

Judge Result

Set Name Subtask All
Score / Max Score 30 / 30 270 / 270
Status
AC × 20
AC × 63
Set Name Test Cases
Subtask subtask_00.txt, subtask_01.txt, subtask_02.txt, subtask_03.txt, subtask_04.txt, subtask_05.txt, subtask_06.txt, subtask_07.txt, subtask_08.txt, subtask_09.txt, subtask_10.txt, subtask_11.txt, subtask_12.txt, subtask_13.txt, subtask_14.txt, subtask_15.txt, subtask_16.txt, subtask_17.txt, subtask_18.txt, subtask_19.txt
All scrambled_00.txt, scrambled_01.txt, scrambled_02.txt, scrambled_03.txt, scrambled_04.txt, scrambled_05.txt, scrambled_06.txt, scrambled_07.txt, scrambled_08.txt, scrambled_09.txt, scrambled_10.txt, scrambled_11.txt, scrambled_12.txt, scrambled_13.txt, scrambled_14.txt, scrambled_15.txt, scrambled_16.txt, scrambled_17.txt, scrambled_18.txt, scrambled_19.txt, scrambled_20.txt, scrambled_21.txt, scrambled_22.txt, scrambled_23.txt, scrambled_24.txt, scrambled_25.txt, scrambled_26.txt, scrambled_27.txt, scrambled_28.txt, scrambled_29.txt, scrambled_30.txt, scrambled_31.txt, scrambled_32.txt, scrambled_33.txt, scrambled_34.txt, scrambled_35.txt, scrambled_36.txt, scrambled_37.txt, scrambled_38.txt, scrambled_39.txt, scrambled_40.txt, scrambled_41.txt, scrambled_42.txt, subtask_00.txt, subtask_01.txt, subtask_02.txt, subtask_03.txt, subtask_04.txt, subtask_05.txt, subtask_06.txt, subtask_07.txt, subtask_08.txt, subtask_09.txt, subtask_10.txt, subtask_11.txt, subtask_12.txt, subtask_13.txt, subtask_14.txt, subtask_15.txt, subtask_16.txt, subtask_17.txt, subtask_18.txt, subtask_19.txt
Case Name Status Exec Time Memory
scrambled_00.txt AC 27 ms 1052 KB
scrambled_01.txt AC 26 ms 1048 KB
scrambled_02.txt AC 25 ms 1044 KB
scrambled_03.txt AC 682 ms 5276 KB
scrambled_04.txt AC 26 ms 1036 KB
scrambled_05.txt AC 26 ms 1040 KB
scrambled_06.txt AC 26 ms 928 KB
scrambled_07.txt AC 25 ms 984 KB
scrambled_08.txt AC 29 ms 984 KB
scrambled_09.txt AC 30 ms 1048 KB
scrambled_10.txt AC 27 ms 1048 KB
scrambled_11.txt AC 27 ms 924 KB
scrambled_12.txt AC 26 ms 988 KB
scrambled_13.txt AC 27 ms 924 KB
scrambled_14.txt AC 1284 ms 21720 KB
scrambled_15.txt AC 1303 ms 21652 KB
scrambled_16.txt AC 1231 ms 21588 KB
scrambled_17.txt AC 1299 ms 21664 KB
scrambled_18.txt AC 1284 ms 21528 KB
scrambled_19.txt AC 1267 ms 21532 KB
scrambled_20.txt AC 1303 ms 21544 KB
scrambled_21.txt AC 1293 ms 21464 KB
scrambled_22.txt AC 1286 ms 21528 KB
scrambled_23.txt AC 1270 ms 21536 KB
scrambled_24.txt AC 1278 ms 21464 KB
scrambled_25.txt AC 1230 ms 21468 KB
scrambled_26.txt AC 1281 ms 21464 KB
scrambled_27.txt AC 1308 ms 21536 KB
scrambled_28.txt AC 26 ms 1048 KB
scrambled_29.txt AC 693 ms 5272 KB
scrambled_30.txt AC 26 ms 1052 KB
scrambled_31.txt AC 894 ms 13472 KB
scrambled_32.txt AC 25 ms 920 KB
scrambled_33.txt AC 28 ms 932 KB
scrambled_34.txt AC 26 ms 1048 KB
scrambled_35.txt AC 27 ms 928 KB
scrambled_36.txt AC 29 ms 1040 KB
scrambled_37.txt AC 1249 ms 21528 KB
scrambled_38.txt AC 1225 ms 21460 KB
scrambled_39.txt AC 1261 ms 21536 KB
scrambled_40.txt AC 1277 ms 21528 KB
scrambled_41.txt AC 1216 ms 21464 KB
scrambled_42.txt AC 1303 ms 21468 KB
subtask_00.txt AC 736 ms 5280 KB
subtask_01.txt AC 736 ms 5208 KB
subtask_02.txt AC 783 ms 5276 KB
subtask_03.txt AC 751 ms 5280 KB
subtask_04.txt AC 28 ms 1044 KB
subtask_05.txt AC 27 ms 1040 KB
subtask_06.txt AC 27 ms 1040 KB
subtask_07.txt AC 27 ms 924 KB
subtask_08.txt AC 27 ms 1044 KB
subtask_09.txt AC 28 ms 928 KB
subtask_10.txt AC 27 ms 1044 KB
subtask_11.txt AC 28 ms 988 KB
subtask_12.txt AC 28 ms 1052 KB
subtask_13.txt AC 26 ms 1048 KB
subtask_14.txt AC 26 ms 1052 KB
subtask_15.txt AC 703 ms 5280 KB
subtask_16.txt AC 28 ms 1052 KB
subtask_17.txt AC 687 ms 5276 KB
subtask_18.txt AC 25 ms 1048 KB
subtask_19.txt AC 25 ms 1052 KB