結果

問題 No.630 門松グラフ
ユーザー sinsincoscossinsincoscos
提出日時 2019-03-14 22:14:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,126 bytes
コンパイル時間 790 ms
コンパイル使用メモリ 87,320 KB
実行使用メモリ 8,752 KB
最終ジャッジ日時 2023-09-09 12:57:01
合計ジャッジ時間 5,538 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,752 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
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((k%2==0 && k*k<M) || (k%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;
    int s_id = 1,b_id = k+2;
    while(M>0){
        int a = s_id,b = b_id;
        if(a>b) swap(a,b);
        if(m.count({a,b})) continue;
        ans.push_back({a,b});
        m[{a,b}]++;
        M--;
        b_id++;
        if(b_id>N){
            s_id++;
            b_id = k+2;
        }
    }
    for(auto x:ans) cout << x.first << " " << x.second << endl;
}
0