結果
| 問題 |
No.1185 完全な3の倍数
|
| コンテスト | |
| ユーザー |
sakaki_tohru
|
| 提出日時 | 2020-08-22 13:33:46 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 113 ms / 2,000 ms |
| コード長 | 893 bytes |
| コンパイル時間 | 901 ms |
| コンパイル使用メモリ | 82,472 KB |
| 最終ジャッジ日時 | 2025-01-13 07:44:06 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 39 |
ソースコード
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
using namespace std;
int main(){
int n;cin>>n;
int ans=0;
for(int i=10;i<=min(100,n);i++){
int a=i/10;
int b=i%10;
if((a+b)%3==0){
ans++;
}
}
if(n<=100){
cout<<ans<<endl;
return 0;
}
queue<string> q;
q.push("3");
q.push("6");
q.push("9");
while(q.size()){
string s=q.front();q.pop();
long long tmp=stoll(s);
if(100<=tmp&&tmp<=n){
ans++;
}
if(tmp>n){
continue;
}
s+="0";
q.push(s);
s.pop_back();
s+="3";
q.push(s);
s.pop_back();
s+="6";
q.push(s);
s.pop_back();
s+="9";
q.push(s);
s.pop_back();
}
cout<<ans<<endl;
return 0;
}
sakaki_tohru