結果

問題 No.1384 Bishop and Rook
ユーザー okok
提出日時 2021-02-07 22:53:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 1,701 bytes
コンパイル時間 688 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-18 00:05:06
合計ジャッジ時間 7,181 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 81 ms
4,380 KB
testcase_02 AC 38 ms
4,376 KB
testcase_03 AC 16 ms
4,376 KB
testcase_04 AC 22 ms
4,376 KB
testcase_05 AC 56 ms
4,380 KB
testcase_06 AC 75 ms
4,380 KB
testcase_07 AC 88 ms
4,376 KB
testcase_08 AC 68 ms
4,380 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 47 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 3 ms
4,380 KB
testcase_14 AC 117 ms
4,380 KB
testcase_15 AC 3 ms
4,380 KB
testcase_16 AC 139 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 112 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 5 ms
4,376 KB
testcase_22 AC 5 ms
4,376 KB
testcase_23 AC 4 ms
4,376 KB
testcase_24 AC 5 ms
4,380 KB
testcase_25 AC 5 ms
4,380 KB
testcase_26 AC 5 ms
4,380 KB
testcase_27 AC 5 ms
4,376 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 5 ms
4,380 KB
testcase_30 AC 4 ms
4,380 KB
testcase_31 AC 4 ms
4,380 KB
testcase_32 AC 4 ms
4,376 KB
testcase_33 AC 5 ms
4,376 KB
testcase_34 AC 4 ms
4,380 KB
testcase_35 AC 4 ms
4,380 KB
testcase_36 AC 3 ms
4,376 KB
testcase_37 AC 3 ms
4,380 KB
testcase_38 AC 3 ms
4,376 KB
testcase_39 AC 3 ms
4,376 KB
testcase_40 AC 4 ms
4,380 KB
testcase_41 AC 15 ms
4,380 KB
testcase_42 AC 15 ms
4,376 KB
testcase_43 AC 17 ms
4,380 KB
testcase_44 AC 19 ms
4,376 KB
testcase_45 AC 19 ms
4,380 KB
testcase_46 AC 15 ms
4,376 KB
testcase_47 AC 17 ms
4,380 KB
testcase_48 AC 16 ms
4,376 KB
testcase_49 AC 10 ms
4,376 KB
testcase_50 AC 11 ms
4,376 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 142 ms
4,380 KB
testcase_53 AC 59 ms
4,380 KB
testcase_54 AC 2 ms
4,376 KB
testcase_55 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

int dy[] = {0, 0, 1, 1};
int dx[] = {0, 1, 0, 1};

#define x first
#define y second

void print(int ny, int nx, vector<int> v){
    // cout<<" <><><> "<<" "<<ny<<" "<<nx<<endl;
    for(int i = 0; i < v.size(); i++){
        cout<<ny+dy[v[i]]+1<<" "<<nx+dx[v[i]]+1<<endl;
        // cout<<dy[v[i]]<<" "<<dx[v[i]]<<" "<<v[i]<<endl;
    }
}

signed main(){
	cout<<fixed<<setprecision(10);
	
    int T;
    
    cin>>T;
	
	for(int _ = 0; _ < T; _++){
        int N, M;
        
        cin>>N>>M;
        
        if(N%2 || M%2) {
            if(N == 1 && M == 1) {
                cout<<0<<endl;
                cout<<1<<" "<<1<<endl;
            } else {
                cout<<-1<<endl;
            }
        } else {
            cout<<N * M -1<<endl;
            
            // cout<<2<<" "<<1<<endl;
            
            for(int i = 0; i < M; i += 4){
                
                print(0, i, {2, 1, 0, 3});
                
                for(int j = 2; j < N; j += 2){
                    print(j, i, {1, 2, 0, 3});
                }
                
                if(i + 2 >= M) break;
                for(int j = N-2; j >= 2; j -= 2){
                    print(j, i+2, {2, 1, 3, 0});
                }
                
                print(0, i+2, {2, 1, 0, 3});
            }
        }
    }
	
	return 0;
}
0