結果

問題 No.831 都市めぐり
ユーザー chocoruskchocorusk
提出日時 2019-05-24 22:40:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 1,455 bytes
コンパイル時間 893 ms
コンパイル使用メモリ 104,860 KB
実行使用メモリ 19,776 KB
最終ジャッジ日時 2023-10-17 12:59:28
合計ジャッジ時間 1,733 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 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 1 ms
4,348 KB
testcase_12 AC 2 ms
4,480 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 3 ms
4,480 KB
testcase_15 AC 13 ms
10,424 KB
testcase_16 AC 6 ms
6,516 KB
testcase_17 AC 14 ms
11,716 KB
testcase_18 AC 17 ms
14,120 KB
testcase_19 AC 26 ms
19,188 KB
testcase_20 AC 26 ms
19,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll n, ans;
int main()
{
    cin>>n;
    if(n==1){
        cout<<0<<endl; return 0;
    }else if(n==2){
        cout<<4<<endl; return 0;
    }
    ans=2*n-1;
    deque<ll> deq;
    for(int i=2; i<=n; i++) deq.push_back(i);
    for(int i=0; ; i++){
        if(n%4==1 && deq.size()==4){
            ans+=deq[0]*deq[1];
            ans+=deq[0]*deq[3];
            ans+=deq[1]*deq[2];
            break;
        }else if(n%4==0 && deq.size()==3){
            ans+=deq[0]*deq[1];
            ans+=deq[0]*deq[2];
            break;
        }else if(n%4==3 && deq.size()==2){
            ans+=deq[0]*deq[1]; break;
        }else if(n%4==2 && deq.size()==3){
            ans+=deq[0]*deq[2];
            ans+=deq[1]*deq[2];
            break;
        }
        ans+=deq[0]*deq.back();
        ans+=deq[1]*deq[deq.size()-2];
        if(i&1){
            deq.pop_front();
            deq.pop_front();
        }else{
            deq.pop_back();
            deq.pop_back();
        }
    }
    cout<<ans<<endl;
    return 0;
}
0