Submission #19016702


Source Code Expand

Copy
#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 N;
int X[101010],Y[101010];

set<int> R[6],C[6];
int A[6];

void GoR(int id,int num) {
	if(R[id].count(num)) {
		R[id].erase(num);
	}
	else {
		R[id].insert(num);
	}
}
void GoC(int id,int num) {
	if(C[id].count(num)) {
		C[id].erase(num);
	}
	else {
		C[id].insert(num);
	}
}
void GoA(int id) {
	A[id]^=1;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>X[i]>>Y[i];
		X[i]--,Y[i]--;
		int id=(X[i]%2)*3+Y[i]%3;
		X[i]/=2;
		Y[i]/=3;
		if(X[i]==0&&Y[i]==0) {
			GoA(id);
		}
		else if(Y[i]==0) {
			GoR(id,X[i]);
		}
		else if(X[i]==0) {
			GoC(id,Y[i]);
		}
		else {
			GoR(id,X[i]);
			GoC(id,Y[i]);
			GoA(id);
		}
	}
	
	FOR(i,3) {
		vector<int> D;
		FORR(r,C[i]) if(C[i+3].count(r)) D.push_back(r);
		FORR(d,D) {
			A[i]^=1;
			A[i+3]^=1;
			C[i].erase(d);
			C[i+3].erase(d);
		}
	}
	FOR(i,6) {
		x=i/3*3;
		vector<int> D;
		FORR(r,R[i]) {
			y=R[x].count(r)+R[x+1].count(r)+R[x+2].count(r);
			if(y>=2) D.push_back(r);
		}
		FORR(d,D) {
			A[x]^=1;
			A[x+1]^=1;
			A[x+2]^=1;
			GoR(x,d);
			GoR(x+1,d);
			GoR(x+2,d);
		}
		
	}
	
	
	int ret=0;
	FOR(i,6) {
		x=R[i].size();
		y=C[i].size();
		r=A[i];
		/*
		cout<<i<<x<<y<<" ";
		FORR(r,R[i]) cout<<r;
		cout<<":";
		FORR(r,C[i]) cout<<r;
		cout<<":";
		cout<<r<<endl;
		*/
		k=min(x,y);
		ret+=k;
		x-=k;
		y-=k;
		r^=k%2;
		ret+=x+y;
	}
	x=0;
	FOR(i,6) x+=A[i];
	ret+=min(x,6-x);
	
	
	cout<<ret<<endl;
	
}


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 - Flipper
User kmjp
Language C++ (GCC 9.2.1)
Score 0
Code Size 2331 Byte
Status WA
Exec Time 103 ms
Memory 9596 KB

Compile Error

./Main.cpp: In function ‘void solve()’:
./Main.cpp:43:8: warning: unused variable ‘j’ [-Wunused-variable]
   43 |  int i,j,k,l,r,x,y; string s;
      |        ^
./Main.cpp:43:12: warning: unused variable ‘l’ [-Wunused-variable]
   43 |  int i,j,k,l,r,x,y; string s;
      |            ^
./Main.cpp: In function ‘int main(int, char**)’:
./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:130:38: note: in expansion of macro ‘FOR’
  130 |  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 0 / 1300
Status
AC × 1
AC × 7
WA × 51
Set Name Test Cases
Sample example0.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, 050.txt, 051.txt, 052.txt, 053.txt, 054.txt, 055.txt, 056.txt, example0.txt
Case Name Status Exec Time Memory
000.txt WA 60 ms 5764 KB
001.txt AC 2 ms 3504 KB
002.txt WA 38 ms 4936 KB
003.txt WA 79 ms 6640 KB
004.txt WA 49 ms 5928 KB
005.txt WA 25 ms 4700 KB
006.txt WA 72 ms 7224 KB
007.txt WA 53 ms 6060 KB
008.txt WA 54 ms 6528 KB
009.txt WA 86 ms 8016 KB
010.txt WA 42 ms 5500 KB
011.txt WA 103 ms 9596 KB
012.txt WA 17 ms 4260 KB
013.txt WA 43 ms 5724 KB
014.txt WA 17 ms 4424 KB
015.txt WA 72 ms 6884 KB
016.txt WA 65 ms 6504 KB
017.txt WA 3 ms 3768 KB
018.txt WA 14 ms 3804 KB
019.txt AC 25 ms 4548 KB
020.txt WA 43 ms 5824 KB
021.txt WA 26 ms 4812 KB
022.txt AC 41 ms 5552 KB
023.txt AC 20 ms 4168 KB
024.txt WA 44 ms 5988 KB
025.txt AC 2 ms 3532 KB
026.txt WA 29 ms 4100 KB
027.txt WA 28 ms 4092 KB
028.txt WA 28 ms 3904 KB
029.txt AC 30 ms 4056 KB
030.txt WA 29 ms 4000 KB
031.txt WA 23 ms 4064 KB
032.txt WA 63 ms 8980 KB
033.txt WA 60 ms 9060 KB
034.txt WA 63 ms 9064 KB
035.txt WA 68 ms 9048 KB
036.txt WA 64 ms 9064 KB
037.txt WA 62 ms 9092 KB
038.txt WA 63 ms 9056 KB
039.txt WA 68 ms 9096 KB
040.txt WA 58 ms 8992 KB
041.txt WA 65 ms 9064 KB
042.txt WA 63 ms 9052 KB
043.txt WA 59 ms 8980 KB
044.txt WA 62 ms 9104 KB
045.txt WA 63 ms 8988 KB
046.txt WA 63 ms 9100 KB
047.txt WA 64 ms 8980 KB
048.txt WA 62 ms 8980 KB
049.txt WA 60 ms 9128 KB
050.txt WA 65 ms 9096 KB
051.txt WA 62 ms 9048 KB
052.txt WA 63 ms 9064 KB
053.txt WA 65 ms 8980 KB
054.txt WA 66 ms 9088 KB
055.txt WA 64 ms 9100 KB
056.txt WA 59 ms 9096 KB
example0.txt AC 2 ms 3628 KB