結果
問題 | No.831 都市めぐり |
ユーザー |
|
提出日時 | 2020-05-23 06:57:27 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 24 ms / 2,000 ms |
コード長 | 723 bytes |
コンパイル時間 | 2,205 ms |
コンパイル使用メモリ | 192,820 KB |
最終ジャッジ日時 | 2025-01-10 15:16:35 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:9:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 9 | int n; scanf("%d",&n); | ~~~~~^~~~~~~~~
ソースコード
#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; }