Submission #667817

# Submission time Handle Problem Language Result Execution time Memory
667817 2022-12-02T05:58:28 Z Kaztaev_Alisher Chessboard (IZhO18_chessboard) C++17
0 / 100
470 ms 1320 KB
//#pragma GCC optomize ("Ofast")
//#pragma GCC optomize ("unroll-loops")
//#pragma GCC target ("avx,avx2,fma")

#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define sz size
#define cl clear
#define ins insert
#define ers erase
#define pii pair < int , int >
#define pll pair< long long  , long long >
#define all(x) x.begin() , x.end()
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define tostr(x) to_string(x)
#define tonum(s) atoi(s.c_str())
#define seon(x) setprecision(x)
#define bpop(x) __builtin_popcount(x)
#define deb(x) cerr << #x  << " = " << x << endl;
#define int ll

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
const double PI = 3.14159265;

const ll N = 1e6+5;
const ll mod = 1e9+7;
const ll inf = 1e9;
const ll INF = 1e18;

using namespace std;

int n;
bool u[N];
vector<int> v;
int cnt1[N] , cnt11[N];
void solve(){
	ll k;
	cin >> n >> k;
	ll mn = INF;
	for(int i = 1; i <= sqrtl(n); i++) {
		v.pb(i); 
		if(i > 1) v.pb(n/i);
	}
	for(int i = 1; i <= k; i++){
		int x , y , x1 , y1;
		cin >> x >> y >> x1 >> y1;
		x--;
		y--;
		for(int i = 0; i < v.sz(); i++){
			if((x/v[i])%2 == (y/v[i])%2) cnt1[i]++;
			else cnt11[i]++;
		}		
	}
	for(int i = 0; i < v.sz(); i++){
		ll ob = (n*n)/(v[i]*v[i]);
		mn = min(mn , (ob+1)/2*v[i]*v[i] - cnt1[i] + cnt11[i]);
		mn = min(mn , ob/2*v[i]*v[i] - cnt11[i] + cnt1[i]);
	}
	cout << mn <<"\n";
}
signed main(){
	ios;
	u[1] = 1;
	for(int i = 2; i <= N-5; i++){
		if(u[i] == 1) continue;
		for(ll j = i*i; j <= N-5; j+=i) u[j] = 1;
	}
	solve();
	return 0;
}
/*
6 8
3 3 3 3
1 2 1 2
3 4 3 4
5 5 5 5
4 3 4 3
4 4 4 4
2 1 2 1
3 6 3 6
*/

Compilation message

chessboard.cpp: In function 'void solve()':
chessboard.cpp:55:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |   for(int i = 0; i < v.sz(); i++){
      |                  ~~^~~~~~~~
chessboard.cpp:60:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |  for(int i = 0; i < v.sz(); i++){
      |                 ~~^~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1236 KB Output is correct
2 Incorrect 3 ms 1236 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 470 ms 1320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1236 KB Output is correct
2 Correct 3 ms 1236 KB Output is correct
3 Incorrect 3 ms 1236 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1236 KB Output is correct
2 Correct 3 ms 1236 KB Output is correct
3 Incorrect 3 ms 1236 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 470 ms 1320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1236 KB Output is correct
2 Incorrect 3 ms 1236 KB Output isn't correct
3 Halted 0 ms 0 KB -