problem_id
stringlengths
6
6
language
stringclasses
2 values
original_status
stringclasses
3 values
original_src
stringlengths
19
243k
changed_src
stringlengths
19
243k
change
stringclasses
3 values
i1
int64
0
8.44k
i2
int64
0
8.44k
j1
int64
0
8.44k
j2
int64
0
8.44k
error
stringclasses
270 values
stderr
stringlengths
0
226k
p02719
C++
Time Limit Exceeded
/* Author:bhagatsunny96 JGEC template__ lets_code_it_ */ #include <bits/stdc++.h> #define mp make_pair #define pb push_back #define ll long long int #define ld long double #define fi first #define se second #define mod 1000000007 #define test \ long long int t; \ cin >> t; \ while (t-- > 0) #define fIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define loop(n) for (long long int i = 0; i < n; i++) #define loopr(n) for (long long int i = n - 1; i >= 0; i--) #define lrp(a, b) for (long long int i = a; i <= b; i++) #define lrn(a, b) for (long long int i = b; i >= a; i--) #define endl '\n' #define ivec vector<ll> #define ivecp vector<pair<ll, ll>> #define imap map<ll, ll> #define uimap unordered_map<ll, ll> #define iset set<ll> #define cvec vector<char> #define civecp vector<pair<char, ll>> #define cimap map<char, ll> #define ucimap unordered_map<char, ll> #define cset set<char> using namespace std; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); } ll power(ll x, unsigned ll y) { ll temp; if (y == 0) return 1; temp = power(x, y / 2); if (y % 2 == 0) return temp * temp; else return x * temp * temp; } bool isPrime(ll num) { bool flag = true; for (ll i = 2; i <= num / 2; i++) { if (num % i == 0) { flag = false; break; } } return flag; } bool isPalin(ll num) { bool flag = false; ll digit, rev = 0, n = num; do { digit = num % 10; rev = (rev * 10) + digit; num = num / 10; } while (num != 0); if (rev == n) flag = true; return flag; } ll sumofdigits(ll n) { ll c = 0; while (n > 0) { c++; n /= 10; } return c; } bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) { return (a.first > b.first); } bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } string sortString(string &str) { sort(str.begin(), str.end()); return str; } void countSort(ll arr[], ll n, ll exp) { ll output[n]; ll i, count[10] = {0}; for (i = 0; i < n; i++) count[(arr[i] / exp) % 10]++; for (i = 1; i < 10; i++) count[i] += count[i - 1]; for (i = n - 1; i >= 0; i--) { output[count[(arr[i] / exp) % 10] - 1] = arr[i]; count[(arr[i] / exp) % 10]--; } for (i = 0; i < n; i++) arr[i] = output[i]; } void radixsort(ll arr[], ll n) { ll mx = arr[0]; for (ll i = 1; i < n; i++) if (arr[i] > mx) mx = arr[i]; ll m = mx; for (ll exp = 1; m / exp > 0; exp *= 10) countSort(arr, n, exp); } void print(ll arr[], ll n) { for (ll i = 0; i < n; i++) cout << arr[i] << " "; } int main() { fIO ll n, k; cin >> n >> k; ll x = n; while (abs(x - k) < x) { x = abs(x - k); } cout << x << endl; return 0; }
/* Author:bhagatsunny96 JGEC template__ lets_code_it_ */ #include <bits/stdc++.h> #define mp make_pair #define pb push_back #define ll long long int #define ld long double #define fi first #define se second #define mod 1000000007 #define test \ long long int t; \ cin >> t; \ while (t-- > 0) #define fIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define loop(n) for (long long int i = 0; i < n; i++) #define loopr(n) for (long long int i = n - 1; i >= 0; i--) #define lrp(a, b) for (long long int i = a; i <= b; i++) #define lrn(a, b) for (long long int i = b; i >= a; i--) #define endl '\n' #define ivec vector<ll> #define ivecp vector<pair<ll, ll>> #define imap map<ll, ll> #define uimap unordered_map<ll, ll> #define iset set<ll> #define cvec vector<char> #define civecp vector<pair<char, ll>> #define cimap map<char, ll> #define ucimap unordered_map<char, ll> #define cset set<char> using namespace std; ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return (a * b) / __gcd(a, b); } ll power(ll x, unsigned ll y) { ll temp; if (y == 0) return 1; temp = power(x, y / 2); if (y % 2 == 0) return temp * temp; else return x * temp * temp; } bool isPrime(ll num) { bool flag = true; for (ll i = 2; i <= num / 2; i++) { if (num % i == 0) { flag = false; break; } } return flag; } bool isPalin(ll num) { bool flag = false; ll digit, rev = 0, n = num; do { digit = num % 10; rev = (rev * 10) + digit; num = num / 10; } while (num != 0); if (rev == n) flag = true; return flag; } ll sumofdigits(ll n) { ll c = 0; while (n > 0) { c++; n /= 10; } return c; } bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) { return (a.first > b.first); } bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } string sortString(string &str) { sort(str.begin(), str.end()); return str; } void countSort(ll arr[], ll n, ll exp) { ll output[n]; ll i, count[10] = {0}; for (i = 0; i < n; i++) count[(arr[i] / exp) % 10]++; for (i = 1; i < 10; i++) count[i] += count[i - 1]; for (i = n - 1; i >= 0; i--) { output[count[(arr[i] / exp) % 10] - 1] = arr[i]; count[(arr[i] / exp) % 10]--; } for (i = 0; i < n; i++) arr[i] = output[i]; } void radixsort(ll arr[], ll n) { ll mx = arr[0]; for (ll i = 1; i < n; i++) if (arr[i] > mx) mx = arr[i]; ll m = mx; for (ll exp = 1; m / exp > 0; exp *= 10) countSort(arr, n, exp); } void print(ll arr[], ll n) { for (ll i = 0; i < n; i++) cout << arr[i] << " "; } int main() { fIO ll n, k; cin >> n >> k; ll x = n - ((n / k) * k); if (abs(-k + x) < x) { x = abs(-k + x); } cout << x << endl; return 0; }
replace
121
124
121
124
TLE
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, K, a, b; cin >> N >> K; a = N % K; b = -a + K; cout << min(a, b) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long N, K, a, b; cin >> N >> K; a = N % K; b = -a + K; cout << min(a, b) << endl; }
replace
4
5
4
5
0
p02719
C++
Time Limit Exceeded
#include <cmath> #include <iostream> using namespace std; int main() { long long n, k, ans; cin >> n >> k; ans = abs(n - k); if (k == 1) ans = 0; else while (2 * ans > k) { ans = min(ans, abs(ans - k)); } cout << ans << endl; }
#include <cmath> #include <iostream> using namespace std; int main() { long long n, k, ans; cin >> n >> k; ans = n % k; if (k == 1) ans = 0; else while (2 * ans > k) { ans = min(ans, abs(ans - k)); } cout << ans << endl; }
replace
6
7
6
7
TLE
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; long long int minnumber = (n % k); int counter = 0; for (int i = 0;; i++) { if (minnumber == 0) { cout << 0 << endl; return 0; } if (counter == 2) { break; } minnumber = min(minnumber, abs(minnumber - k * i)); if (n - k * i < 0) { counter += 1; } } cout << minnumber << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; long long int m = n % k; m = min(m, k - m); cout << m << endl; return 0; }
replace
6
22
6
9
TLE
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; if (n % k == 0) { cout << '0'; return 0; } long long int min = n; long long int last = min; for (int i = 0;; i++) { if (abs(last - k) < min) { min = abs(last - k); } if (last < abs(last - k)) { cout << last; return last; } last = abs(last - k); } }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; cout << min(n % k, k - n % k); }
replace
5
21
5
6
1
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { long long N, K; cin >> N >> K; while (N > abs(N - K)) { N = abs(N - K); } cout << N; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { long long N, K; cin >> N >> K; N = N % K; while (N > abs(N - K)) { N = abs(N - K); } cout << N; }
insert
7
7
7
8
TLE
p02719
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iostream> #include <string> using namespace std; int main() { // code int tc; int i, j, k, n, m, p = 0; cin >> n >> k; cout << min(n % k, abs((n % k) - k)) << endl; return 0; }
#include <algorithm> #include <cmath> #include <iostream> #include <string> using namespace std; int main() { // code long long i, j, k, n, m, p = 0; cin >> n >> k; cout << min(n % k, abs((n % k) - k)) << endl; return 0; }
replace
9
11
9
11
0
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define pb push_back #define all(v) v.begin(), v.end() #define fi first #define se second #define bigger (char)toupper #define smaller (char)tolower using namespace std; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vii; typedef vector<string> vs; typedef vector<char> vc; typedef long long ll; typedef unsigned long long ull; int main() { ll N, K; cin >> N >> K; if (N == K) cout << 0 << endl; else if (N < K) { if (N * 2 > K) cout << K - N << endl; else cout << N << endl; } else { ll a; if (N % K == 0) cout << 0 << endl; else { ll a = (N / K) + 1; ll answer = 100000000000000100; for (ll i = 1; i <= a; i++) { answer = min(answer, abs(N - K * a)); } cout << answer << endl; } } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define pb push_back #define all(v) v.begin(), v.end() #define fi first #define se second #define bigger (char)toupper #define smaller (char)tolower using namespace std; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vii; typedef vector<string> vs; typedef vector<char> vc; typedef long long ll; typedef unsigned long long ull; int main() { ll N, K; cin >> N >> K; if (N == K) cout << 0 << endl; else if (N < K) { if (N * 2 > K) cout << K - N << endl; else cout << N << endl; } else { ll a; if (N % K == 0) cout << 0 << endl; else { ll a = (N / K) + 1; cout << abs(N - K * a) << endl; } } }
replace
33
38
33
34
TLE
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b; cin >> a >> b; long long int curr = a, prev; while (true) { prev = curr; if (abs(curr - b) > prev) { break; } curr = abs(curr - b); } cout << prev << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long int a, b; cin >> a >> b; cout << min(a % b, b - a % b) << endl; }
replace
5
14
5
6
TLE
p02719
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <chrono> #include <cmath> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <stack> #include <unordered_map> #include <vector> using namespace std; using ll = long long; const long long INF = (long long)1e18 + 1; #define DIV 1000000007 int main() { cin.tie(0); ios::sync_with_stdio(false); #ifdef TEST chrono::system_clock::time_point start, end; start = chrono::system_clock::now(); #endif long idx = 0; ll N, K; cin >> N >> K; bool small = true; ll num = N; ll prev_num = N; while (small) { num = abs(num - K); // cerr << num << "," << prev_num << "," << K << endl; if (num >= prev_num) { small = false; } else prev_num = num; } cout << prev_num << endl; #ifdef TEST end = chrono::system_clock::now(); cerr << static_cast<double>( chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl; #endif return 0; }
#include <algorithm> #include <bitset> #include <chrono> #include <cmath> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include <stack> #include <unordered_map> #include <vector> using namespace std; using ll = long long; const long long INF = (long long)1e18 + 1; #define DIV 1000000007 int main() { cin.tie(0); ios::sync_with_stdio(false); #ifdef TEST chrono::system_clock::time_point start, end; start = chrono::system_clock::now(); #endif long idx = 0; ll N, K; cin >> N >> K; ll q = N / K; ll smaller = min(abs(N - q * K), abs(N - (q + 1) * K)); cout << smaller << endl; #ifdef TEST end = chrono::system_clock::now(); cerr << static_cast<double>( chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl; #endif return 0; }
replace
27
39
27
30
TLE
p02719
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdio> using namespace std; typedef unsigned long long llong; #define MAX 1e18 const llong mod = 1000000000 + 7; int main() { llong N, K; llong prevN = mod; scanf("%llu%llu", &N, &K); llong sub; if (N > K) N -= N / K * K; do { prevN = min(prevN, N); if (N > K) sub = N - K; else sub = K - N; N = sub; } while (N != prevN); printf("%llu\n", N); return 0; }
#include <algorithm> #include <cmath> #include <cstdio> using namespace std; typedef unsigned long long llong; #define MAX 1e18 const llong mod = 1000000000 + 7; int main() { llong N, K; llong prevN = MAX; scanf("%llu%llu", &N, &K); llong sub; if (N > K) N -= N / K * K; do { prevN = min(prevN, N); if (N > K) sub = N - K; else sub = K - N; N = sub; } while (N != prevN); printf("%llu\n", N); return 0; }
replace
12
13
12
13
TLE
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define all(n) (n).begin(), (n).end() #define ll long long void solve() { ll n, k; cin >> n >> k; ll ans = n; while (1) { if (ans % k == 0) { ans = 0; break; } n = abs(n - k); if (ans > n) { ans = n; } else { break; } } cout << ans << endl; } int main() { // Write from here. solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define all(n) (n).begin(), (n).end() #define ll long long void solve() { ll n, k; cin >> n >> k; ll ans = n; while (1) { if (ans % k == 0) { ans = 0; break; } n = abs(n - k); if (ans > n) { ans = n; } else { break; } n = n % k; } cout << ans << endl; } int main() { // Write from here. solve(); return 0; }
insert
23
23
23
24
TLE
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; while (true) { if (N < abs(N - K)) { break; } if (N > K) { N = N % K; } else { N = abs(N - K); } } cout << N << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long int N, K; cin >> N >> K; while (true) { if (N < abs(N - K)) { break; } if (N > K) { N = N % K; } else { N = abs(N - K); } } cout << N << endl; }
replace
4
5
4
5
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 1; i < (int)(n); i++) using namespace std; using ll = long long; int main() { ll n, k; cin >> n >> k; int m = n % k; if (m == 0) cout << 0 << endl; else { vector<ll> vec(m + 1); vec.at(0) = n; vec.at(1) = abs(n - k); for (int i = 2; i <= m; i++) { vec.at(i) = abs(vec.at(i - 1) - k); } sort(vec.begin(), vec.end()); cout << vec.at(0) << endl; } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 1; i < (int)(n); i++) using namespace std; using ll = long long; int main() { ll n, k; cin >> n >> k; ll m = n % k; if (abs(m - k) < m) cout << abs(m - k) << endl; else cout << m << endl; }
replace
7
20
7
13
0
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vii = vector<vi>; using vs = vector<string>; using in6 = int64_t; using ind = double; using pii = pair<int, int>; using psi = pair<string, int>; using vpi = vector<pii>; using vps = vector<psi>; #define rep(i, n) for (in6 i = 0; i < (in6)(n); i++) #define repa(i, a, n) for (in6 i = a; i < (in6)(n); i++) #define repdown(i, n) for (in6 i = n; i > 0; i--) #define kyun ios::sync_with_stdio(false) #define hinata cout << "\n" #define all(c) (c).begin(), (c).end() #define pb push_back #define inf 2147483647 #define dset(n) cout << fixed << setprecision(n) void yes() { cout << "Yes"; } void no() { cout << "No"; } int main() { kyun; in6 n, k; cin >> n >> k; in6 ans = n; while (1) { in6 now = abs(ans - k); if (now < ans) ans = now; else break; } cout << ans; hinata; }
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vii = vector<vi>; using vs = vector<string>; using in6 = int64_t; using ind = double; using pii = pair<int, int>; using psi = pair<string, int>; using vpi = vector<pii>; using vps = vector<psi>; #define rep(i, n) for (in6 i = 0; i < (in6)(n); i++) #define repa(i, a, n) for (in6 i = a; i < (in6)(n); i++) #define repdown(i, n) for (in6 i = n; i > 0; i--) #define kyun ios::sync_with_stdio(false) #define hinata cout << "\n" #define all(c) (c).begin(), (c).end() #define pb push_back #define inf 2147483647 #define dset(n) cout << fixed << setprecision(n) void yes() { cout << "Yes"; } void no() { cout << "No"; } int main() { kyun; in6 n, k; cin >> n >> k; in6 ans = n % k; cout << min(ans, abs(ans - k)); hinata; }
replace
29
38
29
31
TLE
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, k; int a; cin >> n >> k; if (n % k == 0) cout << '0'; else { a = min(n % k, k - n % k); cout << a; } }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n, k; long long a; cin >> n >> k; if (n % k == 0) cout << '0'; else { a = min(n % k, k - n % k); cout << a; } }
replace
7
9
7
9
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define for_(i, s, e) for (int i = s; i < e; i++) #define for__(i, s, e) for (ull i = s; i < e; i++) #define SSTR(x) \ static_cast<std::ostringstream &>((std::ostringstream() << std::dec << x)) \ .str() typedef unsigned long long ull; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; int main() { #ifndef ONLINE_JUDGE freopen("test.in", "r", stdin); #endif ios_base::sync_with_stdio(false); cin.tie(0); ll n, k; cin >> n >> k; ll mod = n % k; cout << min(mod, k - mod) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define for_(i, s, e) for (int i = s; i < e; i++) #define for__(i, s, e) for (ull i = s; i < e; i++) #define SSTR(x) \ static_cast<std::ostringstream &>((std::ostringstream() << std::dec << x)) \ .str() typedef unsigned long long ull; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> ii; int main() { ios_base::sync_with_stdio(false); cin.tie(0); ll n, k; cin >> n >> k; ll mod = n % k; cout << min(mod, k - mod) << endl; return 0; }
delete
13
17
13
13
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long #define fio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) using namespace std; int main() { fio; int t; cin >> t; ll n, k, min; cin >> n >> k; if (n % k > k - n % k) cout << (k - n % k) << "\n"; else cout << n % k << "\n"; }
#include <bits/stdc++.h> #define ll long long #define fio \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) using namespace std; int main() { fio; ll n, k, min; cin >> n >> k; if (n % k > k - n % k) cout << (k - n % k) << "\n"; else cout << n % k << "\n"; }
delete
9
11
9
9
0
p02719
C++
Runtime Error
/* --> WHEN IT'S OBVIOUS THAT THE GOAL CANNOT BE REACHED, DON'T ADJUST THE GOALS, ADJUST THE ACTION STEPS. --> THE WAY YOU CONQUER SELF-DOUBT IS BY DOING THINGS THAT MAKE YOU UNCOMFORTABLE. --> IT IS DURING OUR DARKEST MOMENTS WE MUST FOCUS TO SEE LIGHT. */ #include <algorithm> #include <climits> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; #define pb push_back #define F first #define S second #define all(x) x.begin(), x.end() #define sortAll(x) sort(all(x)) #define sz(x) (int)x.size() #define clr(x) memset(x, 0, sizeof(x)) #define PI 3.1415926535897932384626 #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); \ IO(); typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpii; typedef vector<pl> vpl; typedef vector<vi> vvi; typedef vector<vl> vvl; const int MOD = 1e9 + 7; ll power(ll a, ll b) { ll ans = 1; while (b > 0) { if (b & 1) ans *= a; a = a * a; b >>= 1; } return ans; } ll powm(ll a, ll b) { a %= MOD; ll ans = 1; while (b > 0) { if (b & 1) ans = (ans * a) % MOD; a = (a * a) % MOD; b >>= 1; } return ans; } void IO() { #ifndef ONLINE_JUDGE freopen("Input.txt", "r", stdin); freopen("Output.txt", "w", stdout); #endif } //================================ int main() { FAST; ll n, k; cin >> n >> k; cout << min(n % k, abs(n % k - k)) << "\n"; return 0; }
/* --> WHEN IT'S OBVIOUS THAT THE GOAL CANNOT BE REACHED, DON'T ADJUST THE GOALS, ADJUST THE ACTION STEPS. --> THE WAY YOU CONQUER SELF-DOUBT IS BY DOING THINGS THAT MAKE YOU UNCOMFORTABLE. --> IT IS DURING OUR DARKEST MOMENTS WE MUST FOCUS TO SEE LIGHT. */ #include <algorithm> #include <climits> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> using namespace std; #define pb push_back #define F first #define S second #define all(x) x.begin(), x.end() #define sortAll(x) sort(all(x)) #define sz(x) (int)x.size() #define clr(x) memset(x, 0, sizeof(x)) #define PI 3.1415926535897932384626 #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); \ IO(); typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pl; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<pii> vpii; typedef vector<pl> vpl; typedef vector<vi> vvi; typedef vector<vl> vvl; const int MOD = 1e9 + 7; ll power(ll a, ll b) { ll ans = 1; while (b > 0) { if (b & 1) ans *= a; a = a * a; b >>= 1; } return ans; } ll powm(ll a, ll b) { a %= MOD; ll ans = 1; while (b > 0) { if (b & 1) ans = (ans * a) % MOD; a = (a * a) % MOD; b >>= 1; } return ans; } void IO() { #ifndef ONLINE_JUDGE freopen("Input.txt", "r", stdin); freopen("Output.txt", "w", stdout); #endif } //================================ int main() { // FAST; ll n, k; cin >> n >> k; cout << min(n % k, abs(n % k - k)) << "\n"; return 0; }
replace
86
87
86
87
0
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; cin >> N >> K; while (true) { if (N > abs(N - K)) { N = abs(N - K); } else { break; } } cout << N << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; cin >> N >> K; if (N > K * 3) { N = N - ((N / K) - 3) * K; } while (true) { if (N > abs(N - K)) { N = abs(N - K); } else { break; } } cout << N << endl; }
insert
6
6
6
9
TLE
p02719
C++
Runtime Error
#include <iostream> #include <stdio.h> using namespace std; int main() { int N, K; int min; cin >> N >> K; min = N % K; if (min > K - min) min = K - min; cout << min << endl; return 0; }
#include <iostream> #include <stdio.h> using namespace std; int main() { long N, K; long min; cin >> N >> K; min = N % K; if (min > K - min) min = K - min; cout << min << endl; return 0; }
replace
5
7
5
7
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; typedef pair<int, int> P; const int INF = 1e9; const ll mod = 1e9 + 7; const int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1}; int main() { ll n, k; cin >> n >> k; ll a, b; if (n == 1) { cout << 1 << endl; return 0; } else if (k == 1) { cout << 0 << endl; return 0; } if (n > k) { a = n % k; if (a == 0) cout << 0 << endl; else cout << k - a << endl; } else if (n < k) { a = k % n; if (a == 0) cout << n << endl; else cout << a << endl; } else { cout << 0 << endl; } }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long ll; typedef pair<int, int> P; const int INF = 1e9; const ll mod = 1e9 + 7; const int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1}; int main() { ll n, k; cin >> n >> k; ll a = n % k; ll ans = min(a, k - a); cout << ans << endl; }
replace
12
35
12
15
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main(void) { int n, k; cin >> n >> k; cout << min(k - n % k, n % k) << endl; }
#include <bits/stdc++.h> using namespace std; int main(void) { long long n, k; cin >> n >> k; cout << min(k - n % k, n % k) << endl; }
replace
5
6
5
6
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int #define MOD 1000000007 int main() { int n, k; cin >> n >> k; cout << min(n % k, abs(n % k - k)) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long int #define MOD 1000000007 int main() { ll n, k; cin >> n >> k; cout << min(n % k, abs(n % k - k)) << endl; return 0; }
replace
7
8
7
8
0
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main(void) { using namespace std; long int N, K; cin >> N >> K; while (true) { if (K == 1) { printf("0\n"); break; } if (N < abs(N - K)) { printf("%ld\n", N); break; } else { N = abs(N - K); } } }
#include <bits/stdc++.h> using namespace std; int main(void) { using namespace std; long int N, K; cin >> N >> K; if (K == 1) { printf("0\n"); } else if (N > K) { long int tmp = N % K; printf("%ld", abs(tmp - K)); } else { while (true) { if (N < abs(N - K)) { printf("%ld\n", N); break; } else { N = abs(N - K); } } } }
replace
8
18
8
21
TLE
p02719
C++
Time Limit Exceeded
#include <cmath> #include <iostream> using namespace std; int main(void) { long long N, K; cin >> N >> K; if (N % K == 0) { cout << 0 << endl; return 0; } while ((2 * N) > K) { N = abs(N - K); } cout << N << endl; return 0; }
#include <cmath> #include <iostream> using namespace std; int main(void) { long long N, K; cin >> N >> K; if (N % K == 0) { cout << 0 << endl; return 0; } if (N > K) { N = N % K; } while ((2 * N) > K) { N = abs(N - K); } cout << N << endl; return 0; }
insert
12
12
12
16
TLE
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long #define endl '\n' #define REP(i, a, n) for (int i = a; i < n; ++i) #define pb push_back #define sz(x) (int)((x).size()) #define all(x) (x).begin(), (x).end() using namespace std; int main() { ll n, k; cin >> n >> k; if (k == 1) cout << 0 << endl; else { set<ll> abc; while (true) { n = abs(n - k); if (abc.find(n) != abc.end()) break; else abc.insert(n); } cout << *(abc.begin()) << endl; } return 0; }
#include <bits/stdc++.h> #define ll long long #define endl '\n' #define REP(i, a, n) for (int i = a; i < n; ++i) #define pb push_back #define sz(x) (int)((x).size()) #define all(x) (x).begin(), (x).end() using namespace std; int main() { ll n, k; cin >> n >> k; n = n % k; cout << min(n, k - n) << endl; return 0; }
replace
13
26
13
16
TLE
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, k, x; cin >> n >> k; x = min(n % k, k - n % k); cout << x << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k, x; cin >> n >> k; x = min(n % k, k - n % k); cout << x << endl; }
replace
3
4
3
4
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; class Solution { public: void solve() { int n, k; cin >> n >> k; cout << min(n % k, k - n % k) << "\n"; return; }; }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); Solution solution; solution.solve(); return 0; }
#include <bits/stdc++.h> using namespace std; class Solution { public: void solve() { long long n, k; cin >> n >> k; cout << min(n % k, k - n % k) << "\n"; return; }; }; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); Solution solution; solution.solve(); return 0; }
replace
7
8
7
8
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // #define int long long #define ff first #define ss second #define rep(i, a, b) for (int i = a; i < (b); ++i) #define per(i, a, b) for (int i = b - 1; i >= a; i--) #define trav(a, x) for (auto &a : x) #define allin(a, x) for (auto a : x) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define endl "\n" #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define pb(x) push_back(x) typedef long long ll; typedef pair<int, int> pii; typedef vector<ll> vl; typedef vector<pii> vpi; typedef pair<ll, ll> pll; typedef vector<string> vs; typedef vector<pll> vpl; typedef vector<int> vi; inline int mod(int n, int m) { int ret = n % m; if (ret < 0) ret += m; return ret; } ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); } ll exp(ll a, ll b, ll m) { if (b == 0LL) return 1LL; if (b == 1LL) return mod(a, m); ll k = mod(exp(a, b / 2, m), m); if (b & 1LL) { return mod(a * mod(k * k, m), m); } else return mod(k * k, m); } int32_t main() { fastio; int n, k; cin >> n >> k; n = n % k; if (n <= k - n) cout << n << endl; else cout << k - n << endl; // Math -> gcd it all // chack MAXN // check ll // did you check N=1? Did you mix up N,M? }
#include <bits/stdc++.h> using namespace std; #define int long long #define ff first #define ss second #define rep(i, a, b) for (int i = a; i < (b); ++i) #define per(i, a, b) for (int i = b - 1; i >= a; i--) #define trav(a, x) for (auto &a : x) #define allin(a, x) for (auto a : x) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define endl "\n" #define fastio \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define pb(x) push_back(x) typedef long long ll; typedef pair<int, int> pii; typedef vector<ll> vl; typedef vector<pii> vpi; typedef pair<ll, ll> pll; typedef vector<string> vs; typedef vector<pll> vpl; typedef vector<int> vi; inline int mod(int n, int m) { int ret = n % m; if (ret < 0) ret += m; return ret; } ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); } ll exp(ll a, ll b, ll m) { if (b == 0LL) return 1LL; if (b == 1LL) return mod(a, m); ll k = mod(exp(a, b / 2, m), m); if (b & 1LL) { return mod(a * mod(k * k, m), m); } else return mod(k * k, m); } int32_t main() { fastio; int n, k; cin >> n >> k; n = n % k; if (n <= k - n) cout << n << endl; else cout << k - n << endl; // Math -> gcd it all // chack MAXN // check ll // did you check N=1? Did you mix up N,M? }
replace
2
3
2
3
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; cout << min(n % k, abs(k - n % k)); }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; cout << min(n % k, abs(k - n % k)); }
replace
4
5
4
5
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; typedef pair<int, int> P; int main() { int n, k; cin >> n >> k; cout << min({n % k, (n + k - 1) / k * k - n, n}) << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; typedef long long ll; typedef pair<int, int> P; int main() { ll n, k; cin >> n >> k; cout << min({n % k, (n + k - 1) / k * k - n, n}) << endl; return 0; }
replace
7
8
7
8
0
p02719
C++
Time Limit Exceeded
#include <algorithm> #include <cstdlib> #include <iostream> #include <set> #include <string> #include <vector> using namespace std; #define forn(i, n) for (int i = 0; i < int(n); i++) int main() { long long N, K; cin >> N >> K; bool zero = false; long long a = N; long long b; while (!zero) { a = a - K; if (a < 0) { zero = true; b = a; a = a + K; } } b = -b; if (b > a) cout << a << endl; else cout << b << endl; }
#include <algorithm> #include <cstdlib> #include <iostream> #include <set> #include <string> #include <vector> using namespace std; #define forn(i, n) for (int i = 0; i < int(n); i++) int main() { long long N, K; cin >> N >> K; bool zero = false; long long a = N % K; long long b = a - K; b = -b; if (b > a) cout << a << endl; else cout << b << endl; }
replace
15
25
15
17
TLE
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); typedef long long ll; ll strtoint(string str); int main() { fast; ll n, k; cin >> n >> k; while (true) { n = abs(n - k); if (k == 1) break; if (abs(n - k) <= n) continue; else break; } (k == 1) ? cout << 0 << '\n' : cout << n << '\n'; return 0; } ll strtoint(string str) { ll x = 0; stringstream ss; ss << str; ss >> x; return x; }
#include <bits/stdc++.h> using namespace std; #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); typedef long long ll; ll strtoint(string str); int main() { fast; ll n, k; cin >> n >> k; cout << min(n % k, k - n % k) << '\n'; return 0; } ll strtoint(string str) { ll x = 0; stringstream ss; ss << str; ss >> x; return x; }
replace
12
22
12
13
TLE
p02719
C++
Runtime Error
#include <algorithm> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < n; i++) #define all(x) (x).begin(), (x).end() #define pb(a) push_back(a) #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) typedef long long unsigned int ll; typedef pair<ll, ll> P; int main() { int N, K; cin >> N >> K; cout << min(N % K, K - N % K) << endl; }
#include <algorithm> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < n; i++) #define all(x) (x).begin(), (x).end() #define pb(a) push_back(a) #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) typedef long long unsigned int ll; typedef pair<ll, ll> P; int main() { ll N, K; cin >> N >> K; cout << min(N % K, K - N % K) << endl; }
replace
29
30
29
30
0
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long N, K; cin >> N >> K; if (N % K == 0) { N = 0; } if (N > K) { while (N > K) { N -= K; } } long Ans = min(N, abs(N - K)); cout << Ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long N, K; cin >> N >> K; N -= (N / K) * K; long Ans = min(N, abs(N - K)); cout << Ans << endl; return 0; }
replace
5
13
5
6
TLE
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define x first #define y second #define ll long long #define _for(i, j, k) for (int i = j; i < k; i++) #define endl '\n' #define inf 1 << 29 - 1 const int mod = 1e9 + 7; const int MAX = 1e6 + 5; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n, k, t; cin >> n >> k; if (n < k) swap(n, k); n = n % k; if (n == 0) cout << k; else { cout << min(n, k - n); } }
#include <bits/stdc++.h> using namespace std; #define x first #define y second #define ll long long #define _for(i, j, k) for (int i = j; i < k; i++) #define endl '\n' #define inf 1 << 29 - 1 const int mod = 1e9 + 7; const int MAX = 1e6 + 5; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n, k, t; cin >> n >> k; ll MIN = n % k; cout << min(MIN, k - MIN); }
replace
17
25
17
19
0
p02719
C++
Runtime Error
#include <iostream> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); int N, K; cin >> N >> K; if (N > K) { N = N - (N - K) / K * K; } if (N == K) { cout << "0\n"; return 0; } if (N > K) N -= K; if (K - N > N) { cout << N << "\n"; } else cout << K - N << "\n"; }
#include <iostream> using namespace std; int main() { cin.tie(0); ios::sync_with_stdio(false); long long N, K; cin >> N >> K; if (N > K) { N = N - (N - K) / K * K; } if (N == K) { cout << "0\n"; return 0; } if (N > K) N -= K; if (K - N > N) { cout << N << "\n"; } else cout << K - N << "\n"; }
replace
5
6
5
6
0
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define pii pair<int, int> #define pll pair<long long, long long> #define pb push_back #define ll long long #define ld long double #define precision(x, d) cout << fixed << setprecision(d) << x #define fill(a, b) memset((a), (b), sizeof((a))) #define FAST \ ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); \ srand(time(NULL)); ll power(ll x, ll y, ll m) { ll r = 1; for (; y; y >>= 1) { if (y & 1) r = r * x % m; x = x * x % m; } return r; } const ll mod = 1e9 + 7; const ld pi = 3.14159265358979; int run_test() { ll n, k; cin >> n >> k; while (abs(n - k) < n) { n = abs(n - k); } cout << n; return 0; } int main() { FAST; ll t; t = 1; while (t--) { run_test(); } }
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define pii pair<int, int> #define pll pair<long long, long long> #define pb push_back #define ll long long #define ld long double #define precision(x, d) cout << fixed << setprecision(d) << x #define fill(a, b) memset((a), (b), sizeof((a))) #define FAST \ ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); \ srand(time(NULL)); ll power(ll x, ll y, ll m) { ll r = 1; for (; y; y >>= 1) { if (y & 1) r = r * x % m; x = x * x % m; } return r; } const ll mod = 1e9 + 7; const ld pi = 3.14159265358979; int run_test() { ll n, k; cin >> n >> k; ll t = n / k; n -= k * t; if (abs(n - k) < n) { n = abs(n - k); } cout << n; return 0; } int main() { FAST; ll t; t = 1; while (t--) { run_test(); } }
replace
30
31
30
33
TLE
p02719
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <cstdint> #include <cstdlib> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <map> #include <numeric> #include <set> #include <string> #include <type_traits> #include <vector> typedef long long ll; using namespace std; // 素因数分解 void factoring(ll n, map<ll, ll> &mp) { for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { mp[i]++; n /= i; } } if (n != 1) mp[n]++; } // 絶対値 template <class T, class U = std::make_unsigned_t<T>> U SafeAbs(T x) { return x < 0 ? -static_cast<uintmax_t>(x) : x; } int main() { ll n, k; cin >> n >> k; ll min = n; while (true) { if (SafeAbs(min - k) < min) { min = SafeAbs(min - k); } else { break; } } cout << min << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdint> #include <cstdlib> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <map> #include <numeric> #include <set> #include <string> #include <type_traits> #include <vector> typedef long long ll; using namespace std; // 素因数分解 void factoring(ll n, map<ll, ll> &mp) { for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { mp[i]++; n /= i; } } if (n != 1) mp[n]++; } // 絶対値 template <class T, class U = std::make_unsigned_t<T>> U SafeAbs(T x) { return x < 0 ? -static_cast<uintmax_t>(x) : x; } int main() { ll n, k; cin >> n >> k; ll min = n; if (n % k == 0) { min = 0; } else { min = n % k; while (true) { if (SafeAbs(k - min) < min) { min = SafeAbs(min - k); } else { break; } } } cout << min << endl; return 0; }
replace
43
49
43
53
TLE
p02719
C++
Time Limit Exceeded
#include <iostream> #include <math.h> using namespace std; int main() { unsigned long long int n, k, n1; cin >> n >> k; n1 = n; while (n >= 0) { n = n - k; } n = llabs(n); if (n > n1) { cout << n1; } else cout << n; return 0; }
#include <iostream> #include <math.h> using namespace std; int main() { unsigned long long int n, k, n1; cin >> n >> k; if (n > k) n = n % k; cout << min(n, k - n); return 0; }
replace
7
16
7
10
TLE
p02719
C++
Time Limit Exceeded
#include <iostream> #include <vector> using namespace std; int main() { long N, K, cnt = 0; cin >> N >> K; while (N - K > 0) { N -= K; } if (abs(N - K) < N) { N = abs(N - K); } cout << N; }
#include <iostream> #include <vector> using namespace std; int main() { long N, K, cnt = 0; cin >> N >> K; cnt = N % K; if (abs(cnt - K) < cnt) { N = abs(cnt - K); } else { N = cnt; } cout << N; }
replace
6
11
6
11
TLE
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll x, y; ll abs2(ll f) { if (f < 0) return -f; return f; } ll min2(ll a, ll b) { if (a < b) return a; return b; } int main() { cin >> x >> y; while (x > y) { x = x - y; } cout << min2(abs2(x - y), abs2(x)); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll x, y; ll abs2(ll f) { if (f < 0) return -f; return f; } ll min2(ll a, ll b) { if (a < b) return a; return b; } int main() { cin >> x >> y; if (x > y) { x = x - (x / y) * y; } cout << min2(abs2(x - y), abs2(x)); }
replace
16
18
16
18
TLE
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int a, b; cin >> a >> b; a %= b; cout << min(a, abs(a - b)); }
#include <bits/stdc++.h> using namespace std; int main() { long long a, b; cin >> a >> b; a %= b; cout << min(a, abs(a - b)); }
replace
4
5
4
5
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; int long long a; a = n % k; int long long b; b = k - a; if (a <= b) { cout << a << endl; } else { cout << b << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int long long n, k; cin >> n >> k; int long long a; a = n % k; int long long b; b = k - a; if (a <= b) { cout << a << endl; } else { cout << b << endl; } }
replace
4
5
4
5
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) int main() { int a, b, c, d = INT_MAX, e = 0; cin >> a >> b; cout << min(a % b, (a % b - b) * -1); }
#include <bits/stdc++.h> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) int main() { long long int a, b, c, d = INT_MAX, e = 0; cin >> a >> b; cout << min(a % b, (a % b - b) * -1); }
replace
5
6
5
6
0
p02719
C++
Runtime Error
#include <iostream> using namespace std; int main() { int x, k; cin >> x >> k; if (x > k) { x = x % k; } if (x > k / 2) { x = k - x; } cout << x << endl; }
#include <iostream> using namespace std; int main() { long x, k; cin >> x >> k; if (x > k) { x = x % k; } if (x > k / 2) { x = k - x; } cout << x << endl; }
replace
4
5
4
5
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; if (N % K < (K + 1) / 2) cout << N % K << endl; else cout << K - N % K << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int long long N, K; cin >> N >> K; if (N % K < (K + 1) / 2) cout << N % K << endl; else cout << K - N % K << endl; }
replace
4
5
4
5
0
p02719
C++
Time Limit Exceeded
#include <iostream> #include <vector> using namespace std; long long int monmo(long long int n, long long int k, int keta) { if (n == 0) { return 0; } else if (keta == -1) { return n; } else { long long int tmpk; tmpk = k; for (int i = 0; i < keta; i++) { tmpk *= 10; } while (n >= tmpk) { n -= tmpk; } return monmo(n, k, keta - 1); } } int main(void) { long long int n, k, a, b, na, ka; int cn = 0, ck = 0; cin >> n >> k; na = n; ka = k; while (na > 9) { na /= 10; cn++; } while (ka > 9) { ka /= 10; ck++; } a = monmo(n, k, cn - ck); b = a - k; b *= -1; if (a > b) cout << b; else cout << a; }
#include <iostream> #include <vector> using namespace std; long long int monmo(long long int n, long long int k, int keta) { if (n == 0) { return 0; } else if (keta < 0) { return n; } else { long long int tmpk; tmpk = k; for (int i = 0; i < keta; i++) { tmpk *= 10; } while (n >= tmpk) { n -= tmpk; } return monmo(n, k, keta - 1); } } int main(void) { long long int n, k, a, b, na, ka; int cn = 0, ck = 0; cin >> n >> k; na = n; ka = k; while (na > 9) { na /= 10; cn++; } while (ka > 9) { ka /= 10; ck++; } a = monmo(n, k, cn - ck); b = a - k; b *= -1; if (a > b) cout << b; else cout << a; }
replace
7
8
7
8
TLE
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; long long data = 0; long long ans; if (k == 1) { ans = 0; } else { if (n > k) { data = n % k; ans = k - data; } else if (n == k) { ans = 0; } else { if (n == 1) { ans = 0; } else { if (k % n == 0) { ans = n; } else { data = k % n; ans = n - data; } } } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; long long data = n % k; long long ans = min(data, k - data); cout << ans << endl; }
replace
6
29
6
9
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() typedef long long ll; int main() { ll N, K; cin >> N >> K; ll A = abs(N - K); ll D = min(K, A); cout << N % D << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define all(x) (x).begin(), (x).end() typedef long long ll; int main() { ll N, K; cin >> N >> K; cout << min(N % K, K - N % K) << endl; }
replace
10
15
10
11
0
p02719
C++
Runtime Error
// Author - Sumit #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #pragma GCC optimize("O3") #pragma GCC target("avx") #define ll long long #define int ll #define ps push #define pb emplace_back #define INF 10000000000000LL #define MOD 1000000007 #define mp make_pair #define rep(i, a, b) for (int i = a; i < b; i++) #define repd(i, a, b) for (int i = a; i >= b; i--) #define all(v) v.begin(), v.end() #define pii pair<int, int> #define F first #define S second #define mii map<int, int> #define vi vector<int> #define vvi vector<vi> #define vpii vector<pair<int, int>> #define itr ::iterator it #define WL(t) while (t--) #define gcd(a, b) __gcd((a), (b)) #define lcm(a, b) ((a) * (b)) / gcd((a), (b)) #define lower(v, x) (lower_bound(all(v), x) - v.begin()) #define upper(v, x) (upper_bound(all(v), x) - v.begin()) #define debug(x) cout << x << "\n"; #define debug2(x, y) cout << x << " " << y << "\n"; #define debug3(x, y, z) cout << x << " " << y << " " << z << endl; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; template <typename T, typename U> inline void remin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> inline void remax(T &x, U y) { if (x < y) x = y; } template <typename T> T pow(T a, T b, int m) { T ans = 1; while (b > 0) { if (b % 2 == 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans % m; } void solve() { int n, m; cin >> n >> m; if (m == 1) { debug(0); return; } m = abs(n - m); int x = (n % m); x = min(x, m - x); debug(x); } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); clock_t clk = clock(); int t = 1; // cin>>t; while (t--) { solve(); } cerr << ((long double)(1.00 * clock() - clk) / CLOCKS_PER_SEC) << "\n"; }
// Author - Sumit #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace __gnu_pbds; using namespace std; #pragma GCC optimize("O3") #pragma GCC target("avx") #define ll long long #define int ll #define ps push #define pb emplace_back #define INF 10000000000000LL #define MOD 1000000007 #define mp make_pair #define rep(i, a, b) for (int i = a; i < b; i++) #define repd(i, a, b) for (int i = a; i >= b; i--) #define all(v) v.begin(), v.end() #define pii pair<int, int> #define F first #define S second #define mii map<int, int> #define vi vector<int> #define vvi vector<vi> #define vpii vector<pair<int, int>> #define itr ::iterator it #define WL(t) while (t--) #define gcd(a, b) __gcd((a), (b)) #define lcm(a, b) ((a) * (b)) / gcd((a), (b)) #define lower(v, x) (lower_bound(all(v), x) - v.begin()) #define upper(v, x) (upper_bound(all(v), x) - v.begin()) #define debug(x) cout << x << "\n"; #define debug2(x, y) cout << x << " " << y << "\n"; #define debug3(x, y, z) cout << x << " " << y << " " << z << endl; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; template <typename T, typename U> inline void remin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> inline void remax(T &x, U y) { if (x < y) x = y; } template <typename T> T pow(T a, T b, int m) { T ans = 1; while (b > 0) { if (b % 2 == 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans % m; } void solve() { int n, m; cin >> n >> m; int x = n / m; int mm = (x * m); int ans = abs(mm - n); ans = min(m - ans, ans); debug(ans); } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); clock_t clk = clock(); int t = 1; // cin>>t; while (t--) { solve(); } cerr << ((long double)(1.00 * clock() - clk) / CLOCKS_PER_SEC) << "\n"; }
replace
63
71
63
68
0
6.9e-05
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; if (N < abs(N - K)) { cout << N; } if (N % K == 0) { cout << '0'; } if (N % K == 1) { cout << '1'; } }
#include <bits/stdc++.h> using namespace std; int main() { int64_t N, M; cin >> N >> M; long long n = N % M; long long ans; ans = min(n, M - n); cout << ans << endl; }
replace
3
14
3
9
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; cout << min(N % K, K - (N % K)) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int64_t N, K; cin >> N >> K; cout << min(N % K, K - (N % K)) << endl; }
replace
4
5
4
5
0
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) int main() { long long n, k; cin >> n >> k; set<long long> st; long long n_min = n; while (st.count(n) == 0) { st.insert(n); n = abs(n - k); n_min = min(n, n_min); } cout << n_min << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) int main() { long long n, k; cin >> n >> k; n %= k; long long a = abs(n - k); long long ans = min(a, n); cout << ans << endl; }
replace
7
15
7
11
TLE
p02719
C++
Time Limit Exceeded
#include "bits/stdc++.h" using namespace std; int main() { long long n, k; cin >> n >> k; long long min = n; if (n % k == 0) { cout << 0; return 0; } while (1) { n = abs(n - k); if (n < min && n != 0) { min = n; } else { cout << min; return 0; } } if (n != 0) { cout << min; } else { cout << 0; } }
#include "bits/stdc++.h" using namespace std; int main() { long long n, k; cin >> n >> k; long long min = n; if (n > k) { n = n % k; } if (n % k == 0) { cout << 0; return 0; } while (1) { n = abs(n - k); if (n < min && n != 0) { min = n; } else { cout << min; return 0; } } if (n != 0) { cout << min; } else { cout << 0; } }
insert
7
7
7
10
TLE
p02719
C++
Runtime Error
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; cout << min(n % k, k - (n % k)) << endl; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; cout << min(n % k, k - (n % k)) << endl; }
replace
5
6
5
6
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, K, a; cin >> N >> K; a = min(N % K, K - (N % K)); cout << a << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long N, K, a; cin >> N >> K; a = min(N % K, K - (N % K)); cout << a << endl; }
replace
4
5
4
5
0
p02719
C++
Time Limit Exceeded
#include <algorithm> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; #define ll long long int int main(void) { ios::sync_with_stdio(false); cin.tie(0); ll n, m; cin >> n >> m; while (true) { if (n < abs(n - m)) break; n = abs(n - m); } cout << n << endl; return 0; }
#include <algorithm> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <stack> #include <string> #include <vector> using namespace std; #define ll long long int int main(void) { ios::sync_with_stdio(false); cin.tie(0); ll n, m; cin >> n >> m; n %= m; n = (n < abs(n - m)) ? n : abs(n - m); cout << n << endl; return 0; }
replace
22
27
22
25
TLE
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; if (n < k) { cout << min(n, -(n - k)) << endl; return 0; } long long big = n, small = n; while (big % k != 0) { big++; } while (small % k != 0) { small--; } // cout << big << " & " << small << endl; cout << min(big % n, n % small) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; long long t = n % k; cout << min(t, k - t) << endl; return 0; }
replace
6
21
6
8
TLE
p02719
C++
Time Limit Exceeded
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; using ll = long long; using vl = vector<ll>; using vc = vector<char>; using vvl = vector<vector<ll>>; using vvc = vector<vector<char>>; #define rep(i, n) for (ll i = 0; i < ll(n); i++) #define repd(i, n) for (ll i = n - 1; i >= 0; i--) #define all(x) x.begin(), x.end() ll n, k, m, M = 1e9 + 7; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> k; while (abs(n - k) < n) n = abs(n - k); cout << n << endl; }
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; using ll = long long; using vl = vector<ll>; using vc = vector<char>; using vvl = vector<vector<ll>>; using vvc = vector<vector<char>>; #define rep(i, n) for (ll i = 0; i < ll(n); i++) #define repd(i, n) for (ll i = n - 1; i >= 0; i--) #define all(x) x.begin(), x.end() ll n, k, m, M = 1e9 + 7; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> k; if (n > k) n %= k; while (abs(k - n) < n) n = abs(k - n); cout << n << endl; }
replace
22
24
22
27
TLE
p02719
C++
Time Limit Exceeded
#include <algorithm> #include <iostream> #include <string> #include <vector> #define T long long T Abs(T n) { return n > 0 ? n : -n; } int main() { T n, k; std::cin >> n >> k; while (1) { if (Abs(n - k) >= n) { std::cout << n << std::endl; return 0; } else if (n % k == 0) { std::cout << 0 << std::endl; return 0; } n = Abs(n - k); } }
#include <algorithm> #include <iostream> #include <string> #include <vector> #define T long long T Abs(T n) { return n > 0 ? n : -n; } int main() { T n, k; std::cin >> n >> k; if (n > k) { n = n % k; } while (1) { if (Abs(n - k) >= n) { std::cout << n << std::endl; return 0; } else if (n % k == 0) { std::cout << 0 << std::endl; return 0; } n = Abs(n - k); } }
insert
12
12
12
15
TLE
p02719
C++
Time Limit Exceeded
#include <iostream> #include <math.h> using namespace std; int main() { long long int n, k; cin >> n >> k; while (1) { if (n <= 1000 * k) break; n -= 1000 * k; } long long int x = n; while (1) { if (abs(x - k) < x) { x = abs(x - k); // cout << x << endl; } else break; } cout << x << endl; return 0; }
#include <iostream> #include <math.h> using namespace std; int main() { long long int n, k; cin >> n >> k; long long int p, q; p = n % k; q = k - n % k; if (p < q) cout << p << endl; else cout << q << endl; return 0; }
replace
8
24
8
15
TLE
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; long long oper(long long n, long long k) { return abs(n - k); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, k; cin >> n >> k; if (k == 1) cout << 0 << "\n"; else { while (n >= 0) { n = oper(n, k); if (oper(n, k) > n) { cout << n << "\n"; break; } } } return 0; }
#include <bits/stdc++.h> using namespace std; long long oper(long long n, long long k) { return abs(n - k); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long n, k; cin >> n >> k; if (k == 1) cout << 0 << "\n"; else { cout << min(n % k, k - (n % k)) << "\n"; } return 0; }
replace
14
21
14
15
TLE
p02719
C++
Runtime Error
#include <cmath> #include <iostream> typedef long long int ll; #define fr(x, y) for (int x = 0; x < y; x++) #include <algorithm> #include <vector> using namespace std; int main() { int n, k; cin >> n >> k; n = n % k; cout << min(k - n, n); }
#include <cmath> #include <iostream> typedef long long int ll; #define fr(x, y) for (int x = 0; x < y; x++) #include <algorithm> #include <vector> using namespace std; int main() { ll n, k; cin >> n >> k; n = n % k; cout << min(k - n, n); }
replace
10
11
10
11
0
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, k; void solve() { cout << min(n % k, abs(n % k - k)) << endl; } int main() { cin >> n >> k; solve(); }
#include <bits/stdc++.h> using namespace std; int64_t n, k; void solve() { cout << min(n % k, abs(n % k - k)) << endl; } int main() { cin >> n >> k; solve(); }
replace
3
4
3
4
0
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using p = pair<int, int>; typedef long long ll; int main() { ll n, k; cin >> n >> k; while (n > 0) { n -= k; } if (n == 0) { cout << 0 << endl; } else if (n < 0) { cout << min(abs(n), abs(n + k)) << endl; } return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using p = pair<int, int>; typedef long long ll; int main() { ll n, k; cin >> n >> k; cout << min(n % k, k - (n % k)) << endl; return 0; }
replace
10
18
10
12
TLE
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int64_t N, K; cin >> N >> K; if (K == 1) { cout << 0 << endl; } else { for (int i = 0;; i++) { int64_t a = max(N, K), b = min(N, K); if (N <= a - N) { cout << N << endl; break; } else { N = a - b; } } } }
#include <bits/stdc++.h> using namespace std; int main() { int64_t N, K; cin >> N >> K; if (K == 1) { cout << 0 << endl; } else { int64_t a = N % K, b = K - a; int64_t c = min(a, b); cout << c << endl; } }
replace
9
18
9
12
TLE
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> pi; typedef pair<int, int> vi; #define F first #define S second #define PB push_back #define MK make_pair #define REP(i, a, b) for (int i = a; i < b; i++) int main() { ll N, K; cin >> N >> K; pi visited = {N}; ll result = N; if (N % K == 0) { cout << 0 << "\n"; exit(0); } while (N > 0) { N = abs(N - K); if (result < N) { N = 0; } else { result = N; } } cout << result << "\n"; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef vector<ll> pi; typedef pair<int, int> vi; #define F first #define S second #define PB push_back #define MK make_pair #define REP(i, a, b) for (int i = a; i < b; i++) int main() { ll N, K; cin >> N >> K; pi visited = {N}; ll result = N; N = N % K; if (N % K == 0) { cout << 0 << "\n"; exit(0); } while (N > 0) { N = abs(N - K); if (result < N) { N = 0; } else { result = N; } } cout << result << "\n"; }
insert
19
19
19
20
TLE
p02719
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, x; cin >> n >> k; if (n < k) x = k % n; else x = n % k; if (n != k) cout << min(x, k - x) << endl; else cout << 0 << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, x; cin >> n >> k; if (n < k) x = n; else x = n % k; if (n != k) cout << min(x, k - x) << endl; else cout << 0 << endl; }
replace
8
9
8
9
0
p02719
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { long long N, K; cin >> N >> K; while (N > K) { N -= K; } cout << min(N, K - N); }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { long long N, K; cin >> N >> K; if (N > K) { N = N - (N / K) * K; } cout << min(N, K - N); }
replace
7
9
7
9
TLE
p02719
C++
Time Limit Exceeded
#include <cmath> #include <iostream> using namespace std; #define rep(i, n) for (int i = 1; i <= (n); i++) int main() { long long int n, k; cin >> n >> k; while (n > abs(n - k)) { if (n % k == 0) n = 0; n = abs(n - k); } cout << n; }
#include <cmath> #include <iostream> using namespace std; #define rep(i, n) for (int i = 1; i <= (n); i++) int main() { long long int n, k; cin >> n >> k; n = min(n % k, abs(n % k - k)); cout << n; }
replace
7
12
7
8
TLE
p02720
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int k; long long c[13][10] = {}; cin >> k; rep(i, 10) c[0][i] = 1; for (int i = 0;; i++) { for (int j = 1; j < 10; j++) { if (k > c[i][j]) { k -= c[i][j]; } else { long long r = j; i--; for (; i >= 0; i--) { if (j > 0 && c[i][j - 1] >= k) { j = j - 1; r = r * 10 + j; continue; } if (j > 0) k -= c[i][j - 1]; if (c[i][j] >= k) { r = r * 10 + j; continue; } k -= c[i][j]; j = j + 1; r = r * 10 + j; } cout << r << endl; return r; } } for (int j = 0; j < 10; j++) { if (j > 0) { c[i + 1][j] += c[i][j - 1]; } if (j < 9) { c[i + 1][j] += c[i][j + 1]; } c[i + 1][j] += c[i][j]; } } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) int main() { int k; long long c[13][10] = {}; cin >> k; rep(i, 10) c[0][i] = 1; for (int i = 0;; i++) { for (int j = 1; j < 10; j++) { if (k > c[i][j]) { k -= c[i][j]; } else { long long r = j; i--; for (; i >= 0; i--) { if (j > 0 && c[i][j - 1] >= k) { j = j - 1; r = r * 10 + j; continue; } if (j > 0) k -= c[i][j - 1]; if (c[i][j] >= k) { r = r * 10 + j; continue; } k -= c[i][j]; j = j + 1; r = r * 10 + j; } cout << r << endl; return 0; } } for (int j = 0; j < 10; j++) { if (j > 0) { c[i + 1][j] += c[i][j - 1]; } if (j < 9) { c[i + 1][j] += c[i][j + 1]; } c[i + 1][j] += c[i][j]; } } }
replace
33
34
33
34
23
p02720
C++
Runtime Error
#include <iostream> #include <queue> using namespace std; long long lunlun_number(int k) { int count = 0; queue<long long> que; for (int i = 1; i <= 9; i++) { que.push(i); } long long ans; while (count < k) { ans = que.front(); que.pop(); count++; // minus; if (ans % 10 != 0) { que.push(10 * ans + (ans % 10) - 1); } que.push(10 * ans + (ans % 10)); if (ans % 10 != 9) { que.push(10 * ans + (ans % 10) + 1); } } return ans; } int main() { int k; cin >> k; return lunlun_number(k); }
#include <iostream> #include <queue> using namespace std; long long lunlun_number(int k) { int count = 0; queue<long long> que; for (int i = 1; i <= 9; i++) { que.push(i); } long long ans; while (count < k) { ans = que.front(); que.pop(); count++; // minus; if (ans % 10 != 0) { que.push(10 * ans + (ans % 10) - 1); } que.push(10 * ans + (ans % 10)); if (ans % 10 != 9) { que.push(10 * ans + (ans % 10) + 1); } } return ans; } int main() { int k; cin >> k; cout << lunlun_number(k); }
replace
36
37
36
37
23
p02720
C++
Time Limit Exceeded
/* */ #include <bits/stdc++.h> using namespace std; using lint = int64_t; char to_char(int n) { return n + '0'; }; int to_int(char c) { return c - '0'; }; /* */ void solve(string s, int ord, int k); int cnt = 0; int main() { int k; cin >> k; int ord = 1; cnt = 9; ord = 2; while (true) { for (int i = 1; i <= 9; i++) { solve(to_string(i), ord, k); } ord++; } } void solve(string s, int ord, int k) { if (s.size() == ord) { cnt++; if (cnt == k) { cout << s << endl; exit(0); } return; } for (int i = -1; i <= 1; i++) { int tmp = to_int(s.back()) + i; if (tmp < 0 || tmp > 9) continue; s.push_back(to_char(tmp)); solve(s, ord, k); s.pop_back(); } }
/* */ #include <bits/stdc++.h> using namespace std; using lint = int64_t; char to_char(int n) { return n + '0'; }; int to_int(char c) { return c - '0'; }; /* */ void solve(string s, int ord, int k); int cnt = 0; int main() { int k; cin >> k; int ord = 1; if (k < 10) { cout << k << endl; return 0; } cnt = 9; ord = 2; while (true) { for (int i = 1; i <= 9; i++) { solve(to_string(i), ord, k); } ord++; } } void solve(string s, int ord, int k) { if (s.size() == ord) { cnt++; if (cnt == k) { cout << s << endl; exit(0); } return; } for (int i = -1; i <= 1; i++) { int tmp = to_int(s.back()) + i; if (tmp < 0 || tmp > 9) continue; s.push_back(to_char(tmp)); solve(s, ord, k); s.pop_back(); } }
insert
15
15
15
19
TLE
p02720
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, // cmp, rb_tree_tag, tree_order_statistics_node_update>; #define inf 100000000000000000 #define ll long long #define pb push_back #define f first #define s second #define mod 1000000007 #define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define test \ ll t; \ cin >> t; \ while (t--) void mahakal() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif } int main() { mahakal(), fast; ll n; cin >> n; queue<ll> q; for (ll i = 1; i <= 9; i++) q.push(i); while (n > 1) { ll ps = q.front(); q.pop(); // cerr<<ps<<" "; if (ps % 10 != 0) q.push(10 * ps + ps % 10 - 1); q.push(10 * ps + ps % 10); if (ps % 10 != 9) q.push(10 * ps + ps % 10 + 1); n--; } cout << q.front() << endl; return 0; }
#include <bits/stdc++.h> using namespace std; // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, // cmp, rb_tree_tag, tree_order_statistics_node_update>; #define inf 100000000000000000 #define ll long long #define pb push_back #define f first #define s second #define mod 1000000007 #define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL) #define test \ ll t; \ cin >> t; \ while (t--) void mahakal() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif } int main() { // mahakal(),fast; ll n; cin >> n; queue<ll> q; for (ll i = 1; i <= 9; i++) q.push(i); while (n > 1) { ll ps = q.front(); q.pop(); // cerr<<ps<<" "; if (ps % 10 != 0) q.push(10 * ps + ps % 10 - 1); q.push(10 * ps + ps % 10); if (ps % 10 != 9) q.push(10 * ps + ps % 10 + 1); n--; } cout << q.front() << endl; return 0; }
replace
26
27
26
27
-6
p02720
C++
Runtime Error
// // lunlun.cpp // learningCplusplus // // Created by Tran Duc Chinh on 2020/04/04. // Copyright © 2020 Tran Duc Chinh. All rights reserved. // #include <iostream> int main(int argc, const char *argv[]) { int k; std::cin >> k; long long a[k]; int i = 0; for (i = 0; i < 9; i++) { a[i] = i + 1; } int index = 0; while (i < k) { // if (a[index]%10 == 9) { // a[i] = a[index]*10 + (a[index]%10 - 1); // a[i+1] = a[index]*10 + (a[index]%10); // i=i+2; // } // else if (a[index]%10 == 0) { // a[i] = a[index]*10 + (a[index]%10); // a[i+1] = a[index]*10 + (a[index]%10 + 1); // i=i+2; // } // else { // a[i] = a[index]*10 + (a[index]%10 - 1); // a[i+1] = a[index]*10 + (a[index]%10); // a[i+2] = a[index]*10 + (a[index]%10 + 1); // i=i+3; // } if (a[index] % 10 != 0) { a[i] = a[index] * 10 + (a[index] % 10 - 1); i++; } a[i] = a[index] * 10 + (a[index] % 10); i++; if (a[index] % 10 != 9) { a[i] = a[index] * 10 + (a[index] % 10 + 1); i++; } index++; } // for (int i=0; i<k; i++) { // std::cout << a[i] << " "; // } // std::cout << std::endl; // std::cout << "index " << index << std::endl; std::cout << a[k - 1] << std::endl; }
// // lunlun.cpp // learningCplusplus // // Created by Tran Duc Chinh on 2020/04/04. // Copyright © 2020 Tran Duc Chinh. All rights reserved. // #include <iostream> int main(int argc, const char *argv[]) { int k; std::cin >> k; long long a[100000]; int i = 0; for (i = 0; i < 9; i++) { a[i] = i + 1; } int index = 0; while (i < k) { // if (a[index]%10 == 9) { // a[i] = a[index]*10 + (a[index]%10 - 1); // a[i+1] = a[index]*10 + (a[index]%10); // i=i+2; // } // else if (a[index]%10 == 0) { // a[i] = a[index]*10 + (a[index]%10); // a[i+1] = a[index]*10 + (a[index]%10 + 1); // i=i+2; // } // else { // a[i] = a[index]*10 + (a[index]%10 - 1); // a[i+1] = a[index]*10 + (a[index]%10); // a[i+2] = a[index]*10 + (a[index]%10 + 1); // i=i+3; // } if (a[index] % 10 != 0) { a[i] = a[index] * 10 + (a[index] % 10 - 1); i++; } a[i] = a[index] * 10 + (a[index] % 10); i++; if (a[index] % 10 != 9) { a[i] = a[index] * 10 + (a[index] % 10 + 1); i++; } index++; } // for (int i=0; i<k; i++) { // std::cout << a[i] << " "; // } // std::cout << std::endl; // std::cout << "index " << index << std::endl; std::cout << a[k - 1] << std::endl; }
replace
13
14
13
14
0
p02720
C++
Runtime Error
#include <bits/stdc++.h> #include <cstdio> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) int main() { int k; long ans; // scanf("%d", &x); cin >> k; if (k <= 10) { cout << k << endl; return 1; } queue<long> que; long i = 0; rep(j, 9) { que.push(i + 1); i++; } long next; long prev; while (i < k) { prev = que.front(); que.pop(); long d = prev % 10; if (d != 0) { next = prev * 10 + d - 1; que.push(next); i++; } if (i == k) { break; } next = prev * 10 + d; que.push(next); i++; if (i == k) { break; } if (d != 9) { next = prev * 10 + d + 1; que.push(next); i++; } } // printf("%d\n", x * x * x); cout << next << endl; }
#include <bits/stdc++.h> #include <cstdio> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) int main() { int k; long ans; // scanf("%d", &x); cin >> k; if (k <= 10) { cout << k << endl; return 0; } queue<long> que; long i = 0; rep(j, 9) { que.push(i + 1); i++; } long next; long prev; while (i < k) { prev = que.front(); que.pop(); long d = prev % 10; if (d != 0) { next = prev * 10 + d - 1; que.push(next); i++; } if (i == k) { break; } next = prev * 10 + d; que.push(next); i++; if (i == k) { break; } if (d != 9) { next = prev * 10 + d + 1; que.push(next); i++; } } // printf("%d\n", x * x * x); cout << next << endl; }
replace
12
13
12
13
0
p02720
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define pb push_back #define all(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) #define REP(i, n) for (int _n = n, i = 0; i < _n; ++i) #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i) using ull = uint64_t; using ll = int64_t; using PII = pair<int, int>; using VI = vector<int>; string to_string(string s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) void rec(int digits, vector<ll> &nums, string &n) { if (SZ(nums) > 100009) return; if (digits == 0) { if (SZ(n) > 0) { nums.pb(stoll(n)); } } else { for (int i = 0; i < 10; i++) { if (SZ(n) == 0) { if (i > 0) { n.pb('0' + i); } rec(digits - 1, nums, n); n.pop_back(); } else if (abs(*(prev(n.end())) - ('0' + i)) <= 1) { n.pb('0' + i); rec(digits - 1, nums, n); n.pop_back(); } } } } int main() { ios::sync_with_stdio(false), cin.tie(0); int K; cin >> K; string n = ""; vector<ll> nums; rec(10, nums, n); cout << nums[K - 1] << endl; }
// #include <bits/stdc++.h> #include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; #define pb push_back #define all(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) #define REP(i, n) for (int _n = n, i = 0; i < _n; ++i) #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i) using ull = uint64_t; using ll = int64_t; using PII = pair<int, int>; using VI = vector<int>; string to_string(string s) { return '"' + s + '"'; } string to_string(const char *s) { return to_string((string)s); } string to_string(bool b) { return (b ? "true" : "false"); } template <typename A, typename B> string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } template <typename A> string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; } void debug_out() { cerr << endl; } template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); } #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) void rec(int digits, vector<ll> &nums, string &n) { if (SZ(nums) > 100009) return; if (digits == 0) { if (SZ(n) > 0) { nums.pb(stoll(n)); } } else { for (int i = 0; i < 10; i++) { if (SZ(n) == 0) { if (i > 0) { n.pb('0' + i); } rec(digits - 1, nums, n); n.pop_back(); } else if (abs(*(prev(n.end())) - ('0' + i)) <= 1) { n.pb('0' + i); rec(digits - 1, nums, n); n.pop_back(); } } } } int main() { ios::sync_with_stdio(false), cin.tie(0); int K; cin >> K; string n = ""; vector<ll> nums; rec(10, nums, n); cout << nums[K - 1] << endl; }
replace
0
1
0
5
-11
p02720
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define ll long long const int mod = 1000000007; // const int mod = 998244353; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } // combination mod prime // https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619 struct combination { vector<mint> fact, ifact; combination(int n) : fact(n + 1), ifact(n + 1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n] * ifact[k] * ifact[n - k]; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); int K; cin >> K; queue<ll> Q; rep(i, 9) Q.push(i + 1); if (K <= 9) { cout << K << endl; } int k = 9; while (1) { ll x = Q.front(); Q.pop(); ll d = x % 10; for (int dd = -1; dd <= 1; ++dd) { int nd = d + dd; if (nd < 0 || nd > 9) continue; ll nx = 10 * x + nd; k++; // cout << nx << endl; if (k == K) { cout << nx << endl; return 0; } Q.push(10 * x + nd); } } }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); ++i) #define ll long long const int mod = 1000000007; // const int mod = 998244353; struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % mod + mod) % mod) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint &operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { return mint(*this) += a; } mint operator-(const mint a) const { return mint(*this) -= a; } mint operator*(const mint a) const { return mint(*this) *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint &operator/=(const mint a) { return *this *= a.inv(); } mint operator/(const mint a) const { return mint(*this) /= a; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } } ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } // combination mod prime // https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619 struct combination { vector<mint> fact, ifact; combination(int n) : fact(n + 1), ifact(n + 1) { assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n] * ifact[k] * ifact[n - k]; } }; int main() { ios::sync_with_stdio(false); cin.tie(0); int K; cin >> K; queue<ll> Q; rep(i, 9) Q.push(i + 1); if (K <= 9) { cout << K << endl; return 0; } int k = 9; while (1) { ll x = Q.front(); Q.pop(); ll d = x % 10; for (int dd = -1; dd <= 1; ++dd) { int nd = d + dd; if (nd < 0 || nd > 9) continue; ll nx = 10 * x + nd; k++; // cout << nx << endl; if (k == K) { cout << nx << endl; return 0; } Q.push(10 * x + nd); } } }
insert
93
93
93
94
TLE
p02720
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define m_k make_pair #define P pair<int, int> #define V vector typedef long long LL; typedef unsigned long long ULL; // 补题:题解放在了怎么从第1个得到第k个 // 事实上,若a>b,则a变化得到的一定>b变化得到的 int main() { int k; cin >> k; if (k <= 9) { cout << k << endl; return k; } queue<LL> que; for (int i = 1; i <= 9; i++) que.push(i); LL current; for (int i = 1; i <= k; i++) { current = que.front(); // 第k次取出来的就是第k个 que.pop(); int tail = current % 10; if (tail > 0) que.push(current * 10 + tail - 1); que.push(current * 10 + tail); if (tail < 9) que.push(current * 10 + tail + 1); } cout << current << endl; return 0; } /* int f[15][15]; void get(int st,int t,int k,queue<int> &s) { if(t==0) return; { if(st==0) { if(k<f[t][0]){ s.push(0); get(0,t-1,k,s); return; } else{ k-=f[t][0]; s.push(1); get(1,t-1,k,s); return; } } else { for(int i=st-1;i<=st+1;i++) { if(f[t][i]<k) k-=f[t][i]; else{ s.push(i); get(i,t-1,k,s); return; } } } } } int main() { //i位数,首位是j int cnt[15]; for(int i=0;i<=9;i++) f[1][i]=1; cnt[1]=9; for(int i=2;i<=13;i++) { cnt[i]=0; for(int j=0;j<=9;j++) { if(j==0) f[i][j]=f[i-1][0]+f[i-1][1]; else if(j==9) f[i][j]=f[i-1][9]+f[i-1][8]; else f[i][j]=f[i-1][j]+f[i-1][j-1]+f[i-1][j+1]; cnt[i]+=f[i][j]; } } int k; while(cin>>k) { queue<int> ans; int t=1; while(k-cnt[t]>0){ k-=cnt[t]; t++; } //t位数的第k个 for(int i=1;i<=9;i++) { if(f[t][i]<k) k-=f[t][i]; else{ ans.push(i); get(i,t-1,k,ans); break; } } while(!ans.empty()){ cout<<ans.front(); ans.pop(); } cout<<endl; } return 0; } */
#include <bits/stdc++.h> using namespace std; #define m_k make_pair #define P pair<int, int> #define V vector typedef long long LL; typedef unsigned long long ULL; // 补题:题解放在了怎么从第1个得到第k个 // 事实上,若a>b,则a变化得到的一定>b变化得到的 int main() { int k; cin >> k; if (k <= 9) { cout << k << endl; return 0; } queue<LL> que; for (int i = 1; i <= 9; i++) que.push(i); LL current; for (int i = 1; i <= k; i++) { current = que.front(); // 第k次取出来的就是第k个 que.pop(); int tail = current % 10; if (tail > 0) que.push(current * 10 + tail - 1); que.push(current * 10 + tail); if (tail < 9) que.push(current * 10 + tail + 1); } cout << current << endl; return 0; } /* int f[15][15]; void get(int st,int t,int k,queue<int> &s) { if(t==0) return; { if(st==0) { if(k<f[t][0]){ s.push(0); get(0,t-1,k,s); return; } else{ k-=f[t][0]; s.push(1); get(1,t-1,k,s); return; } } else { for(int i=st-1;i<=st+1;i++) { if(f[t][i]<k) k-=f[t][i]; else{ s.push(i); get(i,t-1,k,s); return; } } } } } int main() { //i位数,首位是j int cnt[15]; for(int i=0;i<=9;i++) f[1][i]=1; cnt[1]=9; for(int i=2;i<=13;i++) { cnt[i]=0; for(int j=0;j<=9;j++) { if(j==0) f[i][j]=f[i-1][0]+f[i-1][1]; else if(j==9) f[i][j]=f[i-1][9]+f[i-1][8]; else f[i][j]=f[i-1][j]+f[i-1][j-1]+f[i-1][j+1]; cnt[i]+=f[i][j]; } } int k; while(cin>>k) { queue<int> ans; int t=1; while(k-cnt[t]>0){ k-=cnt[t]; t++; } //t位数的第k个 for(int i=1;i<=9;i++) { if(f[t][i]<k) k-=f[t][i]; else{ ans.push(i); get(i,t-1,k,ans); break; } } while(!ans.empty()){ cout<<ans.front(); ans.pop(); } cout<<endl; } return 0; } */
replace
15
16
15
16
0
p02720
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; // #define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; const ll mod = 1000000007; const ll INF = mod * mod; typedef pair<int, int> P; #define stop \ char nyaa; \ cin >> nyaa; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) #define all(v) (v).begin(), (v).end() typedef pair<ll, ll> LP; typedef long double ld; typedef pair<ld, ld> LDP; const ld eps = 1e-12; const ld pi = acos(-1.0); ll mod_pow(ll a, ll n, ll m = mod) { ll res = 1; while (n) { if (n & 1) res = res * a % m; a = a * a % m; n >>= 1; } return res; } struct modint { ll n; modint() : n(0) { ; } modint(ll m) : n(m) { if (n >= mod) n %= mod; else if (n < 0) n = (n % mod + mod) % mod; } operator int() { return n; } }; bool operator==(modint a, modint b) { return a.n == b.n; } modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod) a.n -= mod; return a; } modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0) a.n += mod; return a; } modint operator*=(modint &a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; } modint operator+(modint a, modint b) { return a += b; } modint operator-(modint a, modint b) { return a -= b; } modint operator*(modint a, modint b) { return a *= b; } modint operator^(modint a, int n) { if (n == 0) return modint(1); modint res = (a * a) ^ (n / 2); if (n % 2) res = res * a; return res; } ll inv(ll a, ll p) { return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p); } modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); } const int max_n = 10000; modint fact[max_n], factinv[max_n]; void init_f() { fact[0] = modint(1); for (int i = 0; i < max_n - 1; i++) { fact[i + 1] = fact[i] * modint(i + 1); } factinv[max_n - 1] = modint(1) / fact[max_n - 1]; for (int i = max_n - 2; i >= 0; i--) { factinv[i] = factinv[i + 1] * modint(i + 1); } } modint comb(int a, int b) { if (a < 0 || b < 0 || a < b) return 0; return fact[a] * factinv[b] * factinv[a - b]; } int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; bool used[10][11]; ll dp[10][11]; ll dfs(int t, int p) { if (t < 0) return 0; if (used[t][p]) return dp[t][p]; used[t][p] = true; ll res = 0; if (p == 10) { if (t == 0) res = 9; else { res += dfs(t - 1, 10); rep1(i, 9) { res += dfs(t - 1, i); } } } else { if (t == 0) { if (p > 0) res++; res++; if (p + 1 < 10) res++; } else { if (p > 0) { res += dfs(t - 1, p - 1); } res += dfs(t - 1, p); if (p + 1 < 10) { res += dfs(t - 1, p + 1); } } } return dp[t][p] = res; } void solve() { ll k; cin >> k; string ans; int sta; rep(i, 10) { if (k <= dfs(i, 10)) { sta = i; break; } } if (k < 10) { cout << k << "\n"; return; } if (k == dfs(sta, 10)) { rep(i, sta + 1) ans.push_back('9'); cout << ans << "\n"; return; } // cout << "??? " << sta << "\n"; k -= dfs(sta - 1, 10); int pre = -1; for (int i = sta; i > 0; i--) { // cout << "?? " << k << "\n"; rep(j, 10) { if (i == sta && j == 0) continue; if (pre >= 0 && abs(pre - j) > 1) continue; if (k <= dfs(i - 1, j)) { ans.push_back('0' + j); pre = j; break; } else { k -= dfs(i - 1, j); } } } if (ans.back() == '0') ans.push_back(ans.back() - 1 + k); else ans.push_back(ans.back() - 2 + k); for (char c : ans) assert('0' <= c && c <= '9'); cout << ans << "\n"; // cout << dfs(4, 10) << "\n"; } signed main() { ios::sync_with_stdio(false); cin.tie(0); // cout << fixed << setprecision(7); // init_f(); // init(); int t; cin >> t; rep(i, t) solve(); // solve(); stop return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <ciso646> #include <cmath> #include <complex> #include <cstdio> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <utility> #include <vector> using namespace std; // #define int long long typedef long long ll; typedef unsigned long long ul; typedef unsigned int ui; const ll mod = 1000000007; const ll INF = mod * mod; typedef pair<int, int> P; #define stop \ char nyaa; \ cin >> nyaa; #define rep(i, n) for (int i = 0; i < n; i++) #define per(i, n) for (int i = n - 1; i >= 0; i--) #define Rep(i, sta, n) for (int i = sta; i < n; i++) #define rep1(i, n) for (int i = 1; i <= n; i++) #define per1(i, n) for (int i = n; i >= 1; i--) #define Rep1(i, sta, n) for (int i = sta; i <= n; i++) #define all(v) (v).begin(), (v).end() typedef pair<ll, ll> LP; typedef long double ld; typedef pair<ld, ld> LDP; const ld eps = 1e-12; const ld pi = acos(-1.0); ll mod_pow(ll a, ll n, ll m = mod) { ll res = 1; while (n) { if (n & 1) res = res * a % m; a = a * a % m; n >>= 1; } return res; } struct modint { ll n; modint() : n(0) { ; } modint(ll m) : n(m) { if (n >= mod) n %= mod; else if (n < 0) n = (n % mod + mod) % mod; } operator int() { return n; } }; bool operator==(modint a, modint b) { return a.n == b.n; } modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod) a.n -= mod; return a; } modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0) a.n += mod; return a; } modint operator*=(modint &a, modint b) { a.n = ((ll)a.n * b.n) % mod; return a; } modint operator+(modint a, modint b) { return a += b; } modint operator-(modint a, modint b) { return a -= b; } modint operator*(modint a, modint b) { return a *= b; } modint operator^(modint a, int n) { if (n == 0) return modint(1); modint res = (a * a) ^ (n / 2); if (n % 2) res = res * a; return res; } ll inv(ll a, ll p) { return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p); } modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); } const int max_n = 10000; modint fact[max_n], factinv[max_n]; void init_f() { fact[0] = modint(1); for (int i = 0; i < max_n - 1; i++) { fact[i + 1] = fact[i] * modint(i + 1); } factinv[max_n - 1] = modint(1) / fact[max_n - 1]; for (int i = max_n - 2; i >= 0; i--) { factinv[i] = factinv[i + 1] * modint(i + 1); } } modint comb(int a, int b) { if (a < 0 || b < 0 || a < b) return 0; return fact[a] * factinv[b] * factinv[a - b]; } int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; bool used[10][11]; ll dp[10][11]; ll dfs(int t, int p) { if (t < 0) return 0; if (used[t][p]) return dp[t][p]; used[t][p] = true; ll res = 0; if (p == 10) { if (t == 0) res = 9; else { res += dfs(t - 1, 10); rep1(i, 9) { res += dfs(t - 1, i); } } } else { if (t == 0) { if (p > 0) res++; res++; if (p + 1 < 10) res++; } else { if (p > 0) { res += dfs(t - 1, p - 1); } res += dfs(t - 1, p); if (p + 1 < 10) { res += dfs(t - 1, p + 1); } } } return dp[t][p] = res; } void solve() { ll k; cin >> k; string ans; int sta; rep(i, 10) { if (k <= dfs(i, 10)) { sta = i; break; } } if (k < 10) { cout << k << "\n"; return; } if (k == dfs(sta, 10)) { rep(i, sta + 1) ans.push_back('9'); cout << ans << "\n"; return; } // cout << "??? " << sta << "\n"; k -= dfs(sta - 1, 10); int pre = -1; for (int i = sta; i > 0; i--) { // cout << "?? " << k << "\n"; rep(j, 10) { if (i == sta && j == 0) continue; if (pre >= 0 && abs(pre - j) > 1) continue; if (k <= dfs(i - 1, j)) { ans.push_back('0' + j); pre = j; break; } else { k -= dfs(i - 1, j); } } } if (ans.back() == '0') ans.push_back(ans.back() - 1 + k); else ans.push_back(ans.back() - 2 + k); for (char c : ans) assert('0' <= c && c <= '9'); cout << ans << "\n"; // cout << dfs(4, 10) << "\n"; } signed main() { ios::sync_with_stdio(false); cin.tie(0); // cout << fixed << setprecision(7); // init_f(); // init(); // int t; cin >> t; rep(i, t)solve(); solve(); stop return 0; }
replace
212
216
212
214
0
p02720
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <iostream> #include <string> #include <typeinfo> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define FORR(i, a, b) for (int i = (b)-1; i >= (a); --i) #define ALL(v) v.begin(), v.end() #define FS first #define SC second #define SZ(a) int((a).size()) #define SORT(c) sort((c).begin(), (c).end()) #define MEMSET(v, h) memset((v), h, sizeof(v)) #define SQR(x) ((x) * (x)) #define BIT(n) (1LL << (n)) #define PCNT(x) __builtin_popcountll(x) #define GCD(x, y) __gcd(x, y) #define LCM(x, y) x / __gcd(x, y) * y #define PB push_back #define MP make_pair #define endl "\n" using namespace std; typedef long long lint; typedef long long LL; typedef long double LD; typedef vector<int> VI; typedef vector<LL> VLL; typedef vector<bool> VB; typedef vector<vector<int>> VVI; typedef vector<vector<LL>> VVLL; typedef vector<vector<bool>> VVB; typedef vector<string> VS; typedef pair<int, int> PII; typedef vector<PII> VPII; const LL INF = 2000000000ll; 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; } int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; map<LL, LL> lun; long long mystoll(string s) { LL ans = 0; for (int i = s.length() - 1; i >= 0; i--) { ans += (s[i] - '0') * pow(10, s.length() - 1 - i); } return ans; } void setdfs(string s) { if (s.length() < 12) { string temp; if (s[0] - '0' > 1 && s[0] - '0' < 9) { temp = (char)(s[0] - 1) + s; lun[mystoll(temp)]++; setdfs(temp); temp = s[0] + s; lun[mystoll(temp)]++; setdfs(temp); temp = (char)(s[0] + 1) + s; lun[mystoll(temp)]++; setdfs(temp); } else if (s[0] == '1') { temp = '1' + s; lun[mystoll(temp)]++; setdfs(temp); temp = '2' + s; lun[mystoll(temp)]++; setdfs(temp); setdfs('0' + s); } else if (s[0] == '0') { temp = '1' + s; lun[mystoll(temp)]++; setdfs('1' + s); setdfs('0' + s); } else if (s[0] == '9') { temp = '9' + s; lun[mystoll(temp)]++; setdfs('9' + s); temp = '8' + s; lun[mystoll(temp)]++; setdfs('8' + s); } } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed << setprecision(10); int K; cin >> K; FOR(i, 1, 10) lun[i]++; setdfs("0"); setdfs("1"); setdfs("2"); setdfs("3"); setdfs("4"); setdfs("5"); setdfs("6"); setdfs("7"); setdfs("8"); setdfs("9"); VLL ans; for (auto itr : lun) { ans.push_back(itr.first); } SORT(ans); cout << ans[K - 1] << endl; }
#include <bits/stdc++.h> #include <iostream> #include <string> #include <typeinfo> #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define FORR(i, a, b) for (int i = (b)-1; i >= (a); --i) #define ALL(v) v.begin(), v.end() #define FS first #define SC second #define SZ(a) int((a).size()) #define SORT(c) sort((c).begin(), (c).end()) #define MEMSET(v, h) memset((v), h, sizeof(v)) #define SQR(x) ((x) * (x)) #define BIT(n) (1LL << (n)) #define PCNT(x) __builtin_popcountll(x) #define GCD(x, y) __gcd(x, y) #define LCM(x, y) x / __gcd(x, y) * y #define PB push_back #define MP make_pair #define endl "\n" using namespace std; typedef long long lint; typedef long long LL; typedef long double LD; typedef vector<int> VI; typedef vector<LL> VLL; typedef vector<bool> VB; typedef vector<vector<int>> VVI; typedef vector<vector<LL>> VVLL; typedef vector<vector<bool>> VVB; typedef vector<string> VS; typedef pair<int, int> PII; typedef vector<PII> VPII; const LL INF = 2000000000ll; 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; } int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; map<LL, LL> lun; long long mystoll(string s) { LL ans = 0; for (int i = s.length() - 1; i >= 0; i--) { ans += (s[i] - '0') * pow(10, s.length() - 1 - i); } return ans; } void setdfs(string s) { if (s.length() < 11) { string temp; if (s[0] - '0' > 1 && s[0] - '0' < 9) { temp = (char)(s[0] - 1) + s; lun[mystoll(temp)]++; setdfs(temp); temp = s[0] + s; lun[mystoll(temp)]++; setdfs(temp); temp = (char)(s[0] + 1) + s; lun[mystoll(temp)]++; setdfs(temp); } else if (s[0] == '1') { temp = '1' + s; lun[mystoll(temp)]++; setdfs(temp); temp = '2' + s; lun[mystoll(temp)]++; setdfs(temp); setdfs('0' + s); } else if (s[0] == '0') { temp = '1' + s; lun[mystoll(temp)]++; setdfs('1' + s); setdfs('0' + s); } else if (s[0] == '9') { temp = '9' + s; lun[mystoll(temp)]++; setdfs('9' + s); temp = '8' + s; lun[mystoll(temp)]++; setdfs('8' + s); } } } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed << setprecision(10); int K; cin >> K; FOR(i, 1, 10) lun[i]++; setdfs("0"); setdfs("1"); setdfs("2"); setdfs("3"); setdfs("4"); setdfs("5"); setdfs("6"); setdfs("7"); setdfs("8"); setdfs("9"); VLL ans; for (auto itr : lun) { ans.push_back(itr.first); } SORT(ans); cout << ans[K - 1] << endl; }
replace
64
65
64
65
TLE
p02720
C++
Runtime Error
#include <bits/stdc++.h> #define fin \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define ii pair<int, int> #define F first #define S second #define pb push_back #define pf push_front #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define fore(i, a, b) for (int i = a; i < b; i += 1) #define forr(i, a) for (int i = a; i >= 0; i--) #define fori(i, m) for (auto i = m.begin(); i != m.end(); i++) #define w(t) while (t--) #define sz(s) int(s.size()) #define cls(a, car) memset(a, car, sizeof(a)) #define what_is(x) cerr << #x << " is " << x << endl; using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ii> vii; const int N = 1 * 1e5 + 5; const ll mod = 1e9 + 7; const int INF = INT_MAX; const ll INFCAD = ll(INT_MAX) * 2 + 1; const double E = 1e-9; // fflush(stdout) // cout << flush // a + b = a ^ b + 2 * (a & b) unordered_set<ll> s; vector<ll> ans; void build() { queue<ll> q; q.push(1LL); q.push(2LL); q.push(3LL); q.push(4LL); q.push(5LL); q.push(6LL); q.push(7LL); q.push(8LL); q.push(9LL); while (sz(q)) { ll a = q.front(); s.insert(a); q.pop(); if (sz(s) <= 100000) for (int i = 0; i <= 9; i++) { if (abs(a % 10 - i) <= 1 && a * 10 + i <= 3234566667) { ll nw = a * 10 + i; s.insert(nw); q.push(nw); } } } } int main() { freopen("in", "r", stdin); freopen("out", "w", stdout); fin; build(); fori(i, s) ans.pb(*i); sort(all(ans)); int k, q; // cin >> q; // w(q){ cin >> k; cout << ans[k - 1] << '\n'; //} // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; return 0; }
#include <bits/stdc++.h> #define fin \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) #define ii pair<int, int> #define F first #define S second #define pb push_back #define pf push_front #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define fore(i, a, b) for (int i = a; i < b; i += 1) #define forr(i, a) for (int i = a; i >= 0; i--) #define fori(i, m) for (auto i = m.begin(); i != m.end(); i++) #define w(t) while (t--) #define sz(s) int(s.size()) #define cls(a, car) memset(a, car, sizeof(a)) #define what_is(x) cerr << #x << " is " << x << endl; using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ii> vii; const int N = 1 * 1e5 + 5; const ll mod = 1e9 + 7; const int INF = INT_MAX; const ll INFCAD = ll(INT_MAX) * 2 + 1; const double E = 1e-9; // fflush(stdout) // cout << flush // a + b = a ^ b + 2 * (a & b) unordered_set<ll> s; vector<ll> ans; void build() { queue<ll> q; q.push(1LL); q.push(2LL); q.push(3LL); q.push(4LL); q.push(5LL); q.push(6LL); q.push(7LL); q.push(8LL); q.push(9LL); while (sz(q)) { ll a = q.front(); s.insert(a); q.pop(); if (sz(s) <= 100000) for (int i = 0; i <= 9; i++) { if (abs(a % 10 - i) <= 1 && a * 10 + i <= 3234566667) { ll nw = a * 10 + i; s.insert(nw); q.push(nw); } } } } int main() { // freopen("in","r",stdin); // freopen("out","w",stdout); fin; build(); fori(i, s) ans.pb(*i); sort(all(ans)); int k, q; // cin >> q; // w(q){ cin >> k; cout << ans[k - 1] << '\n'; //} // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; return 0; }
replace
60
62
60
62
0
p02720
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; #define fast_io \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); int main() { fast_io; queue<long long> q; long long k; cin >> k; for (int i = 1; i <= 9; i++) { q.push(i); } long long x; long long a; while (!q.empty()) { x = q.front(); q.pop(); k--; if (k == 0) { break; } a = x % 10; for (int i = -1; i < 2; i++) { if (a + i >= 0 && a + i < 10) { // cout<<(x*10)+a+i<<endl; q.push((x * 10) + a + i); } } } cout << x << endl; return x; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define fast_io \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); int main() { fast_io; queue<long long> q; long long k; cin >> k; for (int i = 1; i <= 9; i++) { q.push(i); } long long x; long long a; while (!q.empty()) { x = q.front(); q.pop(); k--; if (k == 0) { break; } a = x % 10; for (int i = -1; i < 2; i++) { if (a + i >= 0 && a + i < 10) { // cout<<(x*10)+a+i<<endl; q.push((x * 10) + a + i); } } } cout << x << endl; }
delete
42
44
42
42
23
p02720
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <string> #include <vector> #define REP(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long LL; int main() { int K; cin >> K; vector<vector<int>> count(10, vector<int>()); REP(i, 10) { count[i].push_back(i % 3 == 0 ? 1 : 0); } for (int i = 0; i <= 18; ++i) { count[0].push_back(count[0][i] + count[1][i]); count[9].push_back(count[8][i] + count[9][i]); for (int j = 1; j <= 8; ++j) { count[j].push_back(count[j - 1][i] + count[j][i] + count[j + 1][i]); } } LL ret = 0; for (int keta = 1; keta <= 18; ++keta) { for (int n = 1; n <= 9; ++n) { if (count[n][keta] < K) { K -= count[n][keta]; } else { ret = n; while (--keta > 0) { if (n >= 1 && K <= count[n - 1][keta]) { --n; } else { K -= count[n - 1][keta]; if (K > count[n][keta]) { K -= count[n][keta]; ++n; } } ret = ret * 10 + n; } cout << ret << endl; return 0; } } } }
#include <algorithm> #include <bitset> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <string> #include <vector> #define REP(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef long long LL; int main() { int K; cin >> K; vector<vector<int>> count(10, vector<int>()); REP(i, 10) { count[i].push_back(i % 3 == 0 ? 1 : 0); } for (int i = 0; i <= 18; ++i) { count[0].push_back(count[0][i] + count[1][i]); count[9].push_back(count[8][i] + count[9][i]); for (int j = 1; j <= 8; ++j) { count[j].push_back(count[j - 1][i] + count[j][i] + count[j + 1][i]); } } LL ret = 0; for (int keta = 1; keta <= 18; ++keta) { for (int n = 1; n <= 9; ++n) { if (count[n][keta] < K) { K -= count[n][keta]; } else { ret = n; while (--keta > 0) { if (n >= 1 && K <= count[n - 1][keta]) { --n; } else { if (n >= 1) { K -= count[n - 1][keta]; } if (K > count[n][keta]) { K -= count[n][keta]; ++n; } } ret = ret * 10 + n; } cout << ret << endl; return 0; } } } }
replace
37
38
37
40
0
p02720
C++
Time Limit Exceeded
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; using ll = long long; using LL = long long; class Edge { public: int from, to; ll value, konzatu; Edge(int a, int b, ll c, ll d) { from = a; to = b; value = c; konzatu = d; } Edge(LL a, LL b, LL c) { from = a; to = b; value = c; } Edge(LL a, LL b) { from = a; to = b; } }; ll cnt = 0; int K; void lunlun(int n, string s) { if (n == s.size()) { cnt++; if (cnt == K) { cout << s << endl; } return; } if (s.empty()) { for (int i = 1; i <= 9; i++) { s = to_string(i); lunlun(n, s); } } else { char c = s.back(); for (char i = '0'; i <= '9'; i++) { if (abs(c - i) <= 1) { s.push_back(i); lunlun(n, s); s.pop_back(); } } } } int main() { cin >> K; for (int i = 1; i <= 15; i++) { lunlun(i, string()); } }
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; using ll = long long; using LL = long long; class Edge { public: int from, to; ll value, konzatu; Edge(int a, int b, ll c, ll d) { from = a; to = b; value = c; konzatu = d; } Edge(LL a, LL b, LL c) { from = a; to = b; value = c; } Edge(LL a, LL b) { from = a; to = b; } }; ll cnt = 0; int K; void lunlun(int n, string s) { if (n == s.size()) { cnt++; if (cnt == K) { cout << s << endl; } return; } if (s.empty()) { for (int i = 1; i <= 9; i++) { s = to_string(i); lunlun(n, s); } } else { char c = s.back(); for (char i = '0'; i <= '9'; i++) { if (abs(c - i) <= 1) { s.push_back(i); lunlun(n, s); s.pop_back(); } } } } int main() { cin >> K; for (int i = 1; i <= 12; i++) { lunlun(i, string()); } }
replace
62
63
62
63
TLE
p02720
C++
Runtime Error
#include <algorithm> #include <climits> #include <cmath> #include <cstdlib> #include <ctype.h> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; typedef long long ll; #define REP(i, n) for (ll i = 0; i < (ll)(n); ++i) 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; } ll n; ll ans; ll c = 1; bool f(ll num, ll digit) { if (digit == (ll)log10(num) + 1) { if (n == c) { ans = num; return true; } else { c++; return false; } } int rnum = num % 10; for (int i = max(rnum - 1, 0); i <= min(rnum + 1, 9); i++) { if (f(num * 10 + i, digit)) return true; } } int main() { cin >> n; ll digit = 1; while (true) { bool res = false; for (int i = 1; i <= 9; i++) { res = f(i, digit); if (res) break; } if (res) break; digit++; } cout << ans << endl; return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <cstdlib> #include <ctype.h> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <vector> using namespace std; typedef long long ll; #define REP(i, n) for (ll i = 0; i < (ll)(n); ++i) 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; } ll n; ll ans; ll c = 1; bool f(ll num, ll digit) { if (digit == (ll)log10(num) + 1) { if (n == c) { ans = num; return true; } else { c++; return false; } } int rnum = num % 10; for (int i = max(rnum - 1, 0); i <= min(rnum + 1, 9); i++) { if (f(num * 10 + i, digit)) return true; } return false; } int main() { cin >> n; ll digit = 1; while (true) { bool res = false; for (int i = 1; i <= 9; i++) { res = f(i, digit); if (res) break; } if (res) break; digit++; } cout << ans << endl; return 0; }
insert
50
50
50
51
0
p02720
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cassert> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <vector> // #include <boost/multiprecision/cpp_int.hpp> #include <bitset> #include <complex> #include <cstdio> #include <list> //< in.txt > out.txt using namespace std; // std::ios::sync_with_stdio(false); // std::cin.tie(0); const long long MOD = 1e9 + 7; typedef long long LL; typedef long double LD; typedef pair<LL, LL> PLL; typedef pair<LD, LL> pdl; typedef pair<LD, LD> pdd; typedef vector<LL> VLL; typedef vector<VLL> VVLL; typedef unsigned long long ULL; // typedef boost::multiprecision::cpp_int bigint; int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); LL K; cin >> K; VVLL DP; DP.resize(10, VLL(12, 0)); DP[0][1] = 1; for (LL a = 1; a <= 9; a++) { DP[a][1] = 1; } for (LL n = 2; n <= 11; n++) { for (LL a = 0; a <= 9; a++) { if (a > 0) DP[a][n] += DP[a - 1][n - 1]; DP[a][n] += DP[a][n - 1]; if (a < 9) DP[a][n] += DP[a + 1][n - 1]; } } VVLL X; X.resize(10, VLL(12, 0)); for (LL n = 1; n <= 11; n++) { X[1][n] = X[9][n - 1] + DP[1][n]; for (LL a = 2; a <= 9; a++) { X[a][n] = X[a - 1][n] + DP[a][n]; } } LL N = 1, A = 1; while (X[A][N] < K) { A++; if (A == 10) { N++; A = 1; } } K -= X[A - 1][N]; cout << A; while (N > 1) { LL temp = 0; if (A > 0) { if (0 < K && K <= DP[A - 1][N - 1]) { cout << A - 1; A = A - 1; K -= temp; N--; continue; } temp += DP[A - 1][N - 1]; } if (temp < K && K <= temp + DP[A][N - 1]) { cout << A; K -= temp; N--; continue; } temp += DP[A][N - 1]; if (A < 9) { if (temp < K && K <= temp + DP[A + 1][N - 1]) { cout << A + 1; A = A + 1; K -= temp; N--; continue; } } } cout << "\n"; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <vector> // #include <boost/multiprecision/cpp_int.hpp> #include <bitset> #include <complex> #include <cstdio> #include <list> //< in.txt > out.txt using namespace std; // std::ios::sync_with_stdio(false); // std::cin.tie(0); const long long MOD = 1e9 + 7; typedef long long LL; typedef long double LD; typedef pair<LL, LL> PLL; typedef pair<LD, LL> pdl; typedef pair<LD, LD> pdd; typedef vector<LL> VLL; typedef vector<VLL> VVLL; typedef unsigned long long ULL; // typedef boost::multiprecision::cpp_int bigint; int main() { std::ios::sync_with_stdio(false); std::cin.tie(0); LL K; cin >> K; VVLL DP; DP.resize(10, VLL(12, 0)); DP[0][1] = 1; for (LL a = 1; a <= 9; a++) { DP[a][1] = 1; } for (LL n = 2; n <= 11; n++) { for (LL a = 0; a <= 9; a++) { if (a > 0) DP[a][n] += DP[a - 1][n - 1]; DP[a][n] += DP[a][n - 1]; if (a < 9) DP[a][n] += DP[a + 1][n - 1]; } } VVLL X; X.resize(10, VLL(12, 0)); for (LL n = 1; n <= 11; n++) { X[0][n] = X[9][n - 1]; X[1][n] = X[9][n - 1] + DP[1][n]; for (LL a = 2; a <= 9; a++) { X[a][n] = X[a - 1][n] + DP[a][n]; } } LL N = 1, A = 1; while (X[A][N] < K) { A++; if (A == 10) { N++; A = 1; } } K -= X[A - 1][N]; cout << A; while (N > 1) { LL temp = 0; if (A > 0) { if (0 < K && K <= DP[A - 1][N - 1]) { cout << A - 1; A = A - 1; K -= temp; N--; continue; } temp += DP[A - 1][N - 1]; } if (temp < K && K <= temp + DP[A][N - 1]) { cout << A; K -= temp; N--; continue; } temp += DP[A][N - 1]; if (A < 9) { if (temp < K && K <= temp + DP[A + 1][N - 1]) { cout << A + 1; A = A + 1; K -= temp; N--; continue; } } } cout << "\n"; return 0; }
insert
59
59
59
60
TLE
p02720
C++
Runtime Error
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <iterator> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> #define int long long #define pb push_back #define pi pair<int, int> #define vi vector<int> #define all(v) v.begin(), v.end() #define MOD 1000000007 #define F first #define S second #define FOR(i, r) for (int i = 0; i < r; i++) #define REP(i, l, r) for (int i = l; i < r; i++) #define RER(i, l, r) for (int i = l; i >= r; i--) #define print(v) \ for (auto i : v) \ cout << i << ' '; #define FASTIO \ ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define mem(arr, k) memset(arr, k, sizeof(arr)); #define pii acos(-1.0) #define PI 3.1415926535897932385 #define Sin(a) sin((pi * a) / 180) #define test() \ int x; \ cin >> x; \ while (x--) using namespace std; set<int> res; int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif FASTIO; queue<int> q; REP(i, 1, 10) { q.push(i); } while (!q.empty()) { int nd = q.front(); q.pop(); res.insert(nd); if (res.size() > 1e5) break; int last = nd % 10; if (last - 1 >= 0) q.push(nd * 10 + (last - 1)); q.push(nd * 10 + last); if (last + 1 <= 9) q.push(nd * 10 + (last + 1)); } int k; cin >> k; k--; for (auto i : res) { if (k == 0) { cout << i << endl; return 0; } k--; } return 0; }
#include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <iostream> #include <iterator> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <vector> #define int long long #define pb push_back #define pi pair<int, int> #define vi vector<int> #define all(v) v.begin(), v.end() #define MOD 1000000007 #define F first #define S second #define FOR(i, r) for (int i = 0; i < r; i++) #define REP(i, l, r) for (int i = l; i < r; i++) #define RER(i, l, r) for (int i = l; i >= r; i--) #define print(v) \ for (auto i : v) \ cout << i << ' '; #define FASTIO \ ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define mem(arr, k) memset(arr, k, sizeof(arr)); #define pii acos(-1.0) #define PI 3.1415926535897932385 #define Sin(a) sin((pi * a) / 180) #define test() \ int x; \ cin >> x; \ while (x--) using namespace std; set<int> res; int32_t main() { FASTIO; queue<int> q; REP(i, 1, 10) { q.push(i); } while (!q.empty()) { int nd = q.front(); q.pop(); res.insert(nd); if (res.size() > 1e5) break; int last = nd % 10; if (last - 1 >= 0) q.push(nd * 10 + (last - 1)); q.push(nd * 10 + last); if (last + 1 <= 9) q.push(nd * 10 + (last + 1)); } int k; cin >> k; k--; for (auto i : res) { if (k == 0) { cout << i << endl; return 0; } k--; } return 0; }
delete
48
52
48
48
0
p02720
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, a, n) for (ll i = a; i < n; i++) #define per(i, a, n) for (ll i = n - 1; i >= a; i--) #define fill0(n) setfill('0') << right << setw(n) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define LONGMAX 1e18 #define INTMAX 1000000000 using namespace std; typedef long long ll; typedef pair<ll, ll> P; const ll mod = 1e9 + 7; const long double EPS = 0.0000000001; vector<ll> bfs(int n) { queue<ll> q; vector<ll> ret; int count = 0; for (int i = 1; i < 10; i++) { q.push(i); ret.push_back(i); count++; } while (1) { ll now = q.front(); q.pop(); // string now = to_string(top); // char c = now[now.size()-1]; for (int i = -1; i < 2; i++) { ll check = now % 10 + i; if (check == -1 or check == 10) continue; q.push(now * 10 + check); ret.push_back(now * 10 + check); count++; if (count == n) return ret; } } } int main() { int k; cin >> k; vector<ll> v = bfs(k); // // for(int i = 0; i < v.size(); i++)cout << v[i] << " "; // cout << endl; cout << v[k - 1] << endl; }
#include <bits/stdc++.h> #define rep(i, a, n) for (ll i = a; i < n; i++) #define per(i, a, n) for (ll i = n - 1; i >= a; i--) #define fill0(n) setfill('0') << right << setw(n) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define LONGMAX 1e18 #define INTMAX 1000000000 using namespace std; typedef long long ll; typedef pair<ll, ll> P; const ll mod = 1e9 + 7; const long double EPS = 0.0000000001; vector<ll> bfs(int n) { queue<ll> q; vector<ll> ret; int count = 0; for (int i = 1; i < 10; i++) { q.push(i); ret.push_back(i); count++; if (count == n) return ret; } while (1) { ll now = q.front(); q.pop(); // string now = to_string(top); // char c = now[now.size()-1]; for (int i = -1; i < 2; i++) { ll check = now % 10 + i; if (check == -1 or check == 10) continue; q.push(now * 10 + check); ret.push_back(now * 10 + check); count++; if (count == n) return ret; } } } int main() { int k; cin >> k; vector<ll> v = bfs(k); // // for(int i = 0; i < v.size(); i++)cout << v[i] << " "; // cout << endl; cout << v[k - 1] << endl; }
insert
25
25
25
27
0
p02720
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int k; cin >> k; vector<ll> a; for (int i = 1; i <= 9; ++i) a.push_back(i); while (1) { if (k <= a.size()) { cout << a[k - 1] << endl; } else { k -= a.size(); vector<ll> old; swap(old, a); for (ll x : old) { for (int i = -1; i <= 1; ++i) { int d = x % 10 + i; if (d < 0 || d > 9) { continue; } ll nx = x * 10 + d; a.push_back(nx); } } } } }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int k; cin >> k; vector<ll> a; for (int i = 1; i <= 9; ++i) a.push_back(i); while (1) { if (k <= a.size()) { cout << a[k - 1] << endl; return 0; } else { k -= a.size(); vector<ll> old; swap(old, a); for (ll x : old) { for (int i = -1; i <= 1; ++i) { int d = x % 10 + i; if (d < 0 || d > 9) { continue; } ll nx = x * 10 + d; a.push_back(nx); } } } } }
insert
13
13
13
14
TLE
p02720
Python
Time Limit Exceeded
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) k = int(readline()) q = [(i + 1) for i in range(9)] if k < 10: print(k) cnt = 9 while q: x = q.pop(0) y = int(str(x)[-1]) if y != 0: cnt += 1 if cnt == k: print(10 * x + y - 1) exit() q.append(10 * x + y - 1) cnt += 1 if cnt == k: print(10 * x + y) exit() q.append(10 * x + y) if y != 9: cnt += 1 if cnt == k: print(10 * x + y + 1) exit() q.append(10 * x + y + 1)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10**7) k = int(readline()) q = [(i + 1) for i in range(9)] if k < 10: print(k) exit() cnt = 9 while q: x = q.pop(0) y = int(str(x)[-1]) if y != 0: cnt += 1 if cnt == k: print(10 * x + y - 1) exit() q.append(10 * x + y - 1) cnt += 1 if cnt == k: print(10 * x + y) exit() q.append(10 * x + y) if y != 9: cnt += 1 if cnt == k: print(10 * x + y + 1) exit() q.append(10 * x + y + 1)
insert
11
11
11
12
TLE
p02720
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #define _USE_MATH_DEFINES #include <functional> #include <math.h> using namespace std; #define rep(i, x) for (ll i = 0; i < x; i++) #define repn(i, x) for (ll i = 1; i <= x; i++) typedef long long ll; const ll INF = 1e17; const ll MOD = 1000000007; const ll MAX = 1000001; ll max(ll a, ll b) { if (a > b) { return a; } return b; } ll min(ll a, ll b) { if (a > b) { return b; } return a; } ll gcd(ll a, ll b) { if (b == 0) { return a; } if (a < b) { return gcd(b, a); } return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } struct edge { ll ind; ll fr; ll to; ll d; }; /////////////////////////// ll d(ll n) { if (n < 10) { return 1; } return d(n / 10) + 1; } ll keta(ll n, ll k) { if (k == 1) { return n % 10; } else { return keta(n / 10, k - 1); } } ll p(ll n) { if (n == 0) { return 1; } return p(n / 10) * 10; } int main() { ll X; cin >> X; ll ans = 1; ll c = 0; while (c < X) { ll b = 1; for (ll i = d(ans) - 1; i >= 1; i--) { if (abs(keta(ans, i) - keta(ans, i + 1)) > 1) { b = 0; ans += p(i - 1); break; } } // cout << ans << c << b << endl; if (b == 1) { c++; if (c == X) { break; } ans++; } } cout << ans; system("PAUSE"); }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #define _USE_MATH_DEFINES #include <functional> #include <math.h> using namespace std; #define rep(i, x) for (ll i = 0; i < x; i++) #define repn(i, x) for (ll i = 1; i <= x; i++) typedef long long ll; const ll INF = 1e17; const ll MOD = 1000000007; const ll MAX = 1000001; ll max(ll a, ll b) { if (a > b) { return a; } return b; } ll min(ll a, ll b) { if (a > b) { return b; } return a; } ll gcd(ll a, ll b) { if (b == 0) { return a; } if (a < b) { return gcd(b, a); } return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } struct edge { ll ind; ll fr; ll to; ll d; }; /////////////////////////// ll d(ll n) { if (n < 10) { return 1; } return d(n / 10) + 1; } ll keta(ll n, ll k) { if (k == 1) { return n % 10; } else { return keta(n / 10, k - 1); } } ll p(ll n) { if (n == 0) { return 1; } return p(n - 1) * 10; } int main() { ll X; cin >> X; ll ans = 1; ll c = 0; while (c < X) { ll b = 1; for (ll i = d(ans) - 1; i >= 1; i--) { if (abs(keta(ans, i) - keta(ans, i + 1)) > 1) { b = 0; ans += p(i - 1); break; } } // cout << ans << c << b << endl; if (b == 1) { c++; if (c == X) { break; } ans++; } } cout << ans; system("PAUSE"); }
replace
76
77
76
77
TLE
p02720
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int k; cin >> k; vector<ll> a; for (int i = 1; i <= 9; ++i) a.push_back(i); while (1) { if (k <= a.size()) { cout << a[k - 1] << endl; } k -= a.size(); vector<ll> old; swap(old, a); for (ll x : old) { for (int i = -1; i <= 1; ++i) { int d = x % 10 + i; if (d < 0 || d > 9) continue; ll nx = x * 10 + d; a.push_back(nx); } } } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int k; cin >> k; vector<ll> a; for (int i = 1; i <= 9; ++i) a.push_back(i); while (1) { if (k <= a.size()) { cout << a[k - 1] << endl; return 0; } k -= a.size(); vector<ll> old; swap(old, a); for (ll x : old) { for (int i = -1; i <= 1; ++i) { int d = x % 10 + i; if (d < 0 || d > 9) continue; ll nx = x * 10 + d; a.push_back(nx); } } } return 0; }
insert
14
14
14
15
TLE
p02720
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; bool lun(string n) { int len = n.length(); for (int i = 1; i < len; i++) { if (abs(n[i] - n[i - 1]) > 1) return false; } return true; } string nxt(string n) { int len = n.length(); for (int i = len - 2; i >= 0; i--) { if (n[i] + 1 != n[i + 1] && n[i + 1] != '9') { n[i + 1] += 1; for (int j = i + 2; j < len; j++) { if (n[j - 1] == '0') n[j] = '0'; else n[j] = n[j - 1] - 1; } return n; } } if (n[0] == '9') n = '1' + string(len, '0'); else { n[0]++; for (int i = 1; i < len; i++) { if (n[i - 1] == '0') n[i] = '0'; else n[i] = n[i - 1] - 1; } } return n; } int main(void) { int k; string n = "10"; cin >> k; if (k <= 10) return k; for (int i = 10; i < k; i++) { // cout << n << endl; n = nxt(n); } cout << n << endl; }
#include <iostream> #include <vector> using namespace std; bool lun(string n) { int len = n.length(); for (int i = 1; i < len; i++) { if (abs(n[i] - n[i - 1]) > 1) return false; } return true; } string nxt(string n) { int len = n.length(); for (int i = len - 2; i >= 0; i--) { if (n[i] + 1 != n[i + 1] && n[i + 1] != '9') { n[i + 1] += 1; for (int j = i + 2; j < len; j++) { if (n[j - 1] == '0') n[j] = '0'; else n[j] = n[j - 1] - 1; } return n; } } if (n[0] == '9') n = '1' + string(len, '0'); else { n[0]++; for (int i = 1; i < len; i++) { if (n[i - 1] == '0') n[i] = '0'; else n[i] = n[i - 1] - 1; } } return n; } int main(void) { int k; string n = "10"; cin >> k; if (k <= 10) { cout << k << endl; return 0; } for (int i = 10; i < k; i++) { // cout << n << endl; n = nxt(n); } cout << n << endl; }
replace
42
44
42
46
0
p02720
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; bool lun(string n) { int len = n.length(); for (int i = 1; i < len; i++) { if (abs(n[i] - n[i - 1]) > 1) return false; } return true; } string nxt(string n) { int len = n.length(); for (int i = len - 2; i >= 0; i--) { if (n[i] + 1 != n[i + 1] && n[i + 1] != '9') { n[i + 1] += 1; for (int j = i + 2; j < len; j++) { if (n[j - 1] == '0') n[j] = '0'; else n[j] = n[j - 1] - 1; } return n; } } if (n[0] == '9') n = '1' + string(len, '0'); else { n[0]++; for (int i = 1; i < len; i++) { if (n[i - 1] == '0') n[i] = '0'; else n[i] = n[i - 1] - 1; } } return n; } int main(void) { int k; string n = "10"; cin >> k; if (k <= 10) return k; for (int i = 11; i <= k; i++) { // cout << n << endl; n = nxt(n); } cout << n << endl; }
#include <iostream> #include <vector> using namespace std; bool lun(string n) { int len = n.length(); for (int i = 1; i < len; i++) { if (abs(n[i] - n[i - 1]) > 1) return false; } return true; } string nxt(string n) { int len = n.length(); for (int i = len - 2; i >= 0; i--) { if (n[i] + 1 != n[i + 1] && n[i + 1] != '9') { n[i + 1] += 1; for (int j = i + 2; j < len; j++) { if (n[j - 1] == '0') n[j] = '0'; else n[j] = n[j - 1] - 1; } return n; } } if (n[0] == '9') n = '1' + string(len, '0'); else { n[0]++; for (int i = 1; i < len; i++) { if (n[i - 1] == '0') n[i] = '0'; else n[i] = n[i - 1] - 1; } } return n; } int main(void) { int k; string n = "10"; cin >> k; if (k <= 10) { cout << k << endl; return 0; } for (int i = 10; i < k; i++) { // cout << n << endl; n = nxt(n); } cout << n << endl; }
replace
45
48
45
50
0
p02720
C++
Runtime Error
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define in(s) cin >> s #define out(s) cout << s << endl #define rep(i, n) for (int i = 0; i < n; i++) #define rept(i, a, b) for (int i = a; i < b; i++) #define ll long long #define MOD 1000000007 #define IMIN INT_MIN; #define IMAX INT_MAX; bool checklun(ll val) { ll prev = val % 10; while (val >= 10) { val /= 10; if (abs(val % 10 - prev) > 1) return false; prev = val % 10; } return true; } ll nextlun(ll val) { if (checklun(val + 1)) return val + 1; for (int i = 1; i < 10; i++) { val /= 10; val++; ll tmp = val % 10; if (checklun(val)) { rep(j, i) { val *= 10; tmp = max(tmp - 1, 0LL); val += tmp; } return val; } else val--; } return val; } int main() { ll k; in(k); vector<ll> dp(k + 1, 0); rep(i, 10) dp[i] = i; rept(i, 10, 100001) { // out(i << ' ' << nextlun(dp[i-1])); dp[i] = nextlun(dp[i - 1]); } // rept(i, 1, k) cout << dp[i] << ' '; cout << endl; out(dp[k]); return 0; }
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; #define in(s) cin >> s #define out(s) cout << s << endl #define rep(i, n) for (int i = 0; i < n; i++) #define rept(i, a, b) for (int i = a; i < b; i++) #define ll long long #define MOD 1000000007 #define IMIN INT_MIN; #define IMAX INT_MAX; bool checklun(ll val) { ll prev = val % 10; while (val >= 10) { val /= 10; if (abs(val % 10 - prev) > 1) return false; prev = val % 10; } return true; } ll nextlun(ll val) { if (checklun(val + 1)) return val + 1; for (int i = 1; i < 10; i++) { val /= 10; val++; ll tmp = val % 10; if (checklun(val)) { rep(j, i) { val *= 10; tmp = max(tmp - 1, 0LL); val += tmp; } return val; } else val--; } return val; } int main() { ll k; in(k); vector<ll> dp(100001, 0); rep(i, 10) dp[i] = i; rept(i, 10, 100001) { // out(i << ' ' << nextlun(dp[i-1])); dp[i] = nextlun(dp[i - 1]); } // rept(i, 1, k) cout << dp[i] << ' '; cout << endl; out(dp[k]); return 0; }
replace
63
64
63
64
-11
p02720
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; template <class c, class cmp = less<c>> using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>; #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define ff first #define ss second #define pb push_back #define pf push_front #define mp make_pair #define in insert #define ld long double #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define trace(...) 1 #endif template <class T> ostream &operator<<(ostream &os, vector<T> V) { os << "[ "; for (auto v : V) os << v << " "; return os << "]"; } template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) { return os << "(" << P.first << "," << P.second << ")"; } template <typename T, typename U> pair<T, U> operator+(const pair<T, U> &l, const std::pair<T, U> &r) { return {l.first + r.first, l.second + r.second}; } typedef long long int ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vpii; typedef vector<pll> vpll; #define int ll const ll mod = 1e9 + 7; const ll MAX_NODES = 200001; const ll MAX_LOG = 50; const ll maxn = 400000 + 10; stack<int> st; bool first = true; int k; vl g[10]; int sum = 0; int lev; void dfs(int i, int l) { st.push(i); if (l == lev && k == sum + 1) { vl ans; while (!st.empty()) { ans.push_back(st.top()); st.pop(); } reverse(ans.begin(), ans.end()); bool f = 0; for (int i = 0; i < ans.size(); i++) { if (ans[i] != 0) { f = 1; } if (f) { cout << ans[i]; } } exit(0); } if (l == lev) { st.pop(); sum++; return; } int sum = 0; for (auto x : g[i]) { dfs(x, l + 1); } st.pop(); return; } int32_t main() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif IOS cin >> k; for (int i = 0; i <= 9; i++) { for (int j = max(0ll, i - 1); j <= (min(9ll, i + 1)); j++) { g[i].push_back(j); } } for (int i = 1; i <= 70; i++) { for (int j = 1; j <= 9; j++) { lev = i; dfs(j, 1); } } }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; template <class c, class cmp = less<c>> using ordered_set = tree<c, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>; #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define ff first #define ss second #define pb push_back #define pf push_front #define mp make_pair #define in insert #define ld long double #define TRACE #ifdef TRACE #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char *name, Arg1 &&arg1) { cerr << name << " : " << arg1 << std::endl; } template <typename Arg1, typename... Args> void __f(const char *names, Arg1 &&arg1, Args &&...args) { const char *comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } #else #define trace(...) 1 #endif template <class T> ostream &operator<<(ostream &os, vector<T> V) { os << "[ "; for (auto v : V) os << v << " "; return os << "]"; } template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) { return os << "(" << P.first << "," << P.second << ")"; } template <typename T, typename U> pair<T, U> operator+(const pair<T, U> &l, const std::pair<T, U> &r) { return {l.first + r.first, l.second + r.second}; } typedef long long int ll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vi> vvi; typedef vector<vl> vvl; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vpii; typedef vector<pll> vpll; #define int ll const ll mod = 1e9 + 7; const ll MAX_NODES = 200001; const ll MAX_LOG = 50; const ll maxn = 400000 + 10; stack<int> st; bool first = true; int k; vl g[10]; int sum = 0; int lev; void dfs(int i, int l) { st.push(i); if (l == lev && k == sum + 1) { vl ans; while (!st.empty()) { ans.push_back(st.top()); st.pop(); } reverse(ans.begin(), ans.end()); bool f = 0; for (int i = 0; i < ans.size(); i++) { if (ans[i] != 0) { f = 1; } if (f) { cout << ans[i]; } } exit(0); } if (l == lev) { st.pop(); sum++; return; } int sum = 0; for (auto x : g[i]) { dfs(x, l + 1); } st.pop(); return; } int32_t main() { IOS cin >> k; for (int i = 0; i <= 9; i++) { for (int j = max(0ll, i - 1); j <= (min(9ll, i + 1)); j++) { g[i].push_back(j); } } for (int i = 1; i <= 70; i++) { for (int j = 1; j <= 9; j++) { lev = i; dfs(j, 1); } } }
replace
104
108
104
105
TLE
p02720
C++
Runtime Error
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define EXISTch(s, c) \ ((((s).find_first_of(c)) != std::string::npos) ? 1 : 0) // cがあれば1 if(1) #define SORT(c) sort((c).begin(), (c).end()) #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = (int)1000000007; const LL MOD = (LL)1000000007; // 10^9+7 const LL INF2 = (LL)100000000000000000; // 10^18 void rec(int d, LL val, vector<LL> ans) { ans.push_back(val); if (d == 10) return; for (int j = -1; j <= 1; j++) { int add = (val % 10) + j; if (add >= 0 && add <= 9) rec(d + 1, val * 10 + add, ans); } } int main() { int k; cin >> k; vector<LL> ans; for (int i = 1; i < 10; i++) rec(1, i, ans); sort(ans.begin(), ans.end()); cout << ans[k - 1] << endl; return 0; }
// include //------------------------------------------ #include <algorithm> #include <bitset> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define EXISTch(s, c) \ ((((s).find_first_of(c)) != std::string::npos) ? 1 : 0) // cがあれば1 if(1) #define SORT(c) sort((c).begin(), (c).end()) #define REP(i, n) for (int i = 0; i < (int)n; ++i) #define FOR(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = (int)1000000007; const LL MOD = (LL)1000000007; // 10^9+7 const LL INF2 = (LL)100000000000000000; // 10^18 void rec(int d, LL val, vector<LL> &ans) { ans.push_back(val); if (d == 10) return; for (int j = -1; j <= 1; j++) { int add = (val % 10) + j; if (add >= 0 && add <= 9) rec(d + 1, val * 10 + add, ans); } } int main() { int k; cin >> k; vector<LL> ans; for (int i = 1; i < 10; i++) rec(1, i, ans); sort(ans.begin(), ans.end()); cout << ans[k - 1] << endl; return 0; }
replace
82
83
82
83
-11