結果
| 問題 |
No.3157 Nabeatsu
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-05-23 19:50:19 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,995 bytes |
| コンパイル時間 | 2,254 ms |
| コンパイル使用メモリ | 203,108 KB |
| 実行使用メモリ | 16,072 KB |
| 最終ジャッジ日時 | 2025-05-23 19:50:25 |
| 合計ジャッジ時間 | 5,800 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 TLE * 1 -- * 34 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
double PI = acos(-1.0);
#define sqr(x) ((ll)(x) * (x))
#define ff first
#define ss second
#define pb push_back
#define srt(v) sort(v.begin(), v.end())
#define rsrt(v) sort(v.rbegin(), v.rend())
#define rvrs(v) reverse(v.begin(), v.end())
#define yes printf("YES\n")
#define no printf("NO\n")
#define pf1(a) printf("%lld", a)
#define pf2(a, b) printf("%lld %lld", a, b)
#define case(a) printf("Case %lld: ", a)
#define ses printf("\n")
#define CC(x) cout << "Case #" << ++x << ":";
#define LL_INF (1LL << 62)
#define INF (1 << 30)
#define SetBit(x, k) (x = (1LL << k))
#define ClearBit(x, k) (x &= ~(1LL << k))
#define CheckBit(x, k) ((x >> k) & 1)
void substring(string s, int i, string cur)
{
if (i == s.size())
{
cout << cur << endl;
return;
}
substring(s, i + 1, cur + s[i]);
substring(s, i + 1, cur);
}
ll ch2digit(char s)
{
char charvalue = s;
ll number = (int(charvalue) + 0);
return number - 97;
}
long long Sqrt(long long x)
{
long long l = 1, r = 1e9, ans = 0;
while (l <= r)
{
long long mid = (l + r) >> 1;
if (mid * mid <= x)
{
ans = mid;
l = mid + 1;
}
else
{
r = mid - 1;
}
}
return ans;
}
void permutaion(string s, int l, int r)
{
if (l == r)
{
cout << s << endl;
return;
}
for (int i = l; i <= r; i++)
{
swap(s[l], s[i]);
permutaion(s, l + 1, r);
swap(s[l], s[i]);
}
}
bool pallindrome(string s, int l, int r)
{
if (l >= r)
return true;
if (s[l] != s[r])
return false;
return pallindrome(s, l + 1, r - 1);
}
char int2char(int N)
{
return char(N);
}
void numToBinRepresentation(ll n)
{
for (ll i = 15; i >= 0; --i)
{
// ll x = ((n>>i)&1);
cout << ((n >> i) & 1);
}
cout << endl;
}
const ll P = 31;
const ll MOD = 1e9 + 9;
// Compute power of P
vector<ll> computePowers(int n) {
vector<ll> power(n);
power[0] = 1;
for (int i = 1; i < n; ++i)
power[i] = (power[i - 1] * P) % MOD;
return power;
}
// Compute prefix hash
vector<ll> computePrefixHash(const string &s, const vector<ll>& power) {
int n = s.size();
vector<ll> hash(n);
hash[0] = (s[0] - 'a' + 1);
for (int i = 1; i < n; ++i) {
hash[i] = (hash[i - 1] + (s[i] - 'a' + 1) * power[i]) % MOD;
}
return hash;
}
// Get hash of substring [l, r]
ll getSubHash(const vector<ll> &hash, const vector<ll> &power, int l, int r) {
ll result = hash[r];
if (l > 0) result = (result - hash[l - 1] + MOD) % MOD;
return (result * power[power.size() - 1 - l]) % MOD; // Normalize
}
bool isPalindrome(const string &s) {
string rev = s;
reverse(rev.begin(), rev.end());
int n = s.size();
auto power = computePowers(n + 1);
auto hash1 = computePrefixHash(s, power);
auto hash2 = computePrefixHash(rev, power);
// Compare full normalized hashes
ll hash_original = getSubHash(hash1, power, 0, n - 1);
ll hash_reverse = getSubHash(hash2, power, 0, n - 1);
return hash_original == hash_reverse;
}
string subtractOne(string num) {
int i = num.size() - 1;
while (i >= 0) {
if (num[i] > '0') {
num[i]--;
break;
} else {
num[i] = '9';
i--;
}
}
if (num[0] == '0') num.erase(0, 1);
return num;
}
bool isNabeatsu(const string &num) {
int digitSum = 0;
for (char ch : num) {
if (ch == '3') return true;
digitSum += (ch - '0');
}
return digitSum % 3 == 0;
}
void solve()
{
string n;
cin >> n;
while (isNabeatsu(n)) {
n = subtractOne(n);
}
cout << n << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
ll t = 1;
// cin >> t;
while (t--)
{
solve();
}
}