Codeforces Round #382 (Div. 1), problem: (D) Permutations Solution in C/C++

#include <bits/stdc++.h>
using namespace std; 

const int N=2e3+1;

int n,m,x[N*N],y[N*N];
bitset<N*2> a[N];

int main() {
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++) {
		scanf("%d%d",x+i,y+i);
		x[i]--; y[i]--;
		a[x[i]].set(y[i]);
	} 
	for(int i=0;i<n;i++) a[i][i+n]=1;
	for(int i=0;i<n;i++) {
		for(int j=i;j<n;j++) {
			if(a[j][i]) {
				swap(a[j],a[i]);
				break;
			}
		}
		for(int j=0;j<n;j++) {
			if(j!=i&&a[j][i]) a[j]^=a[i];
		}
	}
	for(int i=1;i<=m;i++) {
		if(a[y[i]][n+x[i]]) puts("NO");
		else puts("YES");		
	}
}
#include <bits/stdc++.h>
using namespace std; 

const int N=2e3+1;

int n,m,x[N*N],y[N*N];
bitset<N*2> a[N];

int main() {
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++) {
		scanf("%d%d",x+i,y+i);
		x[i]--; y[i]--;
		a[x[i]].set(y[i]);
	} 
	for(int i=0;i<n;i++) a[i][i+n]=1;
	for(int i=0;i<n;i++) {
		for(int j=i;j<n;j++) {
			if(a[j][i]) {
				swap(a[j],a[i]);
				break;
			}
		}
		for(int j=0;j<n;j++) {
			if(j!=i&&a[j][i]) a[j]^=a[i];
		}
	}
	for(int i=1;i<=m;i++) {
		if(a[y[i]][n+x[i]]) puts("NO");
		else puts("YES");		
	}
}

More from author

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related posts

Advertismentspot_img

Latest posts

LoanDepot Q2 Revenue Jumps 18% on Home Equity Expansion

Mortgage lender LoanDepot has reported a strong financial turnaround for the second quarter, largely fueled by its aggressive and strategic expansion into home equity...

I Tried Phone Stand For Desk For 30 Days Here Is the Honest Truth

📢 As an Amazon Associate, I earn from qualifying purchases. If you had told me six months ago that a single purchase would change how...

Stop Buying Cheap Alternatives This Wireless Earbuds Accessories Is the Real Deal

📢 As an Amazon Associate, I earn from qualifying purchases. I stumbled across this while desperately trying to fix a recurring problem in my routine....

Want to stay up to date with the latest news?

We would love to hear from you! Please fill in your details and we will stay in touch. It's that simple!