Submission #2359769


Source Code Expand

#include <stdio.h>
#include <algorithm>
using namespace std;

struct matrix{
	matrix(){
		for (int i=0;i<36;i++) for (int j=0;j<36;j++) a[i][j] = 0;
	}
	bool a[36][36];

	matrix operator *(matrix t){
		matrix r;
		for (int i=0;i<36;i++) for (int j=0;j<36;j++) for (int k=0;k<36;k++) if (a[i][k] & t.a[k][j])
			r.a[i][j] ^= 1;
		return r;
	}
};

struct data{
	long long a, l, pos;
	bool operator <(const data &t)const{
		if (a != t.a) return a < t.a;
		return l == -1 ? pos > t.pos : pos < t.pos;
	}
}P[1<<18],Q[1<<18];

int bc[1<<18];

int main()
{
	for (int i=1;i<(1<<18);i++){
		int x = i & (-i);
		bc[i] = bc[i-x] + 1;
	}

	long long A,B,X,T; scanf ("%lld %lld %lld",&A,&B,&X);

	matrix b[19];
	for (int i=0;i<35;i++) b[0].a[i][i+1] = 1;
	for (int i=0;i<36;i++) if (B & (1ll << i)) b[0].a[i][0] = 1;
	for (int i=1;i<=18;i++) b[i] = b[i-1] * b[i-1];

	long long BC[19][36] = {0,};
	for (int k=0;k<=18;k++){
		for (int i=0;i<36;i++) for (int j=0;j<36;j++) if (b[k].a[i][j]) BC[k][i] |= 1ll << j;
	}

	auto nxt = [&](int k, long long x){
		long long n = 0;
		for (int i=0;i<36;i++){
			long long o = BC[k][i] & x;
			if ((bc[o>>18] + bc[o%(1<<18)]) % 2) n |= 1ll << i;
		}
		return n;
	};

	T = X;
	for (int i=0;i<(1<<18);i++){
		long long n = nxt(0,T);
		P[i] = {n,-1,i+1};
		T = n;
	}

	for (int i=0;i<(1<<18);i++){
		long long n = nxt(18,A);
		Q[i] = {n,A,(1ll<<18)*(i+1)};
		A = n;
	}

	sort(P,P+(1<<18));
	sort(Q,Q+(1<<18));

	long long ans = 1e18;
	int i = 0, j = 0;
	while (i < (1<<18) && j < (1<<18)){
		if (P[i].a < Q[j].a) i++;
		else if (P[i].a > Q[j].a) j++;
		else{
			long long a = P[i].a;

			long long st[2],pos[2]; int c = 1;
			st[0] = Q[j].l;
			pos[0] = Q[j].pos;
			j++;
			if (j < (1<<18) && Q[j].a == a){
				st[1] = Q[j].l;
				pos[1] = Q[j].pos;
				c++;
			}

			while (i < (1<<18) && P[i].a == a){
				for (int t=0;t<c;t++) if (ans > pos[t] - P[i].pos){
					long long v = st[t];
					int mv = (1<<18) - P[i].pos;
					for (int k=0;k<18;k++) if (mv & (1 << k)) v = nxt(k,v);

					if (v == X)
						ans = pos[t] - P[i].pos;
				}
				i++;
			}
		}
	}
	if (ans > 1e17) ans = -1;

	printf ("%lld\n",ans);

	return 0;
}

Submission Info

Submission Time
Task K - 乱数調整
User august14
Language C++14 (GCC 5.4.1)
Score 300
Code Size 2254 Byte
Status AC
Exec Time 620 ms
Memory 13568 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:36:54: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  long long A,B,X,T; scanf ("%lld %lld %lld",&A,&B,&X);
                                                      ^

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 87 ms 13568 KB
scrambled_01.txt AC 87 ms 13440 KB
scrambled_02.txt AC 81 ms 13568 KB
scrambled_03.txt AC 69 ms 13568 KB
scrambled_04.txt AC 135 ms 13440 KB
scrambled_05.txt AC 138 ms 13568 KB
scrambled_06.txt AC 136 ms 13568 KB
scrambled_07.txt AC 139 ms 13440 KB
scrambled_08.txt AC 142 ms 13440 KB
scrambled_09.txt AC 135 ms 13440 KB
scrambled_10.txt AC 143 ms 13440 KB
scrambled_11.txt AC 146 ms 13440 KB
scrambled_12.txt AC 139 ms 13568 KB
scrambled_13.txt AC 134 ms 13440 KB
scrambled_14.txt AC 181 ms 13440 KB
scrambled_15.txt AC 189 ms 13568 KB
scrambled_16.txt AC 190 ms 13568 KB
scrambled_17.txt AC 184 ms 13440 KB
scrambled_18.txt AC 189 ms 13440 KB
scrambled_19.txt AC 190 ms 13440 KB
scrambled_20.txt AC 194 ms 13440 KB
scrambled_21.txt AC 193 ms 13568 KB
scrambled_22.txt AC 193 ms 13440 KB
scrambled_23.txt AC 191 ms 13568 KB
scrambled_24.txt AC 194 ms 13440 KB
scrambled_25.txt AC 186 ms 13568 KB
scrambled_26.txt AC 192 ms 13440 KB
scrambled_27.txt AC 192 ms 13440 KB
scrambled_28.txt AC 58 ms 13440 KB
scrambled_29.txt AC 456 ms 13568 KB
scrambled_30.txt AC 60 ms 13440 KB
scrambled_31.txt AC 97 ms 13440 KB
scrambled_32.txt AC 58 ms 13440 KB
scrambled_33.txt AC 67 ms 13568 KB
scrambled_34.txt AC 135 ms 13440 KB
scrambled_35.txt AC 132 ms 13568 KB
scrambled_36.txt AC 132 ms 13568 KB
scrambled_37.txt AC 141 ms 13440 KB
scrambled_38.txt AC 135 ms 13440 KB
scrambled_39.txt AC 176 ms 13440 KB
scrambled_40.txt AC 170 ms 13568 KB
scrambled_41.txt AC 177 ms 13568 KB
scrambled_42.txt AC 193 ms 13568 KB
subtask_00.txt AC 90 ms 13568 KB
subtask_01.txt AC 109 ms 13568 KB
subtask_02.txt AC 620 ms 13568 KB
subtask_03.txt AC 620 ms 13568 KB
subtask_04.txt AC 123 ms 13440 KB
subtask_05.txt AC 110 ms 13440 KB
subtask_06.txt AC 124 ms 13440 KB
subtask_07.txt AC 108 ms 13568 KB
subtask_08.txt AC 124 ms 13568 KB
subtask_09.txt AC 116 ms 13568 KB
subtask_10.txt AC 101 ms 13440 KB
subtask_11.txt AC 120 ms 13440 KB
subtask_12.txt AC 111 ms 13440 KB
subtask_13.txt AC 105 ms 13568 KB
subtask_14.txt AC 59 ms 13440 KB
subtask_15.txt AC 452 ms 13568 KB
subtask_16.txt AC 58 ms 13440 KB
subtask_17.txt AC 59 ms 13440 KB
subtask_18.txt AC 59 ms 13440 KB
subtask_19.txt AC 67 ms 13440 KB