結果
| 問題 | 
                            No.1981 [Cherry 4th Tune N] アルゴリズムが破滅する例
                             | 
                    
| コンテスト | |
| ユーザー | 
                             Nachia
                         | 
                    
| 提出日時 | 2024-04-18 02:40:04 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 33 ms / 2,000 ms | 
| コード長 | 816 bytes | 
| コンパイル時間 | 746 ms | 
| コンパイル使用メモリ | 76,768 KB | 
| 最終ジャッジ日時 | 2025-02-21 02:56:26 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 49 | 
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int N; cin >> N;
    int K; cin >> K;
    if(N > K*2){ cout << "-1\n"; return 0; }
    vector<pair<int,int>> ans;
    while(N){
        if(N != K){
            ans.push_back(make_pair(N-1, N-1));
            ans.push_back(make_pair(N-1, N-2));
            ans.push_back(make_pair(N-2, N-1));
            N -= 2;
            K -= 1;
        }
        else{
            ans.push_back(make_pair(N-1, N-1));
            N -= 1;
            K -= 1;
        }
    }
    cout << ans.size() << '\n';
    for(auto [u,v] : ans){
        cout << (u+1) << ' ' << (v+1) << '\n';
    }
    return 0;
}
            
            
            
        
            
Nachia