結果

問題 No.630 門松グラフ
ユーザー Kutimoti_TKutimoti_T
提出日時 2018-01-05 23:13:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 26 ms / 1,500 ms
コード長 1,430 bytes
コンパイル時間 724 ms
コンパイル使用メモリ 71,172 KB
実行使用メモリ 5,996 KB
最終ジャッジ日時 2023-08-24 21:16:10
合計ジャッジ時間 3,622 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,384 KB
testcase_16 AC 1 ms
4,384 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 26 ms
5,840 KB
testcase_21 AC 16 ms
5,600 KB
testcase_22 AC 25 ms
5,728 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 14 ms
4,572 KB
testcase_25 AC 13 ms
4,384 KB
testcase_26 AC 14 ms
4,668 KB
testcase_27 AC 14 ms
4,600 KB
testcase_28 AC 25 ms
5,996 KB
testcase_29 AC 21 ms
5,356 KB
testcase_30 AC 20 ms
5,416 KB
testcase_31 AC 17 ms
5,028 KB
testcase_32 AC 12 ms
4,384 KB
testcase_33 AC 8 ms
4,384 KB
testcase_34 AC 15 ms
4,720 KB
testcase_35 AC 9 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <sstream>
using namespace std;

#define FOR(i, s, e) for (int i = (s); i <= (e); i++)

int N;
int M;

int a[100001];

int MAX = 100000;
int MIN = 1;

stringstream result;

int main()
{
    cin >> N >> M;

    for (int i = 1; i <= N; i++)
    {
        if (i % 2 == 1)
        {
            a[i] = MAX;
            MAX--;
        }
        else
        {
            a[i] = MIN;
            MIN++;
        }
        if (i <= N - 1)
        {
            result << i << " " << i + 1 << endl;
        }
    }

    if (N - 1 > M)
    {
        cout << "NO" << endl;
        return 0;
    }

    int remain = M - (N - 1);

    if (remain <= 0)
    {
        cout << "YES" << endl;
        FOR(i, 1, N)
            cout << a[i] << " ";
        cout << endl;
        cout << result.str();
        return 0;
    }

    for (int i = 1; i <= N; i++)
    {
        for (int j = i + 3; j <= N; j += 2)
        {
            result << i << " " << j << endl;
            remain--;
            if (remain <= 0)
            {
                cout << "YES" << endl;
                FOR(i, 1, N)
                    cout << a[i] << " ";
                cout << endl;
                cout << result.str();
                return 0;
            }
            
        }
    }
    cout << "NO" << endl;
    return 0;
}
0