結果
問題 | No.1185 完全な3の倍数 |
ユーザー |
![]() |
提出日時 | 2021-08-22 20:04:48 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,400 bytes |
コンパイル時間 | 1,840 ms |
コンパイル使用メモリ | 169,552 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-06 18:57:34 |
合計ジャッジ時間 | 3,173 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 39 |
ソースコード
#include "bits/stdc++.h" using namespace std; using ll=long long; using ld=long double; using vi=vector<int>; using vvi=vector<vi>; using vll=vector<ll>; using vvll=vector<vll>; using pii=pair<int,int>; #define rep(i,n) for(int i=0;i<(n);i++) #define sor(v) sort(v.begin(),v.end()) #define rev(v) reverse(v.begin(),v.end()) #define ALL(v) v.begin(),v.end() #define pb push_back template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;} template<class T>bool chmin(T &a, const T &b) {if (b<a) {a=b; return 1;} return 0;} template<class T>void printv(vector<T> v){ll n=v.size(); rep(i,n){cout<<v[i]; if(i==n-1)cout<<endl; else cout<<' ';}} template<class T>void printvv(vector<vector<T>> v){for(auto V:v) printv(V);} //constexpr int INF=1001001001; //constexpr int mod=1e9+7; //constexpr int mod=998244353; int main(){ int n; cin>>n; string s=to_string(n); int m=(int)s.length(); vi dp(2); rep(j,m){ vi nx(2); rep(b,2){ int lim=b?(s[j]-'0'):9; for(int i=0;i<=lim;i+=3) nx[b&&i==lim]+=dp[b]; } int lim=j?9:s[j]-'0'; for(int i=3;i<=lim;i+=3) nx[j==0&&i==lim]++; swap(dp,nx); } int ans=dp[0]+dp[1]-3; //cout<<ans<<endl; int a[]={1,4,7},b[]={2,5,8}; rep(i,3)rep(j,3){ if(a[i]*10+b[j]<=n) ans++; if(b[j]*10+a[i]<=n) ans++; } cout<<ans<<endl; }