結果

問題 No.831 都市めぐり
ユーザー 沙耶花沙耶花
提出日時 2020-12-09 21:45:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 768 bytes
コンパイル時間 2,425 ms
コンパイル使用メモリ 208,708 KB
実行使用メモリ 45,440 KB
最終ジャッジ日時 2023-10-19 08:10:57
合計ジャッジ時間 4,089 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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 5 ms
5,712 KB
testcase_13 AC 5 ms
5,576 KB
testcase_14 AC 5 ms
5,712 KB
testcase_15 AC 27 ms
23,096 KB
testcase_16 AC 14 ms
13,256 KB
testcase_17 AC 30 ms
25,200 KB
testcase_18 AC 40 ms
37,216 KB
testcase_19 AC 52 ms
44,900 KB
testcase_20 AC 53 ms
45,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 10000000


int main(){
	
	int N;
	cin>>N;
	
	if(N==1){
		cout<<0<<endl;
		return 0;
	}
	
	deque<long long> D(N);
	rep(i,N)D[i] = i+1;
	
	vector<long long> x,y;
	
	while(D.size()!=0){
		x.push_back(D.front());
		D.pop_front();
		if(D.size()==0)break;
		
		y.push_back(D.back());
		D.pop_back();
		if(D.size()==0)break;
		
		x.push_back(D.back());
		D.pop_back();
		if(D.size()==0)break;
		
		y.push_back(D.front());
		D.pop_front();
	}
	
	while(y.size()>0){
		x.push_back(y.back());
		y.pop_back();
	}
	
	x.push_back(1);
	
	
	long long ans = 0LL;
	
	rep(i,N){
		ans += x[i]*x[i+1];
		ans += x[i+1]-x[i];
	}
	
	cout<<ans<<endl;
	
    return 0;
}
0