結果

問題 No.220 世界のなんとか2
ユーザー ei1333333ei1333333
提出日時 2015-11-03 14:56:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 950 bytes
コンパイル時間 1,382 ms
コンパイル使用メモリ 146,692 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-11 13:22:03
合計ジャッジ時間 2,832 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 1 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,352 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 1 ms
4,352 KB
testcase_15 AC 1 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const unsigned long long getDP(string S)
{
  unsigned long long dp[2][2][2][3] = {{{{}}}};
  for(int i = 0; i < S.size(); i++) S[i] -= '0';
  dp[0][0][0][0] = 1;
  for(int i = 0; i < S.size(); i++) {
    memset(dp[(i + 1) & 1], 0, sizeof(dp[(i + 1) & 1]));
    for(int j = 0; j < 2; j++) {
      for(int k = 0; k < 2; k++) {
        for(int l = 0; l < 3; l++) {
          if(dp[i & 1][j][k][l] == 0) continue;
          for(int n = max< int >(9 * j, S[i]); n >= 0; n--) {
            dp[(i + 1) & 1][j|(n != S[i])][k|(n == 3)][(l * 10 + n) % 3] += dp[i & 1][j][k][l];
          }
        }
      }
    }
  }
  unsigned long long ret = 0;
  for(int i = 0; i < 2; i++) {
    for(int k = 0; k < 3; k++) ret += dp[S.size() & 1][i][1][k];
    ret += dp[S.size() & 1][i][0][0];
  }
  return(ret);
}


int main()
{
  int N;
  cin >> N;
  string E = "1";
  while(N--) E += "0";
  cout << getDP(E) - 1 << endl;
}
0