結果
問題 | No.1384 Bishop and Rook |
ユーザー |
![]() |
提出日時 | 2021-02-07 21:42:34 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,607 ms / 2,000 ms |
コード長 | 2,208 bytes |
コンパイル時間 | 3,364 ms |
コンパイル使用メモリ | 198,488 KB |
最終ジャッジ日時 | 2025-01-18 14:39:41 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 55 |
ソースコード
#include <stdio.h> #include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000001 int N,M; vector<pair<int,int>> ans; /* void go_r(){ int y,x,yy; if(ans.back().first!=N){ y = ans.back().first+1; } else{ y = ans.back().first-1; } yy = ans.back().first; x = ans.back().second+1; ans.emplace_back(y,x); ans.emplace_back(yy,x); } void go_l(){ int y,x,yy; if(ans.back().first!=N){ y = ans.back().first+1; } else{ y = ans.back().first-1; } yy = ans.back().first; x = ans.back().second-1; ans.emplace_back(y,x); ans.emplace_back(yy,x); } void go_d(){ int y,x,yy,xx; if(ans.back().second!=M){ x = ans.back().second+1; } else{ x = ans.back().second-1; } xx = ans.back().second; y = ans.back().first+1; ans.emplace_back(y,x); ans.emplace_back(y,xx); } */ int main(){ int T; cin>>T; rep(_,T){ cin>>N>>M; ans.resize(0); if(N==1&&M==1){ ans.emplace_back(1,1); } if(N%2==0&&M%2==0){ ans.emplace_back(1,1); rep(i,N/2){ rep(j,(M/2)){ int y = ans.back().first,x = ans.back().second; if(i%2==0){ if(j!=((M/2)-1)){ ans.emplace_back(y+1,x+1); ans.emplace_back(y+1,x); ans.emplace_back(y,x+1); ans.emplace_back(y,x+2); } else{ ans.emplace_back(y+1,x+1); ans.emplace_back(y,x+1); ans.emplace_back(y+1,x); if(i!=(N/2)-1)ans.emplace_back(y+2,x); } } else{ if(j!=0){ ans.emplace_back(y-1,x-1); ans.emplace_back(y-1,x); ans.emplace_back(y,x-1); } else{ ans.emplace_back(y+1,x+1); ans.emplace_back(y,x+1); ans.emplace_back(y+1,x); } y = ans.back().first,x = ans.back().second; if(j!=((M/2)-1)){ ans.emplace_back(y,x-1); } else{ if(i!=(N/2)-1){ ans.emplace_back(y+1,x); } } } } } } if(ans.size()==0){ cout<<-1<<endl; continue; } cout<<ans.size()-1<<endl; cout<<ans[0].first<<' '<<ans[0].second<<endl; rep(i,ans.size()){ if(i==0)continue; cout<<ans[i].first<<' '<<ans[i].second<<endl; } } return 0; }