제출 #54094

#제출 시각아이디문제언어결과실행 시간메모리
54094egorlifarChessboard (IZhO18_chessboard)C++17
39 / 100
138 ms17564 KiB
/* ЗАПУСКАЕМ ░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░ ▄███▀░◐░░░▌░░░░░░░ ░░░░▌░░░░░▐░░░░░░░ ░░░░▐░░░░░▐░░░░░░░ ░░░░▌░░░░░▐▄▄░░░░░ ░░░░▌░░░░▄▀▒▒▀▀▀▀▄ ░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄ ░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄ ░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄ ░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄ ░░░░░░░░░░░▌▌░▌▌░░░░░ ░░░░░░░░░░░▌▌░▌▌░░░░░ ░░░░░░░░░▄▄▌▌▄▌▌░░░░░ */ #include <iostream> #include <complex> #include <vector> #include <string> #include <algorithm> #include <cstdio> #include <numeric> #include <cstring> #include <ctime> #include <cstdlib> #include <set> #include <map> #include <unordered_map> #include <unordered_set> #include <list> #include <cmath> #include <bitset> #include <cassert> #include <queue> #include <stack> #include <iomanip> #include <deque> using namespace std; template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; } template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; } template<typename T, typename U> inline ostream &operator<< (ostream &_out, const pair<T, U> &_p) { _out << _p.first << ' ' << _p.second; return _out; } template<typename T, typename U> inline istream &operator>> (istream &_in, pair<T, U> &_p) { _in >> _p.first >> _p.second; return _in; } template<typename T> inline ostream &operator<< (ostream &_out, const vector<T> &_v) { if (_v.empty()) { return _out; } _out << _v.front(); for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { _out << ' ' << *_it; } return _out; } template<typename T> inline istream &operator>> (istream &_in, vector<T> &_v) { for (auto &_i : _v) { _in >> _i; } return _in; } template<typename T> inline ostream &operator<< (ostream &_out, const set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; } template<typename T> inline ostream &operator<< (ostream &_out, const multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; } template<typename T> inline ostream &operator<< (ostream &_out, const unordered_set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; } template<typename T> inline ostream &operator<< (ostream &_out, const unordered_multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; } template<typename T, typename U> inline ostream &operator<< (ostream &_out, const map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; } template<typename T, typename U> inline ostream &operator<< (ostream &_out, const unordered_map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; } #define sz(c) (int)(c).size() #define all(c) (c).begin(), (c).end() #define rall(c) (c).rbegin(), (c).rend() #define left left228 #define right right228 #define next next228 #define rank rank228 #define prev prev228 #define y1 y1228 #define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin) #define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout) #define files(FILENAME) read(FILENAME), write(FILENAME) #define pb push_back #define x first #define y second const string FILENAME = "input"; const int MAXN = 100228; //11:50 //16:50 int n, k; int x1[MAXN], y1[MAXN], x2[MAXN], y2[MAXN]; long long ans = 1e18; long long get(int t, int posx, int len, int yl, int yr, int x) { long long res = 0; int ly = yl / x; int ry = yr / x; if (ly == ry) { if ((ly + posx) % 2 == t) { res += 1LL * len * (yr - yl + 1); } else { res -= 1LL * len * (yr - yl + 1); } } else { if (yl % x != 0) { if ((posx + ly) % 2 == t) { res += 1LL * len * (x - yl % x); } else { res -= 1LL * len * (x - yl % x); } ly++; } if (yr % x != x - 1) { if ((posx + ry) % 2 == t) { res += 1LL * len * (yr % x + 1); } else { res -= 1LL * len * (yr % x + 1); } ry--; } if (ly <= ry) { if ((posx + ly) % 2 == t) { if ((ry - ly + 1) % 2) { res += 1LL * len * x; } } else { if ((ry - ly + 1) % 2) { res -= 1LL * len * x; } } } } return res; } long long check(int t, int x) { long long res = 0; if (t == 1) { res += 1LL * ((n / x) * (n / x) + 1) / 2 * x * x; } else { res += 1LL * ((n / x) * (n / x) ) / 2 * x * x; } // cout << res << endl; for (int i = 0; i < k; i++) { int lx = x1[i] / x; int rx = x2[i] / x; int ly = y1[i] / x; int ry = y2[i] / x; if (lx == rx) { res += get(t, lx, x2[i] - x1[i] + 1, y1[i], y2[i], x); continue; } if (x1[i] % x != 0) { res += get(t, lx, x - x1[i] % x, y1[i], y2[i], x); lx++; } if (x2[i] % x != x - 1) { res += get(t, rx, x2[i] % x + 1, y1[i], y2[i], x); rx--; } if (lx <= rx) { if ((rx - lx + 1) % 2 == 1) { res += get(t, lx, x, y1[i], y2[i], x); } } } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); //read(FILENAME); cin >> n >> k; for (int i = 0; i < k; i++) { cin >> x1[i] >> y1[i] >> x2[i] >> y2[i]; x1[i]--; y1[i]--; x2[i]--; y2[i]--; } for (int i = 1; i < n; i++) { if (n % i == 0) { chkmin(ans, check(0, i)); chkmin(ans, check(1, i)); } } cout << ans << '\n'; }

컴파일 시 표준 에러 (stderr) 메시지

chessboard.cpp: In function 'long long int check(int, int)':
chessboard.cpp:133:13: warning: unused variable 'ly' [-Wunused-variable]
         int ly = y1[i] / x;
             ^~
chessboard.cpp:134:13: warning: unused variable 'ry' [-Wunused-variable]
         int ry = y2[i] / x;
             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...