結果
問題 |
No.2824 Lights Up! (Grid Edition)
|
ユーザー |
![]() |
提出日時 | 2024-07-23 16:32:06 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,546 bytes |
コンパイル時間 | 3,338 ms |
コンパイル使用メモリ | 261,484 KB |
実行使用メモリ | 34,784 KB |
最終ジャッジ日時 | 2024-07-26 20:34:10 |
合計ジャッジ時間 | 141,885 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 84 WA * 14 TLE * 2 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; using tll=tuple<ll,ll,ll>; using ld=long double; const ll INF=(1ll<<60); #define rep(i,n) for (ll i=0;i<(ll)(n);i++) #define replr(i,l,r) for (ll i=(ll)(l);i<(ll)(r);i++) #define all(v) v.begin(),v.end() #define len(v) ((ll)v.size()) template<class T> inline bool chmin(T &a,T b){ if(a>b){ a=b; return true; } return false; } template<class T> inline bool chmax(T &a,T b){ if(a<b){ a=b; return true; } return false; } namespace timer{ auto start=chrono::system_clock::now(); void snap(){ start=chrono::system_clock::now(); } int get(){ auto now=chrono::system_clock::now(); int ms=chrono::duration_cast<chrono::milliseconds>(now-start).count(); return ms; } } ll n; void a(ll r,ll c,vector<vector<ll>> &v){ v[r][c]^=1; v[r][(c-1+n)%n]^=1; v[(r-1+n)%n][c]^=1; v[(r-1+n)%n][(c-1+n)%n]^=1; } void b(ll r,ll c,vector<vector<ll>> &v){ a(r,c,v); a(r,0,v); a(0,c,v); } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; vector<vector<ll>> v(n,vector<ll>(n,0)); rep(i,n){ rep(j,n){ char c; cin >> c; if(c=='#') v[i][j]=1; } } vector<vector<ll>> hv=v; vector<ll> ord(n*n); rep(i,n*n) ord[i]=i; mt19937 mt; while(true){ int ms=timer::get(); if(1900<=ms) break; shuffle(all(ord),mt); vector<vector<ll>> f(n,vector<ll>(n,0)); v=hv; while(true){ int ms2=timer::get(); if(1900<=ms2) break; bool ok=true,br=false; for(auto ij:ord){ ll i=ij/n,j=ij%n; if(v[i][j]){ if(f[i][j]){ br=true; break; } f[i][j]^=1; b(i,j,v); ok=false; } } if(br) break; if(ok){ vector<pll> ans; rep(i,n){ rep(j,n){ if(f[i][j]) ans.emplace_back(i,j); } } cout << len(ans) << '\n'; for(auto [i,j]:ans){ cout << i << ' ' << j << '\n'; } exit(0); } } } cout << "-1\n"; }