結果
問題 |
No.2958 Placing Many L-s
|
ユーザー |
|
提出日時 | 2024-11-08 23:17:07 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,343 bytes |
コンパイル時間 | 2,135 ms |
コンパイル使用メモリ | 201,524 KB |
最終ジャッジ日時 | 2025-02-25 03:11:19 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 10 WA * 11 RE * 8 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--){ int N,M; cin >> N >> M; if(N%2 || M%2){cout << "-1\n"; continue;} if(N%4 && M%4) assert(false); //ずる. bool swapped = false; if(N%4) swap(N,M),swapped = true; vector<vector<int>> answer(N,vector<int>(M)); int idx = 1; for(int i=0; i<N; i+=4){ for(int k=0; k<M; k+=2){ answer.at(i).at(k) = idx; answer.at(i).at(k+1) = idx; answer.at(i+1).at(k) = idx+1; answer.at(i+1).at(k+1) = idx; answer.at(i+2).at(k) = idx+1; answer.at(i+2).at(k+1) = idx; answer.at(i+3).at(k) = idx+1; answer.at(i+3).at(k+1) = idx+1; idx += 2; } } if(swapped){ vector<vector<int>> answer2(M,vector<int>(N)); for(int i=0; i<N; i++) for(int k=0; k<M; k++) answer2.at(k).at(N-1-i) = answer.at(i).at(k); swap(answer,answer2); swap(N,M); } cout << N*M/4 << "\n"; for(int i=0; i<N; i++){ for(int k=0; k<M; k++){ if(k) cout << " "; cout << answer.at(i).at(k); } cout << "\n"; } } }