結果
| 問題 |
No.1185 完全な3の倍数
|
| コンテスト | |
| ユーザー |
glreto
|
| 提出日時 | 2021-03-09 17:06:37 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 1,326 bytes |
| コンパイル時間 | 929 ms |
| コンパイル使用メモリ | 94,992 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-11 12:29:17 |
| 合計ジャッジ時間 | 2,615 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 39 |
ソースコード
#include <iostream>
#include <vector>
#include<iomanip>
#include<functional>
#include<algorithm>
#include<deque>
#include<math.h>
#include<set>
#include<string>
#include<queue>
#include<complex>
#include<numeric>
#include<stack>
#include<map>
using namespace std;
#define rep(i,n) for(ll i = 0;i<n;i++)
#define req(i,n) for(ll i = 1;i<=n;i++)
#define rrep(i,n) for(int i = n-1;i>=0;i--)
#define ALL(a) a.begin(),a.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef unsigned long long ll;
typedef long double ld;
int dfs(int n, int now,int cnt) {
int res = 0;
if (cnt == 9) {
if (now > 10&&now <= n) {
return 1;
}
else return 0;
}res += dfs(n, now * 10, cnt + 1);
res += dfs(n, now * 10 + 3, cnt + 1);
res += dfs(n, now * 10 + 6, cnt + 1);
res += dfs(n, now * 10 + 9, cnt + 1);
return res;
}
int main() {
int n,ans = 0; cin >> n;
if (n < 100) {
for (int i = 10; i <= n; i++) {
if (i % 3 == 0) ans++;
}cout << ans << endl;
}
else {
for (int i = 10; i <100; i++) {
if (i % 3 == 0) ans++;
}
cout << ans + dfs(n, 0, 0)-12 << endl;
}
}
glreto