結果

問題 No.5002 stick xor
ユーザー 👑 emthrmemthrm
提出日時 2020-03-16 04:51:23
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 903 ms / 1,000 ms
コード長 3,349 bytes
コンパイル時間 2,183 ms
実行使用メモリ 7,424 KB
スコア 3,943
最終ジャッジ日時 2020-03-16 04:51:59
ジャッジサーバーID
(参考情報)
judge7 /
純コード判定しない問題か言語
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
IOSetup() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
}
} iosetup;
struct Timer {
Timer() { reset(); }
void reset() { beg = chrono::high_resolution_clock::now(); }
ll elapsed() {
chrono::high_resolution_clock::time_point en = chrono::high_resolution_clock::now();
return chrono::duration_cast<chrono::milliseconds>(en - beg).count();
}
private:
chrono::high_resolution_clock::time_point beg;
} timer;
struct Xor128 {
int rand() {
unsigned t = x ^ (x << 11);
x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8));
return static_cast<int>(w);
}
int rand(int ub) {
int res = rand() % ub;
return res < 0 ? res + ub : res;
}
int rand(int lb, int ub) { return lb + rand(ub - lb); }
ll randll() {
unsigned long long res = static_cast<unsigned long long>(rand()) << 32;
return static_cast<ll>(res | rand());
}
ll randll(ll ub) {
ll res = randll() % ub;
return res < 0 ? res + ub : res;
}
ll randll(ll lb, ll ub) { return lb + randll(ub - lb); }
private:
unsigned x = 123456789, y = 362436069, z = 521288629, w = static_cast<unsigned>(time(nullptr));
} xor128;
int main() {
int n, k; cin >> n >> k;
vector<int> l(k); REP(i, k) cin >> l[i];
vector<string> A(n); REP(i, n) cin >> A[i];
int w0 = 0;
REP(i, n) REP(j, n) w0 += A[i][j] == '0';
int score = -w0;
vector<int> a(k, 0), b(k, 0), c(k, 0), d(k);
REP(i, k) d[i] = l[i] - 1;
function<int(vector<int>&, vector<int>&, vector<int>&, vector<int>&)> calc = [&](vector<int> &ai, vector<int> &bi, vector<int> &ci, vector<int> &di
      ) {
vector<vector<bool> > grid(n, vector<bool>(n));
REP(i, n) REP(j, n) grid[i][j] = A[i][j] == '1';
REP(i, k) {
if (xor128.rand(2)) {
int y = xor128.rand(n - l[i] + 1), x = xor128.rand(n);
ai[i] = y;
bi[i] = x;
ci[i] = y + l[i] - 1;
di[i] = x;
FOR(j, y, y + l[i]) grid[j][x] = !grid[j][x];
} else {
int y = xor128.rand(n), x = xor128.rand(n - l[i] + 1);
ai[i] = y;
bi[i] = x;
ci[i] = y;
di[i] = x + l[i] - 1;
FOR(j, x, x + l[i]) grid[y][j] = !grid[y][j];
}
}
int res = -w0;
REP(i, n) REP(j, n) res += !grid[i][j];
return res;
};
while (timer.elapsed() < 900) {
vector<int> ai(k), bi(k), ci(k), di(k);
int now = calc(ai, bi, ci, di);
if (now > score) {
score = now;
a = ai;
b = bi;
c = ci;
d = di;
}
}
REP(i, k) cout << a[i] + 1 << ' ' << b[i] + 1 << ' ' << c[i] + 1 << ' ' << d[i] + 1 << '\n';
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0