結果
| 問題 |
No.2432 Flip and Move
|
| コンテスト | |
| ユーザー |
momoyuu
|
| 提出日時 | 2023-08-18 22:10:20 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,058 bytes |
| コンパイル時間 | 3,410 ms |
| コンパイル使用メモリ | 262,672 KB |
| 実行使用メモリ | 321,424 KB |
| 最終ジャッジ日時 | 2024-11-28 07:34:53 |
| 合計ジャッジ時間 | 100,762 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 5 TLE * 31 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ll h,w;
cin>>h>>w;
ll k;
cin>>k;
vector<vector<vector<int>>> vis(4,vector<vector<int>>(h,vector<int>(w,-1)));
int now = 0;
vector<vector<int>> ans(h,vector<int>(w,0));
int ni = 0;
int nj = 0;
int dx = 1;
int dy = 1;
stack<pair<int,pair<int,int>>> st;
st.push(make_pair(0,make_pair(0,0)));
vis[0][0][0] = 0;
bool fn = false;
while(true){
if(now==k) break;
ans[ni][nj] ^= 1;
int nni = ni + dx;
if(nni<0||nni>=h){
nni = ni;
dx *= -1;
}
int nnj = nj + dy;
if(nnj<0||nnj>=w){
nnj = nj;
dy *= -1;
}
ni = nni;
nj = nnj;
now++;
int mask = 0;
if(dx==-1) mask += 1;
if(dy==-1) mask += 2;
if(vis[mask][nni][nnj]==-1){
vis[mask][nni][nnj] = now;
st.push(make_pair(mask,make_pair(nni,nnj)));
continue;
}
if(fn) continue;
stack<pair<int,int>> nxt;
ll cnt = 0;
pair<int,pair<int,int>> want = make_pair(mask,make_pair(nni,nnj));
while(true){
if(st.top()==want){
cnt++;
nxt.push(make_pair(nni,nnj));
break;
}
int nx = st.top().second.first;
int ny = st.top().second.second;
cnt++;
nxt.push(make_pair(nx,ny));
st.pop();
continue;
}
fn = true;
ll res = k - now;
ll can = res / cnt;
if(can%2==1){
while(nxt.size()){
int ni = nxt.top().first;
int nj = nxt.top().second;
ans[ni][nj] ^= 1;
nxt.pop();
}
}
now += can * cnt;
}
for(int i = 0;i<h;i++){
for(int j = 0;j<w;j++){
if(ans[i][j]==0) cout<<".";
else cout<<"#";
}
cout<<endl;
}
}
momoyuu