結果
問題 | No.2824 Lights Up! (Grid Edition) |
ユーザー |
![]() |
提出日時 | 2024-07-22 21:10:19 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,644 bytes |
コンパイル時間 | 3,710 ms |
コンパイル使用メモリ | 263,516 KB |
実行使用メモリ | 11,648 KB |
最終ジャッジ日時 | 2024-07-26 20:36:31 |
合計ジャッジ時間 | 143,868 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 3 |
other | AC * 62 WA * 38 |
ソースコード
#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; } } bitset<1000> v[1000]; ll n; inline void a(ll r,ll c){ v[r][c].flip(); v[r][(c-1+n)%n].flip(); v[(r-1+n)%n][c].flip(); v[(r-1+n)%n][(c-1+n)%n].flip(); } inline void b(ll r,ll c){ a(r,c); a(r,0); a(0,c); } inline void sa(ll r,ll c,set<pll> &st){ st.insert({r,c}); st.insert({(r-1+n)%n,c}); st.insert({r,(c-1+n)%n}); st.insert({(r-1+n)%n,(c-1+n)%n}); } inline int sb(ll r,ll c){ set<pll> st; sa(r,c,st); sa(r,0,st); sa(0,c,st); ll ret=0; for(auto [i,j]:st) ret+=v[i][j]; return ret; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; ll pre_score=0; rep(i,n){ rep(j,n){ char c; cin >> c; if(c=='#'){ v[i][j]=1; pre_score++; } } } vector<vector<ll>> f(n,vector<ll>(n,0)); mt19937 mt; while(true){ ll ms=timer::get(); if(1900<=ms) break; ll i=mt()%n,j=mt()%n; f[i][j]^=1; ll x=sb(i,j); b(i,j); ll y=sb(i,j); ll new_score=pre_score-x+y; double temp=4.0+(0.1-4.0)*(double)ms/1900.0; double prob=exp((double)(pre_score-new_score)/temp); if(1.0*mt()/mt19937::max()<prob){ pre_score=new_score; }else{ f[i][j]^=1; b(i,j); } if(pre_score==0) break; } if(pre_score!=0){ cout << "-1\n"; }else{ 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+1 << ' ' << j+1 << '\n'; } exit(0); } }