結果
問題 | No.1185 完全な3の倍数 |
ユーザー |
![]() |
提出日時 | 2020-08-22 13:59:13 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,515 bytes |
コンパイル時間 | 1,651 ms |
コンパイル使用メモリ | 171,472 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-24 09:27:16 |
合計ジャッジ時間 | 2,373 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 39 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define int long long #define REP(i,m,n) for(int i=(m);i<(n);i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define all(a) a.begin(),a.end() #define rall(c) (c).rbegin(),(c).rend() #define mp make_pair #define endl '\n' #define vec vector<ll> #define mat vector<vector<ll> > #define fi first #define se second typedef long long ll; typedef unsigned long long ull; typedef pair<ll,ll> pll; typedef long double ld; typedef complex<double> comp; const ll inf=1e9+7; const ll mod=998244353; const int MAX=200010; signed main(){ string s;cin>>s; if(s.size()==2){ ll ans=0; rep(i,2){ ans*=10; ans+=s[i]-'0'; } ans/=3; ans-=3; cout<<ans<<endl; return 0; } ll m=s.size(); vector<vector<ll> >dp(m+1,vector<ll>(2)); dp[0][0]=1; rep(i,m){ ll c=s[i]-'0'; if(c==0){ dp[i+1][0]+=dp[i][0]; }else if(c<3){ dp[i+1][1]+=dp[i][0]; }else if(c==3){ dp[i+1][0]+=dp[i][0]; dp[i+1][1]+=dp[i][0]; }else if(c<6){ dp[i+1][1]+=dp[i][0]*2; }else if(c==6){ dp[i+1][0]+=dp[i][0]; dp[i+1][1]+=dp[i][0]*2; }else if(c<9){ dp[i+1][1]+=dp[i][0]*3; }else{ dp[i+1][0]+=dp[i][0]; dp[i+1][1]+=dp[i][0]*3; } dp[i+1][1]+=dp[i][1]*4; } ll ans=dp[m][0]+dp[m][1]+14; cout<<ans<<endl; }