結果
| 問題 |
No.2112 All 2x2 are Equal
|
| コンテスト | |
| ユーザー |
FplusFplusF
|
| 提出日時 | 2022-10-28 22:41:10 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,082 bytes |
| コンパイル時間 | 2,198 ms |
| コンパイル使用メモリ | 208,764 KB |
| 最終ジャッジ日時 | 2025-02-08 14:49:10 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | WA * 34 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (long long i=0;i<(long long)(n);i++)
#define all(v) v.begin(),v.end()
using ll=long long;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll,ll>;
const ll INF=(1ll<<60);
template<class T> void chmin(T &a,T b){
if(a>b){
a=b;
}
}
template<class T> void chmax(T &a,T b){
if(a<b){
a=b;
}
}
int main(){
double start=clock();
srand((unsigned int)time(NULL));
mt19937 mt(rand());
ll h,w;
cin >> h >> w;
set<ll> st;
rep(i,h*w) st.insert(i+1);
while(true){
double now=clock();
if(1.6<(now-start)/CLOCKS_PER_SEC){
cout << "No" << endl;
return 0;
}
vector<vector<ll>> ans(h,vector<ll>(w,-1));
ll s=0;
rep(i,2){
rep(j,2){
ll k=mt()%(*rbegin(st));
ans[i][j]=*st.upper_bound(k);
st.erase(ans[i][j]);
s+=ans[i][j];
}
}
for(ll j=2;j<w;j++){
ll k=mt()%(*rbegin(st));
ans[0][j]=*st.upper_bound(k);
st.erase(ans[0][j]);
}
for(ll i=2;i<h;i++){
ll k=mt()%(*rbegin(st));
ans[i][0]=*st.upper_bound(k);
st.erase(ans[i][0]);
}
bool b=false;
for(ll i=1;i<h;i++){
for(ll j=1;j<w;j++){
if(i==1&&j==1) continue;
ll x=s-(ans[i-1][j-1]+ans[i-1][j]+ans[i][j-1]);
if(st.count(x)){
ans[i][j]=x;
st.erase(x);
}else{
b=true;
break;
}
}
if(b) break;
}
if(b){
set<ll> st2;
rep(i,h*w) st2.insert(i+1);
swap(st,st2);
}else{
cout << "Yes" << endl;
rep(i,h){
rep(j,w){
cout << ans[i][j] << " ";
}
cout << endl;
}
return 0;
}
}
}
FplusFplusF