1147B - Chladni Figure - CodeForces Solution


brute force strings *1900

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <sstream>
#include <assert.h>

using namespace std;
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define debug(a) cout<<#a<<"="<<a<<endl
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef pair<int,int> PII;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll qmi(ll a,ll k,ll p){ll res=1%p;a%=p;while(k){if(k&1)res=res*a%p;k>>=1;a=a*a%p;}return res;}

const int N = 2e5+10;

PII a[N];

int main()
{
	IOS;
	int n,m;
	cin >> n >> m;
	int h1 = 0;
	rep(i,1,m){
		int x,y;
		cin >> x >> y;
		a[i] = {x%n,y%n};
		if(a[i].fi > a[i].se)
			swap(a[i].fi,a[i].se);
		h1 ^= a[i].first*100000+a[i].second;
	}
	
	for(int i=1;i*i<=n;i++){
		if(n%i == 0){
			int h2=0;
			rep(j,1,m){
				if((a[j].first+i)%n > (a[j].second+i)%n)
					swap(a[j].fi,a[j].se);
				h2 ^= (a[j].fi+i)%n*100000+(a[j].se+i)%n;
			}
			if(h2 == h1){
				cout << "YES" << endl;
				return 0; 
			}
			if(i != n/i && i!=1){
				h2 = 0;
				rep(j,1,m){
					if((a[j].first+n/i)%n > (a[j].second+n/i)%n)
						swap(a[j].fi,a[j].se);
					h2 ^= (a[j].fi+n/i)%n*100000+(a[j].se+n/i)%n;
				}
				if(h2 == h1){
					cout << "YES" << endl;
					return 0; 
				}
			}
		}
	}
	cout << "NO" << endl;
	
	return 0;
}

	  	 						 	 	    	      		  	


Comments

Submit
0 Comments
More Questions

80A - Panoramix's Prediction
1354B - Ternary String
122B - Lucky Substring
266B - Queue at the School
1490A - Dense Array
1650B - DIV + MOD
1549B - Gregor and the Pawn Game
553A - Kyoya and Colored Balls
1364A - XXXXX
1499B - Binary Removals
1569C - Jury Meeting
108A - Palindromic Times
46A - Ball Game
114A - Cifera
776A - A Serial Killer
25B - Phone numbers
1633C - Kill the Monster
1611A - Make Even
1030B - Vasya and Cornfield
1631A - Min Max Swap
1296B - Food Buying
133A - HQ9+
1650D - Twist the Permutation
1209A - Paint the Numbers
1234A - Equalize Prices Again
1613A - Long Comparison
1624B - Make AP
660B - Seating On Bus
405A - Gravity Flip
499B - Lecture