Submission #61396046
Source Code Expand
Copy
/*#pragma GCC optimize("Ofast,unroll-loops")#pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt")*/#include <bits/stdc++.h>#define taskname ""#define all(x) x.begin(), x.end()#define rall(x) x.rbegin(), x.rend()#define i64 long long#define int long long#define isz(x) (int)x.size()using namespace std;void solve() {auto sum = [&](int n) -> int {int res = 0;while (n) {res += n % 10;n /= 10;}
/* #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt") */ #include <bits/stdc++.h> #define taskname "" #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define i64 long long #define int long long #define isz(x) (int)x.size() using namespace std; void solve() { auto sum = [&](int n) -> int { int res = 0; while (n) { res += n % 10; n /= 10; } return res; }; auto check = [&](int n) -> bool { return n % sum(n) == 0; }; vector<int> vec; for (int n = 1; n < (int)2e6; ++n) { if (check(n) and check(n + 1)) { vec.emplace_back(n); } } string s; cin >> s; if (isz(s) < 7) { int n = 0; for (auto val : s) n = n * 10 + val - '0'; int val = *lower_bound(all(vec), n); if (val + 1 > 2 * n) { cout << -1 << endl; } else { cout << val << endl; } return; } auto binpow = [&](int x, int y, int mod) -> int { int res = 1; while (y) { if (y & 1) res = res * x % mod; x = x * x % mod; y >>= 1; } return res; }; int pos = (s[0] - '0') * 10 + (s[1] - '0') + 1, spos = sum(pos); int len = isz(s) - 2; auto ck = [&](int val) -> int { int csum = spos + sum(val); return (pos * binpow(10, len, csum) + val) % csum == 0; }; auto print = [&](int val) -> void { int oval = val, cnt = 0; while (val) { ++cnt; val /= 10; } if (cnt == 0) cnt = 1; cout << pos; for (int i = 0; i < len - cnt; ++i) cout << 0; cout << oval << endl; }; int val = 0; while (val < 1000000) { if (ck(val) and ck(val + 1)) { print(val); return; } ++val; } assert(0); } signed main() { #ifndef CDuongg if (fopen(taskname".inp", "r")) assert(freopen(taskname".inp", "r", stdin)), assert(freopen(taskname".out", "w", stdout)); #else freopen("bai3.inp", "r", stdin); freopen("bai3.out", "w", stdout); auto start = chrono::high_resolution_clock::now(); #endif ios_base::sync_with_stdio(false); cin.tie(nullptr); int t = 1; //cin >> t; while(t--) solve(); #ifdef CDuongg auto end = chrono::high_resolution_clock::now(); cout << "\n"; for(int i = 1; i <= 100; ++i) cout << '='; cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl; #endif }
Submission Info
Submission Time | |
---|---|
Task | E - Digit Sum Divisible 2 |
User | bimatbatmi |
Language | C++ 23 (gcc 12.2) |
Score | 500 |
Code Size | 2773 Byte |
Status | AC |
Exec Time | 22 ms |
Memory | 3804 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 500 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt |
All | 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 01_small_06.txt, 01_small_07.txt, 01_small_08.txt, 01_small_09.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt, 02_random_21.txt, 02_random_22.txt, 02_random_23.txt, 02_random_24.txt, 02_random_25.txt, 02_random_26.txt, 02_random_27.txt, 02_random_28.txt, 02_random_29.txt, 02_random_30.txt, 02_random_31.txt, 03_corner_1_00.txt, 03_corner_1_01.txt, 03_corner_1_02.txt, 03_corner_1_03.txt, 03_corner_1_04.txt, 04_corner_2_00.txt, 04_corner_2_01.txt, 04_corner_2_02.txt, 04_corner_2_03.txt, 04_corner_2_04.txt, 04_corner_2_05.txt, 04_corner_2_06.txt, 04_corner_2_07.txt, 05_corner_3_00.txt, 05_corner_3_01.txt, 06_corner_4_00.txt, 06_corner_4_01.txt, 06_corner_4_02.txt, 06_corner_4_03.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00_sample_00.txt | AC | 19 ms | 3700 KB |
00_sample_01.txt | AC | 19 ms | 3620 KB |
00_sample_02.txt | AC | 19 ms | 3564 KB |
00_sample_03.txt | AC | 20 ms | 3560 KB |
01_small_00.txt | AC | 19 ms | 3632 KB |
01_small_01.txt | AC | 19 ms | 3548 KB |
01_small_02.txt | AC | 19 ms | 3552 KB |
01_small_03.txt | AC | 19 ms | 3688 KB |
01_small_04.txt | AC | 19 ms | 3532 KB |
01_small_05.txt | AC | 19 ms | 3604 KB |
01_small_06.txt | AC | 19 ms | 3632 KB |
01_small_07.txt | AC | 19 ms | 3580 KB |
01_small_08.txt | AC | 19 ms | 3756 KB |
01_small_09.txt | AC | 20 ms | 3572 KB |
02_random_00.txt | AC | 20 ms | 3636 KB |
02_random_01.txt | AC | 22 ms | 3708 KB |
02_random_02.txt | AC | 20 ms | 3704 KB |
02_random_03.txt | AC | 22 ms | 3708 KB |
02_random_04.txt | AC | 20 ms | 3772 KB |
02_random_05.txt | AC | 22 ms | 3736 KB |
02_random_06.txt | AC | 21 ms | 3736 KB |
02_random_07.txt | AC | 22 ms | 3664 KB |
02_random_08.txt | AC | 20 ms | 3640 KB |
02_random_09.txt | AC | 22 ms | 3720 KB |
02_random_10.txt | AC | 21 ms | 3632 KB |
02_random_11.txt | AC | 22 ms | 3732 KB |
02_random_12.txt | AC | 21 ms | 3580 KB |
02_random_13.txt | AC | 22 ms | 3796 KB |
02_random_14.txt | AC | 20 ms | 3540 KB |
02_random_15.txt | AC | 21 ms | 3804 KB |
02_random_16.txt | AC | 21 ms | 3740 KB |
02_random_17.txt | AC | 22 ms | 3632 KB |
02_random_18.txt | AC | 20 ms | 3568 KB |
02_random_19.txt | AC | 22 ms | 3736 KB |
02_random_20.txt | AC | 20 ms | 3636 KB |
02_random_21.txt | AC | 22 ms | 3668 KB |
02_random_22.txt | AC | 20 ms | 3692 KB |
02_random_23.txt | AC | 21 ms | 3796 KB |
02_random_24.txt | AC | 20 ms | 3640 KB |
02_random_25.txt | AC | 21 ms | 3732 KB |
02_random_26.txt | AC | 21 ms | 3732 KB |
02_random_27.txt | AC | 22 ms | 3668 KB |
02_random_28.txt | AC | 21 ms | 3792 KB |
02_random_29.txt | AC | 21 ms | 3680 KB |
02_random_30.txt | AC | 21 ms | 3640 KB |
02_random_31.txt | AC | 22 ms | 3736 KB |
03_corner_1_00.txt | AC | 19 ms | 3596 KB |
03_corner_1_01.txt | AC | 19 ms | 3548 KB |
03_corner_1_02.txt | AC | 19 ms | 3572 KB |
03_corner_1_03.txt | AC | 19 ms | 3636 KB |
03_corner_1_04.txt | AC | 19 ms | 3564 KB |
04_corner_2_00.txt | AC | 21 ms | 3744 KB |
04_corner_2_01.txt | AC | 22 ms | 3740 KB |
04_corner_2_02.txt | AC | 22 ms | 3804 KB |
04_corner_2_03.txt | AC | 22 ms | 3724 KB |
04_corner_2_04.txt | AC | 22 ms | 3680 KB |
04_corner_2_05.txt | AC | 22 ms | 3792 KB |
04_corner_2_06.txt | AC | 22 ms | 3740 KB |
04_corner_2_07.txt | AC | 21 ms | 3712 KB |
05_corner_3_00.txt | AC | 22 ms | 3732 KB |
05_corner_3_01.txt | AC | 21 ms | 3736 KB |
06_corner_4_00.txt | AC | 19 ms | 3628 KB |
06_corner_4_01.txt | AC | 19 ms | 3492 KB |
06_corner_4_02.txt | AC | 19 ms | 3520 KB |
06_corner_4_03.txt | AC | 19 ms | 3696 KB |