結果

問題 No.831 都市めぐり
ユーザー tomarint2tomarint2
提出日時 2019-05-24 22:39:28
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,544 bytes
コンパイル時間 1,354 ms
コンパイル使用メモリ 87,716 KB
実行使用メモリ 19,756 KB
最終ジャッジ日時 2023-10-17 12:59:12
合計ジャッジ時間 2,241 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 3 ms
4,468 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 3 ms
4,468 KB
testcase_15 AC 11 ms
10,404 KB
testcase_16 AC 5 ms
6,496 KB
testcase_17 AC 13 ms
11,700 KB
testcase_18 AC 16 ms
14,100 KB
testcase_19 AC 24 ms
19,168 KB
testcase_20 AC 24 ms
19,756 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <deque>
#include <unordered_map>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))
#define DEBUG 0
template <class T>
void dumplist(T list)
{
    for (auto item : list) {
        cout << item << " ";
    }
    cout << endl;
}

void solve()
{
    ll N;
    cin >> N;
    if (N == 1) {
        cout << 0 << endl;
        return;
    }
    deque<ll> q;
    q.push_back(1);
    ll s = 2;
    ll l = N;
    ll ans = 0;
    while(1) {
        if (s == l) {
            q.push_back(l);
            --l;
            break;
        } else {
            q.push_front(l);
            --l;
            q.push_back(l);
            --l;
            if (s > l) break;
        }

        if (s == l) {
            q.push_back(s);
            ++s;
            break;
        } else {
            q.push_front(s);
            ++s;
            q.push_back(s);
            ++s;
            if (s > l) break;
        }
    }

    ll pre = q.back();
    //dumplist(q);
    for (ll a : q) {
        if (pre == 0) {
            pre = a;
        }
        else {
            ans += (pre * a) + (a - pre);
            pre = a;
        }
    }
    cout << ans << endl;
}

int main()
{
    do {
        solve();
    } while (DEBUG);
}
0