結果

問題 No.1824 門\松\列
ユーザー bonKotsubonKotsu
提出日時 2022-07-28 01:38:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 996 bytes
コンパイル時間 4,319 ms
コンパイル使用メモリ 260,156 KB
実行使用メモリ 10,836 KB
最終ジャッジ日時 2023-09-24 14:41:51
合計ジャッジ時間 5,267 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
10,800 KB
testcase_01 AC 5 ms
10,836 KB
testcase_02 AC 7 ms
10,796 KB
testcase_03 AC 22 ms
10,792 KB
testcase_04 AC 7 ms
10,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define LP pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
template<class T>
void chmax(T& a, T b) { a = max(a, b); };
template<class T>
void chmin(T& a, T b) { a = min(a, b); };
const int MX = 1e6+1;
int main() {
  int t;
  cin >> t;
  vector<ll> dp(MX);

  auto f = [&] {
    vector<int> v = {3,2,1,3,2,1};
    int res = 0;
    rep(i,6)rep(j,i)rep(k,j) {
      if (v[i]==v[j] || v[j]==v[k] || v[k]==v[i]) continue;
      if (v[k]>v[j] && v[j]<v[i]) res++;
      if (v[k]<v[j]&& v[j]>v[i]) res++;
    }
    return res;
  };
  dp[3] = f();
  for (int i = 3; i < MX; i++) dp[i+1] = dp[i] + (ll)2*i*(i-1);


  rep(ti,t) {
    int n;
    cin >> n;
    cout << dp[n] << "\n";


  }
  return 0;
}
0