結果
問題 | No.5002 stick xor |
ユーザー | zenito9970 |
提出日時 | 2018-05-27 22:09:09 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 905 ms / 1,000 ms |
コード長 | 5,430 bytes |
コンパイル時間 | 32,955 ms |
実行使用メモリ | 1,620 KB |
スコア | 35,803 |
最終ジャッジ日時 | 2018-05-27 22:09:44 |
ジャッジサーバーID (参考情報) |
judge8 / |
純コード判定しない問題か言語 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 904 ms
1,616 KB |
testcase_01 | AC | 904 ms
1,616 KB |
testcase_02 | AC | 904 ms
1,616 KB |
testcase_03 | AC | 904 ms
1,616 KB |
testcase_04 | AC | 904 ms
1,612 KB |
testcase_05 | AC | 903 ms
1,620 KB |
testcase_06 | AC | 904 ms
1,612 KB |
testcase_07 | AC | 904 ms
1,612 KB |
testcase_08 | AC | 903 ms
1,616 KB |
testcase_09 | AC | 904 ms
1,612 KB |
testcase_10 | AC | 904 ms
1,612 KB |
testcase_11 | AC | 903 ms
1,616 KB |
testcase_12 | AC | 904 ms
1,616 KB |
testcase_13 | AC | 904 ms
1,612 KB |
testcase_14 | AC | 905 ms
1,616 KB |
testcase_15 | AC | 904 ms
1,612 KB |
testcase_16 | AC | 904 ms
1,616 KB |
testcase_17 | AC | 904 ms
1,616 KB |
testcase_18 | AC | 904 ms
1,612 KB |
testcase_19 | AC | 903 ms
1,616 KB |
testcase_20 | AC | 905 ms
1,616 KB |
testcase_21 | AC | 903 ms
1,616 KB |
testcase_22 | AC | 903 ms
1,612 KB |
testcase_23 | AC | 904 ms
1,616 KB |
testcase_24 | AC | 904 ms
1,620 KB |
testcase_25 | AC | 904 ms
1,616 KB |
testcase_26 | AC | 903 ms
1,616 KB |
testcase_27 | AC | 904 ms
1,616 KB |
testcase_28 | AC | 904 ms
1,616 KB |
testcase_29 | AC | 904 ms
1,612 KB |
testcase_30 | AC | 904 ms
1,616 KB |
testcase_31 | AC | 904 ms
1,612 KB |
ソースコード
#include <bits/stdc++.h> #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,n) FOR(i,0,n) #define repr(i,n) for(int i=(n)-1;0<=i;--i) #define each(e,v) for(auto&& e:(v)) #define all(v) begin(v),end(v) #define dump(x) cerr<<#x<<": "<<(x)<<endl using namespace std; using vint = vector<int>; using ll = long long; using vll = vector<ll>; template <class T> void chmin(T& a, const T& b) { a = min(a, b); } template <class T> void chmax(T& a, const T& b) { a = max(a, b); } #define imosPW(imos,x,y,l) do{\ (imos)[(y)][(x)]++; \ (imos)[(y)][(x)+(l)]--; \ (imos)[(y)+1][(x)]--; \ (imos)[(y)+1][(x)+(l)]++; } while(0) #define imosMW(imos,x,y,l) do{\ (imos)[(y)][(x)]--; \ (imos)[(y)][(x)+(l)]++; \ (imos)[(y)+1][(x)]++; \ (imos)[(y)+1][(x)+(l)]--; } while(0) #define imosPH(imos,x,y,l) do{\ (imos)[(y)][(x)]++; \ (imos)[(y)+(l)][(x)]--; \ (imos)[(y)][(x)+1]--; \ (imos)[(y)+(l)][(x)+1]++; } while(0) #define imosMH(imos,x,y,l) do{\ (imos)[(y)][(x)]--; \ (imos)[(y)+(l)][(x)]++; \ (imos)[(y)][(x)+1]++; \ (imos)[(y)+(l)][(x)+1]--; } while(0) namespace Timer { using namespace std::chrono; high_resolution_clock::time_point start_time; inline void init() { start_time = high_resolution_clock::now(); } inline int now() { auto now = high_resolution_clock::now(); auto t = now - start_time; return duration_cast<milliseconds>(t).count(); } inline bool check(int limit) { return now() < limit; } } struct Data { bool isH; int x, y; }; void output(int l, Data d) { int eX = d.isH ? d.x : (d.x + l - 1); int eY = d.isH ? (d.y + l - 1) : d.y; cout << d.y+1 << " " << d.x+1 << " " << eY+1 << " " << eX+1 << endl; } // vector<vint> imosX2grid(vector<vint> imos) { // const int n = imos.size(); // rep(y, n) rep(x, n-1) { // imos[y][x+1] += imos[y][x]; // } // return imos; // } // int calcScore(const vector<vint>& grid) { // const int n = grid.size(); // int cnt = 0; // rep(y, n) rep(x, n) if(grid[y][x] % 2 == 0) cnt++; // return cnt; // } int calcScore(const vector<vint>& A, vector<vint> imos) { const int n = A.size(); rep(y, n) rep(x, n) imos[y][x+1] += imos[y][x]; rep(x, n) rep(y, n) imos[y+1][x] += imos[y][x]; int cnt = 0; rep(y, n) rep(x, n) if((A[y][x] + imos[y][x]) % 2 == 0) cnt++; return cnt; } int main() { Timer::init(); int n, k; cin >> n >> k; vint L(k); rep(i, k) cin >> L[i]; vector<vint> A(n, vint(n)); rep(y, n) rep(x, n) { char c; cin >> c; A[y][x] = c == '1'; } vector<vint> imos(n+1, vint(n+1, 0)); int initialScore = calcScore(A, imos); dump(initialScore); cerr << "random" << endl; mt19937 mt(random_device{}()); vector<Data> data(k); rep(i, k) { data[i].isH = false; // data[i].x = 0; data[i].x = uniform_int_distribution<>(0, n - L[i])(mt); // data[i].y = 0; data[i].y = uniform_int_distribution<>(0, n-1)(mt); FOR(tx, data[i].x, data[i].x + L[i]) A[data[i].y][tx]++; } int cycle = 0, cntAccept = 0; int beforeScore = calcScore(A, imos); vector<Data> bestData = data; cerr << "while" << endl; /* rep(ck, k) { /*/ while(Timer::check(900)) { cycle++; const int ck = cycle % k; //*/ const int l = L[ck]; int bestScore = -1e9; int bestX = data[ck].x, bestY = data[ck].y; bool bestR = data[ck].isH; if(bestR) FOR(ty, bestY, bestY + l) A[ty][bestX]--; else FOR(tx, bestX, bestX + l) A[bestY][tx]--; int bestDscore = 0; rep(y, n) { rep(x, n - l) { int dscore = 0; if(A[y][x] % 2 == 0) continue; FOR(tx, x, x + l) { A[y][tx]++; if(A[y][tx] % 2 == 0) dscore++; else dscore--; } if(bestDscore < dscore) { bestDscore = dscore; bestX = x; bestY = y; bestR = false; } FOR(tx, x, x + l) A[y][tx]--; } } rep(y, n - l) { rep(x, n) { int dscore = 0; if(A[y][x] % 2 == 0) continue; FOR(ty, y, y + l) { A[ty][x]++; if(A[ty][x] % 2 == 0) dscore++; else dscore--; } if(bestDscore < dscore) { bestDscore = dscore; bestX = x; bestY = y; bestR = true; } FOR(ty, y, y + l) A[ty][x]--; } } // dump(ck); dump(bestX); dump(bestY); if(bestR) FOR(ty, bestY, bestY + l) A[ty][bestX]++; else FOR(tx, bestX, bestX + l) A[bestY][tx]++; data[ck].x = bestX; data[ck].y = bestY; data[ck].isH = bestR; } bestData = data; cerr << "output" << endl; rep(i, k) output(L[i], bestData[i]); int lastScore = [&]() { int score = 0; rep(y, n) rep(x, n) if(A[y][x] % 2 == 0) score++; return score; }(); dump(cycle); dump(cntAccept); cerr << "score: " << (lastScore - initialScore) << endl; dump(Timer::now()); return 0; }