Submission #70102640


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int T;
ll C,X;
pair<int,int> from[33][2];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	/*
	for(X=1;X<=63;X++) {
		cout<<X<<" "<<(98^X)-98<<endl;
	}
	return;
	*/
	cin>>T;
	while(T--) {
		cin>>C>>X;
		int msc=-1,msx=-1;
		FOR(i,30) {
			if(C&(1<<i)) msc=i;
			if(X&(1<<i)) msx=i;
		}
		if(msx!=msc) {
			ll N=(C^X);
			if((C^N)%N==X) {
				cout<<N<<endl;
			}
			else {
				cout<<-1<<endl;
			}
		}
		else {
			ll N=1LL<<34;
			
			MINUS(from);
			from[0][0]={0,0};
			
			FOR(i,32) {
				int c=(C>>i)%2;
				int x=(X>>i)%2;
				//cout<<i<<" "<<c<<" "<<x<<" "<<from[i][0].first<<":"<<from[i][0].second<<" "<<from[i][1].first<<":"<<from[i][1].second<<endl;
				if(c&&x) {
					if(from[i][0].first>=0) {
						from[i+1][0]={0,0};
						from[i+1][1]={1,0};
					}
				}
				if(c==0&&x) {
					if(from[i][1].first>=0) {
						from[i+1][1]={1,1};
					}
				}
				if(c&&x==0) {
					if(from[i][1].first>=0) {
						from[i+1][0]={0,1};
						from[i+1][1]={1,1};
					}
				}
				if(c==0&&x==0) {
					if(from[i][0].first>=0) {
						from[i+1][0]={0,0};
					}
				}
			}
			if(from[32][0].first==-1) {
				cout<<-1<<endl;
			}
			else {
				int p=0;
				for(i=32;i>0;i--) {
					auto q=from[i][p];
					if(q.first) N|=1LL<<(i-1);
					p=q.second;
				}
				cout<<N<<endl;
				
				//cout<<(C^N)%N<<" "<<X<<endl;
				assert((C^N)%N==X);
			}
			
		}
			
	}
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

Submission Info

Submission Time
Task C - Mod of XOR
User kmjp
Language C++ 20 (gcc 12.2)
Score 700
Code Size 2261 Byte
Status AC
Exec Time 294 ms
Memory 3532 KiB

Compile Error

Main.cpp: In function ‘void solve()’:
Main.cpp:21:15: warning: unused variable ‘j’ [-Wunused-variable]
   21 |         int i,j,k,l,r,x,y; string s;
      |               ^
Main.cpp:21:17: warning: unused variable ‘k’ [-Wunused-variable]
   21 |         int i,j,k,l,r,x,y; string s;
      |                 ^
Main.cpp:21:19: warning: unused variable ‘l’ [-Wunused-variable]
   21 |         int i,j,k,l,r,x,y; string s;
      |                   ^
Main.cpp:21:21: warning: unused variable ‘r’ [-Wunused-variable]
   21 |         int i,j,k,l,r,x,y; string s;
      |                     ^
Main.cpp:21:23: warning: unused variable ‘x’ [-Wunused-variable]
   21 |         int i,j,k,l,r,x,y; string s;
      |                       ^
Main.cpp:21:25: warning: unused variable ‘y’ [-Wunused-variable]
   21 |         int i,j,k,l,r,x,y; string s;
      |                         ^
Main.cpp: In function ‘int main(int, char**)’:
Main.cpp:6:19: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
    6 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                   ^~~
Main.cpp:104:9: note: in expansion of macro ‘FOR’
  104 |         FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
      |         ^~~
Main.cpp:6:19: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
    6 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                   ^~~
Main.cpp:104:45: note: in expansion of macro ‘FOR’
  104 |         FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
      |                                             ^~~
Main.cpp:6:28: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
    6 | #define FOR(x,to) for(x=0;x<(to);x++)
      |                            ^
Main.cpp:104:45: note: in expansion of macro ‘FOR’
  104 |         FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
      |                                             ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 1
AC × 22
Set Name Test Cases
Sample 00_sample_00.txt
All 00_sample_00.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 01_handmade_04.txt, 01_handmade_05.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3412 KiB
01_handmade_00.txt AC 250 ms 3416 KiB
01_handmade_01.txt AC 219 ms 3416 KiB
01_handmade_02.txt AC 217 ms 3476 KiB
01_handmade_03.txt AC 221 ms 3420 KiB
01_handmade_04.txt AC 268 ms 3488 KiB
01_handmade_05.txt AC 241 ms 3384 KiB
02_random_00.txt AC 241 ms 3416 KiB
02_random_01.txt AC 241 ms 3476 KiB
02_random_02.txt AC 241 ms 3396 KiB
02_random_03.txt AC 240 ms 3440 KiB
02_random_04.txt AC 240 ms 3400 KiB
02_random_05.txt AC 262 ms 3384 KiB
02_random_06.txt AC 260 ms 3420 KiB
02_random_07.txt AC 261 ms 3400 KiB
02_random_08.txt AC 225 ms 3476 KiB
02_random_09.txt AC 222 ms 3468 KiB
02_random_10.txt AC 222 ms 3512 KiB
02_random_11.txt AC 290 ms 3412 KiB
02_random_12.txt AC 294 ms 3396 KiB
02_random_13.txt AC 294 ms 3532 KiB
02_random_14.txt AC 224 ms 3420 KiB