結果

問題 No.630 門松グラフ
ユーザー sinsincoscossinsincoscos
提出日時 2019-03-14 22:30:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 181 ms / 1,500 ms
コード長 1,309 bytes
コンパイル時間 1,010 ms
コンパイル使用メモリ 88,408 KB
実行使用メモリ 10,400 KB
最終ジャッジ日時 2023-09-09 13:41:43
合計ジャッジ時間 5,632 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,384 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 178 ms
10,236 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 181 ms
10,400 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 173 ms
10,244 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 172 ms
10,236 KB
testcase_27 AC 171 ms
10,276 KB
testcase_28 AC 176 ms
9,944 KB
testcase_29 AC 156 ms
9,092 KB
testcase_30 AC 175 ms
9,828 KB
testcase_31 AC 161 ms
9,300 KB
testcase_32 AC 84 ms
6,276 KB
testcase_33 AC 84 ms
6,564 KB
testcase_34 AC 130 ms
8,120 KB
testcase_35 AC 98 ms
6,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <cassert>
using namespace std;
typedef long long ll;
ll N,M;
int A[100010];
vector<pair<int,int>> ans;
int main(){
    cin >> N >> M;
    if(M<N-1){
        cout << "NO" << endl;
        return 0;
    }
    ll k = (N+1)/2;
    if((N%2==0 && k*k<M) || (N%2==1 && k*(k-1)<M)){
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;
    for(int i=1;i<=N;i++){
        cout << i << (i!=N? " ":"\n");
    }
    map<pair<int,int>,int> m;
    for(int i=1;i<=k;i++){
        if(!(N%2==1 && i==k)){
            ans.push_back({i,i+k});
            m[{i,i+k}]++;
        }
        if(i!=1){
            ans.push_back({i,i+k-1});
            m[{i,i+k-1}]++;
        }
    }
    M -= N-1;
    assert(N-1==m.size());
    int s_id = 1,b_id = k+1;
    while(M>0){
        int a = s_id,b = b_id;
        if(a>b) swap(a,b);
        if(m.count({a,b})){
            b_id++;
            if(b_id>N){
                s_id++;
                b_id = k+1;
            }    
            continue;
        }
        ans.push_back({a,b});
        m[{a,b}]++;
        M--;
        b_id++;
        if(b_id>N){
            s_id++;
            b_id = k+1;
        }
    }
    for(auto x:ans) cout << x.first << " " << x.second << endl;
}
0