結果

問題 No.831 都市めぐり
ユーザー pekempeypekempey
提出日時 2019-05-25 16:53:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,196 bytes
コンパイル時間 663 ms
コンパイル使用メモリ 74,364 KB
実行使用メモリ 19,124 KB
最終ジャッジ日時 2023-10-17 17:44:57
合計ジャッジ時間 1,543 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 WA -
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 1 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 3 ms
4,348 KB
testcase_13 AC 3 ms
4,348 KB
testcase_14 AC 3 ms
4,348 KB
testcase_15 AC 13 ms
10,072 KB
testcase_16 AC 7 ms
6,212 KB
testcase_17 AC 14 ms
11,392 KB
testcase_18 AC 18 ms
14,440 KB
testcase_19 AC 24 ms
18,596 KB
testcase_20 AC 24 ms
19,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main() {
  /*
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    p[i] = i + 1;
  }
  int ans = 1e9;
  do {
    int cost = 0;
    for (int i = 0; i < n; i++) {
      cost += p[i] * p[(i + 1) % n];
    }
    ans = min(ans, cost);
  } while (next_permutation(p.begin(), p.end()));
  do {
    int cost = 0;
    for (int i = 0; i < n; i++) {
      cost += p[i] * p[(i + 1) % n];
    }
    if (cost == ans) {
      for (int i = 0; i < n; i++) {
        cout << p[i] << ' ';
      }
      cout << '\n';
    }
  } while (next_permutation(p.begin(), p.end()));
  1 9 3 7 5 6 4 8 2 10
  */
  int n;
  cin >> n;
  vector<int> L, R;
  int l = 1, r = n;
  for (int i = 1; i <= n; i++) {
    switch ((i - 1) % 4) {
      case 0: L.push_back(l++); break;
      case 1: R.push_back(r--); break;
      case 2: R.push_back(l++); break;
      case 3: L.push_back(r--); break;
    }
  }
  reverse(R.begin(), R.end());
  L.insert(L.end(), R.begin(), R.end());
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    ans += (long long)L[i] * L[(i + 1) % n];
  }
  cout << ans << '\n';
}
0