結果

問題 No.831 都市めぐり
ユーザー renjyaku_int
提出日時 2020-04-10 01:10:16
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 1,157 bytes
コンパイル時間 1,600 ms
コンパイル使用メモリ 171,092 KB
実行使用メモリ 34,648 KB
最終ジャッジ日時 2024-09-14 04:10:28
合計ジャッジ時間 2,794 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

signed main()
{
    ll N;
    cin >> N;
    if (N == 1)
    {
        cout << 0 << endl;
        return 0;
    }
    ll num = 1;
    vector<ll> A, B;
    for (ll i = 0; i < N; i++)
    {
        // 1を先頭に追加
        // ↓
        // Nを後尾に追加
        // ↓
        // 2を後尾に追加
        // ↓
        // N - 1を先頭に追加
        // ↓
        // ⋮
        if (i % 2 == 0)
        {
            if (i % 4 == 0)
            {
                A.push_back(num);
            }
            else
            {
                B.push_back(num);
            }
            num = N - num + 1;
        }
        else
        {
            if (i % 4 == 1)
            {
                B.push_back(num);
            }
            else
            {
                A.push_back(num);
            }
            num = N - num + 2;
        }
    }
    reverse(B.begin(), B.end());
    A.insert(A.end(), B.begin(), B.end());
    ll res = 0;
    for (ll i = 0; i < N; i++)
    {
        res += A[i] * A[(i + 1) % N];
    }
    cout << res << endl;
}
//3隣接積和
0