結果

問題 No.831 都市めぐり
ユーザー leaf_1415leaf_1415
提出日時 2019-05-24 23:20:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 971 bytes
コンパイル時間 1,479 ms
コンパイル使用メモリ 76,060 KB
実行使用メモリ 59,528 KB
最終ジャッジ日時 2023-10-17 14:49:41
合計ジャッジ時間 2,961 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 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 11 ms
6,208 KB
testcase_13 AC 9 ms
6,144 KB
testcase_14 AC 11 ms
6,208 KB
testcase_15 AC 82 ms
30,200 KB
testcase_16 AC 35 ms
16,368 KB
testcase_17 AC 94 ms
32,176 KB
testcase_18 AC 131 ms
50,288 KB
testcase_19 AC 185 ms
58,564 KB
testcase_20 AC 192 ms
59,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <deque>
#include <vector>
#include <algorithm>
#include <utility>
#define llint long long

using namespace std;
typedef pair<llint, llint> P;

deque<llint> deq;
vector<P> vec;
vector<llint> vec2;
llint put[1000005];
llint n;

int main(void)
{
	cin >> n;
	if(n == 1){
		cout << 0 << endl;
		return 0;
	}
	
	for(int i = 1; i <= (n+1)/2; i++){
		if(i%2) deq.push_back(i);
		else deq.push_front(i);
	}
	
	for(int i = 0; i < (int)deq.size()-1; i++) vec.push_back(make_pair(deq[i]+deq[i+1], i));
	vec.push_back(make_pair(deq.back() + deq[0], (int)deq.size()-1));
	sort(vec.begin(), vec.end());
	
	int p = 0;
	for(int i = n; i >= (n+1)/2+1; i--){
		put[vec[p].second] = i;
		p++;
	}
	
	for(int i = 0; i < deq.size(); i++){
		vec2.push_back(deq[i]);
		if(put[i]) vec2.push_back(put[i]);
	}
	
	llint ans = 0;
	for(int i = 0; i < (int)vec2.size()-1; i++){
		ans += vec2[i]*vec2[i+1];
	}
	ans += vec2[0]*vec2.back();
	cout << ans << endl;
	
	return 0;
}
0