結果
| 問題 | No.831 都市めぐり |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-23 06:57:27 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 11 ms / 2,000 ms |
| コード長 | 723 bytes |
| 記録 | |
| コンパイル時間 | 1,289 ms |
| コンパイル使用メモリ | 214,296 KB |
| 実行使用メモリ | 19,072 KB |
| 最終ジャッジ日時 | 2026-06-10 07:21:45 |
| 合計ジャッジ時間 | 2,459 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using lint=long long;
int main(){
int n; scanf("%d",&n);
// experiment
/*
vector<lint> p(n);
iota(p.begin(),p.end(),1);
lint ans=1e7;
vector<lint> pans;
do{
lint cost=0;
rep(i,n) cost+=p[i]*p[(i+1)%n];
if(ans>cost){
ans=cost;
pans=p;
}
}while(next_permutation(p.begin(),p.end()));
cout<<ans<<endl;
rep(i,n) cout<<pans[i]<<" "; cout<<endl;
*/
if(n==1) return puts("0"),0;
vector<lint> p(n);
int a=1,b=n,l=0,r=n-1;
for(bool f=true;l<=r;f=!f){
if(f) p[l]=a, p[r]=b;
else p[l]=b, p[r]=a;
a++;
b--;
l++;
r--;
}
lint ans=0;
rep(i,n) ans+=p[i]*p[(i+1)%n];
printf("%lld\n",ans);
return 0;
}