結果

問題 No.831 都市めぐり
ユーザー Manuel1024Manuel1024
提出日時 2021-12-19 02:24:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,731 bytes
コンパイル時間 952 ms
コンパイル使用メモリ 72,992 KB
実行使用メモリ 10,856 KB
最終ジャッジ日時 2023-10-13 18:34:44
合計ジャッジ時間 2,626 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 1 ms
4,352 KB
testcase_08 AC 1 ms
4,352 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,356 KB
testcase_14 AC 3 ms
4,352 KB
testcase_15 AC 5 ms
6,240 KB
testcase_16 AC 3 ms
4,368 KB
testcase_17 AC 4 ms
6,936 KB
testcase_18 AC 5 ms
8,216 KB
testcase_19 AC 7 ms
10,524 KB
testcase_20 AC 7 ms
10,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long int;

ll guchoku(int n){
    vector<ll> arr(n);
    for(int i = 0; i < n; i++) arr[i] = i+1;
    ll ans = 1LL << 60;
    do{
        ll res = 0;
        for(int i = 1; i < n; i++){
            res += arr[i]*arr[i-1] + arr[i]-arr[i-1];
        }
        res += arr[0]*arr[n-1] + arr[0]-arr[n-1];
        ans = min(ans, res);
        // for(int i = 0; i < n; i++) cout << arr[i] << " ";
        // cout << res << endl;
    }while(next_permutation(arr.begin(), arr.end()));
    do{
        ll res = 0;
        for(int i = 1; i < n; i++){
            res += arr[i]*arr[i-1] + arr[i]-arr[i-1];
        }
        res += arr[0]*arr[n-1] + arr[0]-arr[n-1];
        if(res == ans){
            for(int i = 0; i < n; i++) cout << arr[i] << " ";
            cout << res << endl;
        }
    }while(next_permutation(arr.begin(), arr.end()));
    return ans;
}

ll solve(int n){
    if(n == 1) return 0;
    if(n == 2) return 4;
    if(n%2 == 1){
        vector<ll> b(n/2);
        b[0] = 10;
        for(int i = 1; i < b.size(); i++){
            b[i] = b[i-1] + 8*(i+1);
        }
        ll ans = 1;
        // for(int i = 0; i < b.size(); i++) cout << b[i] << " ";
        for(auto &it: b) ans += it;
        return ans;
    }else{
        vector<ll> b(n/2-1);
        b[0] = 17;
        for(int i = 1; i < b.size(); i++){
            b[i] = b[i-1] + 8*i+12;
        }
        ll ans = 4;
        // for(int i = 0; i < b.size(); i++) cout << b[i] << " ";
        for(auto &it: b) ans += it;
        return ans;
    }
}

int main(){
    int n;
    cin >> n;
    cout << solve(n) << endl;
    // cout << guchoku(n) << endl;
    return 0;
}
0