結果
| 問題 | No.220 世界のなんとか2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-06-09 05:35:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 1,000 ms |
| コード長 | 528 bytes |
| コンパイル時間 | 2,923 ms |
| コンパイル使用メモリ | 191,444 KB |
| 最終ジャッジ日時 | 2025-01-11 00:24:44 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:25:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
25 | 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;
lint memo[20][3][2];
lint dfs(int n,int sum,bool f){
if(memo[n][sum][f]!=-1) return memo[n][sum][f];
if(n==0) return memo[n][sum][f]=((sum==0||f)?1:0);
if(f) return memo[n][sum][f]=10*dfs(n-1,sum,true);
lint res=0;
rep(d,10){
res+=dfs(n-1,(sum+d)%3,d==3);
}
return memo[n][sum][f]=res;
}
int main(){
int n; scanf("%d",&n);
memset(memo,-1,sizeof memo);
printf("%lld\n",dfs(n,0,false)-1);
return 0;
}