結果
| 問題 |
No.2824 Lights Up! (Grid Edition)
|
| コンテスト | |
| ユーザー |
FplusFplusF
|
| 提出日時 | 2024-07-23 23:36:39 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 325 ms / 2,000 ms |
| コード長 | 2,261 bytes |
| コンパイル時間 | 3,269 ms |
| コンパイル使用メモリ | 256,696 KB |
| 実行使用メモリ | 28,996 KB |
| 最終ジャッジ日時 | 2024-07-26 20:34:25 |
| 合計ジャッジ時間 | 14,191 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 100 |
ソースコード
#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;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n;
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;
}
}
if(n==1){
if(v[0][0]){
cout << "-1\n";
}else{
cout << "1\n";
cout << "0 0\n";
}
return 0;
}else if(n==2){
if((v[0][0]+v[0][1]+v[1][0]+v[1][1])==0){
cout << "0\n";
}else if((v[0][0]+v[0][1]+v[1][0]+v[1][1])==4){
cout << "1\n";
cout << "0 0\n";
}else{
cout << "-1\n";
}
return 0;
}
vector<vector<ll>> f(n,vector<ll>(n,0));
auto a=[&](ll r,ll c){
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;
};
auto b=[&](ll r,ll c){
a(r,c);
a(r,0);
a(0,c);
f[r][c]^=1;
};
replr(i,1,n){
replr(j,1,n){
if(!v[i-1][j-1]) continue;
b(i,j);
}
}
replr(i,1,n){
if(!v[i-1][0]) continue;
replr(j,1,n) b(i,j);
}
replr(j,1,n){
if(!v[0][j-1]) continue;
replr(i,1,n) b(i,j);
}
if(v[0][0]) b(0,0);
rep(i,n){
rep(j,n){
if(v[i][j]){
cout << "-1\n";
return 0;
}
}
}
vector<pll> ans;
rep(i,n){
rep(j,n){
if(f[i][j]) ans.emplace_back(i,j);
}
}
cout << len(ans) << '\n';
for(auto [l,r]:ans) cout << l << ' ' << r << '\n';
}
FplusFplusF