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
p02602
C++
Runtime Error
// https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_c #include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; vector<long long> a(n + 1); a[0] = 1; for (int i = 1; i <= n; i++) { cin >> a[i]; a[i] *= a[i - 1]; } for (int i = k + 1; i <= n; i++) { if (a[i] / a[i - k] > a[i - 1] / a[i - k - 1]) cout << "Yes\n"; else cout << "No\n"; } return 0; }
// https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_c #include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; vector<long long> a(n + 1); a[0] = 1; for (int i = 1; i <= n; i++) { cin >> a[i]; if (i <= k) ; else { if (a[i] > a[i - k]) cout << "Yes\n"; else cout << "No\n"; } } return 0; }
replace
12
19
12
20
0
p02602
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) using namespace std; #define INF ((1 << 30) - 1) #define LINF (1LL << 60) #define EPS (1e-10) typedef long long ll; typedef pair<ll, ll> P; const int MOD = 1000000007; const int MOD2 = 998244353; ll a[100010]; int main() { int n, k; cin >> n >> k; rep(i, n) cin >> a[i + 1]; vector<string> ans; for (int i = k + 1; i <= n; i++) { if (a[i] > a[i - k]) ans.push_back("Yes"); else ans.push_back("No"); } for (auto e : ans) cout << e << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define rrep(i, n) for (int i = n - 1; i >= 0; i--) using namespace std; #define INF ((1 << 30) - 1) #define LINF (1LL << 60) #define EPS (1e-10) typedef long long ll; typedef pair<ll, ll> P; const int MOD = 1000000007; const int MOD2 = 998244353; ll a[200010]; int main() { int n, k; cin >> n >> k; rep(i, n) cin >> a[i + 1]; vector<string> ans; for (int i = k + 1; i <= n; i++) { if (a[i] > a[i - k]) ans.push_back("Yes"); else ans.push_back("No"); } for (auto e : ans) cout << e << endl; return 0; }
replace
12
13
12
13
0
p02602
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A.at(i); } for (int i = K + 1; i <= N; i++) { if (A.at(i - K) < A.at(i)) { cout << "Yes" << endl; } else { cout << "No" << endl; } } }
#include <bits/stdc++.h> using namespace std; int main() { int N, K; cin >> N >> K; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A.at(i); } for (int i = K; i < N; i++) { if (A.at(i - K) < A.at(i)) { cout << "Yes" << endl; } else { cout << "No" << endl; } } }
replace
10
11
10
11
-6
terminate called after throwing an instance of 'std::out_of_range' what(): vector::_M_range_check: __n (which is 5) >= this->size() (which is 5)
p02602
C++
Runtime Error
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~= *$* WRITER:kakitamasziru/OxOmisosiru *$* ~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/ #ifdef LOCAL_JUDGE #define _GLIBCXX_DEBUG #endif #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <cstdint> // int64_t, int*_t #include <iomanip> #include <iostream> // cout, endl, cin #include <limits> //setprecision #include <string> // string, to_string, stoi #include <tuple> // tuple, make_tuple #include <utility> // pair, make_pair #include <vector> // vector // #include <cstdio> // printf #include <map> // map #include <queue> // queue, priority_queue #include <set> // set // #include <unordered_set> //unordered_set #include <bitset> // bitset #include <cmath> //abs,,, #include <deque> // deque #include <math.h> //pow,,, #include <stack> // stack #define endl "\n"; using namespace std; const long long INF = 100100100100100; const int MOD = 1000000007; const int inf = 1001001001; typedef pair<int, int> P; // Solve N^M. This, mod_pow use Iterative Square Method. long long mod_pow(long long N, long long M) { if (M == 0) return 1; long long res = mod_pow((N * N) % MOD, M / 2); // 最下位ビット(*N)が1の時は単独でNをかける if (M & 1) res = (res * N) % MOD; return res %= MOD; } int gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a % b); } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); int N, K; cin >> N >> K; vector<long long> retu(N); for (int i = 0; i < N; i++) cin >> retu.at(i); queue<long long> Q; for (int i = 0; i < K; i++) { Q.push(retu.at(i)); } for (int i = K; i < N; i++) { long long from = Q.front(); long long to = retu.at(i); Q.pop(); if (from >= to) { cout << "No" << endl; } else { cout << "Yes" << endl; } } }
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~= *$* WRITER:kakitamasziru/OxOmisosiru *$* ~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/ #ifdef LOCAL_JUDGE #define _GLIBCXX_DEBUG #endif #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound #include <cstdint> // int64_t, int*_t #include <iomanip> #include <iostream> // cout, endl, cin #include <limits> //setprecision #include <string> // string, to_string, stoi #include <tuple> // tuple, make_tuple #include <utility> // pair, make_pair #include <vector> // vector // #include <cstdio> // printf #include <map> // map #include <queue> // queue, priority_queue #include <set> // set // #include <unordered_set> //unordered_set #include <bitset> // bitset #include <cmath> //abs,,, #include <deque> // deque #include <math.h> //pow,,, #include <stack> // stack #define endl "\n"; using namespace std; const long long INF = 100100100100100; const int MOD = 1000000007; const int inf = 1001001001; typedef pair<int, int> P; // Solve N^M. This, mod_pow use Iterative Square Method. long long mod_pow(long long N, long long M) { if (M == 0) return 1; long long res = mod_pow((N * N) % MOD, M / 2); // 最下位ビット(*N)が1の時は単独でNをかける if (M & 1) res = (res * N) % MOD; return res %= MOD; } int gcd(long long a, long long b) { if (b == 0) return a; else return gcd(b, a % b); } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); int N, K; cin >> N >> K; vector<long long> retu(N); for (int i = 0; i < N; i++) cin >> retu.at(i); queue<long long> Q; for (int i = 0; i < K; i++) { Q.push(retu.at(i)); } for (int i = K; i < N; i++) { long long from = Q.front(); long long to = retu.at(i); Q.push(to); Q.pop(); if (from >= to) { cout << "No" << endl; } else { cout << "Yes" << endl; } } }
insert
69
69
69
70
0
p02602
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, n; cin >> n >> k; long long a[n + 1]; for (i = 0; i < n; i++) { cin >> a[i]; } i = 0; j = k; while (j < n) { if (a[j] > a[i]) { cout << "Yes" << endl; } else { cout << "No" << endl; } } }
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, n; cin >> n >> k; long long a[n + 1]; for (i = 0; i < n; i++) { cin >> a[i]; } i = 0; j = k; while (j < n) { if (a[j] > a[i]) { cout << "Yes" << endl; } else { cout << "No" << endl; } i++; j++; } }
insert
17
17
17
19
TLE
p02602
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> Pii; typedef pair<int, ll> Pil; typedef pair<ll, ll> Pll; typedef pair<ll, int> Pli; #define fi first #define se second const ll MOD = 1e9 + 7; const ll MOD2 = 998244353; const ll MOD3 = 1812447359; const ll INF = 1ll << 62; const double PI = 2 * asin(1); void yes() { printf("yes\n"); } void no() { printf("no\n"); } void Yes() { printf("Yes\n"); } void No() { printf("No\n"); } void YES() { printf("YES\n"); } void NO() { printf("NO\n"); } int N, K; int A[int(1e5 + 5)]; int main() { cin >> N >> K; for (int i = 0; i < N; i++) cin >> A[i]; for (int i = K; i < N; i++) { if (A[i - K] < A[i]) Yes(); else No(); } return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> Pii; typedef pair<int, ll> Pil; typedef pair<ll, ll> Pll; typedef pair<ll, int> Pli; #define fi first #define se second const ll MOD = 1e9 + 7; const ll MOD2 = 998244353; const ll MOD3 = 1812447359; const ll INF = 1ll << 62; const double PI = 2 * asin(1); void yes() { printf("yes\n"); } void no() { printf("no\n"); } void Yes() { printf("Yes\n"); } void No() { printf("No\n"); } void YES() { printf("YES\n"); } void NO() { printf("NO\n"); } int N, K; int A[int(2e5 + 5)]; int main() { cin >> N >> K; for (int i = 0; i < N; i++) cin >> A[i]; for (int i = K; i < N; i++) { if (A[i - K] < A[i]) Yes(); else No(); } return 0; }
replace
28
29
28
29
0
p02602
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctype.h> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <unordered_map> #include <vector> using namespace std; #define all(vec) vec.begin(), vec.end() typedef long long ll; ll gcd(ll x, ll y) { if (y == 0) return x; return gcd(y, x % y); } ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } ll kai(ll x, ll y, ll m) { ll res = 1; for (ll i = x - y + 1; i <= x; i++) { res *= i; res %= m; } return res; } ll mod_pow(ll x, ll y, ll m) { ll res = 1; while (y > 0) { if (y & 1) { res = res * x % m; } x = x * x % m; y >>= 1; } return res; } ll comb(ll x, ll y, ll m) { if (y > x) return 0; return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m; } int n, k, a[100010]; signed main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = k; i < n; i++) { if (a[i - k] < a[i]) cout << "Yes" << endl; else cout << "No" << endl; } }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <ctype.h> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <string.h> #include <string> #include <unordered_map> #include <vector> using namespace std; #define all(vec) vec.begin(), vec.end() typedef long long ll; ll gcd(ll x, ll y) { if (y == 0) return x; return gcd(y, x % y); } ll lcm(ll x, ll y) { return x / gcd(x, y) * y; } ll kai(ll x, ll y, ll m) { ll res = 1; for (ll i = x - y + 1; i <= x; i++) { res *= i; res %= m; } return res; } ll mod_pow(ll x, ll y, ll m) { ll res = 1; while (y > 0) { if (y & 1) { res = res * x % m; } x = x * x % m; y >>= 1; } return res; } ll comb(ll x, ll y, ll m) { if (y > x) return 0; return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m; } int n, k, a[200010]; signed main() { cin >> n >> k; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = k; i < n; i++) { if (a[i - k] < a[i]) cout << "Yes" << endl; else cout << "No" << endl; } }
replace
53
54
53
54
0
p02602
C++
Runtime Error
#include <bits/stdc++.h> #define pb push_back #define pf push_front #define in insert #define ff first #define ss second #define int long long #define rep(i, x, m) for (int i = x; i < m; i++) #define repr(i, x, m) for (int i = x; i >= m; i--) #define MOD 1000000007 #define endl "\n" #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define vi vector<int> #define pi pair<int, int> #define sz(x) (int)x.size() #define pq priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define fix(y) fixed << setprecision(y) #define print(v) \ for (int i = 0; i < v.size(); i++) \ cout << v[i] << " "; \ cout << endl #define FIO \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); using namespace std; int fac[2000005] = {0}; void factorial() { fac[0] = 1; fac[1] = 1; for (int i = 2; i < 200005; i++) fac[i] = ((i % MOD) * (fac[i - 1] % MOD)) % MOD; } int power(int n, int m) { int p = 1; if (m == 0) return 1; p = (power(n, m / 2) % MOD); p = (p % MOD * p % MOD) % MOD; return (m & 1 ? ((p % MOD * n % MOD) % MOD) : (p % MOD)); } int ncr(int n, int r) { return ((fac[n] * power(fac[r], MOD - 2)) % MOD * power(fac[n - r], MOD - 2)) % MOD; } void ram5564() { int n, k; cin >> n >> k; vi v; int sum[n + 1]; int a[n + 1]; rep(i, 1, n + 1) cin >> a[i]; // int sum=1; rep(i, 0, n + 1) { if (i == 0) { sum[i] = 1; continue; } if (i == 1) { sum[i] = a[i]; continue; } sum[i] = sum[i - 1] * a[i]; } // rep(i,0,n+1) // { // cout<<sum[i]<<endl; // } for (int i = k; i <= n; ++i) { v.pb(sum[i] / sum[i - k]); } rep(i, 1, sz(v)) { if (v[i] > v[i - 1]) { cout << "Yes\n"; } else { cout << "No\n"; } } } signed main() { FIO // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif int t = 1; // cin>>t; while (t--) ram5564(); cerr << "\n" << (float)clock() / CLOCKS_PER_SEC * 1000 << " ms" << endl; return 0; }
#include <bits/stdc++.h> #define pb push_back #define pf push_front #define in insert #define ff first #define ss second #define int long long #define rep(i, x, m) for (int i = x; i < m; i++) #define repr(i, x, m) for (int i = x; i >= m; i--) #define MOD 1000000007 #define endl "\n" #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define vi vector<int> #define pi pair<int, int> #define sz(x) (int)x.size() #define pq priority_queue<int> #define pqs priority_queue<int, vi, greater<int>> #define fix(y) fixed << setprecision(y) #define print(v) \ for (int i = 0; i < v.size(); i++) \ cout << v[i] << " "; \ cout << endl #define FIO \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); using namespace std; int fac[2000005] = {0}; void factorial() { fac[0] = 1; fac[1] = 1; for (int i = 2; i < 200005; i++) fac[i] = ((i % MOD) * (fac[i - 1] % MOD)) % MOD; } int power(int n, int m) { int p = 1; if (m == 0) return 1; p = (power(n, m / 2) % MOD); p = (p % MOD * p % MOD) % MOD; return (m & 1 ? ((p % MOD * n % MOD) % MOD) : (p % MOD)); } int ncr(int n, int r) { return ((fac[n] * power(fac[r], MOD - 2)) % MOD * power(fac[n - r], MOD - 2)) % MOD; } void ram5564() { int n, k; cin >> n >> k; int a[n]; rep(i, 0, n) { cin >> a[i]; } rep(i, k, n) { if (a[i] > a[i - k]) { cout << "Yes\n"; } else { cout << "No\n"; } } } signed main() { FIO // #ifndef ONLINE_JUDGE // freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); // #endif int t = 1; // cin>>t; while (t--) ram5564(); cerr << "\n" << (float)clock() / CLOCKS_PER_SEC * 1000 << " ms" << endl; return 0; }
replace
53
78
53
57
0
22.244 ms
p02602
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int N, K; cin >> N >> K; vector<ll> A(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } deque<ll> inter; for (int i = 0; i < K; ++i) { inter.push_back(A[i]); } for (int i = K; i < N; ++i) { ll first = inter.front(); inter.pop_front(); ll last = A[i]; if (first < last) cout << "Yes" << endl; else cout << "No" << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int N, K; cin >> N >> K; vector<ll> A(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } deque<ll> inter; for (int i = 0; i < K; ++i) { inter.push_back(A[i]); } for (int i = K; i < N; ++i) { ll first = inter.front(); inter.pop_front(); ll last = A[i]; inter.push_back(A[i]); if (first < last) cout << "Yes" << endl; else cout << "No" << endl; } }
insert
19
19
19
20
0
p02602
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; vector<int> v; for (int i = 0; i < n; i++) cin >> v[i]; for (int i = 0; i < n - k; i++) { if (v[i + k] > v[i]) cout << "Yes"; else cout << "No"; cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; vector<int> v(n); for (int i = 0; i < n; i++) cin >> v[i]; for (int i = 0; i < n - k; i++) { if (v[i + k] > v[i]) cout << "Yes"; else cout << "No"; cout << endl; } return 0; }
replace
6
7
6
7
-11
p02602
C++
Runtime Error
#include <algorithm> #include <assert.h> #include <cmath> #include <complex> #include <cstring> #include <deque> #include <fstream> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string.h> #include <unordered_map> #include <vector> using namespace std; using ll = long long; using ld = long double; const int mxn = 1e5 + 10; int a[mxn]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = k + 1; i <= n; i++) { if (a[i] > a[i - k]) cout << "Yes\n"; else cout << "No\n"; } return 0; }
#include <algorithm> #include <assert.h> #include <cmath> #include <complex> #include <cstring> #include <deque> #include <fstream> #include <functional> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string.h> #include <unordered_map> #include <vector> using namespace std; using ll = long long; using ld = long double; const int mxn = 2e5 + 10; int a[mxn]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = k + 1; i <= n; i++) { if (a[i] > a[i - k]) cout << "Yes\n"; else cout << "No\n"; } return 0; }
replace
19
20
19
20
0
p02602
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define INF 1001001001 using ll = long long; using dd = long double; const int D = 60; const int MAX_N = 200005; int to[D][MAX_N]; int main() { std::ifstream in("input.txt"); std::cin.rdbuf(in.rdbuf()); ll n, k; cin >> n >> k; vector<ll> v(n + 10, 1); vector<ll> A(n); for (int i = 0; i < n; ++i) { cin >> A[i]; if (i < k) { v[k - 1] *= A[i]; }; } for (int i = k; i < n; ++i) { // v[i] = (v[i-1]/A[i-k])*A[i]; // if (v[i] > v[i-1]) { if (A[i] > A[i - k]) { cout << "Yes" << endl; } else { cout << "No" << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define INF 1001001001 using ll = long long; using dd = long double; const int D = 60; const int MAX_N = 200005; int to[D][MAX_N]; int main() { ll n, k; cin >> n >> k; vector<ll> v(n + 10, 1); vector<ll> A(n); for (int i = 0; i < n; ++i) { cin >> A[i]; if (i < k) { v[k - 1] *= A[i]; }; } for (int i = k; i < n; ++i) { // v[i] = (v[i-1]/A[i-k])*A[i]; // if (v[i] > v[i-1]) { if (A[i] > A[i - k]) { cout << "Yes" << endl; } else { cout << "No" << endl; } } return 0; }
delete
12
15
12
12
0
p02602
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; bool cmp(long long int x, long long int y) { return x > y; } int main(void) { long long int t, n, m, k, x, y, a[100001]; vector<long long int> v, v1, v2; vector<pair<long long int, long long int>> p, p1, p2; set<long long int> st; priority_queue<long long int> pq; priority_queue<long long int, vector<long long int>, greater<long long int>> lpq; priority_queue<pair<long long int, long long int>, vector<pair<long long int, long long int>>, greater<pair<long long int, long long int>>> plpq; string s; cin >> n >> k; for (long long int i = 0; i < n; i++) { cin >> a[i]; } for (long long int i = k; i < n; i++) { if (a[i] > a[i - k]) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; bool cmp(long long int x, long long int y) { return x > y; } int main(void) { long long int t, n, m, k, x, y, a[200001]; vector<long long int> v, v1, v2; vector<pair<long long int, long long int>> p, p1, p2; set<long long int> st; priority_queue<long long int> pq; priority_queue<long long int, vector<long long int>, greater<long long int>> lpq; priority_queue<pair<long long int, long long int>, vector<pair<long long int, long long int>>, greater<pair<long long int, long long int>>> plpq; string s; cin >> n >> k; for (long long int i = 0; i < n; i++) { cin >> a[i]; } for (long long int i = k; i < n; i++) { if (a[i] > a[i - k]) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
replace
4
5
4
5
0
p02602
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; ll n, k; ll a[100005]; int main(void) { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; if (i >= k) { if (a[i] > a[i - k]) { cout << "Yes" << endl; } else { cout << "No" << endl; } } } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; ll n, k; ll a[200005]; int main(void) { cin >> n >> k; for (int i = 0; i < n; i++) { cin >> a[i]; if (i >= k) { if (a[i] > a[i - k]) { cout << "Yes" << endl; } else { cout << "No" << endl; } } } }
replace
5
6
5
6
0
p02602
C++
Runtime Error
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_poizcy.hpp> typedef long long ll; #define pb push_back #define mp make_pair #define all(a) (a).begin(), (a).end() #define clr(a, h) memset(a, (h), sizeof(a)) #define mem(a, h) memset(a, (h), sizeof(a)) #define fi first #define se second #define por(a, b) (((a % MOD) * (b % MOD)) % MOD) #define forg(i, b, e, c) for (ll i = (ll)b; i < (ll)e; i += c) #define forr(i, b, e) for (ll i = b; i < e; i++) using namespace std; // using namespace __gnu_pbds; typedef double lldb; typedef pair<ll, ll> ii; typedef pair<double, double> iidb; typedef pair<ll, ii> iii; typedef vector<ll> vi; typedef vector<vi> vvi; typedef vector<ii> vii; typedef vector<ll> vll; // typedef // tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> // ordered_set; const ll INF = 1e9 + 7; const double PI = acos(-1); const ll MOD = 1e9 + 7; #define initseg ll new_nodo = (nodo * 2), mid = (iz + der) / 2; // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define tam 110000 #define offset 200 #define ptr nodo * const ll inf = 2e18; double v[tam]; const double EPS = 1e-9; int main() { int n, k; cin >> n >> k; forr(i, 0, n) { cin >> v[i]; v[i] = log(v[i]); } double tot, sigtot; tot = sigtot = 0; /*forr(i,0,n) { cout<<v[i]<<" "; } cout<<endl;*/ forr(i, 0, k) { tot += v[i]; } // cout<<tot<<endl; forr(i, k, n) { if (v[i - k] < v[i]) cout << "Yes\n"; else cout << "No\n"; tot = sigtot; } }
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_poizcy.hpp> typedef long long ll; #define pb push_back #define mp make_pair #define all(a) (a).begin(), (a).end() #define clr(a, h) memset(a, (h), sizeof(a)) #define mem(a, h) memset(a, (h), sizeof(a)) #define fi first #define se second #define por(a, b) (((a % MOD) * (b % MOD)) % MOD) #define forg(i, b, e, c) for (ll i = (ll)b; i < (ll)e; i += c) #define forr(i, b, e) for (ll i = b; i < e; i++) using namespace std; // using namespace __gnu_pbds; typedef double lldb; typedef pair<ll, ll> ii; typedef pair<double, double> iidb; typedef pair<ll, ii> iii; typedef vector<ll> vi; typedef vector<vi> vvi; typedef vector<ii> vii; typedef vector<ll> vll; // typedef // tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> // ordered_set; const ll INF = 1e9 + 7; const double PI = acos(-1); const ll MOD = 1e9 + 7; #define initseg ll new_nodo = (nodo * 2), mid = (iz + der) / 2; // mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define tam 210000 #define offset 200 #define ptr nodo * const ll inf = 2e18; double v[tam]; const double EPS = 1e-9; int main() { int n, k; cin >> n >> k; forr(i, 0, n) { cin >> v[i]; v[i] = log(v[i]); } double tot, sigtot; tot = sigtot = 0; /*forr(i,0,n) { cout<<v[i]<<" "; } cout<<endl;*/ forr(i, 0, k) { tot += v[i]; } // cout<<tot<<endl; forr(i, k, n) { if (v[i - k] < v[i]) cout << "Yes\n"; else cout << "No\n"; tot = sigtot; } }
replace
34
35
34
35
0
p02602
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; namespace AC { #define ll long long #define PLL pair<ll, ll> #define PDD pair<double, double> #define PDPLL pair<double, PLL> #define PLPLL pair<ll, PLL> #define pb push_back #define fi first #define se second #define ls rt << 1 #define rs rt << 1 | 1 const ll N = 1e5 + 66; ll BUGS = 1; inline ll read() { ll x = 0; bool flag = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') flag = 0; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + ch - '0'; ch = getchar(); } if (flag) return x; return (~(x - 1)); } inline void read(ll arr[], ll s, ll e) { for (ll i = s; i <= e; ++i) arr[i] = read(); } inline void write(ll x) { if (x < 0) { x = ~(x - 1); putchar('-'); } if (x > 9) write(x / 10); putchar(x % 10 + '0'); } inline void print(ll x) { write(x); puts(""); } inline void print(ll arr[], ll s, ll e) { for (ll i = s; i <= e - 1; ++i) write(arr[i]), putchar(' '); write(arr[e]); puts(""); } inline ll max3(ll a, ll b, ll c) { return max(a, max(b, c)); } inline ll min3(ll a, ll b, ll c) { return min(a, min(b, c)); } inline void debugNum(ll num, string ss) { cout << "BUGS" << BUGS++ << " : " << ss << " : " << num << endl; } inline void debugArr(ll arr[], ll s, ll e, string ss) { cout << "BUGS" << BUGS++ << " : " << ss << " : " << endl; for (ll i = s; i <= e; ++i) cout << "i : " << i << " val : " << arr[i] << endl; } inline void IO() { // ios::sync_with_stdio(false), cout.tie(0), cin.tie(0); // cout << setiosflags(ios::fixed) << setprecision(1); //保留小数点后1位 // cout << setprecision(1); //保留1位有效数字 freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); } } // namespace AC using namespace AC; ll n, k, arr[N]; int main() { // IO(); while (~scanf("%lld", &n)) { k = read(), read(arr, 1, n); for (ll i = 1; i <= n; ++i) { ll j = i + k; if (j > n) break; if (arr[j] > arr[i]) puts("Yes"); else puts("No"); } } return 0; }
#include <bits/stdc++.h> using namespace std; namespace AC { #define ll long long #define PLL pair<ll, ll> #define PDD pair<double, double> #define PDPLL pair<double, PLL> #define PLPLL pair<ll, PLL> #define pb push_back #define fi first #define se second #define ls rt << 1 #define rs rt << 1 | 1 const ll N = 2e5 + 66; ll BUGS = 1; inline ll read() { ll x = 0; bool flag = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') flag = 0; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + ch - '0'; ch = getchar(); } if (flag) return x; return (~(x - 1)); } inline void read(ll arr[], ll s, ll e) { for (ll i = s; i <= e; ++i) arr[i] = read(); } inline void write(ll x) { if (x < 0) { x = ~(x - 1); putchar('-'); } if (x > 9) write(x / 10); putchar(x % 10 + '0'); } inline void print(ll x) { write(x); puts(""); } inline void print(ll arr[], ll s, ll e) { for (ll i = s; i <= e - 1; ++i) write(arr[i]), putchar(' '); write(arr[e]); puts(""); } inline ll max3(ll a, ll b, ll c) { return max(a, max(b, c)); } inline ll min3(ll a, ll b, ll c) { return min(a, min(b, c)); } inline void debugNum(ll num, string ss) { cout << "BUGS" << BUGS++ << " : " << ss << " : " << num << endl; } inline void debugArr(ll arr[], ll s, ll e, string ss) { cout << "BUGS" << BUGS++ << " : " << ss << " : " << endl; for (ll i = s; i <= e; ++i) cout << "i : " << i << " val : " << arr[i] << endl; } inline void IO() { // ios::sync_with_stdio(false), cout.tie(0), cin.tie(0); // cout << setiosflags(ios::fixed) << setprecision(1); //保留小数点后1位 // cout << setprecision(1); //保留1位有效数字 freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); } } // namespace AC using namespace AC; ll n, k, arr[N]; int main() { // IO(); while (~scanf("%lld", &n)) { k = read(), read(arr, 1, n); for (ll i = 1; i <= n; ++i) { ll j = i + k; if (j > n) break; if (arr[j] > arr[i]) puts("Yes"); else puts("No"); } } return 0; }
replace
15
16
15
16
0
p02602
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #include <iomanip> #include <math.h> 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; } const int INF = 1001001001; vector<pair<int64_t, int64_t>> prime_factorize(int64_t x) { vector<pair<int64_t, int64_t>> p; for (int64_t i = 2; i * i <= x; i++) { int cnt = 0; if (x % i == 0) { while (x % i == 0) { cnt++; x /= i; } p.push_back(make_pair(i, cnt)); } } if (x != 1) { p.push_back(make_pair(x, 1)); } return p; } int main() { int64_t N, K; cin >> N >> K; vector<int64_t> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } vector<int64_t> table(N + 1); table[0] = 1; int64_t sum = 1; for (int i = 0; i < N; i++) { sum *= A[i]; table[i + 1] = sum; } for (int i = K; i <= N - 1; i++) { if (table[i] / table[i - K] < table[i + 1] / table[i + 1 - K]) { cout << "Yes" << endl; } else { cout << "No" << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; #include <iomanip> #include <math.h> 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; } const int INF = 1001001001; vector<pair<int64_t, int64_t>> prime_factorize(int64_t x) { vector<pair<int64_t, int64_t>> p; for (int64_t i = 2; i * i <= x; i++) { int cnt = 0; if (x % i == 0) { while (x % i == 0) { cnt++; x /= i; } p.push_back(make_pair(i, cnt)); } } if (x != 1) { p.push_back(make_pair(x, 1)); } return p; } int main() { int64_t N, K; cin >> N >> K; vector<int64_t> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } for (int64_t i = K; i < N; i++) { if (A[i - K] < A[i]) { cout << "Yes" << endl; } else { cout << "No" << endl; } } return 0; }
replace
43
53
43
45
0
p02602
C++
Runtime Error
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") #pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define watch(x) cout << (#x) << " is " << (x) << endl #define debug cout << "hi" << endl using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; const int MOD = 1e9 + 7; const int INF32 = 1 << 30; const ll INF64 = 1LL << 60; void solve() { int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n - k; i++) { if (a[i + k] > a[i]) cout << "Yes\n"; else cout << "No\n"; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T; cin >> T; while (T--) solve(); return 0; }
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops,no-stack-protector") #pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #define watch(x) cout << (#x) << " is " << (x) << endl #define debug cout << "hi" << endl using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; const int MOD = 1e9 + 7; const int INF32 = 1 << 30; const ll INF64 = 1LL << 60; void solve() { int n, k; cin >> n >> k; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n - k; i++) { if (a[i + k] > a[i]) cout << "Yes\n"; else cout << "No\n"; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); return 0; }
replace
31
35
31
32
0
p02602
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; cin >> N >> K; long long A[N + 1]; for (int i = 1; i <= N; i++) { cin >> A[i]; } long long past = 0; long long current = 0; for (int i = 1; i <= K; i++) { past += A[i]; } for (int i = K + 1; i <= N; i++) { current = 0; for (int n = 0; n < K; n++) { current += A[i - n]; } if (current > past) { cout << "Yes" << endl; } else { cout << "No" << endl; } past = current; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; cin >> N >> K; long long A[N + 1]; for (int i = 1; i <= N; i++) { cin >> A[i]; } long long past = 0; long long current = 0; for (int i = 1; i <= K; i++) { past += A[i]; } for (int i = K + 1; i <= N; i++) { current = past - A[i - K] + A[i]; if (current > past) { cout << "Yes" << endl; } else { cout << "No" << endl; } past = current; } return 0; }
replace
21
25
21
22
TLE
p02602
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x) { x = 0; int f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = x * 10 + (ch ^ 48), ch = getchar(); x *= f; return; } template <typename T> void write(T x) { if (x < 0) putchar('-'), x = -x; if (x >= 10) write(x / 10); putchar(x % 10 + '0'); return; } const int MAXN = 100010; int n, k; int a[MAXN]; int main() { read(n), read(k); for (int i = 1; i <= n; ++i) read(a[i]); for (int i = k + 1; i <= n; ++i) if (a[i] > a[i - k]) printf("Yes\n"); else printf("No\n"); return 0; }
#include <bits/stdc++.h> using namespace std; template <typename T> inline void read(T &x) { x = 0; int f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') x = x * 10 + (ch ^ 48), ch = getchar(); x *= f; return; } template <typename T> void write(T x) { if (x < 0) putchar('-'), x = -x; if (x >= 10) write(x / 10); putchar(x % 10 + '0'); return; } const int MAXN = 200010; int n, k; int a[MAXN]; int main() { read(n), read(k); for (int i = 1; i <= n; ++i) read(a[i]); for (int i = k + 1; i <= n; ++i) if (a[i] > a[i - k]) printf("Yes\n"); else printf("No\n"); return 0; }
replace
24
25
24
25
0
p02602
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long lld; int main() { std::ios::sync_with_stdio(false); lld tc = 1; // cin >> tc; while (tc--) { lld n, k; cin >> n >> k; vector<lld> v(n); for (lld i = 0; i < n; i++) { cin >> v[i]; } map<lld, lld> mp; for (lld i = 0; i < k; i++) { mp[v[i]]++; } for (lld i = k; i < n; i++) { map<lld, lld> pre = mp; mp[v[i - k]]--; mp[v[i]]++; if (v[i] > v[i - k]) { cout << "Yes\n"; } else { cout << "No\n"; } } } }
#include <bits/stdc++.h> using namespace std; typedef long long lld; int main() { std::ios::sync_with_stdio(false); lld tc = 1; // cin >> tc; while (tc--) { lld n, k; cin >> n >> k; vector<lld> v(n); for (lld i = 0; i < n; i++) { cin >> v[i]; } map<lld, lld> mp; for (lld i = 0; i < k; i++) { mp[v[i]]++; } for (lld i = k; i < n; i++) { mp[v[i - k]]--; mp[v[i]]++; if (v[i] > v[i - k]) { cout << "Yes\n"; } else { cout << "No\n"; } } } }
delete
20
21
20
20
TLE
p02602
C++
Runtime Error
#include <iostream> using namespace std; int main() { int a[2000], n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n - k; i++) { if (a[i] / a[i + k] > 0) cout << "No" << endl; else { cout << "Yes" << endl; } } return 0; }
#include <iostream> using namespace std; int main() { int a[200005], n, k; cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 1; i <= n - k; i++) { if (a[i] / a[i + k] > 0) cout << "No" << endl; else { cout << "Yes" << endl; } } return 0; }
replace
4
5
4
5
0
p02602
C++
Runtime Error
/***** author : C0d1ngPhenomena *****/ #include <bits/stdc++.h> #define endl "\n" #define ll long long int #define TestCases \ int T; \ cin >> T; \ while (T--) #define rep(i, a, b) for (ll i = a; i < b; i++) #define revrep(i, a, b) for (ll i = b - 1; i >= a; i--) #define vll vector<ll> #define vvll vector<vll> #define pll pair<ll, ll> #define vpll vector<pll> #define mp(x, y) make_pair(x, y) #define mod 1000000007 #define inf 1000000000000000001; #define all(c) c.begin(), c.end() #define alld(c) c.begin(), c.end(), greater<int>() #define mem(a, val) memset(a, val, sizeof(a)) #define f first #define s second #define pb push_back using namespace std; bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n, k; cin >> n >> k; vll arr(n); rep(i, 0, n) cin >> arr[i]; rep(i, 0, n - k) { if (arr[i] * arr[k - 1 + i] < arr[i + i] * arr[k + i]) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
/***** author : C0d1ngPhenomena *****/ #include <bits/stdc++.h> #define endl "\n" #define ll long long int #define TestCases \ int T; \ cin >> T; \ while (T--) #define rep(i, a, b) for (ll i = a; i < b; i++) #define revrep(i, a, b) for (ll i = b - 1; i >= a; i--) #define vll vector<ll> #define vvll vector<vll> #define pll pair<ll, ll> #define vpll vector<pll> #define mp(x, y) make_pair(x, y) #define mod 1000000007 #define inf 1000000000000000001; #define all(c) c.begin(), c.end() #define alld(c) c.begin(), c.end(), greater<int>() #define mem(a, val) memset(a, val, sizeof(a)) #define f first #define s second #define pb push_back using namespace std; bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } int main() { std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll n, k; cin >> n >> k; vll arr(n); rep(i, 0, n) cin >> arr[i]; rep(i, 0, n - k) { if (arr[i] < arr[k + i]) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
replace
40
41
40
41
0
p02603
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; using vi = vector<int>; int main() { int n; cin >> n; vi a(n); rep(i, n) cin >> a.at(i); ll money = 1000; ll kabu = 0; int start = a.at(0); for (int i = 1; i < n; i++) { if (start < a.at(i)) { while (money >= start) { money -= start; kabu++; } while (kabu > 0) { money += a.at(i); kabu--; } start = a.at(i); } else { start = a.at(i); } } cout << money << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; using vi = vector<int>; int main() { int n; cin >> n; vi a(n); rep(i, n) cin >> a.at(i); ll money = 1000; ll kabu = 0; int start = a.at(0); for (int i = 1; i < n; i++) { if (start < a.at(i)) { kabu = money / start; money = money % start; ll sell = a.at(i) * kabu; money += sell; kabu = 0; start = a.at(i); } else { start = a.at(i); } } cout << money << endl; return 0; }
replace
19
27
19
24
TLE
p02603
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define contains(v, t) (find(v.begin(), v.end(), t) != v.end()) #define MOD 1000000007 using ll = long long; using ull = unsigned long long; using Pii = pair<int, int>; int main() { int n; cin >> n; vector<int> a(n + 1); rep(i, n) { cin >> a[i]; } a[n + 1] = a[n]; ull m = 1000; ull c = 0; rep(i, n) { // cout << i << "日目: " << a[i] << endl; int cur = a[i]; int pos = 0; for (int j = i + 1; j <= n; j++) { if (cur < a[j]) { pos = 1; break; } if (cur > a[j]) { pos = -1; break; } } ull curm = cur; if (pos == 1 && m >= curm) { c = m / cur; m = m - c * cur; } else if (pos == -1) { m = m + c * cur; c = 0; } // cout << m << " " << c << endl; } cout << m; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define contains(v, t) (find(v.begin(), v.end(), t) != v.end()) #define MOD 1000000007 using ll = long long; using ull = unsigned long long; using Pii = pair<int, int>; int main() { int n; cin >> n; vector<int> a(n + 100); rep(i, n) { cin >> a[i]; } a[n + 1] = a[n]; ull m = 1000; ull c = 0; rep(i, n) { // cout << i << "日目: " << a[i] << endl; int cur = a[i]; int pos = 0; for (int j = i + 1; j <= n; j++) { if (cur < a[j]) { pos = 1; break; } if (cur > a[j]) { pos = -1; break; } } ull curm = cur; if (pos == 1 && m >= curm) { c = m / cur; m = m - c * cur; } else if (pos == -1) { m = m + c * cur; c = 0; } // cout << m << " " << c << endl; } cout << m; }
replace
13
14
13
14
0
p02603
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int N; cin >> N; vector<ll> A(N); for (ll &i : A) cin >> i; ll money = 1000; ll beat = 0; vector<bool> B(N); // BY(0),SE(0); for (ll i = 0; i < N - 1; i++) { if ((long double)A[i + 1] / A[i] > 1) B[i] = true; // BY.push_back(i); else B[i] = false; // SE.push_back(i); } for (ll i = 0; i < N; i++) { if (B[i]) { while (money - A[i] >= 0) { beat++; money -= A[i]; } } else { money += beat * A[i]; beat = 0; } } cout << money << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { int N; cin >> N; vector<ll> A(N); for (ll &i : A) cin >> i; ll money = 1000; ll beat = 0; vector<bool> B(N); // BY(0),SE(0); for (ll i = 0; i < N - 1; i++) { if ((long double)A[i + 1] / A[i] > 1) B[i] = true; // BY.push_back(i); else B[i] = false; // SE.push_back(i); } for (ll i = 0; i < N; i++) { if (B[i]) { /* while(money-A[i]>=0){ beat++; money-=A[i]; }*/ beat += money / A[i]; money = money % A[i]; } else { money += beat * A[i]; beat = 0; } } cout << money << endl; }
replace
22
26
22
28
TLE
p02603
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define debug(n) cout << "DEBUG1 " << n << "\n"; #define debug2(n, m) cout << "DEBUG2 " << n << ' ' << m << "\n"; #define debug3(n, m, x) cout << "DEBUG3 " << n << ' ' << m << ' ' << x << "\n"; #define debug4(n, m, x, y) \ cout << "DEBUG3 " << n << ' ' << m << ' ' << x << ' ' << y << "\n"; #define ss_def \ stringstream ss // stringstream, do ss_def(str), then ss >> n (n is int) #define upzero(n) \ if (n < 0) \ n = 0 #pragma GCC optimize("Ofast") using namespace std; ll int BtoPmodM(ll int b, ll int p, ll int m) { // (b ^ p) % m (Big Mod) b %= m; if (p == 0) return 1; else if (p % 2 == 0) return (BtoPmodM(b, p / 2, m) * BtoPmodM(b, p / 2, m)) % m; // a^(p/2) * a^(p/2) = a^p else if (p % 2 == 1) return (BtoPmodM(b, (p - 1) / 2, m) * BtoPmodM(b, (p - 1) / 2, m) * b) % m; // +1 else return 0; // a function must return something } ll int gcd(ll int a, ll int b) { // Euclidean Algorithm if (b == 0) return a; else return gcd(b, a % b); } bool coprime(ll int a, ll int b) { if (gcd(a, b) == 1) return true; else return false; } ll int factModP(ll int n, ll int p) { ll int fac[n - 1]; fac[0] = 1; for (ll int i = 1; i <= n; i++) { fac[i] = fac[i - 1] * i % p; } return fac[n]; } ll int power(ll int x, ll int y, ll int p) { // x ^ y % p ll int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y /= 2; x = (x * x) % p; } return res; } ll int modInverse(ll int n, ll int p) { return power(n, p - 2, p); } ll int nCrModP(ll int n, ll int r, ll int p) { if (r == 0) return 1; else if (r > n) return 0; ll int fac[n + 1]; fac[0] = 1; for (ll int i = 1; i <= n; i++) { fac[i] = fac[i - 1] * i % p; } return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; } ll int nCr(ll int n, ll int r) { ll int ans = 1; if (r >= n - r) { for (ll int i = r + 1; i <= n; i++) ans *= i; for (ll int i = 1; i <= n - r; i++) ans /= i; } else { for (ll int i = n - r + 1; i <= n; i++) ans *= i; for (ll int i = 1; i <= r; i++) ans /= i; } return ans; } ll int string_to_int(string str) { int strl = str.length(); ll int ans = 0; if (str[0] == '-') { for (int i = 1; i < strl; i++) ans += pow(10, strl - i - 1) * (str[i] - 48); ans = 0 - ans; return ans; } for (int i = 0; i < strl; i++) ans += pow(10, strl - i - 1) * (str[i] - 48); return ans; } struct edge_stru { int u, v, w; // node 1, node 2, weight }; edge_stru make_edge_stru(int u, int v, int w) { edge_stru a = {u, v, w}; return a; } class cmp { // sorting edges public: bool operator()(edge_stru a, edge_stru b) { return a.w > b.w; // sort in ascending order of weight } }; void make_set(int v, int *parent, int *rank) { parent[v] = v; // set as the root rank[v] = 0; // first rank is 0 return; } int find_set(int v, int *parent) { if (v == parent[v]) return v; // finds root // return parent[v] = find_set(parent[v], parent); // Path compression // optimization return find_set(parent[v], parent); } void union_sets(int a, int b, int *parent, int *rank) { // a = find_set(a, parent); // find root of a // b = find_set(b, parent); // find root of b if (rank[a] > rank[b]) swap(a, b); // let a be the bigger rank (root a < root b) parent[b] = a; // set node b as root a's parent if (rank[a] == rank[b]) rank[b]++; // if same rank set b as the child of a return; } bool binSearch(ll *arr, ll n, ll target) { ull l = 0, r = n - 1; while (l < r) { int mid = (l + r) / 2; if (arr[mid] >= target) { r = mid; } else { l = mid + 1; } } if (arr[l] == target) { return true; } else { return false; } } void solve() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; ll int tot = 1000; for (int i = 1; i < n; i++) { if (a[i - 1] <= a[i]) { ll int cnt = 0; while (tot >= a[i - 1]) { tot -= a[i - 1]; cnt++; } tot += cnt * a[i]; } } cout << tot << endl; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // implementation solve(); }
#include <bits/stdc++.h> #define ll long long #define ull unsigned long long #define debug(n) cout << "DEBUG1 " << n << "\n"; #define debug2(n, m) cout << "DEBUG2 " << n << ' ' << m << "\n"; #define debug3(n, m, x) cout << "DEBUG3 " << n << ' ' << m << ' ' << x << "\n"; #define debug4(n, m, x, y) \ cout << "DEBUG3 " << n << ' ' << m << ' ' << x << ' ' << y << "\n"; #define ss_def \ stringstream ss // stringstream, do ss_def(str), then ss >> n (n is int) #define upzero(n) \ if (n < 0) \ n = 0 #pragma GCC optimize("Ofast") using namespace std; ll int BtoPmodM(ll int b, ll int p, ll int m) { // (b ^ p) % m (Big Mod) b %= m; if (p == 0) return 1; else if (p % 2 == 0) return (BtoPmodM(b, p / 2, m) * BtoPmodM(b, p / 2, m)) % m; // a^(p/2) * a^(p/2) = a^p else if (p % 2 == 1) return (BtoPmodM(b, (p - 1) / 2, m) * BtoPmodM(b, (p - 1) / 2, m) * b) % m; // +1 else return 0; // a function must return something } ll int gcd(ll int a, ll int b) { // Euclidean Algorithm if (b == 0) return a; else return gcd(b, a % b); } bool coprime(ll int a, ll int b) { if (gcd(a, b) == 1) return true; else return false; } ll int factModP(ll int n, ll int p) { ll int fac[n - 1]; fac[0] = 1; for (ll int i = 1; i <= n; i++) { fac[i] = fac[i - 1] * i % p; } return fac[n]; } ll int power(ll int x, ll int y, ll int p) { // x ^ y % p ll int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y /= 2; x = (x * x) % p; } return res; } ll int modInverse(ll int n, ll int p) { return power(n, p - 2, p); } ll int nCrModP(ll int n, ll int r, ll int p) { if (r == 0) return 1; else if (r > n) return 0; ll int fac[n + 1]; fac[0] = 1; for (ll int i = 1; i <= n; i++) { fac[i] = fac[i - 1] * i % p; } return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p; } ll int nCr(ll int n, ll int r) { ll int ans = 1; if (r >= n - r) { for (ll int i = r + 1; i <= n; i++) ans *= i; for (ll int i = 1; i <= n - r; i++) ans /= i; } else { for (ll int i = n - r + 1; i <= n; i++) ans *= i; for (ll int i = 1; i <= r; i++) ans /= i; } return ans; } ll int string_to_int(string str) { int strl = str.length(); ll int ans = 0; if (str[0] == '-') { for (int i = 1; i < strl; i++) ans += pow(10, strl - i - 1) * (str[i] - 48); ans = 0 - ans; return ans; } for (int i = 0; i < strl; i++) ans += pow(10, strl - i - 1) * (str[i] - 48); return ans; } struct edge_stru { int u, v, w; // node 1, node 2, weight }; edge_stru make_edge_stru(int u, int v, int w) { edge_stru a = {u, v, w}; return a; } class cmp { // sorting edges public: bool operator()(edge_stru a, edge_stru b) { return a.w > b.w; // sort in ascending order of weight } }; void make_set(int v, int *parent, int *rank) { parent[v] = v; // set as the root rank[v] = 0; // first rank is 0 return; } int find_set(int v, int *parent) { if (v == parent[v]) return v; // finds root // return parent[v] = find_set(parent[v], parent); // Path compression // optimization return find_set(parent[v], parent); } void union_sets(int a, int b, int *parent, int *rank) { // a = find_set(a, parent); // find root of a // b = find_set(b, parent); // find root of b if (rank[a] > rank[b]) swap(a, b); // let a be the bigger rank (root a < root b) parent[b] = a; // set node b as root a's parent if (rank[a] == rank[b]) rank[b]++; // if same rank set b as the child of a return; } bool binSearch(ll *arr, ll n, ll target) { ull l = 0, r = n - 1; while (l < r) { int mid = (l + r) / 2; if (arr[mid] >= target) { r = mid; } else { l = mid + 1; } } if (arr[l] == target) { return true; } else { return false; } } void solve() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; ll int tot = 1000; for (int i = 1; i < n; i++) { if (a[i - 1] <= a[i]) { ll int cnt = tot / a[i - 1]; tot += (a[i] - a[i - 1]) * cnt; } } cout << tot << endl; } int main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); // implementation solve(); }
replace
161
167
161
163
TLE
p02603
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> // #include <boost/multiprecision/cpp_int.hpp> // // using namespace boost::multiprecision; using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; /*** Typedef ***/ typedef long long ll; typedef long long int lli; typedef unsigned long long ull; typedef long double ld; // typedef unordered_set<ll> usll; // typedef unordered_multiset<ll> umsll; /*** Loops ***/ #define ffit(i, dat) \ for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i) #define ff1(i, a, b) for (ll i = a; i < b; i++) #define ff2(i, a, b) for (ll i = b - 1; i >= a; i--) #define ff3(i, a, b, m) for (ll i = a; i < b; i += m) #define ipar(ar, n) \ ll ar[n]; \ ff1(i, 0, n) cin >> ar[i]; #define opar(ar, n) ff1(i, 0, n) cout << ar[i] << " "; #define foRev(num) for (ll i = num - 1; i >= 0; i--) #define forIn(arr, num) \ for (ll i = 0; i < num; i++) \ sc1(arr[i]); #define forIn1(arr, num) \ for (ll i = 1; i <= num; i++) \ sc1(arr[i]); #define vpnt(ans) \ for (ll i = 0; i < ans.size(); i++) \ cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n'); #define apnt(arr, num) \ for (ll i = 0; i < num; i++) \ cout << arr[i] << (i + 1 < num ? ' ' : '\n'); /*** Define Values ***/ #define PI acos(-1.0) #define eps 1e-7 #define size1 15 /*** STLs ***/ #define cu continue #define br break #define rsz resize #define ins insert #define ft front #define bk back #define eb emplace_back #define lb lower_bound #define ub upper_bound #define pb push_back #define ff first #define ss second #define mp make_pair #define mem(name, value) memset(name, value, sizeof(name)) #define MN3(n1, n2, n3) min(n1, min(n2, n3)) #define MN4(n1, n2, n3, n4) min(n1, min(n2, min(n3, n4))) #define MX3(n1, n2, n3) max(n1, max(n2, n3)) #define MX4(n1, n2, n3, n4) max(n1, max(n2, max(n3, n4))) #define mxar(a, n) *max_element(a, a + n) #define mnar(a, n) *min_element(a, a + n) #define arr_sm(a, n) accumulate(a, a + n, 0) #define vc_sm(ve) accumulate(ve.begin(), ve.end(), 0) #define mx_vc(ve) *max_element(ve.begin(), ve.end()) #define mn_vc(ve) *min_element(ve.begin(), ve.end()) // #define endl " \n" /*** STLs ***/ typedef vector<ll> vll; #define vvll vector<vll> typedef set<ll> sll; typedef multiset<ll> msll; // typedef multimap <ll> mpll; typedef queue<ll> qll; typedef map<ll, ll> mll; typedef pair<ll, ll> pll; typedef vector<pair<ll, ll>> vpll; typedef priority_queue<pair<ll, ll>> pqpll; #define maxpq priority_queue<int> #define minpq priority_queue<int, vector<int>, greater<int>> #define ml unordered_map<ll, ll> /// typedef unordered_multiset<int> umsi; typedef unordered_set<ll> us; /// vector<vector<int>> v(10, vector<int>(20,500)); 2d vector initialization. of /// 10 rows and 20 columns, with value 500. /*** Sorts ***/ #define czero(n) \ __builtin_popcountll( \ n) // count the number of 1's in the bit representation of a number #define cenzero(n) \ __builtin_ctzll(n) // count the number of zereos from the end of the bit // representation of a number until a 1 #define countbegzero(n) __builtin_clzxll(n) #define checkparity(n) \ __builtin_parityll(n) // checks whether the number of bits are even or odd #define all(v) (v).begin(), (v).end() #define rev(v) reverse(all(v)) #define srt(v) sort(all(v)) #define srtgrt(v) sort(all(v), greater<ll>()) #define prsrt greater<pair<int, int>>() /*** Some Prints ***/ #define ip(n) \ ll n; \ cin >> n; #define ipp(n, k) \ ll n; \ cin >> n; \ ll k; \ cin >> k; #define ip3(n, m, k) \ ll n; \ cin >> n; \ ll m; \ cin >> m; \ ll k; \ cin >> k; #define kl '\n' #define no cout << "NO" << '\n' #define yes cout << "YES" << '\n' #define case cout << "Case " << t++ << ": "; // #define ps(x,y) fixed<<setprecision(y)<<x #define inf 1e18 #define dbg(x) cout << '>' << #x << ':' << x << kl; #define trc(x) cerr << #x << ": " << x << kl #define trc2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << kl #define trc3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << kl #define trc4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << kl #define trc5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << kl #define trc6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << kl #define w(x) \ ll x; \ cin >> x; \ while (x--) #define go(i, a) for (auto &i : a) #define go1(it, v) for (auto it = v.begin(); it != v.end(); ++it) #define mk(arr, n, type) type *arr = new type[n]; #define sz(obj) (int(obj.size())) #define ipve(vc, n) \ vll vc(n); \ ff1(i, 0, n) { cin >> vc[i]; } #define ipvc(vc, n) \ vll vc; \ ff1(i, 0, n) { \ ip(x); \ vc.pb(x); \ } #define depressed() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) // bool ans = all_of(arr, arr + 6, [](int x) {return x & 1; } ); const double pi = 3.141592653589793238460; bool isptsquare(long double x) { long double sr = sqrt(x); return ((sr - floor(sr)) == 0); } ll facts(ll n, ll mod) { ll prod = 1; for (ll i = 1; i <= n; i++) { prod = (prod * i) % mod; } return prod; } ll binpow(ll a, ll b, ll mod) { ll ans = 1; while (b) { if (b & 1) ans *= a; a *= a; ans %= mod; a %= mod; b /= 2; } return ans; } ll mod = 1e9 + 7; vector<ll> factors(ll n) { // returns all factors of a given number ll lim = sqrt(n); vector<ll> f; for (int i = 1; i <= lim; i++) { if (n % i == 0) { f.push_back(i); f.push_back(n / i); if (i * i == n) { f.pop_back(); } } } return f; } ll ceilAB(ll a, ll b) { return (a + b - 1) / b; } ll bigmod(ll n, ll pow) { if (pow == 0) return 1; if (pow == 1) return n % mod; ll ans = bigmod(n, pow / 2); ans = (ans * ans) % mod; if (pow % 2 == 1) { ans = (ans * n) % mod; } return ans % mod; } const int mxn = 1e3; ll fact[mxn + 1]; void calcfac(ll n, ll mod = 2e18) { fact[0] = 1; for (int i = 1; i <= n; ++i) { fact[i] = fact[i - 1] * i; fact[i] %= mod; } } ll nCr(ll p, ll q, ll mod = 2e18) { ll val = fact[p]; ll invfact = fact[q] * fact[p - q]; val %= mod; invfact %= mod; val *= binpow(invfact, mod - 2, mod); return val % mod; } ll nPr(ll p, ll q, ll mod = 2e18) { ll val = nCr(p, q, mod); val *= fact[q]; val %= mod; return val; } bool isprime(ll n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } ll power(ll x, ll y) { ll temp; if (y == 0) return 1; temp = power(x, y / 2); if (y % 2 == 0) return temp * temp; else { if (y > 0) return (x * temp * temp); else return ((temp * temp) / x); } } // ll pmod(ll a,ll b){ll res=1;a%=mod;assert(b>=0);for(; b; // b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll expo(ll x, ll y){ ll // res = 1; x = x % mod; while (y > 0) { if (y & 1)res = (res*x) % mod; y = // y>>1;x = (x*x) % mod;}return res;} void matmul(ll a[][2], ll b[][2]) { ll // tmp[2][2]; for(int i=0; i<2; i++) { for(int j=0; j<2; j++) { tmp[i][j] = 0; // for(int k=0; k<2; k++) tmp[i][j] = (tmp[i][j] + a[i][k]*b[k][j]) % mod; }} // for(int i=0; i<2; i++) for(int j=0; j<2; j++) a[i][j] = tmp[i][j]; } ll // fibo(int n) // returns nth fibonacci number, also S(n) = f(n+2)-1 { if(n //== 0) return 0; else if(n == 1) return 1; ll T[2][2] = { {0, 1} , {1, 1} }; ll //res[2][2] = { {1, 0}, {0,1} }; n--; while(n) { if(n & 1) matmul(res, T); n >>= //1; matmul(T, T); } return res[1][1]; } ll cbtr(ll n, ll m) { ll sm = 1; ff1(i, 1, m + 1) { sm *= (n - i + 1); sm /= i; } return sm; } // string a="cdefghijklmnopqrstuvwxyz"; ld f(ld n) { ld sm = 1; ff1(i, 1, n + 1) { sm *= i; } return sm; } ld pc(ld n, ld k) { ld sm = f(n) / f(n - k); return sm; } vll prime; void seive(ll n) { prime.resize(n + 1, 1); iota(prime.begin(), prime.end(), 0); prime[0] = 0, prime[1] = 1; for (int i = 2; i * i <= n; i++) if (prime[i] == i) for (int j = i * i; j <= n; j += i) prime[j] = i; } map<ll, ll> prime_factor(ll n) { map<ll, ll> ret; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } bool p2(ll n) { if (n == 0) return false; return (ceil(log2(n)) == floor(log2(n))); } #define cer \ cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC \ << "ms\n"; #define ps(x, y) fixed << setprecision(y) << x ll modInverse(ll n, ll m) { return binpow(n, m - 2, m); } bool cmp(pll a, pll b) { if (a.ss == b.ss) { return a.ff > b.ff; } return a.ff > b.ff; } void fun() { ip(n); ipvc(a, n); vll b, c; ff1(i, 0, n - 1) { if (a[i + 1] > a[i]) { c.pb(a[i]); c.pb(a[i + 1]); } } ll sm = 1000; // go(i,c) cout<<i<<kl; ff1(i, 0, sz(c)) { ll k = sm / a[i]; sm -= k * c[i]; sm += k * c[i + 1]; i++; } cout << sm; } int main() { depressed(); ll t = 1; // cin>>t; while (t--) { fun(); } // cer; return 0; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> // #include <boost/multiprecision/cpp_int.hpp> // // using namespace boost::multiprecision; using namespace __gnu_pbds; using namespace std; typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; /*** Typedef ***/ typedef long long ll; typedef long long int lli; typedef unsigned long long ull; typedef long double ld; // typedef unordered_set<ll> usll; // typedef unordered_multiset<ll> umsll; /*** Loops ***/ #define ffit(i, dat) \ for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i) #define ff1(i, a, b) for (ll i = a; i < b; i++) #define ff2(i, a, b) for (ll i = b - 1; i >= a; i--) #define ff3(i, a, b, m) for (ll i = a; i < b; i += m) #define ipar(ar, n) \ ll ar[n]; \ ff1(i, 0, n) cin >> ar[i]; #define opar(ar, n) ff1(i, 0, n) cout << ar[i] << " "; #define foRev(num) for (ll i = num - 1; i >= 0; i--) #define forIn(arr, num) \ for (ll i = 0; i < num; i++) \ sc1(arr[i]); #define forIn1(arr, num) \ for (ll i = 1; i <= num; i++) \ sc1(arr[i]); #define vpnt(ans) \ for (ll i = 0; i < ans.size(); i++) \ cout << ans[i] << (i + 1 < ans.size() ? ' ' : '\n'); #define apnt(arr, num) \ for (ll i = 0; i < num; i++) \ cout << arr[i] << (i + 1 < num ? ' ' : '\n'); /*** Define Values ***/ #define PI acos(-1.0) #define eps 1e-7 #define size1 15 /*** STLs ***/ #define cu continue #define br break #define rsz resize #define ins insert #define ft front #define bk back #define eb emplace_back #define lb lower_bound #define ub upper_bound #define pb push_back #define ff first #define ss second #define mp make_pair #define mem(name, value) memset(name, value, sizeof(name)) #define MN3(n1, n2, n3) min(n1, min(n2, n3)) #define MN4(n1, n2, n3, n4) min(n1, min(n2, min(n3, n4))) #define MX3(n1, n2, n3) max(n1, max(n2, n3)) #define MX4(n1, n2, n3, n4) max(n1, max(n2, max(n3, n4))) #define mxar(a, n) *max_element(a, a + n) #define mnar(a, n) *min_element(a, a + n) #define arr_sm(a, n) accumulate(a, a + n, 0) #define vc_sm(ve) accumulate(ve.begin(), ve.end(), 0) #define mx_vc(ve) *max_element(ve.begin(), ve.end()) #define mn_vc(ve) *min_element(ve.begin(), ve.end()) // #define endl " \n" /*** STLs ***/ typedef vector<ll> vll; #define vvll vector<vll> typedef set<ll> sll; typedef multiset<ll> msll; // typedef multimap <ll> mpll; typedef queue<ll> qll; typedef map<ll, ll> mll; typedef pair<ll, ll> pll; typedef vector<pair<ll, ll>> vpll; typedef priority_queue<pair<ll, ll>> pqpll; #define maxpq priority_queue<int> #define minpq priority_queue<int, vector<int>, greater<int>> #define ml unordered_map<ll, ll> /// typedef unordered_multiset<int> umsi; typedef unordered_set<ll> us; /// vector<vector<int>> v(10, vector<int>(20,500)); 2d vector initialization. of /// 10 rows and 20 columns, with value 500. /*** Sorts ***/ #define czero(n) \ __builtin_popcountll( \ n) // count the number of 1's in the bit representation of a number #define cenzero(n) \ __builtin_ctzll(n) // count the number of zereos from the end of the bit // representation of a number until a 1 #define countbegzero(n) __builtin_clzxll(n) #define checkparity(n) \ __builtin_parityll(n) // checks whether the number of bits are even or odd #define all(v) (v).begin(), (v).end() #define rev(v) reverse(all(v)) #define srt(v) sort(all(v)) #define srtgrt(v) sort(all(v), greater<ll>()) #define prsrt greater<pair<int, int>>() /*** Some Prints ***/ #define ip(n) \ ll n; \ cin >> n; #define ipp(n, k) \ ll n; \ cin >> n; \ ll k; \ cin >> k; #define ip3(n, m, k) \ ll n; \ cin >> n; \ ll m; \ cin >> m; \ ll k; \ cin >> k; #define kl '\n' #define no cout << "NO" << '\n' #define yes cout << "YES" << '\n' #define case cout << "Case " << t++ << ": "; // #define ps(x,y) fixed<<setprecision(y)<<x #define inf 1e18 #define dbg(x) cout << '>' << #x << ':' << x << kl; #define trc(x) cerr << #x << ": " << x << kl #define trc2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << kl #define trc3(x, y, z) \ cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \ << z << kl #define trc4(a, b, c, d) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << kl #define trc5(a, b, c, d, e) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << kl #define trc6(a, b, c, d, e, f) \ cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \ << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \ << #f << ": " << f << kl #define w(x) \ ll x; \ cin >> x; \ while (x--) #define go(i, a) for (auto &i : a) #define go1(it, v) for (auto it = v.begin(); it != v.end(); ++it) #define mk(arr, n, type) type *arr = new type[n]; #define sz(obj) (int(obj.size())) #define ipve(vc, n) \ vll vc(n); \ ff1(i, 0, n) { cin >> vc[i]; } #define ipvc(vc, n) \ vll vc; \ ff1(i, 0, n) { \ ip(x); \ vc.pb(x); \ } #define depressed() \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL) // bool ans = all_of(arr, arr + 6, [](int x) {return x & 1; } ); const double pi = 3.141592653589793238460; bool isptsquare(long double x) { long double sr = sqrt(x); return ((sr - floor(sr)) == 0); } ll facts(ll n, ll mod) { ll prod = 1; for (ll i = 1; i <= n; i++) { prod = (prod * i) % mod; } return prod; } ll binpow(ll a, ll b, ll mod) { ll ans = 1; while (b) { if (b & 1) ans *= a; a *= a; ans %= mod; a %= mod; b /= 2; } return ans; } ll mod = 1e9 + 7; vector<ll> factors(ll n) { // returns all factors of a given number ll lim = sqrt(n); vector<ll> f; for (int i = 1; i <= lim; i++) { if (n % i == 0) { f.push_back(i); f.push_back(n / i); if (i * i == n) { f.pop_back(); } } } return f; } ll ceilAB(ll a, ll b) { return (a + b - 1) / b; } ll bigmod(ll n, ll pow) { if (pow == 0) return 1; if (pow == 1) return n % mod; ll ans = bigmod(n, pow / 2); ans = (ans * ans) % mod; if (pow % 2 == 1) { ans = (ans * n) % mod; } return ans % mod; } const int mxn = 1e3; ll fact[mxn + 1]; void calcfac(ll n, ll mod = 2e18) { fact[0] = 1; for (int i = 1; i <= n; ++i) { fact[i] = fact[i - 1] * i; fact[i] %= mod; } } ll nCr(ll p, ll q, ll mod = 2e18) { ll val = fact[p]; ll invfact = fact[q] * fact[p - q]; val %= mod; invfact %= mod; val *= binpow(invfact, mod - 2, mod); return val % mod; } ll nPr(ll p, ll q, ll mod = 2e18) { ll val = nCr(p, q, mod); val *= fact[q]; val %= mod; return val; } bool isprime(ll n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } ll power(ll x, ll y) { ll temp; if (y == 0) return 1; temp = power(x, y / 2); if (y % 2 == 0) return temp * temp; else { if (y > 0) return (x * temp * temp); else return ((temp * temp) / x); } } // ll pmod(ll a,ll b){ll res=1;a%=mod;assert(b>=0);for(; b; // b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll expo(ll x, ll y){ ll // res = 1; x = x % mod; while (y > 0) { if (y & 1)res = (res*x) % mod; y = // y>>1;x = (x*x) % mod;}return res;} void matmul(ll a[][2], ll b[][2]) { ll // tmp[2][2]; for(int i=0; i<2; i++) { for(int j=0; j<2; j++) { tmp[i][j] = 0; // for(int k=0; k<2; k++) tmp[i][j] = (tmp[i][j] + a[i][k]*b[k][j]) % mod; }} // for(int i=0; i<2; i++) for(int j=0; j<2; j++) a[i][j] = tmp[i][j]; } ll // fibo(int n) // returns nth fibonacci number, also S(n) = f(n+2)-1 { if(n //== 0) return 0; else if(n == 1) return 1; ll T[2][2] = { {0, 1} , {1, 1} }; ll //res[2][2] = { {1, 0}, {0,1} }; n--; while(n) { if(n & 1) matmul(res, T); n >>= //1; matmul(T, T); } return res[1][1]; } ll cbtr(ll n, ll m) { ll sm = 1; ff1(i, 1, m + 1) { sm *= (n - i + 1); sm /= i; } return sm; } // string a="cdefghijklmnopqrstuvwxyz"; ld f(ld n) { ld sm = 1; ff1(i, 1, n + 1) { sm *= i; } return sm; } ld pc(ld n, ld k) { ld sm = f(n) / f(n - k); return sm; } vll prime; void seive(ll n) { prime.resize(n + 1, 1); iota(prime.begin(), prime.end(), 0); prime[0] = 0, prime[1] = 1; for (int i = 2; i * i <= n; i++) if (prime[i] == i) for (int j = i * i; j <= n; j += i) prime[j] = i; } map<ll, ll> prime_factor(ll n) { map<ll, ll> ret; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } bool p2(ll n) { if (n == 0) return false; return (ceil(log2(n)) == floor(log2(n))); } #define cer \ cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC \ << "ms\n"; #define ps(x, y) fixed << setprecision(y) << x ll modInverse(ll n, ll m) { return binpow(n, m - 2, m); } bool cmp(pll a, pll b) { if (a.ss == b.ss) { return a.ff > b.ff; } return a.ff > b.ff; } void fun() { ip(n); ipvc(a, n); vll b, c; ff1(i, 0, n - 1) { if (a[i + 1] > a[i]) { c.pb(a[i]); c.pb(a[i + 1]); } } ll sm = 1000; // go(i,c) cout<<i<<kl; ff1(i, 0, sz(c)) { ll k = sm / c[i]; sm -= k * c[i]; sm += k * c[i + 1]; i++; } cout << sm; } int main() { depressed(); ll t = 1; // cin>>t; while (t--) { fun(); } // cer; return 0; }
replace
371
372
371
372
0
p02603
C++
Time Limit Exceeded
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <vector> using namespace std; int main() { int N; cin >> N; vector<int> A(N, 0); for (int i = 0; i < N; i++) cin >> A[i]; long long int money = 1000, stock = 0; A.push_back(0); for (int i = 0; i < N; i++) { if (A[i] == A[i + 1]) continue; if (A[i] < A[i + 1]) { while (money >= A[i]) { money -= A[i]; stock++; } } else if (A[i] > A[i + 1]) { money += stock * A[i]; stock = 0; } } cout << money << endl; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <vector> using namespace std; int main() { int N; cin >> N; vector<int> A(N, 0); for (int i = 0; i < N; i++) cin >> A[i]; long long int money = 1000, stock = 0; A.push_back(0); for (int i = 0; i < N; i++) { if (A[i] == A[i + 1]) continue; if (A[i] < A[i + 1]) { long long int tmp = money / A[i]; money -= A[i] * tmp; stock += tmp; } else if (A[i] > A[i + 1]) { money += stock * A[i]; stock = 0; } } cout << money << endl; }
replace
18
22
18
21
TLE
p02603
C++
Time Limit Exceeded
#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() #define mod 1000000007 typedef long long ll; int main() { ll money = 1000; ll kabu = 0; ll n; cin >> n; vector<ll> vec(n); rep(i, n) cin >> vec[i]; bool up = false; rep(i, n - 1) { bool cup; if (vec[i + 1] > vec[i]) cup = true; else if (vec[i + 1] < vec[i]) cup = false; else continue; if (up && cup) continue; else if (!up && cup) { while (money - vec[i] >= 0) { money -= vec[i]; kabu++; } } else if (up && !cup) { money += kabu * vec[i]; kabu = 0; } else continue; up = cup; } if (up) money += kabu * vec.back(); cout << money << endl; return 0; }
#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() #define mod 1000000007 typedef long long ll; int main() { ll money = 1000; ll kabu = 0; ll n; cin >> n; vector<ll> vec(n); rep(i, n) cin >> vec[i]; bool up = false; rep(i, n - 1) { bool cup; if (vec[i + 1] > vec[i]) cup = true; else if (vec[i + 1] < vec[i]) cup = false; else continue; if (up && cup) continue; else if (!up && cup) { kabu = money / vec[i]; money %= vec[i]; } else if (up && !cup) { money += kabu * vec[i]; kabu = 0; } else continue; up = cup; } if (up) money += kabu * vec.back(); cout << money << endl; return 0; }
replace
28
32
28
30
TLE
p02603
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; const int mod = 1000000007; const double PI = acos(-1); int main() { ll n; cin >> n; vector<ll> a(n); for (ll i = 0; i < n; i++) cin >> a[i]; ll money = 1000; ll stock = 0; for (ll i = 0; i < n; i++) { money += a[i] * stock; stock = 0; if (i != n - 1) { if (a[i] < a[i + 1]) { while (0 <= money - a[i]) { money -= a[i]; stock++; } } } } cout << money << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int mod = 1000000007; const double PI = acos(-1); int main() { ll n; cin >> n; vector<ll> a(n); for (ll i = 0; i < n; i++) cin >> a[i]; ll money = 1000; ll stock = 0; for (ll i = 0; i < n; i++) { money += a[i] * stock; stock = 0; if (i != n - 1) { if (a[i] < a[i + 1]) { stock = money / a[i]; money = money % a[i]; } } } cout << money << endl; }
replace
20
24
20
22
TLE
p02603
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long int #define mod 1000000007 #define pi 3.14159265358979323846264338327950288419716939937510 #define setbit(x) __builtin_popcountll(x) #define db long double #define pp(x) pair<x, x> #define ff first #define ss second #define FIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define tc \ ll tc; \ cin >> tc; \ for (ll number = 1; number <= tc; number++) #define vv(x) vector<x> #define pb push_back #define pob pop_back #define pf push_front #define pof pop_front #define endl "\n" #define pq priority_queue #define dbg(x) \ { cout << #x << ": " << (x) << endl; } #define dbg2(x, y) \ { cout << #x << ": " << (x) << " , " << #y << ": " << (y) << endl; } #define bp \ ll kkk; \ cin >> kkk; #define dbgArr(a, n) \ cout << "Array " << #a << endl; \ for (ll i = 0; i < n; i++) \ cout << a[i] << " "; \ cout << endl; #define maxE(a, n) *max_element(a, a + n); #define minE(a, n) *min_element(a, a + n); #define forn(i, s, n) for (ll i = s; i < n; i++) #define fornr(i, e, s) for (ll i = e - 1; i >= s; i--) #define arr(a, n) \ for (ll i = 0; i < n; i++) { \ cin >> a[i]; \ } #define arr1(a, n) \ for (ll i = 1; i <= n; i++) { \ cin >> a[i]; \ } #define file \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout) #define print cout << "Case #" << number << ": " #define all(x) x.begin(), x.end() ll power(ll x, ll b, ll m) { ll p = 1; while (b > 0) { if (b & 1) { p = p * x; p %= m; } b >>= 1; x *= x; x %= m; } return p % m; } using namespace std; #define INF 1e15 struct lex_compare { bool operator()(pp(ll) p1, pp(ll) p2) { return p1.ff >= p2.ff; } }; map<pair<ll, pp(ll)>, ll> dp; ll n; ll rec(ll i, ll money, ll arr[], ll stocksleft) { if (i == n) { return money; } if (dp.count({i, {money, stocksleft}}) != 0) return dp[{i, {money, stocksleft}}]; ll ans = 0; for (ll j = 0; j <= stocksleft; j++) { ans = max(ans, rec(i + 1, money + arr[i] * j, arr, stocksleft - j)); } ll maxbuy = (money / arr[i]); for (ll j = 1; j <= maxbuy; j++) { ans = max(ans, rec(i + 1, money - j * arr[i], arr, stocksleft + j)); } return dp[{i, {money, stocksleft}}] = ans; } int main() { FIO; cin >> n; ll arr[n]; forn(i, 0, n) cin >> arr[i]; // memset(dp,-1,sizeof(dp)); ll currp = 1000; ll ans = rec(0, 1000, arr, 0); cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define ll long long int #define mod 1000000007 #define pi 3.14159265358979323846264338327950288419716939937510 #define setbit(x) __builtin_popcountll(x) #define db long double #define pp(x) pair<x, x> #define ff first #define ss second #define FIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); #define tc \ ll tc; \ cin >> tc; \ for (ll number = 1; number <= tc; number++) #define vv(x) vector<x> #define pb push_back #define pob pop_back #define pf push_front #define pof pop_front #define endl "\n" #define pq priority_queue #define dbg(x) \ { cout << #x << ": " << (x) << endl; } #define dbg2(x, y) \ { cout << #x << ": " << (x) << " , " << #y << ": " << (y) << endl; } #define bp \ ll kkk; \ cin >> kkk; #define dbgArr(a, n) \ cout << "Array " << #a << endl; \ for (ll i = 0; i < n; i++) \ cout << a[i] << " "; \ cout << endl; #define maxE(a, n) *max_element(a, a + n); #define minE(a, n) *min_element(a, a + n); #define forn(i, s, n) for (ll i = s; i < n; i++) #define fornr(i, e, s) for (ll i = e - 1; i >= s; i--) #define arr(a, n) \ for (ll i = 0; i < n; i++) { \ cin >> a[i]; \ } #define arr1(a, n) \ for (ll i = 1; i <= n; i++) { \ cin >> a[i]; \ } #define file \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout) #define print cout << "Case #" << number << ": " #define all(x) x.begin(), x.end() ll power(ll x, ll b, ll m) { ll p = 1; while (b > 0) { if (b & 1) { p = p * x; p %= m; } b >>= 1; x *= x; x %= m; } return p % m; } using namespace std; #define INF 1e15 struct lex_compare { bool operator()(pp(ll) p1, pp(ll) p2) { return p1.ff >= p2.ff; } }; map<pair<ll, pp(ll)>, ll> dp; ll n; ll rec(ll i, ll money, ll arr[], ll stocksleft) { if (i == n) { return money; } if (dp.count({i, {money, stocksleft}}) != 0) return dp[{i, {money, stocksleft}}]; ll ans = 0; for (ll j = 0; j <= stocksleft; j++) { ans = max(ans, rec(i + 1, money + arr[i] * j, arr, stocksleft - j)); } ll maxbuy = (money / arr[i]); for (ll j = 1; j <= maxbuy; j++) { ans = max(ans, rec(i + 1, money - j * arr[i], arr, stocksleft + j)); } return dp[{i, {money, stocksleft}}] = ans; } int main() { FIO; cin >> n; ll arr[n]; forn(i, 0, n) cin >> arr[i]; // memset(dp,-1,sizeof(dp)); ll currp = 1000; // ll ans = rec(0,1000,arr,0); ll ans = 1000; ll minc = INT_MAX; ll amount = 1000; ll stocks = 0; set<ll> s; ll i = 0; while (i < n) { ll j = i + 1; while (j < n && arr[j] >= arr[j - 1]) { j++; } j--; ll stocks = (amount / arr[i]); amount = (amount - stocks * arr[i]); amount += (stocks * arr[j]); i = j + 1; // dbg2(i,amount); // dbg(stocks); } cout << amount << endl; return 0; }
replace
97
99
97
118
TLE
p02603
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) #define rep2(i, s, n) for (long long i = (s); i < (long long)(n); i++) #define repi(i, n) for (int i = 0; i < (int)(n); i++) #define rep2i(i, s, n) for (int i = (s); i < (int)(n); i++) #define all(v) v.begin(), v.end() #define deg2rad(deg) (((deg) / 360) * 2 * M_PI) #define rad2deg(rad) (((rad) / 2 / M_PI) * 360) using ll = long long; using ld = long double; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<ll, ll>; using vi = vector<int>; using vvi = vector<vi>; const ll INF = (1LL << 60); const int INFi = (1 << 29); /*素数判定*/ bool is_prime(ll n) { if (n == 1) return false; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } /*約数列挙*/ vll enum_divisors(ll n) { vll l; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { l.push_back(i); if (n / i != i) l.push_back(n / i); } } sort(all(l)); return l; } /*素因数分解*/ vector<P> prime_factorize(ll n) { vector<P> l; for (ll i = 2; i * i <= n; i++) { if (n % i != 0) continue; ll e = 0; while (n % i == 0) { e++; n /= i; } l.push_back({i, e}); } if (n != 1) l.push_back({n, 1}); return l; } /*最小公倍数*/ ll lcm(ll a, ll b) { return a * b / __gcd(a, b); } /*最大公約数*/ ll gcd(ll a, ll b) { return __gcd(a, b); } /*組み合わせ(Combination)*/ const ll CMAX = 1010000; const ll CMOD = 1e9 + 7; ll fac[CMAX], finv[CMAX], inv[CMAX]; // テーブルを作る前処理 void combinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < CMAX; i++) { fac[i] = fac[i - 1] * i % CMOD; inv[i] = CMOD - inv[CMOD % i] * (CMOD / i) % CMOD; finv[i] = finv[i - 1] * inv[i] % CMOD; } } // 二項係数計算 ll comb(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD; } int main() { ll n; cin >> n; vll a(n); rep(i, n) cin >> a[i]; vll b(n, 0); rep2(i, 1, n) { if (a[i] > a[i - 1]) { b[i] = 1; } else if (a[i] < a[i - 1]) { b[i] = -1; } } ll ans = 1000; ll kabu = 0; rep(i, n - 1) { if (b[i] < b[i + 1]) { while (a[i] <= ans) { kabu++; ans -= a[i]; } } else if (b[i] > b[i + 1]) { ans += kabu * a[i]; kabu = 0; } } if (kabu) { ans += kabu * a[n - 1]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (long long i = 0; i < (long long)(n); i++) #define rep2(i, s, n) for (long long i = (s); i < (long long)(n); i++) #define repi(i, n) for (int i = 0; i < (int)(n); i++) #define rep2i(i, s, n) for (int i = (s); i < (int)(n); i++) #define all(v) v.begin(), v.end() #define deg2rad(deg) (((deg) / 360) * 2 * M_PI) #define rad2deg(rad) (((rad) / 2 / M_PI) * 360) using ll = long long; using ld = long double; using vll = vector<ll>; using vvll = vector<vll>; using P = pair<ll, ll>; using vi = vector<int>; using vvi = vector<vi>; const ll INF = (1LL << 60); const int INFi = (1 << 29); /*素数判定*/ bool is_prime(ll n) { if (n == 1) return false; for (ll i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } /*約数列挙*/ vll enum_divisors(ll n) { vll l; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { l.push_back(i); if (n / i != i) l.push_back(n / i); } } sort(all(l)); return l; } /*素因数分解*/ vector<P> prime_factorize(ll n) { vector<P> l; for (ll i = 2; i * i <= n; i++) { if (n % i != 0) continue; ll e = 0; while (n % i == 0) { e++; n /= i; } l.push_back({i, e}); } if (n != 1) l.push_back({n, 1}); return l; } /*最小公倍数*/ ll lcm(ll a, ll b) { return a * b / __gcd(a, b); } /*最大公約数*/ ll gcd(ll a, ll b) { return __gcd(a, b); } /*組み合わせ(Combination)*/ const ll CMAX = 1010000; const ll CMOD = 1e9 + 7; ll fac[CMAX], finv[CMAX], inv[CMAX]; // テーブルを作る前処理 void combinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < CMAX; i++) { fac[i] = fac[i - 1] * i % CMOD; inv[i] = CMOD - inv[CMOD % i] * (CMOD / i) % CMOD; finv[i] = finv[i - 1] * inv[i] % CMOD; } } // 二項係数計算 ll comb(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % CMOD) % CMOD; } int main() { ll n; cin >> n; vll a(n); rep(i, n) cin >> a[i]; vll b(n, 0); rep2(i, 1, n) { if (a[i] > a[i - 1]) { b[i] = 1; } else if (a[i] < a[i - 1]) { b[i] = -1; } } ll ans = 1000; ll kabu = 0; rep(i, n - 1) { if (b[i] < b[i + 1]) { if (a[i] <= ans) { kabu = ans / a[i]; ans -= kabu * a[i]; } } else if (b[i] > b[i + 1]) { ans += kabu * a[i]; kabu = 0; } } if (kabu) { ans += kabu * a[n - 1]; } cout << ans << endl; return 0; }
replace
116
119
116
119
TLE
p02603
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define MOD (long long)(1e9 + 7) #define INF (1LL << 60) #define rep(i, n) for (ll i = 0; i < (n); i++) #define rep1(i, n) for (ll i = 1; i <= (n); i++) template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } // 最大公約数 ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } // mod m におけるa の逆元 ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } // 素因数分解 vector<pair<ll, ll>> prim; void pf(ll n) { ll s = sqrt(n); ll r = 0; for (ll i = 2; i <= s; i++) { if ((n % i) == 0) { r = 0; do { r++; n = n / i; } while ((n % i) == 0); prim.push_back({i, r}); } } if (n > s) { prim.push_back({n, 1}); } } void solve() { ll N; cin >> N; // ll N, K; cin >> N >> K; // ll x, y, z; cin >> x >> y >> z; // ll a, b, c; cin >> a >> b >> c; // string s; cin >> s; vector<ll> a(N); rep(i, N) cin >> a[i]; ll ans = 1000; ll kabu = 0; ll day = 0; while (day < N - 1) { if (a[day] < a[day + 1]) { kabu = ans / a[day]; ans = ans % a[day]; day++; while (day < N - 1 && a[day] <= a[day + 1]) { day++; } } else if (a[day] > a[day + 1]) { ans += kabu * a[day]; kabu = 0; day++; while (day < N - 1 && a[day] >= a[day + 1]) { day++; } } } ans += kabu * a[N - 1]; cout << ans << endl; } int main(void) { // ll t; cin >> t; rep(i, t) solve(); }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define MOD (long long)(1e9 + 7) #define INF (1LL << 60) #define rep(i, n) for (ll i = 0; i < (n); i++) #define rep1(i, n) for (ll i = 1; i <= (n); i++) template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } // 最大公約数 ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } // mod m におけるa の逆元 ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } // 素因数分解 vector<pair<ll, ll>> prim; void pf(ll n) { ll s = sqrt(n); ll r = 0; for (ll i = 2; i <= s; i++) { if ((n % i) == 0) { r = 0; do { r++; n = n / i; } while ((n % i) == 0); prim.push_back({i, r}); } } if (n > s) { prim.push_back({n, 1}); } } void solve() { ll N; cin >> N; // ll N, K; cin >> N >> K; // ll x, y, z; cin >> x >> y >> z; // ll a, b, c; cin >> a >> b >> c; // string s; cin >> s; vector<ll> a(N); rep(i, N) cin >> a[i]; ll ans = 1000; ll kabu = 0; ll day = 0; while (day < N - 1) { if (a[day] < a[day + 1]) { kabu = ans / a[day]; ans = ans % a[day]; day++; while (day < N - 1 && a[day] <= a[day + 1]) { day++; } } else if (a[day] > a[day + 1]) { ans += kabu * a[day]; kabu = 0; day++; while (day < N - 1 && a[day] >= a[day + 1]) { day++; } } else { day++; } } ans += kabu * a[N - 1]; cout << ans << endl; } int main(void) { // ll t; cin >> t; rep(i, t) solve(); }
insert
99
99
99
101
TLE
p02603
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n, a[87] = {0}; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; ll money = 1000; ll cnt = 0; for (int i = 0; i < n; i++) { if (a[i] < a[i + 1]) { cnt += money / a[i]; while (money >= a[i]) money -= a[i]; } else { money += cnt * a[i]; cnt = 0; } } cout << money << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n, a[87] = {0}; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; ll money = 1000; ll cnt = 0; for (int i = 0; i < n; i++) { if (a[i] < a[i + 1]) { cnt += money / a[i]; ll num = money / a[i]; money -= a[i] * num; } else { money += cnt * a[i]; cnt = 0; } } cout << money << endl; }
replace
14
16
14
16
TLE
p02603
C++
Time Limit Exceeded
#include <algorithm> //sort,二分探索,など #include <bitset> //固定長bit集合 #include <cmath> //pow,logなど #include <complex> //複素数 #include <deque> //両端アクセスのキュー #include <functional> //sortのgreater #include <iomanip> //setprecision(浮動小数点の出力の誤差) #include <iostream> //入出力 #include <iterator> //集合演算(積集合,和集合,差集合など) #include <map> //map(辞書) #include <numeric> //iota(整数列の生成),gcdとlcm(c++17) #include <queue> //キュー #include <set> //集合 #include <stack> //スタック #include <string> //文字列 #include <unordered_map> //イテレータあるけど順序保持しないmap #include <unordered_set> //イテレータあるけど順序保持しないset #include <utility> //pair #include <vector> //可変長配列 using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<vector<int>> vvi; typedef vector<vector<ll>> vvll; typedef vector<vector<string>> vvs; typedef vector<vector<bool>> vvb; const ll MOD = 1000000007; const ll INF = 1000000000000000000; #define rep(i, n) for (int i = 0; i < n; i++) #define repl(i, s, e) for (int i = s; i < e; i++) #define reple(i, s, e) for (int i = s; i <= e; i++) #define revrep(i, n) for (int i = n - 1; i >= 0; i--) #define all(x) (x).begin(), (x).end() template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vll A; rep(i, N) { ll a; cin >> a; if (A.empty() || a != A.back()) A.push_back(a); } ll money = 1000; ll stock = 0; set<int> us, ls; us.insert(A.size() - 1); reple(i, 1, A.size() - 2) { if (A[i] > A[i - 1] && A[i] > A[i + 1]) { us.insert(i); } else if (A[i] < A[i - 1] && A[i] < A[i + 1]) { ls.insert(i); } } bool flg = false; rep(i, A.size()) { if (us.count(i) == 1) { if (!flg) { stock += money / A[0]; money %= A[0]; flg = true; } money += A[i] * stock; stock = 0; } else if (ls.count(i) == 1) { auto itr = us.upper_bound(i); if (itr != us.end()) { stock += money / A[i]; money %= A[i]; flg = true; } } } cout << max(money, 1000LL) << endl; return 0; }
#include <algorithm> //sort,二分探索,など #include <bitset> //固定長bit集合 #include <cmath> //pow,logなど #include <complex> //複素数 #include <deque> //両端アクセスのキュー #include <functional> //sortのgreater #include <iomanip> //setprecision(浮動小数点の出力の誤差) #include <iostream> //入出力 #include <iterator> //集合演算(積集合,和集合,差集合など) #include <map> //map(辞書) #include <numeric> //iota(整数列の生成),gcdとlcm(c++17) #include <queue> //キュー #include <set> //集合 #include <stack> //スタック #include <string> //文字列 #include <unordered_map> //イテレータあるけど順序保持しないmap #include <unordered_set> //イテレータあるけど順序保持しないset #include <utility> //pair #include <vector> //可変長配列 using namespace std; typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<vector<int>> vvi; typedef vector<vector<ll>> vvll; typedef vector<vector<string>> vvs; typedef vector<vector<bool>> vvb; const ll MOD = 1000000007; const ll INF = 1000000000000000000; #define rep(i, n) for (int i = 0; i < n; i++) #define repl(i, s, e) for (int i = s; i < e; i++) #define reple(i, s, e) for (int i = s; i <= e; i++) #define revrep(i, n) for (int i = n - 1; i >= 0; i--) #define all(x) (x).begin(), (x).end() template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vll A; rep(i, N) { ll a; cin >> a; if (A.empty() || a != A.back()) A.push_back(a); } if (A.size() <= 1) { cout << 1000 << endl; return 0; } ll money = 1000; ll stock = 0; set<int> us, ls; us.insert(A.size() - 1); reple(i, 1, A.size() - 2) { if (A[i] > A[i - 1] && A[i] > A[i + 1]) { us.insert(i); } else if (A[i] < A[i - 1] && A[i] < A[i + 1]) { ls.insert(i); } } bool flg = false; rep(i, A.size()) { if (us.count(i) == 1) { if (!flg) { stock += money / A[0]; money %= A[0]; flg = true; } money += A[i] * stock; stock = 0; } else if (ls.count(i) == 1) { auto itr = us.upper_bound(i); if (itr != us.end()) { stock += money / A[i]; money %= A[i]; flg = true; } } } cout << max(money, 1000LL) << endl; return 0; }
insert
71
71
71
76
TLE
p02603
Python
Time Limit Exceeded
n = int(input()) A = list(map(int, input().split())) ans = 1000 for ii in range(2**n): tmp = 1000 kab = 0 action = "buy" for i in range(n): if (ii >> i) & 1: if action == "buy": if tmp < A[i]: break kab += tmp // A[i] tmp = tmp % A[i] action = "sell" elif action == "sell": if kab == 0: break tmp += kab * A[i] kab = 0 action = "buy" else: ans = max(ans, tmp) print(ans)
n = int(input()) A = list(map(int, input().split())) ans = 1000 for i in range(n - 1): if A[i] < A[i + 1]: ans += ans // A[i] * (A[i + 1] - A[i]) print(ans)
replace
3
25
3
6
TLE
p02603
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <chrono> #include <cmath> #include <cstdint> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define N_TIMES(i, n) for (uint64_t i = 0; i < n; ++i) #define N_TIMES_REV(i, n) for (int64_t i = n - 1; i >= 0; --i) template <typename T> using maximum_heap = std::priority_queue<T, std::vector<T>, std::less<T>>; template <typename T> using minimum_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>; template <typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (typename std::vector<T>::size_type i = 0; i < v.size(); ++i) { is >> v[i]; } return is; } using namespace std; struct DPItem { uint64_t money, stock, price; DPItem(uint64_t money, uint64_t stock, uint64_t price) : money(money), stock(stock), price(price) {} uint64_t operator()() const { return money + stock * price; } bool operator<(const DPItem &rhs) const { return (*this)() < rhs(); } bool operator>(const DPItem &rhs) const { return (*this)() > rhs(); } }; const uint64_t M = 1e+6; int main() { uint64_t N; cin >> N; vector<uint64_t> A(N); cin >> A; vector<maximum_heap<DPItem>> dp(N + 1); dp[0].emplace(1000, 0, 0); N_TIMES(n, N) { uint64_t cnt = 0; while (!dp[n].empty() && cnt < M) { DPItem item = dp[n].top(); dp[n].pop(); // 何もしない dp[n + 1].push(item); ++cnt; // 全株売却 if (item.stock > 0 && item.price < A[n]) { if ((n == N - 1) || (n < N - 1 && A[n] > A[n + 1])) { dp[n + 1].emplace(item.money + item.stock * A[n], 0, 0); ++cnt; } } // 最大購入 uint64_t c = item.money / A[n]; if (item.stock == 0 && c > 0) { if ((n == N - 1) || (n < N - 1 && A[n] < A[n + 1])) { dp[n + 1].emplace(item.money % A[n], item.stock + c, A[n]); ++cnt; } } } } uint64_t max_money = 0; while (!dp[N].empty()) { DPItem item = dp[N].top(); dp[N].pop(); max_money = max(max_money, item()); } cout << max_money << endl; return 0; }
#include <algorithm> #include <bitset> #include <chrono> #include <cmath> #include <cstdint> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define N_TIMES(i, n) for (uint64_t i = 0; i < n; ++i) #define N_TIMES_REV(i, n) for (int64_t i = n - 1; i >= 0; --i) template <typename T> using maximum_heap = std::priority_queue<T, std::vector<T>, std::less<T>>; template <typename T> using minimum_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>; template <typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (typename std::vector<T>::size_type i = 0; i < v.size(); ++i) { is >> v[i]; } return is; } using namespace std; struct DPItem { uint64_t money, stock, price; DPItem(uint64_t money, uint64_t stock, uint64_t price) : money(money), stock(stock), price(price) {} uint64_t operator()() const { return money + stock * price; } bool operator<(const DPItem &rhs) const { return (*this)() < rhs(); } bool operator>(const DPItem &rhs) const { return (*this)() > rhs(); } }; const uint64_t M = 1e+5; int main() { uint64_t N; cin >> N; vector<uint64_t> A(N); cin >> A; vector<maximum_heap<DPItem>> dp(N + 1); dp[0].emplace(1000, 0, 0); N_TIMES(n, N) { uint64_t cnt = 0; while (!dp[n].empty() && cnt < M) { DPItem item = dp[n].top(); dp[n].pop(); // 何もしない dp[n + 1].push(item); ++cnt; // 全株売却 if (item.stock > 0 && item.price < A[n]) { if ((n == N - 1) || (n < N - 1 && A[n] > A[n + 1])) { dp[n + 1].emplace(item.money + item.stock * A[n], 0, 0); ++cnt; } } // 最大購入 uint64_t c = item.money / A[n]; if (item.stock == 0 && c > 0) { if ((n == N - 1) || (n < N - 1 && A[n] < A[n + 1])) { dp[n + 1].emplace(item.money % A[n], item.stock + c, A[n]); ++cnt; } } } } uint64_t max_money = 0; while (!dp[N].empty()) { DPItem item = dp[N].top(); dp[N].pop(); max_money = max(max_money, item()); } cout << max_money << endl; return 0; }
replace
47
48
47
48
TLE
p02603
C++
Runtime Error
#include <algorithm> #include <iomanip> // std::setprecision() #include <iostream> #include <map> #include <math.h> #include <queue> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; #define rep(i, a, b) for (ll i = (a); i < (b); i++) #define YES cout << "YES" << endl; #define NO cout << "NO" << endl; #define yes cout << "Yes" << endl; #define no cout << "No" << endl; #define pai 3.14159265358979323846 ll gcd(ll a, ll b) { if (a % b == 0) return (b); else return (gcd(b, a % b)); } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } /* map<string,int> */ /* 大文字を小文字に変換 tolower*/ /* 小文字を大文字に変換 toupper*/ /* 辞書順 next_permutation(a.begin(),a.end()) */ int main() { ll n; cin >> n; vector<ll> a(n); rep(i, 1, n + 1) { cin >> a[i]; } vector<ll> dp(n + 1); dp[1] = 1000; rep(i, 2, n + 1) { dp[i] = dp[i - 1]; rep(j, 1, i) { ll c = dp[j] / a[j]; ll m = dp[j] + (a[i] - a[j]) * c; dp[i] = max(dp[i], m); } } cout << dp[n] << endl; ; return 0; }
#include <algorithm> #include <iomanip> // std::setprecision() #include <iostream> #include <map> #include <math.h> #include <queue> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long; #define rep(i, a, b) for (ll i = (a); i < (b); i++) #define YES cout << "YES" << endl; #define NO cout << "NO" << endl; #define yes cout << "Yes" << endl; #define no cout << "No" << endl; #define pai 3.14159265358979323846 ll gcd(ll a, ll b) { if (a % b == 0) return (b); else return (gcd(b, a % b)); } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } /* map<string,int> */ /* 大文字を小文字に変換 tolower*/ /* 小文字を大文字に変換 toupper*/ /* 辞書順 next_permutation(a.begin(),a.end()) */ int main() { ll n; cin >> n; vector<ll> a(n + 1); rep(i, 1, n + 1) { cin >> a[i]; } vector<ll> dp(n + 1); dp[1] = 1000; rep(i, 2, n + 1) { dp[i] = dp[i - 1]; rep(j, 1, i) { ll c = dp[j] / a[j]; ll m = dp[j] + (a[i] - a[j]) * c; dp[i] = max(dp[i], m); } } cout << dp[n] << endl; ; return 0; }
replace
32
33
32
33
-6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
p02603
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int64_t> data(n); for (int i = 0; i < n; ++i) { cin >> data[i]; } int fin = 0; for (int i = 0; i < n - 1; ++i) { if (data[i] < data[i + 1]) { fin = i; } } int64_t g = 1000LL; int64_t k = 0LL; for (int i = 0; i < n; ++i) { if (i > fin) { g += (int64_t)data[i] * k; k = 0ll; break; } else if (data[i] < data[i + 1]) { while (g >= data[i]) { g -= data[i]; k++; } // int num = g / data[i]; // g -= num * (int64_t)data[i]; // k += num; } else if (data[i] > data[i + 1]) { g += int64_t(data[i]) * k; k = 0LL; } } cout << g; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int64_t> data(n); for (int i = 0; i < n; ++i) { cin >> data[i]; } int fin = 0; for (int i = 0; i < n - 1; ++i) { if (data[i] < data[i + 1]) { fin = i; } } int64_t g = 1000LL; int64_t k = 0LL; for (int i = 0; i < n; ++i) { if (i > fin) { g += (int64_t)data[i] * k; k = 0ll; break; } else if (data[i] < data[i + 1]) { // while(g >= data[i]) { // g -= data[i]; // k ++; // } int64_t num = g / data[i]; int64_t u = num * (int64_t)data[i]; g -= u; k += num; } else if (data[i] > data[i + 1]) { g += int64_t(data[i]) * k; k = 0LL; } } cout << g; return 0; }
replace
27
34
27
35
TLE
p02603
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define d(x) cerr << #x ":" << x << endl; #define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl #define rep(i, n) for (int i = (int)(0); i < (int)(n); i++) #define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define all(v) v.begin(), v.end() #define dump(v) \ cerr << #v ":[ "; \ for (auto macro_vi : v) { \ cerr << macro_vi << " "; \ } \ cerr << "]" << endl; #define ddump(v) \ cerr << #v ":" << endl; \ for (auto macro_row : v) { \ cerr << "["; \ for (auto macro__vi : macro_row) { \ cerr << macro__vi << " "; \ } \ cerr << "]" << endl; \ } using lint = long long; const int INF = 1e9; const lint LINF = 1e18; const lint MOD = 1e9 + 7; const double EPS = 1e-10; // const int M = 100000; const int M = 20; int main() { int N; cin >> N; vector<lint> A(N, 0); rep(i, N) cin >> A[i]; A.push_back(-1); lint sum = 1000; lint k = 0; for (int i = 0; i < N; i++) { while (A[i + 1] <= A[i]) { continue; } for (int j = i + 1; j < N; j++) { if (A[j] > A[i] and A[j] > A[j + 1]) { k = sum / A[i]; sum -= A[i] * k; sum += k * A[j]; k = 0; i = j; break; } } } cout << sum << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define d(x) cerr << #x ":" << x << endl; #define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl #define rep(i, n) for (int i = (int)(0); i < (int)(n); i++) #define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define all(v) v.begin(), v.end() #define dump(v) \ cerr << #v ":[ "; \ for (auto macro_vi : v) { \ cerr << macro_vi << " "; \ } \ cerr << "]" << endl; #define ddump(v) \ cerr << #v ":" << endl; \ for (auto macro_row : v) { \ cerr << "["; \ for (auto macro__vi : macro_row) { \ cerr << macro__vi << " "; \ } \ cerr << "]" << endl; \ } using lint = long long; const int INF = 1e9; const lint LINF = 1e18; const lint MOD = 1e9 + 7; const double EPS = 1e-10; // const int M = 100000; const int M = 20; int main() { int N; cin >> N; vector<lint> A(N, 0); rep(i, N) cin >> A[i]; A.push_back(-1); lint sum = 1000; lint k = 0; for (int i = 0; i < N; i++) { if (A[i + 1] <= A[i]) { continue; } for (int j = i + 1; j < N; j++) { if (A[j] > A[i] and A[j] > A[j + 1]) { k = sum / A[i]; sum -= A[i] * k; sum += k * A[j]; k = 0; i = j; break; } } } cout << sum << endl; return 0; }
replace
43
44
43
44
TLE
p02603
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { // your code goes here long long n; cin >> n; vector<long long> a; for (int i = 0; i < n; i++) { long long b; cin >> b; a.push_back(b); } long long num = 0; long long money = 1000; decltype(a)::iterator result = std::unique(a.begin(), a.end()); // [v.begin(), result)の範囲に、重複を除いた結果が入っている。 // 不要になった要素を削除 a.erase(result, a.end()); // 折り返し地点を探す string turn[a.size()]; for (int i = 1; i < a.size() - 1; i++) { if (a.at(i - 1) < a.at(i) && a.at(i) > a.at(i + 1)) { turn[i] = "down"; } else if (a.at(i - 1) > a.at(i) && a.at(i) < a.at(i + 1)) { turn[i] = "up"; } else { turn[i] = "keep"; } } if (a.at(0) < a.at(1)) { num += money / a.at(0); money %= a.at(0); } for (int i = 0; i < a.size() - 1; i++) { if (turn[i] == "down") { money += a.at(i) * num; num = 0; } else if (turn[i] == "up") { num += money / a.at(i); money %= a.at(i); } } if (a.at(a.size() - 2) < a.at(a.size() - 1)) { money += a.at(a.size() - 1) * num; num = 0; } cout << money << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { // your code goes here long long n; cin >> n; vector<long long> a; for (int i = 0; i < n; i++) { long long b; cin >> b; a.push_back(b); } long long num = 0; long long money = 1000; decltype(a)::iterator result = std::unique(a.begin(), a.end()); // [v.begin(), result)の範囲に、重複を除いた結果が入っている。 // 不要になった要素を削除 a.erase(result, a.end()); if (a.size() == 1) { cout << money << endl; return 0; } // 折り返し地点を探す string turn[a.size()]; for (int i = 1; i < a.size() - 1; i++) { if (a.at(i - 1) < a.at(i) && a.at(i) > a.at(i + 1)) { turn[i] = "down"; } else if (a.at(i - 1) > a.at(i) && a.at(i) < a.at(i + 1)) { turn[i] = "up"; } else { turn[i] = "keep"; } } if (a.at(0) < a.at(1)) { num += money / a.at(0); money %= a.at(0); } for (int i = 0; i < a.size() - 1; i++) { if (turn[i] == "down") { money += a.at(i) * num; num = 0; } else if (turn[i] == "up") { num += money / a.at(i); money %= a.at(i); } } if (a.at(a.size() - 2) < a.at(a.size() - 1)) { money += a.at(a.size() - 1) * num; num = 0; } cout << money << endl; return 0; }
insert
21
21
21
26
0
p02603
C++
Time Limit Exceeded
// TO KAISE HAI AAP LOG!! // #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define lb lower_bound #define ub upper_bound #define bs binary_search #define F first #define S second #define all(v) v.begin(), v.end() ll mod = 1e9 + 7; /*/----------------------------- Code begins -----------------------------/*/ int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll t = 1, tc; // cin>>t; for (tc = 1; tc <= t; tc++) { ll n, k, i, j, s = 1000, f, m, c, pos; cin >> n; ll a[n + 5]; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n - 1;) { f = 0; m = a[i]; j = i + 1; while (j < n) { if (a[j] > m) { f = 1; pos = j; break; } m = min(a[j], m); j++; } if (f == 0) break; c = 0; while (s - m >= 0) { s -= m; c++; } while (c--) { s += a[pos]; } i = j; } cout << s; } return 0; }
// TO KAISE HAI AAP LOG!! // #include <bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define lb lower_bound #define ub upper_bound #define bs binary_search #define F first #define S second #define all(v) v.begin(), v.end() ll mod = 1e9 + 7; /*/----------------------------- Code begins -----------------------------/*/ int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ll t = 1, tc; // cin>>t; for (tc = 1; tc <= t; tc++) { ll n, k, i, j, s = 1000, f, m, c, pos; cin >> n; ll a[n + 5]; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n - 1;) { f = 0; m = a[i]; j = i + 1; while (j < n) { if (a[j] > m) { f = 1; pos = j; break; } m = min(a[j], m); j++; } if (f == 0) break; c = 0; ll x = (s / m); s = s - (x * m); s = s + (x * a[pos]); i = j; } cout << s; } return 0; }
replace
46
53
46
49
TLE
p02603
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define ll long long #define FAST \ { \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ } #define f(i, a, b) for (ll i = a; i < b; i++) #define fr(i, a, b) for (ll i = a; i >= b; i--) #define pb push_back #define mp make_pair #define F first #define S second #define pll pair<ll, ll> #define LB lower_bound #define UB upper_bound #define endl "\n" using namespace std; int main() { FAST ll mon = 1000, st = 0; ll n; cin >> n; ll a[n]; f(i, 0, n) cin >> a[i]; ll start = 0; while (start < n - 1 && a[start] >= a[start + 1]) start++; if (start == n - 1) { cout << 1000 << endl; return 0; } while (mon - a[start] >= 0) mon -= a[start], st++; ll pos = start + 1; while (1) { while (pos < n - 1 && a[pos] <= a[pos + 1]) pos++; while (st) mon += a[pos], st--; while (pos < n - 1 && a[pos] >= a[pos + 1]) pos++; if (pos != n - 1) { while (mon - a[pos] >= 0) mon -= a[pos], st++; } else if (pos >= n - 1) break; } cout << mon << endl; }
#include <bits/stdc++.h> #define ll long long #define FAST \ { \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ } #define f(i, a, b) for (ll i = a; i < b; i++) #define fr(i, a, b) for (ll i = a; i >= b; i--) #define pb push_back #define mp make_pair #define F first #define S second #define pll pair<ll, ll> #define LB lower_bound #define UB upper_bound #define endl "\n" using namespace std; int main() { FAST ll mon = 1000, st = 0; ll n; cin >> n; ll a[n]; f(i, 0, n) cin >> a[i]; ll start = 0; while (start < n - 1 && a[start] >= a[start + 1]) start++; if (start == n - 1) { cout << 1000 << endl; return 0; } while (mon - a[start] >= 0) mon -= a[start], st++; ll pos = start + 1; while (1) { while (pos < n - 1 && a[pos] <= a[pos + 1]) pos++; while (st) mon += a[pos], st--; while (pos < n - 1 && a[pos] >= a[pos + 1]) pos++; if (pos != n - 1) { st += mon / a[pos]; mon -= st * a[pos]; } else if (pos >= n - 1) break; } cout << mon << endl; }
replace
43
45
43
45
TLE
p02603
C++
Runtime Error
/*input 7 100 130 130 130 115 115 150 */ // #include<bits/stdc++.h> #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103L #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <cstdint> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <type_traits> #include <typeindex> #include <unordered_map> #include <unordered_set> #endif using namespace std; long long mod = 1e9 + 7; long long INF = 1e7; double EPS = 1e-12; const long long lim = 2e5 + 100; typedef long long int lld; typedef long long ll; #define Error(x...) \ { \ cout << "(" << #x << ")" \ << " = ( "; \ printIt(x); \ } template <typename T1> void printIt(T1 t1) { cout << t1 << " )" << endl; } template <typename T1, typename... T2> void printIt(T1 t1, T2... t2) { cout << t1 << " , "; printIt(t2...); } #define popcount __builtin_popcountll ll powP(ll x, ll y) { ll ans = 1, po = x % mod; while (y > 0) { if (y & 1) ans = ans * po % mod; y >>= 1; po = po * po % mod; } return ans; } vector<pair<ll, ll>> V; ll Array[lim], C[lim]; vector<pair<ll, ll>> Allstocks; int main() { ios::sync_with_stdio(0); cin.tie(0); lld T, i, p, j, l, e, r, b, c, k, m, q, a, d, w, x, y, u, v, z, t, curr, prev, sum = 0, val, countA = 0, indicator = 0, pos, h, minA, maxA, type, n, ans = 0, left, right; cin >> n; for (int i = 1; i <= n; i++) cin >> Array[i]; Array[0] = mod; Array[n + 1] = 0; for (int i = 1; i <= n + 1; i++) { if (Array[i] < Array[i - 1]) { V.push_back(make_pair(Array[prev], Array[i - 1])); prev = i; } } val = 1000; for (auto i : V) { val = (val / i.first) * i.second + val - (val / i.first) * i.first; } cout << val << endl; return 0; }
/*input 7 100 130 130 130 115 115 150 */ // #include<bits/stdc++.h> #include <algorithm> #include <bitset> #include <complex> #include <deque> #include <exception> #include <fstream> #include <functional> #include <iomanip> #include <ios> #include <iosfwd> #include <iostream> #include <istream> #include <iterator> #include <limits> #include <list> #include <locale> #include <map> #include <memory> #include <new> #include <numeric> #include <ostream> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdexcept> #include <streambuf> #include <string> #include <typeinfo> #include <utility> #include <valarray> #include <vector> #if __cplusplus >= 201103L #include <array> #include <atomic> #include <chrono> #include <condition_variable> #include <cstdint> #include <forward_list> #include <future> #include <initializer_list> #include <mutex> #include <random> #include <ratio> #include <regex> #include <scoped_allocator> #include <system_error> #include <thread> #include <tuple> #include <type_traits> #include <typeindex> #include <unordered_map> #include <unordered_set> #endif using namespace std; long long mod = 1e9 + 7; long long INF = 1e7; double EPS = 1e-12; const long long lim = 2e5 + 100; typedef long long int lld; typedef long long ll; #define Error(x...) \ { \ cout << "(" << #x << ")" \ << " = ( "; \ printIt(x); \ } template <typename T1> void printIt(T1 t1) { cout << t1 << " )" << endl; } template <typename T1, typename... T2> void printIt(T1 t1, T2... t2) { cout << t1 << " , "; printIt(t2...); } #define popcount __builtin_popcountll ll powP(ll x, ll y) { ll ans = 1, po = x % mod; while (y > 0) { if (y & 1) ans = ans * po % mod; y >>= 1; po = po * po % mod; } return ans; } vector<pair<ll, ll>> V; ll Array[lim], C[lim]; vector<pair<ll, ll>> Allstocks; int main() { ios::sync_with_stdio(0); cin.tie(0); lld T, i, p, j, l, e, r, b, c, k, m, q, a, d, w, x, y, u, v, z, t, curr, prev, sum = 0, val, countA = 0, indicator = 0, pos, h, minA, maxA, type, n, ans = 0, left, right; cin >> n; for (int i = 1; i <= n; i++) cin >> Array[i]; Array[0] = mod; Array[n + 1] = 0; prev = 0; for (int i = 1; i <= n + 1; i++) { if (Array[i] < Array[i - 1]) { V.push_back(make_pair(Array[prev], Array[i - 1])); prev = i; } } val = 1000; for (auto i : V) { val = (val / i.first) * i.second + val - (val / i.first) * i.first; } cout << val << endl; return 0; }
insert
112
112
112
113
-11
p02603
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #if __has_include(<boost/multiprecision/cpp_int.hpp>) #include <boost/multiprecision/cpp_int.hpp> #include <boost/multiprecision/cpp_dec_float.hpp> using bll = boost::multiprecision::cpp_int; using bdouble = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<100>>; using namespace boost::multiprecision; #endif #if __has_include(<boost/stacktrace.hpp>) #define BOOST_STACKTRACE_USE_ADDR2LINE #define BOOST_STACKTRACE_ADDR2LINE_LOCATION \ / usr / local / opt / binutils / bin / addr2line #define _GNU_SOURCE 1 #include <boost/stacktrace.hpp> #endif #ifdef LOCAL_TEST namespace std { template <typename T> class dvector : public std::vector<T> { public: dvector() : std::vector<T>() {} explicit dvector(size_t n, const T &value = T()) : std::vector<T>(n, value) {} dvector(const std::vector<T> &v) : std::vector<T>(v) {} dvector(const std::initializer_list<T> il) : std::vector<T>(il) {} dvector(const std::string::iterator first, const std::string::iterator last) : std::vector<T>(first, last) {} dvector(const typename std::vector<T>::iterator first, const typename std::vector<T>::iterator last) : std::vector<T>(first, last) {} dvector(const typename std::vector<T>::reverse_iterator first, const typename std::vector<T>::reverse_iterator last) : std::vector<T>(first, last) {} dvector(const typename std::vector<T>::const_iterator first, const typename std::vector<T>::const_iterator last) : std::vector<T>(first, last) {} dvector(const typename std::vector<T>::const_reverse_iterator first, const typename std::vector<T>::const_reverse_iterator last) : std::vector<T>(first, last) {} T &operator[](size_t n) { try { return this->at(n); } catch (const std::exception &e) { std::cerr << boost::stacktrace::stacktrace() << '\n'; return this->at(n); } } const T &operator[](size_t n) const { try { return this->at(n); } catch (const std::exception &e) { std::cerr << boost::stacktrace::stacktrace() << '\n'; return this->at(n); } } }; } // namespace std class dbool { private: bool boolvalue; public: dbool() : boolvalue(false) {} dbool(bool b) : boolvalue(b) {} operator bool &() { return boolvalue; } operator const bool &() const { return boolvalue; } }; #define vector dvector #define bool dbool #endif #ifdef LOCAL_DEV template <typename T> std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) { for (size_t i = 0; i < v.size(); ++i) { s << v[i]; if (i < v.size() - 1) s << "\t"; } return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::vector<std::vector<T>> &vv) { s << "\\\n"; for (size_t i = 0; i < vv.size(); ++i) { s << vv[i] << "\n"; } return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::deque<T> &v) { for (size_t i = 0; i < v.size(); ++i) { s << v[i]; if (i < v.size() - 1) s << "\t"; } return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::set<T> &se) { s << "{ "; for (auto itr = se.begin(); itr != se.end(); ++itr) { s << (*itr) << "\t"; } s << "}"; return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::multiset<T> &se) { s << "{ "; for (auto itr = se.begin(); itr != se.end(); ++itr) { s << (*itr) << "\t"; } s << "}"; return s; } template <typename T, size_t N> std::ostream &operator<<(std::ostream &s, const std::array<T, N> &a) { s << "{ "; for (size_t i = 0; i < N; ++i) { s << a[i] << "\t"; } s << "}"; return s; } template <typename T1, typename T2> std::ostream &operator<<(std::ostream &s, const std::map<T1, T2> &m) { s << "{\n"; for (auto itr = m.begin(); itr != m.end(); ++itr) { s << "\t" << (*itr).first << " : " << (*itr).second << "\n"; } s << "}"; return s; } template <typename T1, typename T2> std::ostream &operator<<(std::ostream &s, const std::pair<T1, T2> &p) { return s << "(" << p.first << ", " << p.second << ")"; } class SIGFPE_exception : std::exception {}; class SIGSEGV_exception : std::exception {}; void catch_SIGFPE([[maybe_unused]] int e) { std::cerr << boost::stacktrace::stacktrace() << '\n'; throw SIGFPE_exception(); } void catch_SIGSEGV([[maybe_unused]] int e) { std::cerr << boost::stacktrace::stacktrace() << '\n'; throw SIGSEGV_exception(); } signed convertedmain(); signed main() { signal(SIGFPE, catch_SIGFPE); signal(SIGSEGV, catch_SIGSEGV); return convertedmain(); } #define main() convertedmain() void debug_impl() { std::cerr << '\n'; } template <typename Head, typename... Tail> void debug_impl(Head head, Tail... tail) { std::cerr << " " << head << (sizeof...(tail) ? "," : ""); debug_impl(tail...); } #define debug(...) \ do { \ std::cerr << "(" << #__VA_ARGS__ << ") ="; \ debug_impl(__VA_ARGS__); \ } while (false) #else #define debug(...) \ do { \ } while (false) #endif // #define int long long using ll = long long; // constexpr int INF = (ll)1e9 + 7;//INT_MAX=(1<<31)-1=2147483647 constexpr ll INF = (ll)1e18; //(1LL<<63)-1=9223372036854775807 constexpr ll MOD = (ll)1e9 + 7; constexpr double EPS = 1e-9; constexpr ll dx[4] = {1, 0, -1, 0}; constexpr ll dy[4] = {0, 1, 0, -1}; constexpr ll dx8[8] = {1, 0, -1, 0, 1, 1, -1, -1}; constexpr ll dy8[8] = {0, 1, 0, -1, 1, -1, 1, -1}; #define rep(i, n) for (ll i = 0, i##_length = (n); i < i##_length; ++i) #define repeq(i, n) for (ll i = 1, i##_length = (n); i <= i##_length; ++i) #define rrep(i, n) for (ll i = (n)-1; i >= 0; --i) #define rrepeq(i, n) for (ll i = (n); i >= 1; --i) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() void p() { std::cout << '\n'; } template <typename Head, typename... Tail> void p(Head head, Tail... tail) { std::cout << head << (sizeof...(tail) ? " " : ""); p(tail...); } template <typename T> inline void pv(std::vector<T> &v) { for (ll i = 0, N = v.size(); i < N; i++) std::cout << v[i] << " \n"[i == N - 1]; } template <typename T> inline bool chmax(T &a, T b) { return a < b && (a = b, true); } template <typename T> inline bool chmin(T &a, T b) { return a > b && (a = b, true); } template <typename T> inline void uniq(std::vector<T> &v) { v.erase(std::unique(v.begin(), v.end()), v.end()); } /*-----8<-----template-----8<-----*/ class Item { public: ll value, weight, index; Item() {} Item(ll value, ll weight, ll index) : value(value), weight(weight), index(index) {} }; ostream &operator<<(ostream &s, const Item &item) { s << "{ " << item.index << " : value = " << item.value << ", weight = " << item.weight << " }"; return s; } class KnapsackBB { public: // 商品一覧 vector<Item> items; // 各商品の在庫数 vector<ll> item_size; // 商品の種類数 ll N; // ナップサックの容量 ll W; // 現在探索している商品の選び方 used_items[i]=j -> i番目の商品をj個選択 vector<ll> used_items; // 現時点で最適な商品の選び方 opt_items[i]=j -> i番目の商品をj個選択 vector<ll> opt_items; // 現時点で最適な商品の選び方をしたときの価値合計 ll opt_value = 0; KnapsackBB(vector<Item> &items, vector<ll> &item_size, ll W) : items(items), item_size(item_size), N(items.size()), W(W) {} // 分枝限定法で探索 // index=index-1番目の商品までは選択が終わった、index番目からの商品はまだ調べてない // value=今のところの価値合計 // weight=今のところの重さ合計 void searchbb(ll index, ll value, ll weight) { // 全部調べ終わった if (index == N || items[index].value <= 0) { if (opt_value < value) { opt_items = used_items; opt_value = value; } return; } // 緩和問題を解く ll tmp_weight = weight; double tmp_value = value; for (ll i = index; i < N; i++) { ll size = (W - tmp_weight) / items[i].weight; if (item_size[i] > size) { // 重さの余りを詰める double sizedouble = (double)(W - tmp_weight) / items[i].weight; tmp_value += items[i].value * sizedouble; tmp_weight = W; break; } else if (item_size[i] == size && (W - tmp_weight) % items[i].weight == 0) { // 緩和問題の解が元の問題でも実現可能→暫定解として使えるかも tmp_value += items[i].value * size; if (opt_value < tmp_value) { opt_value = tmp_value; opt_items = used_items; for (ll j = index; j < i; j++) { opt_items[j] = item_size[j]; } opt_items[i] = size; } return; } else { tmp_value += items[i].value * item_size[i]; tmp_weight += items[i].weight * item_size[i]; } } // 緩和問題ですら暫定解を超えられない→これ以上調査する意味がない if (tmp_value < opt_value) { return; } // 重量制限が許されれば、index番目をi個選ぶ場合で探索 for (ll i = min(item_size[index], (W - weight) / items[index].weight); i >= 0; i--) { used_items[index] = i; searchbb(index + 1, value + (items[index].value * i), weight + (items[index].weight * i)); } } ll search() { // 商品をコスパのよい順に並び替え sort(items.begin(), items.end(), [](const Item &x, const Item &y) { return ((double)x.value / x.weight) > ((double)y.value / y.weight); }); // 暫定解として貪欲に選んでみる ll opt_weight = 0; opt_value = 0; opt_items.assign(N, 0); for (ll i = 0; i < N; i++) { if (items[i].value <= 0) break; ll size = (W - opt_weight) / items[i].weight; if (item_size[i] >= size) { opt_weight += items[i].weight * size; opt_value += items[i].value * size; opt_items[i] = size; } else { opt_weight += items[i].weight * item_size[i]; opt_value += items[i].value * item_size[i]; opt_items[i] = item_size[i]; } } used_items.assign(N, 0); searchbb(0, 0, 0); return opt_value; } }; /*-----8<-----library-----8<-----*/ constexpr ll N_MAX = 80; constexpr ll A_I_MAX = 200; ll N; vector<ll> A; void solve() { cin >> N; A = vector<ll>(N); rep(i, N) { cin >> A[i]; } ll W = 1000; // 1000; /* vector<Item> items; rep(i,N-1){ items.push_back(Item(A[i+1]-A[i], A[i], i)); } */ /* //Item(ll value, ll weight, ll index) items.push_back(Item(A[i+1]-A[i], A[i], 0)); vector<ll> item_size(items.size(), INF); KnapsackBB knapsack(items, item_size, W); ll opt_value = knapsack.search(); W+=opt_value; */ vector<Item> items; rep(i, N - 1) items.push_back(Item(A[i + 1] - A[i], A[i], i)); vector<vector<ll>> dp(N + 1, vector<ll>(1e6 + 1, 0)); // rep(i,N-1){ for (ll n = 0; n < N - 1; n++) { for (ll w = 0; w <= W; w++) { if (w < items[n].weight) { // 範囲外参照しないためのガードと考えても良い dp[n + 1][w] = dp[n][w]; } else { // 商品の個数制限1つ // dp[n+1][w]=max(dp[n][w], dp[n][w-items[n].weight]+items[n].value); // 商品の個数制限なし // dp[n+1][w]=max(dp[n][w], dp[n+1][w-items[n].weight]+items[n].value); dp[n + 1][w] = max(0LL, dp[n + 1][w - items[n].weight] + items[n].value); } } W += dp[n + 1][W]; debug(W); } debug(dp); //} cout << W << endl; } // https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_d signed main() { solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #if __has_include(<boost/multiprecision/cpp_int.hpp>) #include <boost/multiprecision/cpp_int.hpp> #include <boost/multiprecision/cpp_dec_float.hpp> using bll = boost::multiprecision::cpp_int; using bdouble = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<100>>; using namespace boost::multiprecision; #endif #if __has_include(<boost/stacktrace.hpp>) #define BOOST_STACKTRACE_USE_ADDR2LINE #define BOOST_STACKTRACE_ADDR2LINE_LOCATION \ / usr / local / opt / binutils / bin / addr2line #define _GNU_SOURCE 1 #include <boost/stacktrace.hpp> #endif #ifdef LOCAL_TEST namespace std { template <typename T> class dvector : public std::vector<T> { public: dvector() : std::vector<T>() {} explicit dvector(size_t n, const T &value = T()) : std::vector<T>(n, value) {} dvector(const std::vector<T> &v) : std::vector<T>(v) {} dvector(const std::initializer_list<T> il) : std::vector<T>(il) {} dvector(const std::string::iterator first, const std::string::iterator last) : std::vector<T>(first, last) {} dvector(const typename std::vector<T>::iterator first, const typename std::vector<T>::iterator last) : std::vector<T>(first, last) {} dvector(const typename std::vector<T>::reverse_iterator first, const typename std::vector<T>::reverse_iterator last) : std::vector<T>(first, last) {} dvector(const typename std::vector<T>::const_iterator first, const typename std::vector<T>::const_iterator last) : std::vector<T>(first, last) {} dvector(const typename std::vector<T>::const_reverse_iterator first, const typename std::vector<T>::const_reverse_iterator last) : std::vector<T>(first, last) {} T &operator[](size_t n) { try { return this->at(n); } catch (const std::exception &e) { std::cerr << boost::stacktrace::stacktrace() << '\n'; return this->at(n); } } const T &operator[](size_t n) const { try { return this->at(n); } catch (const std::exception &e) { std::cerr << boost::stacktrace::stacktrace() << '\n'; return this->at(n); } } }; } // namespace std class dbool { private: bool boolvalue; public: dbool() : boolvalue(false) {} dbool(bool b) : boolvalue(b) {} operator bool &() { return boolvalue; } operator const bool &() const { return boolvalue; } }; #define vector dvector #define bool dbool #endif #ifdef LOCAL_DEV template <typename T> std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) { for (size_t i = 0; i < v.size(); ++i) { s << v[i]; if (i < v.size() - 1) s << "\t"; } return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::vector<std::vector<T>> &vv) { s << "\\\n"; for (size_t i = 0; i < vv.size(); ++i) { s << vv[i] << "\n"; } return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::deque<T> &v) { for (size_t i = 0; i < v.size(); ++i) { s << v[i]; if (i < v.size() - 1) s << "\t"; } return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::set<T> &se) { s << "{ "; for (auto itr = se.begin(); itr != se.end(); ++itr) { s << (*itr) << "\t"; } s << "}"; return s; } template <typename T> std::ostream &operator<<(std::ostream &s, const std::multiset<T> &se) { s << "{ "; for (auto itr = se.begin(); itr != se.end(); ++itr) { s << (*itr) << "\t"; } s << "}"; return s; } template <typename T, size_t N> std::ostream &operator<<(std::ostream &s, const std::array<T, N> &a) { s << "{ "; for (size_t i = 0; i < N; ++i) { s << a[i] << "\t"; } s << "}"; return s; } template <typename T1, typename T2> std::ostream &operator<<(std::ostream &s, const std::map<T1, T2> &m) { s << "{\n"; for (auto itr = m.begin(); itr != m.end(); ++itr) { s << "\t" << (*itr).first << " : " << (*itr).second << "\n"; } s << "}"; return s; } template <typename T1, typename T2> std::ostream &operator<<(std::ostream &s, const std::pair<T1, T2> &p) { return s << "(" << p.first << ", " << p.second << ")"; } class SIGFPE_exception : std::exception {}; class SIGSEGV_exception : std::exception {}; void catch_SIGFPE([[maybe_unused]] int e) { std::cerr << boost::stacktrace::stacktrace() << '\n'; throw SIGFPE_exception(); } void catch_SIGSEGV([[maybe_unused]] int e) { std::cerr << boost::stacktrace::stacktrace() << '\n'; throw SIGSEGV_exception(); } signed convertedmain(); signed main() { signal(SIGFPE, catch_SIGFPE); signal(SIGSEGV, catch_SIGSEGV); return convertedmain(); } #define main() convertedmain() void debug_impl() { std::cerr << '\n'; } template <typename Head, typename... Tail> void debug_impl(Head head, Tail... tail) { std::cerr << " " << head << (sizeof...(tail) ? "," : ""); debug_impl(tail...); } #define debug(...) \ do { \ std::cerr << "(" << #__VA_ARGS__ << ") ="; \ debug_impl(__VA_ARGS__); \ } while (false) #else #define debug(...) \ do { \ } while (false) #endif // #define int long long using ll = long long; // constexpr int INF = (ll)1e9 + 7;//INT_MAX=(1<<31)-1=2147483647 constexpr ll INF = (ll)1e18; //(1LL<<63)-1=9223372036854775807 constexpr ll MOD = (ll)1e9 + 7; constexpr double EPS = 1e-9; constexpr ll dx[4] = {1, 0, -1, 0}; constexpr ll dy[4] = {0, 1, 0, -1}; constexpr ll dx8[8] = {1, 0, -1, 0, 1, 1, -1, -1}; constexpr ll dy8[8] = {0, 1, 0, -1, 1, -1, 1, -1}; #define rep(i, n) for (ll i = 0, i##_length = (n); i < i##_length; ++i) #define repeq(i, n) for (ll i = 1, i##_length = (n); i <= i##_length; ++i) #define rrep(i, n) for (ll i = (n)-1; i >= 0; --i) #define rrepeq(i, n) for (ll i = (n); i >= 1; --i) #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() void p() { std::cout << '\n'; } template <typename Head, typename... Tail> void p(Head head, Tail... tail) { std::cout << head << (sizeof...(tail) ? " " : ""); p(tail...); } template <typename T> inline void pv(std::vector<T> &v) { for (ll i = 0, N = v.size(); i < N; i++) std::cout << v[i] << " \n"[i == N - 1]; } template <typename T> inline bool chmax(T &a, T b) { return a < b && (a = b, true); } template <typename T> inline bool chmin(T &a, T b) { return a > b && (a = b, true); } template <typename T> inline void uniq(std::vector<T> &v) { v.erase(std::unique(v.begin(), v.end()), v.end()); } /*-----8<-----template-----8<-----*/ class Item { public: ll value, weight, index; Item() {} Item(ll value, ll weight, ll index) : value(value), weight(weight), index(index) {} }; ostream &operator<<(ostream &s, const Item &item) { s << "{ " << item.index << " : value = " << item.value << ", weight = " << item.weight << " }"; return s; } class KnapsackBB { public: // 商品一覧 vector<Item> items; // 各商品の在庫数 vector<ll> item_size; // 商品の種類数 ll N; // ナップサックの容量 ll W; // 現在探索している商品の選び方 used_items[i]=j -> i番目の商品をj個選択 vector<ll> used_items; // 現時点で最適な商品の選び方 opt_items[i]=j -> i番目の商品をj個選択 vector<ll> opt_items; // 現時点で最適な商品の選び方をしたときの価値合計 ll opt_value = 0; KnapsackBB(vector<Item> &items, vector<ll> &item_size, ll W) : items(items), item_size(item_size), N(items.size()), W(W) {} // 分枝限定法で探索 // index=index-1番目の商品までは選択が終わった、index番目からの商品はまだ調べてない // value=今のところの価値合計 // weight=今のところの重さ合計 void searchbb(ll index, ll value, ll weight) { // 全部調べ終わった if (index == N || items[index].value <= 0) { if (opt_value < value) { opt_items = used_items; opt_value = value; } return; } // 緩和問題を解く ll tmp_weight = weight; double tmp_value = value; for (ll i = index; i < N; i++) { ll size = (W - tmp_weight) / items[i].weight; if (item_size[i] > size) { // 重さの余りを詰める double sizedouble = (double)(W - tmp_weight) / items[i].weight; tmp_value += items[i].value * sizedouble; tmp_weight = W; break; } else if (item_size[i] == size && (W - tmp_weight) % items[i].weight == 0) { // 緩和問題の解が元の問題でも実現可能→暫定解として使えるかも tmp_value += items[i].value * size; if (opt_value < tmp_value) { opt_value = tmp_value; opt_items = used_items; for (ll j = index; j < i; j++) { opt_items[j] = item_size[j]; } opt_items[i] = size; } return; } else { tmp_value += items[i].value * item_size[i]; tmp_weight += items[i].weight * item_size[i]; } } // 緩和問題ですら暫定解を超えられない→これ以上調査する意味がない if (tmp_value < opt_value) { return; } // 重量制限が許されれば、index番目をi個選ぶ場合で探索 for (ll i = min(item_size[index], (W - weight) / items[index].weight); i >= 0; i--) { used_items[index] = i; searchbb(index + 1, value + (items[index].value * i), weight + (items[index].weight * i)); } } ll search() { // 商品をコスパのよい順に並び替え sort(items.begin(), items.end(), [](const Item &x, const Item &y) { return ((double)x.value / x.weight) > ((double)y.value / y.weight); }); // 暫定解として貪欲に選んでみる ll opt_weight = 0; opt_value = 0; opt_items.assign(N, 0); for (ll i = 0; i < N; i++) { if (items[i].value <= 0) break; ll size = (W - opt_weight) / items[i].weight; if (item_size[i] >= size) { opt_weight += items[i].weight * size; opt_value += items[i].value * size; opt_items[i] = size; } else { opt_weight += items[i].weight * item_size[i]; opt_value += items[i].value * item_size[i]; opt_items[i] = item_size[i]; } } used_items.assign(N, 0); searchbb(0, 0, 0); return opt_value; } }; /*-----8<-----library-----8<-----*/ constexpr ll N_MAX = 80; constexpr ll A_I_MAX = 200; ll N; vector<ll> A; void solve() { cin >> N; A = vector<ll>(N); rep(i, N) { cin >> A[i]; } ll W = 1000; // 1000; rep(i, N - 1) { if (A[i] < A[i + 1]) { ll t = W / A[i]; ll s = (A[i + 1] - A[i]) * t; W += s; } else { } } cout << W << endl; } // https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_d signed main() { solve(); return 0; }
replace
343
379
343
351
0
p02603
C++
Time Limit Exceeded
// g++ .cpp && ./a.out #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef pair<int, int> p; typedef long long ll; const int mod = 1000000007; const int inf = 1000000007; int main() { int n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a[i]; ll ans = 0; ll tmp = 1000; for (int i = 0; i < n - 1; i++) { if (a[i] < a[i + 1]) { ll cnt = 0; while (tmp >= a[i]) { tmp -= a[i]; cnt++; } tmp += cnt * a[i + 1]; // cout << tmp << endl; } } cout << tmp << endl; }
// g++ .cpp && ./a.out #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; typedef pair<int, int> p; typedef long long ll; const int mod = 1000000007; const int inf = 1000000007; int main() { int n; cin >> n; vector<ll> a(n); rep(i, n) cin >> a[i]; ll ans = 0; ll tmp = 1000; for (int i = 0; i < n - 1; i++) { if (a[i] < a[i + 1]) { ll cnt = tmp / a[i]; tmp -= cnt * a[i]; tmp += cnt * a[i + 1]; // cout << tmp << endl; } } cout << tmp << endl; }
replace
20
25
20
22
TLE
p02603
C++
Time Limit Exceeded
#include <iostream> using namespace std; int a[86]; int main() { int N; cin >> N; for (int i = 0; i < N; i++) { cin >> a[i]; } long long int sum = 1000, stk = 0; for (int i = 0; i < N; i++) { if (a[i] < a[i + 1]) { while (sum > 0) { if (sum - a[i] >= 0) { sum -= a[i]; stk++; } else { break; } } } else { sum += stk * a[i]; stk = 0; } } cout << sum << endl; }
#include <iostream> using namespace std; int a[86]; int main() { int N; cin >> N; for (int i = 0; i < N; i++) { cin >> a[i]; } long long int sum = 1000, stk = 0; for (int i = 0; i < N; i++) { if (a[i] < a[i + 1]) { stk += sum / a[i]; sum = sum - (sum / a[i] * a[i]); } else { sum += stk * a[i]; stk = 0; } } cout << sum << endl; }
replace
12
20
12
14
TLE
p02603
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { int n, i, j, k; cin >> n; vector<int> a(n, 0); j = 0; for (i = 0; i < n; i++) { cin >> a.at(j); if (j == 0 || a.at(j) != a.at(j - 1)) { j++; } } n = j; /*for(i=0;i<n;i++){ cout << a.at(i) << endl; }*/ vector<int> vl(n), mt(n); j = 0; k = 0; if (a.at(0) < a.at(1)) { vl.at(0) = a.at(0); j = 1; } for (i = 1; i < n - 1; i++) { if (a.at(i) > a.at(i - 1) && a.at(i) > a.at(i + 1)) { mt.at(k) = a.at(i); k++; } else if (a.at(i) < a.at(i - 1) && a.at(i) < a.at(i + 1)) { vl.at(j) = a.at(i); j++; } } if (a.at(n - 1) > a.at(n - 2)) { mt.at(k) = a.at(n - 1); k++; } /*for(i=0;i<k;i++){ cout << vl.at(i) << " " << mt.at(i) << endl; }*/ ll money = 1000; for (i = 0; i < k; i++) { money += (money / vl.at(i)) * (mt.at(i) - vl.at(i)); } cout << money << endl; }
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { int n, i, j, k; cin >> n; vector<int> a(n, 0); j = 0; for (i = 0; i < n; i++) { cin >> a.at(j); if (j == 0 || a.at(j) != a.at(j - 1)) { j++; } } n = j; if (n == 1) { cout << 1000 << endl; return 0; } /*for(i=0;i<n;i++){ cout << a.at(i) << endl; }*/ vector<int> vl(n), mt(n); j = 0; k = 0; if (a.at(0) < a.at(1)) { vl.at(0) = a.at(0); j = 1; } for (i = 1; i < n - 1; i++) { if (a.at(i) > a.at(i - 1) && a.at(i) > a.at(i + 1)) { mt.at(k) = a.at(i); k++; } else if (a.at(i) < a.at(i - 1) && a.at(i) < a.at(i + 1)) { vl.at(j) = a.at(i); j++; } } if (a.at(n - 1) > a.at(n - 2)) { mt.at(k) = a.at(n - 1); k++; } /*for(i=0;i<k;i++){ cout << vl.at(i) << " " << mt.at(i) << endl; }*/ ll money = 1000; for (i = 0; i < k; i++) { money += (money / vl.at(i)) * (mt.at(i) - vl.at(i)); } cout << money << endl; }
insert
16
16
16
20
0
p02603
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int N = 100; int a[N]; int main() { LL n, num = 1000, num1 = 0; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", a + i); a[n] = 0; for (int i = 0; i < n; i++) { if (a[i] < a[i + 1]) num1 += num / a[i], num %= a[i]; else num += num1 * a[i], num1 = 0; } printf("%lld", num); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int N = 100; int a[N]; int main() { LL n = 0, num = 1000, num1 = 0; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", a + i); a[n] = 0; for (int i = 0; i < n; i++) { if (a[i] < a[i + 1]) num1 += num / a[i], num %= a[i]; else num += num1 * a[i], num1 = 0; } printf("%lld", num); return 0; }
replace
6
7
6
7
TLE
p02603
C++
Time Limit Exceeded
#include <cassert> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <deque> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <vector> #include <algorithm> #include <bitset> #include <functional> #include <memory> #include <string> #include <tuple> #include <utility> using namespace std; #define lowbit(x) ((x) & -(x)) #define lson l, mid, id << 1 #define rson mid + 1, r, id << 1 | 1 #define ls id << 1 #define rs id << 1 | 1 #define MID(l, r) ((l) + (((r) - (l)) >> 1)) #define fi first #define se second #define mk make_pair #define mt make_tuple #define pb push_back #define epb emplace_back #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() using LL = long long; // using LL = __int64; using pii = pair<int, int>; using pdd = pair<double, double>; using pLL = pair<LL, LL>; const int INF = 0x3f3f3f3f; const LL LINF = 0x3f3f3f3f3f3f3f3f; const double pi = acos(-1.0); const double eps = 1e-8; const int e5 = 100000; // 1e5 const int e6 = 1000000; // 1e6; const int MOD_1e9 = 1000000007; // 1e9 + 7 const int MOD_998 = 998244353; const int MOD = MOD_1e9; template <typename T> inline void get_min(T &x, T y) { if (y < x) x = y; } template <typename T> inline void get_max(T &x, T y) { if (x < y) x = y; } template <typename T> inline void get_unique(vector<T> &vec) { sort(all(vec)); vec.erase(unique(all(vec)), vec.end()); } inline int sig(double x) { return x < -eps ? -1 : eps < x; } LL fp(LL a, LL n, LL mod = MOD) { if (n < 0) a = fp(a, mod - 2, mod), n = -n; LL res = 1; for (; n; n >>= 1, a = a * a % mod) if (n & 1) res = res * a % mod; return res; } template <int mod> struct Mint { int x; Mint() : x(0) {} Mint(int _x) : x(_x) { if (x < 0 || x >= mod) x %= mod; if (x < 0) x += mod; } Mint(LL _x) { if (_x < 0 || _x >= mod) _x %= mod; if (_x < 0) _x += mod; x = _x; } Mint operator-() const { return Mint(mod - x); } Mint operator+(const Mint &rhs) const { return Mint(x + rhs.x >= mod ? x + rhs.x - mod : x + rhs.x); } Mint operator-(const Mint &rhs) const { return Mint(x - rhs.x < 0 ? x - rhs.x + mod : x - rhs.x); } Mint operator*(const Mint &rhs) const { return Mint((LL)x * rhs.x % mod); } Mint operator/(const Mint &rhs) const { return Mint((LL)x * fp(rhs.x, -1, mod) % mod); } bool operator==(const Mint &rhs) const { return x == rhs.x; } bool operator!=(const Mint &rhs) const { return x != rhs.x; } Mint &operator+=(const Mint &rhs) { x += rhs.x; if (x >= mod) x -= mod; return *this; } Mint &operator-=(const Mint &rhs) { x -= rhs.x; if (x < 0) x += mod; return *this; } Mint &operator*=(const Mint &rhs) { x = (LL)x * rhs.x % mod; return *this; } Mint &operator/=(const Mint &rhs) { x = (LL)x * fp(rhs.x, -1, mod) % mod; return *this; } friend ostream &operator<<(ostream &out, const Mint &rhs) { return out << to_string(rhs.x); } Mint inv() { return Mint(fp(x, -1, mod)); } Mint pow(int k) { return Mint(fp(x, k, mod)); } Mint pow(const Mint &t) { return Mint(fp(x, t.x, mod)); } }; class fast_reader { private: int buff_size; char *buff_ptr; char *ptr; char *tail; bool is_open; fast_reader(const fast_reader &) = delete; fast_reader &operator=(const fast_reader &) = delete; public: fast_reader() : buff_size(0), buff_ptr(nullptr), ptr(nullptr), tail(nullptr), is_open(false) {} ~fast_reader() { if (is_open) free(buff_ptr); } inline void open_alter(int _base_size = 1 << 24) // 2^24B = 16MB { if (is_open) throw runtime_error("fast reader is reopened!"); int input_size = 0; int call_size = _base_size; buff_ptr = (char *)malloc(call_size); input_size += fread(buff_ptr, 1, call_size, stdin); while (feof(stdin) == 0) { int recall_size = call_size; buff_ptr = (char *)realloc(buff_ptr, call_size + recall_size); tail = buff_ptr + call_size; input_size += fread(tail, 1, recall_size, stdin); call_size += recall_size; } buff_ptr = (char *)realloc(buff_ptr, input_size); ptr = buff_ptr; tail = buff_ptr + input_size; buff_size = input_size; is_open = true; } template <typename T> inline void read_i(T &x) { char c = '\0'; bool f = false; x = 0; while (ptr < tail && (c < '0' || '9' < c)) { if (c == '-') f = true; c = *ptr++; } while (ptr < tail && ('0' <= c && c <= '9')) { x = (x << 1) + (x << 3) + (c & 0xf); c = *ptr++; } if (f) x = -x; } inline void read(int &x) { read_i(x); } inline void read(unsigned &x) { read_i(x); } inline void read(long long &x) { read_i(x); } inline void read(unsigned long long &x) { read_i(x); } template <typename T> inline void read_f(T &x) { static char t_buff[1 << 6]; read(t_buff); x = atof(t_buff); } inline void read(float &x) { read_f(x); } inline void read(double &x) { read_f(x); } inline bool is_blank() { return *ptr == ' ' || *ptr == '\n' || *ptr == '\t' || *ptr == '\0'; } inline void read(char *str) { while (ptr < tail && is_blank()) ptr++; while (ptr < tail && !is_blank()) *str = *ptr++, str++; *str = '\0'; } inline void read(string &s) { while (ptr < tail && is_blank()) ptr++; char *pre = ptr; while (ptr < tail && !is_blank()) ptr++; s = std::move( string(pre, ptr)); // C++11 #include<utility> -> move return a rvalue } template <typename T, typename... Args> inline void read(T &x, Args &...args) { read(x); read(args...); } inline bool is_end() { while (ptr < tail && is_blank()) ptr++; return ptr >= tail; } } reader; const int maxn = (int)1e4 + 20; const int maxm = (int)2e6 + 20; void work() { int n; reader.read(n); vector<int> a(n); for (int i = 0; i < n; i++) reader.read(a[i]); vector<vector<int>> dp(n + 1); dp[0] = vector<int>{1000}; for (int i = 0; i < n; i++) { int mx = 0; for (int j = 0; j < dp[i].size(); j++) mx = max(mx, j + dp[i][j] / a[i]); dp[i + 1] = vector<int>(mx + 1, 0); for (int j = 0; j < dp[i].size(); j++) { for (int k = 0; k * a[i] <= dp[i][j]; k++) get_max(dp[i + 1][j + k], dp[i][j] - k * a[i]); } for (int j = dp[i + 1].size() - 1; j; j--) get_max(dp[i + 1][j - 1], dp[i + 1][j] + a[i]); } int ans = 1000; for (int i = 0; i <= n; i++) get_max(ans, dp[i][0]); cout << ans << endl; } int main() { #ifdef yukihana0416 freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #endif // yukihana0416 reader.open_alter(); int tc = 1; // reader.read(tc); for (int ca = 1; ca <= tc; ca++) { // printf("Case #%d: ", ca); // printf("Case #%d:\n", ca); work(); } return 0; }
#include <cassert> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iostream> #include <deque> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <unordered_map> #include <unordered_set> #include <vector> #include <algorithm> #include <bitset> #include <functional> #include <memory> #include <string> #include <tuple> #include <utility> using namespace std; #define lowbit(x) ((x) & -(x)) #define lson l, mid, id << 1 #define rson mid + 1, r, id << 1 | 1 #define ls id << 1 #define rs id << 1 | 1 #define MID(l, r) ((l) + (((r) - (l)) >> 1)) #define fi first #define se second #define mk make_pair #define mt make_tuple #define pb push_back #define epb emplace_back #define all(a) a.begin(), a.end() #define rall(a) a.rbegin(), a.rend() using LL = long long; // using LL = __int64; using pii = pair<int, int>; using pdd = pair<double, double>; using pLL = pair<LL, LL>; const int INF = 0x3f3f3f3f; const LL LINF = 0x3f3f3f3f3f3f3f3f; const double pi = acos(-1.0); const double eps = 1e-8; const int e5 = 100000; // 1e5 const int e6 = 1000000; // 1e6; const int MOD_1e9 = 1000000007; // 1e9 + 7 const int MOD_998 = 998244353; const int MOD = MOD_1e9; template <typename T> inline void get_min(T &x, T y) { if (y < x) x = y; } template <typename T> inline void get_max(T &x, T y) { if (x < y) x = y; } template <typename T> inline void get_unique(vector<T> &vec) { sort(all(vec)); vec.erase(unique(all(vec)), vec.end()); } inline int sig(double x) { return x < -eps ? -1 : eps < x; } LL fp(LL a, LL n, LL mod = MOD) { if (n < 0) a = fp(a, mod - 2, mod), n = -n; LL res = 1; for (; n; n >>= 1, a = a * a % mod) if (n & 1) res = res * a % mod; return res; } template <int mod> struct Mint { int x; Mint() : x(0) {} Mint(int _x) : x(_x) { if (x < 0 || x >= mod) x %= mod; if (x < 0) x += mod; } Mint(LL _x) { if (_x < 0 || _x >= mod) _x %= mod; if (_x < 0) _x += mod; x = _x; } Mint operator-() const { return Mint(mod - x); } Mint operator+(const Mint &rhs) const { return Mint(x + rhs.x >= mod ? x + rhs.x - mod : x + rhs.x); } Mint operator-(const Mint &rhs) const { return Mint(x - rhs.x < 0 ? x - rhs.x + mod : x - rhs.x); } Mint operator*(const Mint &rhs) const { return Mint((LL)x * rhs.x % mod); } Mint operator/(const Mint &rhs) const { return Mint((LL)x * fp(rhs.x, -1, mod) % mod); } bool operator==(const Mint &rhs) const { return x == rhs.x; } bool operator!=(const Mint &rhs) const { return x != rhs.x; } Mint &operator+=(const Mint &rhs) { x += rhs.x; if (x >= mod) x -= mod; return *this; } Mint &operator-=(const Mint &rhs) { x -= rhs.x; if (x < 0) x += mod; return *this; } Mint &operator*=(const Mint &rhs) { x = (LL)x * rhs.x % mod; return *this; } Mint &operator/=(const Mint &rhs) { x = (LL)x * fp(rhs.x, -1, mod) % mod; return *this; } friend ostream &operator<<(ostream &out, const Mint &rhs) { return out << to_string(rhs.x); } Mint inv() { return Mint(fp(x, -1, mod)); } Mint pow(int k) { return Mint(fp(x, k, mod)); } Mint pow(const Mint &t) { return Mint(fp(x, t.x, mod)); } }; class fast_reader { private: int buff_size; char *buff_ptr; char *ptr; char *tail; bool is_open; fast_reader(const fast_reader &) = delete; fast_reader &operator=(const fast_reader &) = delete; public: fast_reader() : buff_size(0), buff_ptr(nullptr), ptr(nullptr), tail(nullptr), is_open(false) {} ~fast_reader() { if (is_open) free(buff_ptr); } inline void open_alter(int _base_size = 1 << 24) // 2^24B = 16MB { if (is_open) throw runtime_error("fast reader is reopened!"); int input_size = 0; int call_size = _base_size; buff_ptr = (char *)malloc(call_size); input_size += fread(buff_ptr, 1, call_size, stdin); while (feof(stdin) == 0) { int recall_size = call_size; buff_ptr = (char *)realloc(buff_ptr, call_size + recall_size); tail = buff_ptr + call_size; input_size += fread(tail, 1, recall_size, stdin); call_size += recall_size; } buff_ptr = (char *)realloc(buff_ptr, input_size); ptr = buff_ptr; tail = buff_ptr + input_size; buff_size = input_size; is_open = true; } template <typename T> inline void read_i(T &x) { char c = '\0'; bool f = false; x = 0; while (ptr < tail && (c < '0' || '9' < c)) { if (c == '-') f = true; c = *ptr++; } while (ptr < tail && ('0' <= c && c <= '9')) { x = (x << 1) + (x << 3) + (c & 0xf); c = *ptr++; } if (f) x = -x; } inline void read(int &x) { read_i(x); } inline void read(unsigned &x) { read_i(x); } inline void read(long long &x) { read_i(x); } inline void read(unsigned long long &x) { read_i(x); } template <typename T> inline void read_f(T &x) { static char t_buff[1 << 6]; read(t_buff); x = atof(t_buff); } inline void read(float &x) { read_f(x); } inline void read(double &x) { read_f(x); } inline bool is_blank() { return *ptr == ' ' || *ptr == '\n' || *ptr == '\t' || *ptr == '\0'; } inline void read(char *str) { while (ptr < tail && is_blank()) ptr++; while (ptr < tail && !is_blank()) *str = *ptr++, str++; *str = '\0'; } inline void read(string &s) { while (ptr < tail && is_blank()) ptr++; char *pre = ptr; while (ptr < tail && !is_blank()) ptr++; s = std::move( string(pre, ptr)); // C++11 #include<utility> -> move return a rvalue } template <typename T, typename... Args> inline void read(T &x, Args &...args) { read(x); read(args...); } inline bool is_end() { while (ptr < tail && is_blank()) ptr++; return ptr >= tail; } } reader; const int maxn = (int)1e4 + 20; const int maxm = (int)2e6 + 20; void work() { int n; reader.read(n); vector<int> a(n); for (int i = 0; i < n; i++) reader.read(a[i]); LL ans = 1000; for (int i = 1; i < n; i++) { if (a[i] > a[i - 1]) { ans += (a[i] - a[i - 1]) * (ans / a[i - 1]); } } cout << ans << endl; } int main() { #ifdef yukihana0416 freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #endif // yukihana0416 reader.open_alter(); int tc = 1; // reader.read(tc); for (int ca = 1; ca <= tc; ca++) { // printf("Case #%d: ", ca); // printf("Case #%d:\n", ca); work(); } return 0; }
replace
257
277
257
264
TLE
p02604
C++
Time Limit Exceeded
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; #define $(x) (int)((x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define endl '\n' #define x first #define y second #define int long long #define double long double #define pii pair<int, int> #define pb push_back #define vec vector #define beg begin #define dbg(x) cerr << #x << " = " << x << endl; template <class T> ostream &operator<<(ostream &str, vector<T> &a) { for (auto &i : a) { str << i << " "; } return str; } template <class T> istream &operator>>(istream &str, vector<T> &a) { for (auto &i : a) { str >> i; } return str; } template <class T> ostream &operator<<(ostream &str, pair<T, T> &a) { str << a.first << " " << a.second; return str; } template <class T> istream &operator>>(istream &str, pair<T, T> &a) { str >> a.first >> a.second; return str; } void solve(); signed main() { #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif srand(time(0)); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(6); solve(); return 0; } const int MOD = 998244353, MAXN = 5e5 + 10, INF = 1e18 + 10, BASE = 37; int n; vec<vec<int>> p; vec<int> ans; vec<int> prefix; vec<int> v, h; void check(int i) { if (i == n) { int cnt = 0; h.clear(), v.clear(); for (int i = 0; i < n; ++i) { if (prefix[i] >= 1) { cnt++; } if (prefix[i] == 1) { h.pb(p[i][1]); } if (prefix[i] == 2) { v.pb(p[i][0]); } } v.pb(0); h.pb(0); int cur = 0; for (int i = 0; i < n; ++i) { int tmp = INF; for (int j = 0; j < $(h); ++j) { tmp = min(tmp, abs(h[j] - p[i][1])); } for (int j = 0; j < $(v); ++j) { tmp = min(tmp, abs(v[j] - p[i][0])); } cur += tmp * p[i][2]; } ans[cnt] = min(ans[cnt], cur); return; } else { for (int j = 0; j < 3; ++j) { prefix.pb(j); check(i + 1); prefix.pop_back(); } } } void solve() { cin >> n; p.resize(n, vec<int>(3)); cin >> p; ans.resize(n + 1, INF); check(0); for (int i = 0; i <= n; ++i) { cout << ans[i] << endl; } }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; #define $(x) (int)((x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define endl '\n' #define x first #define y second #define int long long #define double long double #define pii pair<int, int> #define pb push_back #define vec vector #define beg begin #define dbg(x) cerr << #x << " = " << x << endl; template <class T> ostream &operator<<(ostream &str, vector<T> &a) { for (auto &i : a) { str << i << " "; } return str; } template <class T> istream &operator>>(istream &str, vector<T> &a) { for (auto &i : a) { str >> i; } return str; } template <class T> ostream &operator<<(ostream &str, pair<T, T> &a) { str << a.first << " " << a.second; return str; } template <class T> istream &operator>>(istream &str, pair<T, T> &a) { str >> a.first >> a.second; return str; } void solve(); signed main() { #ifdef LOCAL freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif srand(time(0)); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(6); solve(); return 0; } const int MOD = 998244353, MAXN = 5e5 + 10, INF = 1e18 + 10, BASE = 37; int n; vec<vec<int>> p; vec<int> ans; vec<int> prefix; vec<int> v, h; void check(int i) { if (i == n) { int cnt = 0; h.clear(), v.clear(); for (int i = 0; i < n; ++i) { if (prefix[i] >= 1) { cnt++; } if (prefix[i] == 1) { h.pb(p[i][1]); } if (prefix[i] == 2) { v.pb(p[i][0]); } } v.pb(0); h.pb(0); int cur = 0; for (int i = 0; i < n; ++i) { if (prefix[i] == 1 || prefix[i] == 2) continue; int tmp = INF; for (int j = 0; j < $(h); ++j) { tmp = min(tmp, abs(h[j] - p[i][1])); } for (int j = 0; j < $(v); ++j) { tmp = min(tmp, abs(v[j] - p[i][0])); } cur += tmp * p[i][2]; } ans[cnt] = min(ans[cnt], cur); return; } else { for (int j = 0; j < 3; ++j) { prefix.pb(j); check(i + 1); prefix.pop_back(); } } } void solve() { cin >> n; p.resize(n, vec<int>(3)); cin >> p; ans.resize(n + 1, INF); check(0); for (int i = 0; i <= n; ++i) { cout << ans[i] << endl; } }
insert
84
84
84
86
TLE
p02604
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (long long i = 0; i < n; i++) #define Rep(i, m, n) for (long long i = m; i < n; i++) #define REP(i, m, n, p) for (long long i = m; i < n; i += p) #define all(v) v.begin(), v.end() #define pq priority_queue #define bcnt(n) __builtin_popcountll(n) const int mod = 1000000007; // const int mod = 998244353; using vi = vector<int>; // intの1次元の型に vi という別名をつける using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける using vvvi = vector<vvi>; using ll = long long; // long longをllだけにした using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; using vb = vector<bool>; using vvb = vector<vb>; using mii = map<int, int>; using pqll = priority_queue<long long>; using pqllg = priority_queue<long long, vector<long long>, greater<long long>>; using mll = map<long long, long long>; using pll = pair<long long, long long>; using sll = set<long long>; using vpll = vector<pair<long long, long long>>; using mlv = map<long long, vector<long long>>; long long divup(long long a, long long b); long long kaijou(long long i); long long P(long long n, long long k); long long C(long long n, long long k); long long GCD(long long a, long long b); long long LCM(long long a, long long b); bool prime(long long N); double distance(vector<long long> p, vector<long long> q, long long n); void press(vector<long long> &v); void ranking(vector<long long> &v); void erase(vector<long long> &v, long long i); void unique(vector<long long> &v); void printv(vector<long long> v); vector<long long> keta(ll x); long long modpow(long long a, long long n, long long mod); long long modinv(long long a, long long mod); // 20200416 vector<long long> inputv(long long n); // 20200417 vector<long long> yakusuu(int n); map<long long, long long> soinsuu(long long n); vector<vector<long long>> maze(long long i, long long j, vector<string> &s); // 20200423 vector<long long> eratos(long long n); set<long long> eraset(long long n); ////////////////////////////////////////////////////// // 端数繰りあがり割り算(検証済) // a÷bの端数繰り上げ // b!=0のデバグはしてないので分母に0を入れないように // 負数対応 long long divup(long long a, long long b) { long long x = abs(a); long long y = abs(b); long long z = (x + y - 1) / y; if ((a < 0 && b > 0) || (a > 0 && b < 0)) return -z; else if (a == 0) return 0; else return z; } // 階乗 // 検証済み long long kaijou(long long i) { if (i == 0) return 1; long long j = 1; for (long long k = 1; k <= i; k++) { j *= k; } return j; } // 順列nPk(完成) // n個の異なる要素から、取り出す順序を区別してk個取り出す場合の数 // n<kなら0を返す // 敢えて負数時のデバグはしてない long long P(long long n, long long k) { if (n < k) return 0; long long y = 1; for (long long i = 0; i < k; i++) { y *= (n - i); } return y; } // 組み合わせnCk(検証済み) // P,kaijouと併用 long long C(long long n, long long k) { if (n < k) return 0; return P(n, k) / kaijou(k); } // nHk // 区別しないn個の要素を、区別するk個のグループに分ける // 0個のグループがあっ // て良い // C必須 // 最大公約数GCD,最小公倍数LCM // LCMを使うときはGCDをセットで // 検証済み long long GCD(long long a, long long b) { if (a < b) swap(a, b); long long d = a % b; if (d == 0) { return b; } return GCD(b, d); } long long LCM(long long a, long long b) { return (a / GCD(a, b)) * b; } // 素数判定 // 素数ならばtrue、素数以外の整数にはfalse // 負数は全てfalse // 検証済み bool prime(long long N) { if (N == 1) { return false; } if (N < 0) return false; long long p = sqrt(N); for (long long i = 2; i <= p; i++) { if (N % i == 0) { return false; } } return true; } // ユークリッド距離 // 検証済み // 位置ベクトル1,位置ベクトル2,ベクトルの次元(2または3が一般的) double distance(vector<long long> p, vector<long long> q, long long n) { double x = 0; for (long long i = 0; i < n; i++) { x += pow((p.at(i) - q.at(i)), 2); } return sqrt(x); } // 配列圧縮(検証済) //{1,36,1,3,8,-2,-92}を //{2, 5,2,3,4, 1, 0}にする void press(vector<long long> &v) { long long n = v.size(); vector<long long> w(n); map<long long, long long> m; for (auto &p : v) { m[p] = 0; } long long i = 0; for (auto &p : m) { p.second = i; i++; } for (long long i = 0; i < n; i++) { w.at(i) = m[v.at(i)]; } v = w; return; } // 配列のi番目の要素がj番目に小さいとき、j番目の数がiであるベクトルを返す関数 // 配列の要素が全て異なるときにしか正常に動作しない // 配列の要素に同じものが含まれても見かけ上動作はするが意味のない値を戻し、 // エラーも起きないので注意 // 検証済 //{2,4,1,6,0,3,8,9,5}を //{4,2,0,5,1,8,3,6,7}にして返す //"rank"という名前にするとSTLの関数(配列の次元を返す関数)になるので注意 void ranking(vector<long long> &v) { long long n = v.size(); map<long long, long long> m; long long i; for (i = 0; i < n; i++) { m[v.at(i)] = i; } vector<long long> w(n); i = 0; for (auto &p : m) { v.at(i) = p.second; i++; } return; } // 部分削除(未検証) // ベクトルのi番目(i=0,1,2,...,n-1)の要素を削除し、 // 以降の要素を全て前に1ずらして参照返し // ベクトル長は1小さくなって返る // i>n-1の時は変化しない void erase(vector<long long> &v, long long i) { long long n = v.size(); if (i > n - 1) return; for (long long j = i; j < n - 1; j++) { v.at(j) = v.at(j + 1); } v.pop_back(); return; } // 重複削除(未完成) // 引数ベクトルに同一要素が複数あるとき、先頭を残し他は削除 // 参照返し // ベクトル長も変化する // O(logn)くらい void unique(vector<long long> &v) { long long n = v.size(); set<long long> s; long long i = 0; while (i < n) { if (s.count(v.at(i))) { erase(v, i); n--; } else { s.insert(v.at(i)); i++; } } return; } // ベクトルの出力(検証済) // debug用にvectorの中身を出力する void printv(vector<long long> v) { cout << "{ "; for (auto &p : v) { cout << p << ","; } cout << "}" << endl; } // 10進法でn桁の整数xに対して、大きい方の位から、その位の1桁の数字を // 収納した長さnのベクトルを返す // 0に対しては{0}を返す // 検証済み vector<ll> keta(ll x) { if (x == 0) return {0}; ll n = log10(x) + 1; // xの桁数 vll w(n, 0); for (ll i = 0; i < n; i++) { ll p; p = x % 10; x = x / 10; w[n - 1 - i] = p; } return w; } // 20200415 // a^n mod を計算する long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // a^{-1} mod を計算する // modとaが互いに素のときのみ有効(数学的に逆元が一意に定まるのがそのときのみ) long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); } // 整数n個の入力を受け取ってベクトルに突っ込んで返す // チェック済み vector<long long> inputv(long long n) { vector<long long> v(n); for (long long i = 0; i < n; i++) { cin >> v[i]; } return v; } vector<long long> yakusuu(long long n) // nの約数を列挙 { vector<long long> ret; for (long long i = 1; i <= sqrt(n); ++i) { if (n % i == 0) { ret.push_back(i); if (i * i != n) { ret.push_back(n / i); } } } sort(ret.begin(), ret.end()); return ret; } map<long long, long long> soinsuu(long long n) { map<long long, long long> m; long long p = sqrt(n); while (n % 2 == 0) { n /= 2; if (m.count(2)) { m[2]++; } else { m[2] = 1; } } for (long long i = 3; i * i <= n; i += 2) { while (n % i == 0) { n /= i; if (m.count(i)) { m[i]++; } else { m[i] = 1; } } } if (n != 1) m[n] = 1; return m; } // スタートが(i,j)の迷路の全ての地点までの距離を幅優先探索で解く // スタートから何マス離れているか(辿り着けない場合は-1)を入れたベクトルを返す // 壁からスタートしても正常に動作するので注意(この関数の外で処理が必要) // 検証済み 一応O(地図の広さ)くらい vector<vector<long long>> maze(ll i, ll j, vector<string> &s) { ll h = s.size(); ll w = s[0].size(); queue<vector<long long>> q; vector<vector<long long>> dis(h, vll(w, -1)); q.push({i, j}); dis[i][j] = 0; while (!q.empty()) { auto v = q.front(); q.pop(); if (v[0] > 0 && s[v[0] - 1][v[1]] == '.' && dis[v[0] - 1][v[1]] == -1) { dis[v[0] - 1][v[1]] = dis[v[0]][v[1]] + 1; q.push({v[0] - 1, v[1]}); } if (v[1] > 0 && s[v[0]][v[1] - 1] == '.' && dis[v[0]][v[1] - 1] == -1) { dis[v[0]][v[1] - 1] = dis[v[0]][v[1]] + 1; q.push({v[0], v[1] - 1}); } if (v[0] < h - 1 && s[v[0] + 1][v[1]] == '.' && dis[v[0] + 1][v[1]] == -1) { dis[v[0] + 1][v[1]] = dis[v[0]][v[1]] + 1; q.push({v[0] + 1, v[1]}); } if (v[1] < w - 1 && s[v[0]][v[1] + 1] == '.' && dis[v[0]][v[1] + 1] == -1) { dis[v[0]][v[1] + 1] = dis[v[0]][v[1]] + 1; q.push({v[0], v[1] + 1}); } } return dis; // スタートから何マス離れているか(辿り着けない場合は-1) } // エラトステネスのふるいによりn以下の素数を全てベクトルに入れて返す // vector<long long> eratos(long long n){ // } // 二項係数の剰余を求める // 引数は剰余の形ではなくもとの数そのものである // 未検証(検証サンプルがない) long long modC(long long n, long long k, long long mod) { if (n < k) return 0; long long p = 1, q = 1; for (long long i = 0; i < k; i++) { p = p * (n - i) % mod; q = q * (i + 1) % mod; } return p * modinv(q, mod) % mod; } // 20200418 // 整数のとき限定の普通のPOW関数 // 標準機能のpow(a,n)は整数だとバグるのでこちらを使う long long POW(long long a, long long n) { long long res = 1; while (n > 0) { if (n & 1) res = res * a; a = a * a; n >>= 1; } return res; } // 20200423 // エラトステネスのふるいによりn以下の素数を全てベクトルに入れて返す vector<long long> eratos(long long n) { if (n < 2) return {}; vll v(n - 1); rep(i, n - 1) { v[i] = i + 2; // 2からnまで } ll i = 0; while (i < n - 1) { ll p = v[i]; for (ll j = i + 1; j < n - 1; j++) { if (v[j] % p == 0) { v.erase(v.begin() + j); n--; } } i++; } v.resize(n - 1); return v; } // n以下の素数を全て詰めたset set<long long> eraset(long long n) { set<long long> s; vll v = eratos(n); for (auto &t : v) { s.insert(t); } return s; } // 20200428 //(x1,y1),(x2,y2)を通る直線をax+by+c=0としたとき //{a,b,c}を返す vll line(ll x1, ll y1, ll x2, ll y2) { vector<ll> v(3); v[0] = y1 - y2; v[1] = x2 - x1; v[2] = -x1 * (y1 - y2) + y1 * (x1 - x2); return v; } //(x,y)とv[0]x+v[1]y+v[2]=0との距離 double dis(vll v, ll x, ll y) { double s = sqrt(v[0] * v[0] + v[1] * v[1]); return (double)abs(v[0] * x + v[1] * y + v[2]) / s; } // 20200502 void maxin(ll &a, ll b) { a = max(a, b); return; } void minin(ll &a, ll b) { a = min(a, b); return; } // 20200506 map<long long, long long> countv(vll v) { map<long long, long long> m; for (auto &g : v) { if (m.count(g)) m[g]++; else m[g] = 1; } return m; } // nCk modを求める const ll MAX = 510000; // この値は求める二項計数の値に応じて変える // MAX=3*10^7のとき1900msほど、ほぼ比例 // MAX=5*10^6程度ならそれほど気にしなくてよい(300ms程) long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void cominit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } // 二項係数計算 long long commod(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } // 順列計算 long long pmod(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * finv[n - k] % mod; } /* next combination */ // 次の組み合わせをbitで返す // 全探索のloopに使える long long next_combination(long long sub) { long long x = sub & -sub, y = sub + x; return (((sub & ~y) / x) >> 1) | y; } // 20200617 void warshall(vector<vector<long long>> &v) { ll n = v.size(); rep(i, n) { rep(j, n) { rep(k, n) { // cout << i << " " << j << " " << k << "\n"; // cout << v[j][k] << " " << v[j][i] << " " << v[i][k] << "\n\n"; v[j][k] = min(v[j][k], v[j][i] + v[i][k]); } } } return; } // 20200626 vvll comb(100, vll(100, -1)); long long com(long long n, long long k) { if (n < 0 || k < 0) return -1; if (n < k) return comb[n][k] = 0; if (comb[n][k] != -1) return comb[n][k]; ll res; if (n - k < k) res = com(n, n - k); else if (k == 0) res = 1; else res = com(n - 1, k - 1) + com(n - 1, k); comb[n][k] = res; return res; } long long com2(long long n, long long k) { if (n < 0 || k < 0) return -1; if (n < k) return comb[n][k] = 0; ll res; if (n - k < k) res = com(n, n - k); else if (k == 0) res = 1; else res = com(n - 1, k - 1) + com(n - 1, k); return res; } void comset() { rep(i, 100) rep(j, 100) com(i, j); } // 20200709 string bits(long long n, long long k) { // nをk桁のbitで表示したstringを返す string s = ""; rep(i, k) { char c = '0' + (n % 2); s += c; n /= 2; } reverse(all(s)); return s; } ////////////////////////////////////////// struct UF { // サイズが測れるUF vector<long long> par, size; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 // sizeはiを根とする木のサイズ UF(long long N) : par(N), size(N) { // 最初は全てが根であるとして初期化 for (long long i = 0; i < N; i++) { par[i] = i; size[i] = 1; } } long long root( long long x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(long long x, long long y) { // xとyの木を併合 long long rx = root(x); // xの根をrx long long ry = root(y); // yの根をry if (rx == ry) return; // xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける size[ry] += size[rx]; size[rx] = 0; // サイズの処理 根じゃなくなったらサイズは0になる } bool same(long long x, long long y) { // 2つのデータx, yが属する木が同じならtrueを返す long long rx = root(x); long long ry = root(y); return rx == ry; } }; // auto mod int // https://youtu.be/L8grWxBlIZ4?t=9858 // https://youtu.be/ERZuLAxZffQ?t=4807 : optimize // https://youtu.be/8uowVvQ_-Mo?t=1329 : division 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; } void debug(ll &a) { cout << a << endl; } void debug(vll &a) { cout << "debug vector" << endl; cout << "{ "; for (auto t : a) { cout << t << ","; } cout << " }" << endl; cout << "debug finished" << endl; } void debug(set<long long> &a) { cout << "debug set" << endl; for (auto t : a) { cout << t << endl; } cout << "debug finished" << endl; } void debug(map<long long, long long> a) { cout << "debug map" << endl; for (auto t : a) { cout << t.first << " " << t.second << endl; } cout << "debug finished" << endl; } void debug(queue<long long> a) { cout << "debug queue" << endl; while (!a.empty()) { ll t = a.front(); a.pop(); cout << t << endl; } cout << "debug finished" << endl; } // 20200604 struct STmax { // 最大値を測るセグ木 ll size; // treeの葉の数=m*2-1 ll m; // tree最下段の数 vector<long long> seg; STmax(long long n) : size(n), m(n), seg(0) { m = 1; while (m < n) { m *= 2; } size = m * 2 - 1; rep(i, size) { seg.push_back(-99999999977); } } // ここまで共通 // minの場合はpush_backの値をdekaiにする? void update(ll i, ll k) { // i番目をkに更新 ll v = i + m - 1; seg[v] = k; while (v > 0) { v = (v - 1) / 2; seg[v] = max(seg[v * 2 + 1], seg[v * 2 + 2]); } } ll query(ll a, ll b, ll k, ll l, ll r) { // 区間[a,b)での最大値を求める if (r <= a || b <= l) return -99999999977; if (a <= l && r <= b) return seg[k]; // cout << "#" << a << " " << b << " " << k << " " << l << " " << r << endl; ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2); ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return max(vl, vr); } ll largest(ll a, ll b) { if (a >= b) return -99999999977; return query(a, b, 0, 0, m); } }; struct STmin { // 最小値を測るセグ木 ll size; // treeの葉の数=m*2-1 ll m; // tree最下段の数 vector<long long> seg; STmin(long long n) : size(n), m(n), seg(0) { m = 1; while (m < n) { m *= 2; } size = m * 2 - 1; rep(i, size) { seg.push_back(99999999977); } } // ここまで共通 // minの場合はpush_backの値をdekaiにする? void update(ll i, ll k) { // i番目をkに更新 ll v = i + m - 1; seg[v] = k; while (v > 0) { v = (v - 1) / 2; seg[v] = min(seg[v * 2 + 1], seg[v * 2 + 2]); } } ll query(ll a, ll b, ll k, ll l, ll r) { // 区間[a,b)での最大値を求める if (r <= a || b <= l) return 99999999977; if (a <= l && r <= b) return seg[k]; // cout << "#" << a << " " << b << " " << k << " " << l << " " << r << endl; ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2); ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return min(vl, vr); } ll smallest(ll a, ll b) { if (a >= b) return 99999999977; return query(a, b, 0, 0, m); } }; struct STsum { // 区間の合計値を測るセグ木 ll size; // treeの葉の数=m*2-1 ll m; // tree最下段の数 vector<long long> seg; STsum(long long n) : size(n), m(n), seg(0) { m = 1; while (m < n) { m *= 2; } size = m * 2 - 1; rep(i, size) { seg.push_back(0); } // 改造時はここをまず変える } // ここまで共通 // minの場合はpush_backの値をdekaiにする void update(ll i, ll k) { // i番目をkに更新 ll v = i + m - 1; seg[v] = k; while (v > 0) { v = (v - 1) / 2; seg[v] = seg[v * 2 + 1] + seg[v * 2 + 2]; // 改造時はここを変える } } ll query(ll a, ll b, ll k, ll l, ll r) { // 区間[a,b)での最大値を求める if (r <= a || b <= l) return 0; if (a <= l && r <= b) return seg[k]; // cout << "#" << a << " " << b << " " << k << " " << l << " " << r << endl; ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2); ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return vl + vr; // 改造時はここを変える } ll sum(ll a, ll b) { if (a >= b) return 0; return query(a, b, 0, 0, m); } }; ////////////////////////////////////////////// // // 多倍長テンプレ // /* ---------------------- ここから ---------------------- */ // #include <boost/multiprecision/cpp_dec_float.hpp> // #include <boost/multiprecision/cpp_int.hpp> // namespace mp = boost::multiprecision; // // 任意長整数型 // using Bint = mp::cpp_int; // // 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする) // using Real = mp::number<mp::cpp_dec_float<1024>>; // /* ---------------------- ここまで ---------------------- */ // ll const mod=1e9+7; ll const dekai = 922645807; // POW(2,63)-1.素数. ll dx[4] = {-1, 0, 1, 0}; ll dy[4] = {0, -1, 0, 1}; ll ddx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}; ll ddy[8] = {-1, 0, 1, -1, 1, -1, 0, 1}; // cout<<fixed<<setprecision(10); #define ednl endl #define endk endl #define enld endl ////////////////////////////////////////////////// ll n; vll ans; using t = pair<pll, ll>; vector<t> a; vll dist; void sol(ll num, ll tate, ll yoko) { if (num == n) { ll res = 0; rep(i, n) { res += dist[i] * a[i].second; } minin(ans[tate + yoko], res); return; } sol(num + 1, tate, yoko); auto dist2 = dist; rep(i, n) { minin(dist[i], abs(a[i].first.first - a[num].first.first)); } sol(num + 1, tate + 1, yoko); dist = dist2; rep(i, n) { minin(dist[i], abs(a[i].first.second - a[num].first.second)); } sol(num + 1, tate, yoko + 1); dist = dist2; return; } int main() { cin >> n; ans.resize(n, 10000000000LL); a.resize(n); dist.resize(n); rep(i, n) { ll b, c, d; cin >> b >> c >> d; a[i] = {{b, c}, d}; } rep(i, n) { dist[i] = min(abs(a[i].first.first), abs(a[i].first.second)); } sol(0LL, 0LL, 0LL); rep(i, n) cout << ans[i] << endl; cout << 0 << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (long long i = 0; i < n; i++) #define Rep(i, m, n) for (long long i = m; i < n; i++) #define REP(i, m, n, p) for (long long i = m; i < n; i += p) #define all(v) v.begin(), v.end() #define pq priority_queue #define bcnt(n) __builtin_popcountll(n) const int mod = 1000000007; // const int mod = 998244353; using vi = vector<int>; // intの1次元の型に vi という別名をつける using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける using vvvi = vector<vvi>; using ll = long long; // long longをllだけにした using vll = vector<ll>; using vvll = vector<vll>; using vvvll = vector<vvll>; using vb = vector<bool>; using vvb = vector<vb>; using mii = map<int, int>; using pqll = priority_queue<long long>; using pqllg = priority_queue<long long, vector<long long>, greater<long long>>; using mll = map<long long, long long>; using pll = pair<long long, long long>; using sll = set<long long>; using vpll = vector<pair<long long, long long>>; using mlv = map<long long, vector<long long>>; long long divup(long long a, long long b); long long kaijou(long long i); long long P(long long n, long long k); long long C(long long n, long long k); long long GCD(long long a, long long b); long long LCM(long long a, long long b); bool prime(long long N); double distance(vector<long long> p, vector<long long> q, long long n); void press(vector<long long> &v); void ranking(vector<long long> &v); void erase(vector<long long> &v, long long i); void unique(vector<long long> &v); void printv(vector<long long> v); vector<long long> keta(ll x); long long modpow(long long a, long long n, long long mod); long long modinv(long long a, long long mod); // 20200416 vector<long long> inputv(long long n); // 20200417 vector<long long> yakusuu(int n); map<long long, long long> soinsuu(long long n); vector<vector<long long>> maze(long long i, long long j, vector<string> &s); // 20200423 vector<long long> eratos(long long n); set<long long> eraset(long long n); ////////////////////////////////////////////////////// // 端数繰りあがり割り算(検証済) // a÷bの端数繰り上げ // b!=0のデバグはしてないので分母に0を入れないように // 負数対応 long long divup(long long a, long long b) { long long x = abs(a); long long y = abs(b); long long z = (x + y - 1) / y; if ((a < 0 && b > 0) || (a > 0 && b < 0)) return -z; else if (a == 0) return 0; else return z; } // 階乗 // 検証済み long long kaijou(long long i) { if (i == 0) return 1; long long j = 1; for (long long k = 1; k <= i; k++) { j *= k; } return j; } // 順列nPk(完成) // n個の異なる要素から、取り出す順序を区別してk個取り出す場合の数 // n<kなら0を返す // 敢えて負数時のデバグはしてない long long P(long long n, long long k) { if (n < k) return 0; long long y = 1; for (long long i = 0; i < k; i++) { y *= (n - i); } return y; } // 組み合わせnCk(検証済み) // P,kaijouと併用 long long C(long long n, long long k) { if (n < k) return 0; return P(n, k) / kaijou(k); } // nHk // 区別しないn個の要素を、区別するk個のグループに分ける // 0個のグループがあっ // て良い // C必須 // 最大公約数GCD,最小公倍数LCM // LCMを使うときはGCDをセットで // 検証済み long long GCD(long long a, long long b) { if (a < b) swap(a, b); long long d = a % b; if (d == 0) { return b; } return GCD(b, d); } long long LCM(long long a, long long b) { return (a / GCD(a, b)) * b; } // 素数判定 // 素数ならばtrue、素数以外の整数にはfalse // 負数は全てfalse // 検証済み bool prime(long long N) { if (N == 1) { return false; } if (N < 0) return false; long long p = sqrt(N); for (long long i = 2; i <= p; i++) { if (N % i == 0) { return false; } } return true; } // ユークリッド距離 // 検証済み // 位置ベクトル1,位置ベクトル2,ベクトルの次元(2または3が一般的) double distance(vector<long long> p, vector<long long> q, long long n) { double x = 0; for (long long i = 0; i < n; i++) { x += pow((p.at(i) - q.at(i)), 2); } return sqrt(x); } // 配列圧縮(検証済) //{1,36,1,3,8,-2,-92}を //{2, 5,2,3,4, 1, 0}にする void press(vector<long long> &v) { long long n = v.size(); vector<long long> w(n); map<long long, long long> m; for (auto &p : v) { m[p] = 0; } long long i = 0; for (auto &p : m) { p.second = i; i++; } for (long long i = 0; i < n; i++) { w.at(i) = m[v.at(i)]; } v = w; return; } // 配列のi番目の要素がj番目に小さいとき、j番目の数がiであるベクトルを返す関数 // 配列の要素が全て異なるときにしか正常に動作しない // 配列の要素に同じものが含まれても見かけ上動作はするが意味のない値を戻し、 // エラーも起きないので注意 // 検証済 //{2,4,1,6,0,3,8,9,5}を //{4,2,0,5,1,8,3,6,7}にして返す //"rank"という名前にするとSTLの関数(配列の次元を返す関数)になるので注意 void ranking(vector<long long> &v) { long long n = v.size(); map<long long, long long> m; long long i; for (i = 0; i < n; i++) { m[v.at(i)] = i; } vector<long long> w(n); i = 0; for (auto &p : m) { v.at(i) = p.second; i++; } return; } // 部分削除(未検証) // ベクトルのi番目(i=0,1,2,...,n-1)の要素を削除し、 // 以降の要素を全て前に1ずらして参照返し // ベクトル長は1小さくなって返る // i>n-1の時は変化しない void erase(vector<long long> &v, long long i) { long long n = v.size(); if (i > n - 1) return; for (long long j = i; j < n - 1; j++) { v.at(j) = v.at(j + 1); } v.pop_back(); return; } // 重複削除(未完成) // 引数ベクトルに同一要素が複数あるとき、先頭を残し他は削除 // 参照返し // ベクトル長も変化する // O(logn)くらい void unique(vector<long long> &v) { long long n = v.size(); set<long long> s; long long i = 0; while (i < n) { if (s.count(v.at(i))) { erase(v, i); n--; } else { s.insert(v.at(i)); i++; } } return; } // ベクトルの出力(検証済) // debug用にvectorの中身を出力する void printv(vector<long long> v) { cout << "{ "; for (auto &p : v) { cout << p << ","; } cout << "}" << endl; } // 10進法でn桁の整数xに対して、大きい方の位から、その位の1桁の数字を // 収納した長さnのベクトルを返す // 0に対しては{0}を返す // 検証済み vector<ll> keta(ll x) { if (x == 0) return {0}; ll n = log10(x) + 1; // xの桁数 vll w(n, 0); for (ll i = 0; i < n; i++) { ll p; p = x % 10; x = x / 10; w[n - 1 - i] = p; } return w; } // 20200415 // a^n mod を計算する long long modpow(long long a, long long n, long long mod) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } // a^{-1} mod を計算する // modとaが互いに素のときのみ有効(数学的に逆元が一意に定まるのがそのときのみ) long long modinv(long long a, long long mod) { return modpow(a, mod - 2, mod); } // 整数n個の入力を受け取ってベクトルに突っ込んで返す // チェック済み vector<long long> inputv(long long n) { vector<long long> v(n); for (long long i = 0; i < n; i++) { cin >> v[i]; } return v; } vector<long long> yakusuu(long long n) // nの約数を列挙 { vector<long long> ret; for (long long i = 1; i <= sqrt(n); ++i) { if (n % i == 0) { ret.push_back(i); if (i * i != n) { ret.push_back(n / i); } } } sort(ret.begin(), ret.end()); return ret; } map<long long, long long> soinsuu(long long n) { map<long long, long long> m; long long p = sqrt(n); while (n % 2 == 0) { n /= 2; if (m.count(2)) { m[2]++; } else { m[2] = 1; } } for (long long i = 3; i * i <= n; i += 2) { while (n % i == 0) { n /= i; if (m.count(i)) { m[i]++; } else { m[i] = 1; } } } if (n != 1) m[n] = 1; return m; } // スタートが(i,j)の迷路の全ての地点までの距離を幅優先探索で解く // スタートから何マス離れているか(辿り着けない場合は-1)を入れたベクトルを返す // 壁からスタートしても正常に動作するので注意(この関数の外で処理が必要) // 検証済み 一応O(地図の広さ)くらい vector<vector<long long>> maze(ll i, ll j, vector<string> &s) { ll h = s.size(); ll w = s[0].size(); queue<vector<long long>> q; vector<vector<long long>> dis(h, vll(w, -1)); q.push({i, j}); dis[i][j] = 0; while (!q.empty()) { auto v = q.front(); q.pop(); if (v[0] > 0 && s[v[0] - 1][v[1]] == '.' && dis[v[0] - 1][v[1]] == -1) { dis[v[0] - 1][v[1]] = dis[v[0]][v[1]] + 1; q.push({v[0] - 1, v[1]}); } if (v[1] > 0 && s[v[0]][v[1] - 1] == '.' && dis[v[0]][v[1] - 1] == -1) { dis[v[0]][v[1] - 1] = dis[v[0]][v[1]] + 1; q.push({v[0], v[1] - 1}); } if (v[0] < h - 1 && s[v[0] + 1][v[1]] == '.' && dis[v[0] + 1][v[1]] == -1) { dis[v[0] + 1][v[1]] = dis[v[0]][v[1]] + 1; q.push({v[0] + 1, v[1]}); } if (v[1] < w - 1 && s[v[0]][v[1] + 1] == '.' && dis[v[0]][v[1] + 1] == -1) { dis[v[0]][v[1] + 1] = dis[v[0]][v[1]] + 1; q.push({v[0], v[1] + 1}); } } return dis; // スタートから何マス離れているか(辿り着けない場合は-1) } // エラトステネスのふるいによりn以下の素数を全てベクトルに入れて返す // vector<long long> eratos(long long n){ // } // 二項係数の剰余を求める // 引数は剰余の形ではなくもとの数そのものである // 未検証(検証サンプルがない) long long modC(long long n, long long k, long long mod) { if (n < k) return 0; long long p = 1, q = 1; for (long long i = 0; i < k; i++) { p = p * (n - i) % mod; q = q * (i + 1) % mod; } return p * modinv(q, mod) % mod; } // 20200418 // 整数のとき限定の普通のPOW関数 // 標準機能のpow(a,n)は整数だとバグるのでこちらを使う long long POW(long long a, long long n) { long long res = 1; while (n > 0) { if (n & 1) res = res * a; a = a * a; n >>= 1; } return res; } // 20200423 // エラトステネスのふるいによりn以下の素数を全てベクトルに入れて返す vector<long long> eratos(long long n) { if (n < 2) return {}; vll v(n - 1); rep(i, n - 1) { v[i] = i + 2; // 2からnまで } ll i = 0; while (i < n - 1) { ll p = v[i]; for (ll j = i + 1; j < n - 1; j++) { if (v[j] % p == 0) { v.erase(v.begin() + j); n--; } } i++; } v.resize(n - 1); return v; } // n以下の素数を全て詰めたset set<long long> eraset(long long n) { set<long long> s; vll v = eratos(n); for (auto &t : v) { s.insert(t); } return s; } // 20200428 //(x1,y1),(x2,y2)を通る直線をax+by+c=0としたとき //{a,b,c}を返す vll line(ll x1, ll y1, ll x2, ll y2) { vector<ll> v(3); v[0] = y1 - y2; v[1] = x2 - x1; v[2] = -x1 * (y1 - y2) + y1 * (x1 - x2); return v; } //(x,y)とv[0]x+v[1]y+v[2]=0との距離 double dis(vll v, ll x, ll y) { double s = sqrt(v[0] * v[0] + v[1] * v[1]); return (double)abs(v[0] * x + v[1] * y + v[2]) / s; } // 20200502 void maxin(ll &a, ll b) { a = max(a, b); return; } void minin(ll &a, ll b) { a = min(a, b); return; } // 20200506 map<long long, long long> countv(vll v) { map<long long, long long> m; for (auto &g : v) { if (m.count(g)) m[g]++; else m[g] = 1; } return m; } // nCk modを求める const ll MAX = 510000; // この値は求める二項計数の値に応じて変える // MAX=3*10^7のとき1900msほど、ほぼ比例 // MAX=5*10^6程度ならそれほど気にしなくてよい(300ms程) long long fac[MAX], finv[MAX], inv[MAX]; // テーブルを作る前処理 void cominit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % mod; inv[i] = mod - inv[mod % i] * (mod / i) % mod; finv[i] = finv[i - 1] * inv[i] % mod; } } // 二項係数計算 long long commod(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % mod) % mod; } // 順列計算 long long pmod(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * finv[n - k] % mod; } /* next combination */ // 次の組み合わせをbitで返す // 全探索のloopに使える long long next_combination(long long sub) { long long x = sub & -sub, y = sub + x; return (((sub & ~y) / x) >> 1) | y; } // 20200617 void warshall(vector<vector<long long>> &v) { ll n = v.size(); rep(i, n) { rep(j, n) { rep(k, n) { // cout << i << " " << j << " " << k << "\n"; // cout << v[j][k] << " " << v[j][i] << " " << v[i][k] << "\n\n"; v[j][k] = min(v[j][k], v[j][i] + v[i][k]); } } } return; } // 20200626 vvll comb(100, vll(100, -1)); long long com(long long n, long long k) { if (n < 0 || k < 0) return -1; if (n < k) return comb[n][k] = 0; if (comb[n][k] != -1) return comb[n][k]; ll res; if (n - k < k) res = com(n, n - k); else if (k == 0) res = 1; else res = com(n - 1, k - 1) + com(n - 1, k); comb[n][k] = res; return res; } long long com2(long long n, long long k) { if (n < 0 || k < 0) return -1; if (n < k) return comb[n][k] = 0; ll res; if (n - k < k) res = com(n, n - k); else if (k == 0) res = 1; else res = com(n - 1, k - 1) + com(n - 1, k); return res; } void comset() { rep(i, 100) rep(j, 100) com(i, j); } // 20200709 string bits(long long n, long long k) { // nをk桁のbitで表示したstringを返す string s = ""; rep(i, k) { char c = '0' + (n % 2); s += c; n /= 2; } reverse(all(s)); return s; } ////////////////////////////////////////// struct UF { // サイズが測れるUF vector<long long> par, size; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2 // sizeはiを根とする木のサイズ UF(long long N) : par(N), size(N) { // 最初は全てが根であるとして初期化 for (long long i = 0; i < N; i++) { par[i] = i; size[i] = 1; } } long long root( long long x) { // データxが属する木の根を再帰で得る:root(x) = {xの木の根} if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(long long x, long long y) { // xとyの木を併合 long long rx = root(x); // xの根をrx long long ry = root(y); // yの根をry if (rx == ry) return; // xとyの根が同じ(=同じ木にある)時はそのまま par[rx] = ry; // xとyの根が同じでない(=同じ木にない)時:xの根rxをyの根ryにつける size[ry] += size[rx]; size[rx] = 0; // サイズの処理 根じゃなくなったらサイズは0になる } bool same(long long x, long long y) { // 2つのデータx, yが属する木が同じならtrueを返す long long rx = root(x); long long ry = root(y); return rx == ry; } }; // auto mod int // https://youtu.be/L8grWxBlIZ4?t=9858 // https://youtu.be/ERZuLAxZffQ?t=4807 : optimize // https://youtu.be/8uowVvQ_-Mo?t=1329 : division 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; } void debug(ll &a) { cout << a << endl; } void debug(vll &a) { cout << "debug vector" << endl; cout << "{ "; for (auto t : a) { cout << t << ","; } cout << " }" << endl; cout << "debug finished" << endl; } void debug(set<long long> &a) { cout << "debug set" << endl; for (auto t : a) { cout << t << endl; } cout << "debug finished" << endl; } void debug(map<long long, long long> a) { cout << "debug map" << endl; for (auto t : a) { cout << t.first << " " << t.second << endl; } cout << "debug finished" << endl; } void debug(queue<long long> a) { cout << "debug queue" << endl; while (!a.empty()) { ll t = a.front(); a.pop(); cout << t << endl; } cout << "debug finished" << endl; } // 20200604 struct STmax { // 最大値を測るセグ木 ll size; // treeの葉の数=m*2-1 ll m; // tree最下段の数 vector<long long> seg; STmax(long long n) : size(n), m(n), seg(0) { m = 1; while (m < n) { m *= 2; } size = m * 2 - 1; rep(i, size) { seg.push_back(-99999999977); } } // ここまで共通 // minの場合はpush_backの値をdekaiにする? void update(ll i, ll k) { // i番目をkに更新 ll v = i + m - 1; seg[v] = k; while (v > 0) { v = (v - 1) / 2; seg[v] = max(seg[v * 2 + 1], seg[v * 2 + 2]); } } ll query(ll a, ll b, ll k, ll l, ll r) { // 区間[a,b)での最大値を求める if (r <= a || b <= l) return -99999999977; if (a <= l && r <= b) return seg[k]; // cout << "#" << a << " " << b << " " << k << " " << l << " " << r << endl; ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2); ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return max(vl, vr); } ll largest(ll a, ll b) { if (a >= b) return -99999999977; return query(a, b, 0, 0, m); } }; struct STmin { // 最小値を測るセグ木 ll size; // treeの葉の数=m*2-1 ll m; // tree最下段の数 vector<long long> seg; STmin(long long n) : size(n), m(n), seg(0) { m = 1; while (m < n) { m *= 2; } size = m * 2 - 1; rep(i, size) { seg.push_back(99999999977); } } // ここまで共通 // minの場合はpush_backの値をdekaiにする? void update(ll i, ll k) { // i番目をkに更新 ll v = i + m - 1; seg[v] = k; while (v > 0) { v = (v - 1) / 2; seg[v] = min(seg[v * 2 + 1], seg[v * 2 + 2]); } } ll query(ll a, ll b, ll k, ll l, ll r) { // 区間[a,b)での最大値を求める if (r <= a || b <= l) return 99999999977; if (a <= l && r <= b) return seg[k]; // cout << "#" << a << " " << b << " " << k << " " << l << " " << r << endl; ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2); ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return min(vl, vr); } ll smallest(ll a, ll b) { if (a >= b) return 99999999977; return query(a, b, 0, 0, m); } }; struct STsum { // 区間の合計値を測るセグ木 ll size; // treeの葉の数=m*2-1 ll m; // tree最下段の数 vector<long long> seg; STsum(long long n) : size(n), m(n), seg(0) { m = 1; while (m < n) { m *= 2; } size = m * 2 - 1; rep(i, size) { seg.push_back(0); } // 改造時はここをまず変える } // ここまで共通 // minの場合はpush_backの値をdekaiにする void update(ll i, ll k) { // i番目をkに更新 ll v = i + m - 1; seg[v] = k; while (v > 0) { v = (v - 1) / 2; seg[v] = seg[v * 2 + 1] + seg[v * 2 + 2]; // 改造時はここを変える } } ll query(ll a, ll b, ll k, ll l, ll r) { // 区間[a,b)での最大値を求める if (r <= a || b <= l) return 0; if (a <= l && r <= b) return seg[k]; // cout << "#" << a << " " << b << " " << k << " " << l << " " << r << endl; ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2); ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r); return vl + vr; // 改造時はここを変える } ll sum(ll a, ll b) { if (a >= b) return 0; return query(a, b, 0, 0, m); } }; ////////////////////////////////////////////// // // 多倍長テンプレ // /* ---------------------- ここから ---------------------- */ // #include <boost/multiprecision/cpp_dec_float.hpp> // #include <boost/multiprecision/cpp_int.hpp> // namespace mp = boost::multiprecision; // // 任意長整数型 // using Bint = mp::cpp_int; // // 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする) // using Real = mp::number<mp::cpp_dec_float<1024>>; // /* ---------------------- ここまで ---------------------- */ // ll const mod=1e9+7; ll const dekai = 922645807; // POW(2,63)-1.素数. ll dx[4] = {-1, 0, 1, 0}; ll dy[4] = {0, -1, 0, 1}; ll ddx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}; ll ddy[8] = {-1, 0, 1, -1, 1, -1, 0, 1}; // cout<<fixed<<setprecision(10); #define ednl endl #define endk endl #define enld endl ////////////////////////////////////////////////// ll n; vll ans; using t = pair<pll, ll>; vector<t> a; vll dist; void sol(ll num, ll tate, ll yoko) { if (num == n) { ll res = 0; rep(i, n) { res += dist[i] * a[i].second; } minin(ans[tate + yoko], res); return; } sol(num + 1, tate, yoko); auto dist2 = dist; rep(i, n) { minin(dist[i], abs(a[i].first.first - a[num].first.first)); } sol(num + 1, tate + 1, yoko); dist = dist2; rep(i, n) { minin(dist[i], abs(a[i].first.second - a[num].first.second)); } sol(num + 1, tate, yoko + 1); dist = dist2; return; } int main() { cin >> n; ans.resize(n + 1, 100000000000000LL); a.resize(n); dist.resize(n); rep(i, n) { ll b, c, d; cin >> b >> c >> d; a[i] = {{b, c}, d}; } rep(i, n) { dist[i] = min(abs(a[i].first.first), abs(a[i].first.second)); } sol(0LL, 0LL, 0LL); rep(i, n) cout << ans[i] << endl; cout << 0 << endl; }
replace
877
878
877
878
-6
free(): invalid pointer
p02604
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; using ll = long long; using P = pair<int, int>; const ll INF = 1LL << 62; int main() { ll n; cin >> n; vector<ll> x(n), y(n), p(n); rep(i, n) cin >> x[i] >> y[i] >> p[i]; vector<vector<ll>> xsel(1 << n, vector<ll>(n)); vector<vector<ll>> ysel(1 << n, vector<ll>(n)); rep(i, 1 << n) { rep(j, n) { xsel[i][j] = abs(x[j]); ysel[i][j] = abs(y[j]); rep(k, n) { if ((i >> k) & 1) { xsel[i][j] = min(xsel[i][j], abs(x[j] - x[k])); ysel[i][j] = min(ysel[i][j], abs(y[j] - y[k])); } } } } vector<ll> ans(n + 1, INF); rep(i, pow(3, n)) { int info = i; vector<vector<int>> state(3); // 0: x train, 1: y train, 2: no train rep(j, n) state[info % 3].push_back(j), info /= 3; int xi = 0, yi = 0; for (auto a : state[0]) xi += pow(2, a); for (auto a : state[1]) yi += pow(2, a); ll cost = 0; for (auto k : state[2]) cost += 1LL * min(xsel[xi][k], ysel[yi][k]) * p[k]; int cnt = state[0].size() + state[1].size(); ans[cnt] = min(ans[cnt], cost); } for (ll i = 0; i <= n; i++) cout << ans[i] << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; using ll = long long; using P = pair<int, int>; const ll INF = 1LL << 62; int main() { ll n; cin >> n; vector<ll> x(n), y(n), p(n); rep(i, n) cin >> x[i] >> y[i] >> p[i]; vector<vector<ll>> xsel(1 << n, vector<ll>(n)); vector<vector<ll>> ysel(1 << n, vector<ll>(n)); rep(i, 1 << n) { rep(j, n) { xsel[i][j] = abs(x[j]); ysel[i][j] = abs(y[j]); rep(k, n) { if ((i >> k) & 1) { xsel[i][j] = min(xsel[i][j], abs(x[j] - x[k])); ysel[i][j] = min(ysel[i][j], abs(y[j] - y[k])); } } } } vector<ll> ans(n + 1, INF); rep(i, 1 << n) { ll cnt = __builtin_popcount(i); for (ll j = i; j >= 0; j--) { j &= i; ll cost = 0; rep(k, n) { if (!((i >> k) & 1)) { cost += 1LL * min(xsel[j][k], ysel[i - j][k]) * p[k]; } } ans[cnt] = min(ans[cnt], cost); } } for (ll i = 0; i <= n; i++) cout << ans[i] << endl; }
replace
30
47
30
42
TLE
p02604
C++
Time Limit Exceeded
// #include <cstdio> #include <algorithm> #include <iostream> #include <map> #include <set> #include <string> #include <vector> // #include <queue> // #include <stack> #include <cassert> #include <cstring> #include <cstdlib> using namespace std; #ifdef LOCAL_DEBUG #include <local_debug.h> #define DEBUG(...) DBG2::print(#__VA_ARGS__, __LINE__, __VA_ARGS__) #else #define DEBUG(...) #endif #define SZ(a) int((a).size()) #define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i) #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) typedef long long llong; typedef vector<int> VI; typedef vector<VI> VVI; int N; int X[15], Y[15], P[15]; const llong INF = 1e18; inline int nearest_dist(int k, int V[], int pos) { int dist = 2000000001; /* int j = lower_bound(V, V+k, pos) - V; if (j < k) dist = min(dist, V[j]-pos); if (j > 0) dist = min(dist, pos-V[j-1]); */ for (int i = 0; i < k; ++i) { int d = abs(pos - V[i]); if (dist > d) dist = d; } return dist; } int main(int argc, char *argv[]) { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> N; REP(i, N) cin >> X[i] >> Y[i] >> P[i]; /* srand(123); for (int i = N-1; i > 0; --i) { int j = rand() % (i+1); if (i != j) { swap(X[i], X[j]); swap(Y[i], Y[j]); swap(P[i], P[j]); } } */ int P3 = 1; for (int n = 1; n <= N; ++n) P3 *= 3; llong ans[16]; FOR(k, 0, N) ans[k] = INF; int Vx[16], Vy[16]; REP(mask, P3) { int kx = 1, ky = 1; Vx[0] = 0, Vy[0] = 0; for (int m = mask, i = 0; i < N; ++i) { switch (m % 3) { case 1: Vx[kx++] = X[i]; break; case 2: Vy[ky++] = Y[i]; break; } m /= 3; } sort(Vx, Vx + kx); sort(Vy, Vy + ky); int k = (kx - 1) + (ky - 1); llong cost = 0; REP(i, N) { int distx = nearest_dist(kx, Vx, X[i]); int disty = nearest_dist(ky, Vy, Y[i]); cost += min(distx, disty) * 1LL * P[i]; if (ans[k] <= cost) break; } if (ans[k] > cost) { ans[k] = cost; FOR(kk, k, N) { if (ans[kk] <= ans[k]) break; ans[kk] = ans[k]; } } } FOR(k, 0, N) cout << ans[k] << '\n'; return 0; }
// #include <cstdio> #include <algorithm> #include <iostream> #include <map> #include <set> #include <string> #include <vector> // #include <queue> // #include <stack> #include <cassert> #include <cstring> #include <cstdlib> using namespace std; #ifdef LOCAL_DEBUG #include <local_debug.h> #define DEBUG(...) DBG2::print(#__VA_ARGS__, __LINE__, __VA_ARGS__) #else #define DEBUG(...) #endif #define SZ(a) int((a).size()) #define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i) #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) typedef long long llong; typedef vector<int> VI; typedef vector<VI> VVI; int N; int X[15], Y[15], P[15]; const llong INF = 1e18; inline int nearest_dist(int k, int V[], int pos) { int dist = 2000000001; /* int j = lower_bound(V, V+k, pos) - V; if (j < k) dist = min(dist, V[j]-pos); if (j > 0) dist = min(dist, pos-V[j-1]); */ for (int i = 0; i < k; ++i) { int d = abs(pos - V[i]); if (dist > d) dist = d; } return dist; } int main(int argc, char *argv[]) { ios_base::sync_with_stdio(false); cin.tie(nullptr); cin >> N; REP(i, N) cin >> X[i] >> Y[i] >> P[i]; /* srand(123); for (int i = N-1; i > 0; --i) { int j = rand() % (i+1); if (i != j) { swap(X[i], X[j]); swap(Y[i], Y[j]); swap(P[i], P[j]); } } */ int P3 = 1; for (int n = 1; n <= N; ++n) P3 *= 3; llong ans[16]; FOR(k, 0, N) ans[k] = INF; int Vx[16], Vy[16]; REP(mask, P3) { int kx = 1, ky = 1; Vx[0] = 0, Vy[0] = 0; for (int m = mask, i = 0; i < N; ++i) { switch (m % 3) { case 1: Vx[kx++] = X[i]; break; case 2: Vy[ky++] = Y[i]; break; } m /= 3; } // sort(Vx, Vx+kx); // sort(Vy, Vy+ky); int k = (kx - 1) + (ky - 1); llong cost = 0; REP(i, N) { int distx = nearest_dist(kx, Vx, X[i]); int disty = nearest_dist(ky, Vy, Y[i]); cost += min(distx, disty) * 1LL * P[i]; if (ans[k] <= cost) break; } if (ans[k] > cost) { ans[k] = cost; FOR(kk, k, N) { if (ans[kk] <= ans[k]) break; ans[kk] = ans[k]; } } } FOR(k, 0, N) cout << ans[k] << '\n'; return 0; }
replace
100
102
100
102
TLE
p02604
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define R cin >> #define ll long long #define ln cout << '\n' #define in(a) insert(a) #define pb(a) push_back(a) #define pd(a) printf("%.10f\n", a) #define mem(a) memset(a, 0, sizeof(a)) #define all(c) (c).begin(), (c).end() #define iter(c) __typeof((c).begin()) #define rrep(i, n) for (ll i = (ll)(n)-1; i >= 0; i--) #define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++) #define rep(i, n) REP(i, 0, n) #define tr(it, c) for (iter(c) it = (c).begin(); it != (c).end(); it++) ll check(ll n, ll m, ll x, ll y) { return x >= 0 && x < n && y >= 0 && y < m; } void pr() { ln; } template <class A, class... B> void pr(const A &a, const B &...b) { cout << a << (sizeof...(b) ? " " : ""); pr(b...); } template <class A> void PR(A a, ll n) { rep(i, n) cout << (i ? " " : "") << a[i]; ln; } const ll MAX = 1e9 + 7, MAXL = 1LL << 61, dx[8] = {-1, 0, 1, 0, -1, -1, 1, 1}, dy[8] = {0, 1, 0, -1, -1, 1, 1, -1}; typedef pair<ll, ll> P; typedef pair<P, ll> PP; void Main() { ll n; R n; PP a[n]; rep(i, n) cin >> a[i].F.F >> a[i].F.S >> a[i].S; ll ans[n + 1]; rep(i, n + 1) ans[i] = MAXL; vector<P> v; rep(i, n) { v.pb(P(a[i].F.F, 0)); v.pb(P(a[i].F.S, 1)); } v.pb(P(0, 0)); v.pb(P(0, 1)); ll d[n][v.size()]; vector<P> b[n]; rep(i, n) { rep(j, v.size()) { if (v[j].S == 0) d[i][j] = abs(a[i].F.F - v[j].F) * a[i].S; else d[i][j] = abs(a[i].F.S - v[j].F) * a[i].S; } rep(j, v.size()) b[i].pb(P(d[i][j], j)); sort(all(b[i])); } rep(t, pow(3, n)) { bitset<33> e; ll r = t, c = 0; rep(i, n) { if (r % 3 == 1) e.set(i * 2), c++; else if (r % 3 == 2) e.set(i * 2 + 1), c++; r /= 3; } e.set(n * 2); e.set(n * 2 + 1); ll sum = 0; rep(i, n) { ll M = MAXL; rep(j, b[i].size()) { if (e.test(b[i][j].S)) { M = d[i][b[i][j].S]; break; } } sum += M; if (sum > ans[c]) goto next; } ans[c] = min(ans[c], sum); next:; } rep(i, n + 1) pr(ans[i]); } int main() { ios::sync_with_stdio(0); cin.tie(0); Main(); return 0; }
#include <bits/stdc++.h> using namespace std; #define F first #define S second #define R cin >> #define ll long long #define ln cout << '\n' #define in(a) insert(a) #define pb(a) push_back(a) #define pd(a) printf("%.10f\n", a) #define mem(a) memset(a, 0, sizeof(a)) #define all(c) (c).begin(), (c).end() #define iter(c) __typeof((c).begin()) #define rrep(i, n) for (ll i = (ll)(n)-1; i >= 0; i--) #define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++) #define rep(i, n) REP(i, 0, n) #define tr(it, c) for (iter(c) it = (c).begin(); it != (c).end(); it++) ll check(ll n, ll m, ll x, ll y) { return x >= 0 && x < n && y >= 0 && y < m; } void pr() { ln; } template <class A, class... B> void pr(const A &a, const B &...b) { cout << a << (sizeof...(b) ? " " : ""); pr(b...); } template <class A> void PR(A a, ll n) { rep(i, n) cout << (i ? " " : "") << a[i]; ln; } const ll MAX = 1e9 + 7, MAXL = 1LL << 61, dx[8] = {-1, 0, 1, 0, -1, -1, 1, 1}, dy[8] = {0, 1, 0, -1, -1, 1, 1, -1}; typedef pair<ll, ll> P; typedef pair<P, ll> PP; void Main() { ll n; R n; PP a[n]; rep(i, n) cin >> a[i].F.F >> a[i].F.S >> a[i].S; ll ans[n + 1]; rep(i, n + 1) ans[i] = MAXL; vector<P> v; rep(i, n) { v.pb(P(a[i].F.F, 0)); v.pb(P(a[i].F.S, 1)); } v.pb(P(0, 0)); v.pb(P(0, 1)); ll d[n][v.size()]; vector<P> b[n]; rep(i, n) { rep(j, v.size()) { if (v[j].S == 0) d[i][j] = abs(a[i].F.F - v[j].F) * a[i].S; else d[i][j] = abs(a[i].F.S - v[j].F) * a[i].S; } rep(j, v.size()) b[i].pb(P(d[i][j], j)); sort(all(b[i])); } rrep(t, pow(3, n)) { bitset<33> e; ll r = t, c = 0; rep(i, n) { if (r % 3 == 1) e.set(i * 2), c++; else if (r % 3 == 2) e.set(i * 2 + 1), c++; r /= 3; } e.set(n * 2); e.set(n * 2 + 1); ll sum = 0; rep(i, n) { ll M = MAXL; rep(j, b[i].size()) { if (e.test(b[i][j].S)) { M = d[i][b[i][j].S]; break; } } sum += M; if (sum > ans[c]) goto next; } ans[c] = min(ans[c], sum); next:; } rep(i, n + 1) pr(ans[i]); } int main() { ios::sync_with_stdio(0); cin.tie(0); Main(); return 0; }
replace
58
59
58
59
TLE
p02604
C++
Time Limit Exceeded
#include <algorithm> #include <cassert> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <vector> #define syosu(x) fixed << setprecision(x) using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int, int> P; typedef pair<double, double> pdd; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<string> vs; typedef vector<P> vp; typedef vector<vp> vvp; typedef vector<pll> vpll; typedef pair<int, P> pip; typedef vector<pip> vip; const int inf = 1 << 28; const ll INF = 1ll << 60; const double pi = acos(-1); const double eps = 1e-8; const ll mod = 998244353; const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1}; int n; vl a, x, y, p; int main() { cin >> n; a = vl(n + 1, INF); x = y = p = vl(n); for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> p[i]; int N = 1; for (int i = 0; i < n; i++) N *= 3; for (int i = 0; i < N; i++) { vi b(n); int t = i; for (int j = 0; j < n; j++) { b[j] = t % 3; t /= 3; } t = 0; for (int j = 0; j < n; j++) if (b[j]) t++; ll sum = 0; for (int j = 0; j < n; j++) if (!b[j]) { ll tmp = min(abs(x[j]), abs(y[j])); for (int k = 0; k < n; k++) { if (b[k] == 1) tmp = min(tmp, abs(x[j] - x[k])); if (b[k] == 2) tmp = min(tmp, abs(y[j] - y[k])); } sum += tmp * p[j]; if (sum > a[t]) break; } a[t] = min(a[t], sum); } for (auto i : a) cout << i << endl; }
#include <algorithm> #include <cassert> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <vector> #define syosu(x) fixed << setprecision(x) using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int, int> P; typedef pair<double, double> pdd; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<string> vs; typedef vector<P> vp; typedef vector<vp> vvp; typedef vector<pll> vpll; typedef pair<int, P> pip; typedef vector<pip> vip; const int inf = 1 << 28; const ll INF = 1ll << 60; const double pi = acos(-1); const double eps = 1e-8; const ll mod = 998244353; const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1}; int n; vl a, x, y, p; int main() { cin >> n; a = vl(n + 1, INF); x = y = p = vl(n); for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> p[i]; int N = 1; for (int i = 0; i < n; i++) N *= 3; for (int i = 0; i < N; i++) { vi b(n); int t = i; for (int j = 0; j < n; j++) { b[j] = t % 3; t /= 3; } t = 0; for (int j = 0; j < n; j++) if (b[j]) t++; ll sum = 0; for (int j = 0; j < n; j++) if (!b[j]) { ll tmp = min(abs(x[j]), abs(y[j])); for (int k = 0; k < n; k++) { if (b[k] == 1) tmp = min(tmp, abs(x[j] - x[k])); if (b[k] == 2) tmp = min(tmp, abs(y[j] - y[k])); } sum += tmp * p[j]; if (sum >= a[t]) break; } a[t] = min(a[t], sum); } for (auto i : a) cout << i << endl; }
replace
71
72
71
72
TLE
p02604
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; #define REP(i, n) for (ll i = 0; i < (n); ++i) #define RREP(i, n) for (ll i = (n)-1; i >= 0; --i) #define ALL(v) (v).begin(), (v).end() template <class T> using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>; int main() { ll n; cin >> n; vector<ll> x(n), y(n), p(n); REP(i, n) { cin >> x[i] >> y[i] >> p[i]; } map<ll, vector<ll>> x2d, y2d; REP(i, (1LL << n)) { vector<ll> xs, ys; REP(j, n) { if ((i >> j) & 1) { xs.push_back(x.at(j)); ys.push_back(y.at(j)); } } sort(ALL(xs)); sort(ALL(ys)); x2d[i].resize(n, numeric_limits<ll>::max()); y2d[i].resize(n, numeric_limits<ll>::max()); REP(j, n) { { ll dx = abs(x.at(j)); ll idx = lower_bound(ALL(xs), x.at(j)) - xs.begin(); if (idx < xs.size()) { dx = min(dx, xs.at(idx) - x.at(j)); } if (idx > 0) { dx = min(dx, x.at(j) - xs.at(idx - 1)); } x2d.at(i).at(j) = dx; } { ll dy = abs(y.at(j)); ll idx = lower_bound(ALL(ys), y.at(j)) - ys.begin(); if (idx < ys.size()) { dy = min(dy, ys.at(idx) - y.at(j)); } if (idx > 0) { dy = min(dy, y.at(j) - ys.at(idx - 1)); } y2d.at(i).at(j) = dy; } } } ll ub = 1; REP(i, n) { ub *= 3; } vector<ll> ans(n + 1, numeric_limits<ll>::max()); REP(i, ub) { ll ix = 0, iy = 0, k = 0; { ll m = i; REP(j, n) { const ll l = m % 3; if (l == 1) { ix += (1LL << j); k++; } else if (l == 2) { iy += (1LL << j); k++; } m /= 3; } } ll s = 0; const auto &dx = x2d.at(ix), dy = y2d.at(iy); REP(j, n) { ll d = min(dx.at(j), dy.at(j)); s += p.at(j) * d; } ans.at(k) = min(ans.at(k), s); } for (auto ai : ans) { cout << ai << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; #define REP(i, n) for (ll i = 0; i < (n); ++i) #define RREP(i, n) for (ll i = (n)-1; i >= 0; --i) #define ALL(v) (v).begin(), (v).end() template <class T> using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>; int main() { ll n; cin >> n; vector<ll> x(n), y(n), p(n); REP(i, n) { cin >> x[i] >> y[i] >> p[i]; } vector<vector<ll>> x2d(1LL << n), y2d(1LL << n); REP(i, (1LL << n)) { vector<ll> xs, ys; REP(j, n) { if ((i >> j) & 1) { xs.push_back(x.at(j)); ys.push_back(y.at(j)); } } sort(ALL(xs)); sort(ALL(ys)); x2d[i].resize(n, numeric_limits<ll>::max()); y2d[i].resize(n, numeric_limits<ll>::max()); REP(j, n) { { ll dx = abs(x.at(j)); ll idx = lower_bound(ALL(xs), x.at(j)) - xs.begin(); if (idx < xs.size()) { dx = min(dx, xs.at(idx) - x.at(j)); } if (idx > 0) { dx = min(dx, x.at(j) - xs.at(idx - 1)); } x2d.at(i).at(j) = dx; } { ll dy = abs(y.at(j)); ll idx = lower_bound(ALL(ys), y.at(j)) - ys.begin(); if (idx < ys.size()) { dy = min(dy, ys.at(idx) - y.at(j)); } if (idx > 0) { dy = min(dy, y.at(j) - ys.at(idx - 1)); } y2d.at(i).at(j) = dy; } } } ll ub = 1; REP(i, n) { ub *= 3; } vector<ll> ans(n + 1, numeric_limits<ll>::max()); REP(i, ub) { ll ix = 0, iy = 0, k = 0; { ll m = i; REP(j, n) { const ll l = m % 3; if (l == 1) { ix += (1LL << j); k++; } else if (l == 2) { iy += (1LL << j); k++; } m /= 3; } } ll s = 0; const auto &dx = x2d.at(ix), dy = y2d.at(iy); REP(j, n) { ll d = min(dx.at(j), dy.at(j)); s += p.at(j) * d; } ans.at(k) = min(ans.at(k), s); } for (auto ai : ans) { cout << ai << endl; } return 0; }
replace
16
17
16
17
TLE
p02604
C++
Runtime Error
#include <bits/stdc++.h> #define M_PI 3.14159265358979323846 // pi using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<ll> VI; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> t3; typedef tuple<ll, ll, ll, ll> t4; typedef tuple<ll, ll, ll, ll, ll> t5; #define rep(a, n) for (ll a = 0; a < n; a++) #define repi(a, b, n) for (ll a = b; a < n; a++) using namespace std; static const ll INF = 1e15; const ll mod = 1000000007; template <typename T> static inline void chmin(T &ref, const T value) { if (ref > value) ref = value; } template <typename T> static inline void chmax(T &ref, const T value) { if (ref < value) ref = value; } vector<ll> pow3() { vector<ll> ans; ll b = 1; for (int i = 0; i <= 15; i++) { ans.push_back(b); b *= 3; } return ans; } inline int pop3(ll j) { int a = 0; while (j) { if (j % 3) a++; j /= 3; } return a; } int main() { ll n; cin >> n; vector<ll> xs(n), ys(n), ps(n); rep(i, n) { cin >> xs[i] >> ys[i] >> ps[i]; } vector<vector<ll>> dxs(n, vector<ll>(n)); vector<vector<ll>> dys(n, vector<ll>(n)); rep(i, n) { rep(j, n) { dxs[i][j] = min(abs(xs[i] - xs[j]), abs(xs[i])); dys[i][j] = min(abs(ys[i] - ys[j]), abs(ys[i])); } } const auto table = pow3(); vector<int> popcounts(table[n]); for (ll j = 0; j < table[n]; j++) { popcounts[j] = pop3(j); } vector<ll> nxs(table[n], 0); vector<ll> nys(table[n], 0); for (ll j = 0; j < table[n]; j++) { ll c = j; for (int a = 0; a < n && c > 0; a++) { if (c % 3 == 1) { nxs[j] |= (1LL << a); } else if (c % 3 == 2) { nys[j] |= (1LL << a); } c /= 3; } } vector<vector<ll>> xss(n, vector<ll>(1LL << n, 0)); vector<vector<ll>> yss(n, vector<ll>(1LL << n, 0)); rep(j, 1LL << n) { rep(k, n) { ll dx = abs(xs[k]); ll dy = abs(ys[k]); rep(i, n) { if (j & (1LL << i)) { dx = min(dx, dxs[k][i]); dy = min(dy, dys[k][i]); } } xss[k][j] = dx; yss[k][j] = dy; } } vector<ll> memo(table[n]); for (ll j = 0; j < table[n]; j++) { ll d = 0; for (int k = 0; k < n; k++) { ll dx = xss[j][nxs[j]]; ll dy = yss[j][nys[j]]; d += min(dx, dy) * ps[k]; } memo[j] = d; } vector<ll> ans(n + 1, INF); for (ll j = 0; j < table[n]; j++) { ans[popcounts[j]] = min(ans[popcounts[j]], memo[j]); } for (int i = 0; i <= n; i++) { cout << ans[i] << endl; } return 0; }
#include <bits/stdc++.h> #define M_PI 3.14159265358979323846 // pi using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<ll> VI; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> t3; typedef tuple<ll, ll, ll, ll> t4; typedef tuple<ll, ll, ll, ll, ll> t5; #define rep(a, n) for (ll a = 0; a < n; a++) #define repi(a, b, n) for (ll a = b; a < n; a++) using namespace std; static const ll INF = 1e15; const ll mod = 1000000007; template <typename T> static inline void chmin(T &ref, const T value) { if (ref > value) ref = value; } template <typename T> static inline void chmax(T &ref, const T value) { if (ref < value) ref = value; } vector<ll> pow3() { vector<ll> ans; ll b = 1; for (int i = 0; i <= 15; i++) { ans.push_back(b); b *= 3; } return ans; } inline int pop3(ll j) { int a = 0; while (j) { if (j % 3) a++; j /= 3; } return a; } int main() { ll n; cin >> n; vector<ll> xs(n), ys(n), ps(n); rep(i, n) { cin >> xs[i] >> ys[i] >> ps[i]; } vector<vector<ll>> dxs(n, vector<ll>(n)); vector<vector<ll>> dys(n, vector<ll>(n)); rep(i, n) { rep(j, n) { dxs[i][j] = min(abs(xs[i] - xs[j]), abs(xs[i])); dys[i][j] = min(abs(ys[i] - ys[j]), abs(ys[i])); } } const auto table = pow3(); vector<int> popcounts(table[n]); for (ll j = 0; j < table[n]; j++) { popcounts[j] = pop3(j); } vector<ll> nxs(table[n], 0); vector<ll> nys(table[n], 0); for (ll j = 0; j < table[n]; j++) { ll c = j; for (int a = 0; a < n && c > 0; a++) { if (c % 3 == 1) { nxs[j] |= (1LL << a); } else if (c % 3 == 2) { nys[j] |= (1LL << a); } c /= 3; } } vector<vector<ll>> xss(n, vector<ll>(1LL << n, 0)); vector<vector<ll>> yss(n, vector<ll>(1LL << n, 0)); rep(j, 1LL << n) { rep(k, n) { ll dx = abs(xs[k]); ll dy = abs(ys[k]); rep(i, n) { if (j & (1LL << i)) { dx = min(dx, dxs[k][i]); dy = min(dy, dys[k][i]); } } xss[k][j] = dx; yss[k][j] = dy; } } vector<ll> memo(table[n]); for (ll j = 0; j < table[n]; j++) { ll d = 0; for (int k = 0; k < n; k++) { ll dx = xss[k][nxs[j]]; ll dy = yss[k][nys[j]]; d += min(dx, dy) * ps[k]; } memo[j] = d; } vector<ll> ans(n + 1, INF); for (ll j = 0; j < table[n]; j++) { ans[popcounts[j]] = min(ans[popcounts[j]], memo[j]); } for (int i = 0; i <= n; i++) { cout << ans[i] << endl; } return 0; }
replace
103
105
103
105
-11
p02604
Python
Time Limit Exceeded
# 解説と 提出 #15122924 を参考に作成. # 遅い. PyPyで出すと通る. はず. # import sys # sys.setrecursionlimit(10 ** 6) # import bisect # from collections import deque # from decorator import stop_watch # # # @stop_watch def solve(N, X, Y, P): inf = 10**18 cnb_N = 2**N # 前計算 # # 集落の部分集合毎の、Y軸X軸へのそれぞれの最短経路 to_x = [[0] * N for _ in range(cnb_N)] to_y = [[0] * N for _ in range(cnb_N)] for cn in range(cnb_N): for n in range(N): to_x[cn][n] = abs(X[n]) * P[n] to_y[cn][n] = abs(Y[n]) * P[n] for n2 in range(N): if cn >> n2 & 1: to_x[cn][n] = min(to_x[cn][n], abs(X[n] - X[n2]) * P[n]) to_y[cn][n] = min(to_y[cn][n], abs(Y[n] - Y[n2]) * P[n]) # 実計算 # # 各集落の集合に対して、Y軸を取った場合とX軸を取った場合で最短となる経路を算出 ans = [inf] * (N + 1) for cn in range(cnb_N): count = 0 for i in range(N): count += 1 if cn >> i & 1 else 0 cn2 = cn while cn2 >= 0: cn2 = cn2 & cn subsum = 0 for n in range(N): # if not (cn >> n & 1): subsum += min(to_x[cn - cn2][n], to_y[cn2][n]) ans[count] = min(ans[count], subsum) cn2 -= 1 for n in range(N + 1): print(ans[n]) if __name__ == "__main__": # S = input() N = int(input()) # N, M = map(int, input().split()) X, Y, P = [], [], [] for _ in range(N): tmp = [int(i) for i in input().split()] X.append(tmp[0]) Y.append(tmp[1]) P.append(tmp[2]) solve(N, X, Y, P)
# 解説と 提出 #15122924 を参考に作成. # 遅い. PyPyで出すと通る. はず. # import sys # sys.setrecursionlimit(10 ** 6) # import bisect # from collections import deque # from decorator import stop_watch # # # @stop_watch def solve(N, X, Y, P): inf = 10**18 cnb_N = 2**N # 前計算 # # 集落の部分集合毎の、Y軸X軸へのそれぞれの最短経路 to_x = [[0] * N for _ in range(cnb_N)] to_y = [[0] * N for _ in range(cnb_N)] for cn in range(cnb_N): for n in range(N): to_x[cn][n] = abs(X[n]) * P[n] to_y[cn][n] = abs(Y[n]) * P[n] for n2 in range(N): if cn >> n2 & 1: to_x[cn][n] = min(to_x[cn][n], abs(X[n] - X[n2]) * P[n]) to_y[cn][n] = min(to_y[cn][n], abs(Y[n] - Y[n2]) * P[n]) # 実計算 # # 各集落の集合に対して、Y軸を取った場合とX軸を取った場合で最短となる経路を算出 ans = [inf] * (N + 1) for cn in range(cnb_N): count = 0 for i in range(N): count += 1 if cn >> i & 1 else 0 cn2 = cn while cn2 >= 0: cn2 = cn2 & cn subsum = 0 for n in range(N): if not (cn >> n & 1): subsum += min(to_x[cn - cn2][n], to_y[cn2][n]) ans[count] = min(ans[count], subsum) cn2 -= 1 for n in range(N + 1): print(ans[n]) if __name__ == "__main__": # S = input() N = int(input()) # N, M = map(int, input().split()) X, Y, P = [], [], [] for _ in range(N): tmp = [int(i) for i in input().split()] X.append(tmp[0]) Y.append(tmp[1]) P.append(tmp[2]) solve(N, X, Y, P)
replace
40
42
40
42
TLE
p02604
C++
Time Limit Exceeded
#pragma G++ optimize(O2) #pragma G++ optimize(O3) #include <bits/stdc++.h> using namespace std; typedef long long LL; const int N = 16; LL res[N]; struct node { int x, y, p; } a[N]; int vis[N]; int dis[N]; void solve() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].p); } memset(res, 0x3f, sizeof res); // i:选择哪几个点上添加横线,1为添加,0为不添加 for (int i = 0; i < (1 << n); i++) { int cnt = 0; for (int j = 0; j < n; j++) if ((i >> j) & 1) vis[++cnt] = j + 1; // j:选择的点的所有状态,1为x方向,0为y方向 for (int j = 0; j < (1 << cnt); j++) { for (int k = 1; k <= n; k++) dis[k] = min(abs(a[k].x), abs(a[k].y)); for (int k = 0; k < cnt; k++) { if ((j >> k) & 1) { for (int t = 1; t <= n; t++) { dis[t] = min(dis[t], abs(a[t].x - a[vis[k + 1]].x)); } } else { for (int t = 1; t <= n; t++) { dis[t] = min(dis[t], abs(a[t].y - a[vis[k + 1]].y)); } } } LL sum = 0; for (int k = 1; k <= n; k++) sum += (LL)dis[k] * a[k].p; res[cnt] = min(res[cnt], sum); } } for (int i = 0; i <= n; i++) printf("%lld\n", res[i]); } int main() { // freopen("in.txt", "r", stdin); solve(); return 0; }
#pragma G++ optimize(O2) #pragma G++ optimize(O3) #pragma GCC optimize(2) #pragma GCC optimize(3) #include <bits/stdc++.h> using namespace std; typedef long long LL; const int N = 16; LL res[N]; struct node { int x, y, p; } a[N]; int vis[N]; int dis[N]; void solve() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d%d", &a[i].x, &a[i].y, &a[i].p); } memset(res, 0x3f, sizeof res); // i:选择哪几个点上添加横线,1为添加,0为不添加 for (int i = 0; i < (1 << n); i++) { int cnt = 0; for (int j = 0; j < n; j++) if ((i >> j) & 1) vis[++cnt] = j + 1; // j:选择的点的所有状态,1为x方向,0为y方向 for (int j = 0; j < (1 << cnt); j++) { for (int k = 1; k <= n; k++) dis[k] = min(abs(a[k].x), abs(a[k].y)); for (int k = 0; k < cnt; k++) { if ((j >> k) & 1) { for (int t = 1; t <= n; t++) { dis[t] = min(dis[t], abs(a[t].x - a[vis[k + 1]].x)); } } else { for (int t = 1; t <= n; t++) { dis[t] = min(dis[t], abs(a[t].y - a[vis[k + 1]].y)); } } } LL sum = 0; for (int k = 1; k <= n; k++) sum += (LL)dis[k] * a[k].p; res[cnt] = min(res[cnt], sum); } } for (int i = 0; i <= n; i++) printf("%lld\n", res[i]); } int main() { // freopen("in.txt", "r", stdin); solve(); return 0; }
insert
2
2
2
4
TLE
p02604
C++
Time Limit Exceeded
#include <bits/stdc++.h> #pragma GCC optimize(2) // 手动O2开关 using namespace std; const int maxn = 30; typedef long long ll; int x[maxn], y[maxn], r[maxn], d[maxn], dd[maxn], cun[maxn]; ll ans[maxn]; int cnt; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d%d", &x[i], &y[i], &r[i]); d[i] = min(abs(x[i]), abs(y[i])); } memset(ans, 0x3f, sizeof(ans)); for (int i = 0; i < (1 << n); i++) { int now = i; cnt = 0; for (int j = 0; j < 15; j++) { if ((now >> j) & 1) cun[++cnt] = j + 1; } for (int j = 0; j < (1 << cnt); j++) { ll ans_ = 0; memcpy(dd, d, sizeof(dd)); for (int k = 0; k < cnt; k++) { if ((j >> k) & 1) { for (int e = 1; e <= n; e++) { dd[e] = min(dd[e], abs(x[e] - x[cun[k + 1]])); } } else { for (int e = 1; e <= n; e++) { dd[e] = min(dd[e], abs(y[e] - y[cun[k + 1]])); } } } for (int i = 1; i <= n; i++) { ans_ += 1ll * dd[i] * r[i]; } ans[cnt] = min(ans[cnt], ans_); } } for (int i = 0; i <= n; i++) { printf("%lld\n", ans[i]); } }
#include <bits/stdc++.h> #pragma GCC optimize(2) // 手动O2开关 using namespace std; const int maxn = 17; typedef long long ll; int x[maxn], y[maxn], r[maxn], d[maxn], dd[maxn], cun[maxn]; ll ans[maxn]; int cnt; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d%d%d", &x[i], &y[i], &r[i]); d[i] = min(abs(x[i]), abs(y[i])); } memset(ans, 0x3f, sizeof(ans)); for (int i = 0; i < (1 << n); i++) { int now = i; cnt = 0; for (int j = 0; j < 15; j++) { if ((now >> j) & 1) cun[++cnt] = j + 1; } for (int j = 0; j < (1 << cnt); j++) { ll ans_ = 0; memcpy(dd, d, sizeof(dd)); for (int k = 0; k < cnt; k++) { if ((j >> k) & 1) { for (int e = 1; e <= n; e++) { dd[e] = min(dd[e], abs(x[e] - x[cun[k + 1]])); } } else { for (int e = 1; e <= n; e++) { dd[e] = min(dd[e], abs(y[e] - y[cun[k + 1]])); } } } for (int i = 1; i <= n; i++) { ans_ += 1ll * dd[i] * r[i]; } ans[cnt] = min(ans[cnt], ans_); } } for (int i = 0; i <= n; i++) { printf("%lld\n", ans[i]); } }
replace
3
4
3
4
TLE
p02604
C++
Runtime Error
#define taskname "test" #include <bits/stdc++.h> using namespace std; #define sz(x) (int)x.size() #define fi first #define se second typedef long long lli; typedef pair<int, int> pii; const int maxn = 15; const lli inf = 1e18 + 7; int n; int x[maxn], y[maxn], p[maxn]; lli dp[maxn][(1 << maxn) + 5]; lli pre[maxn + 5], su[maxn + 5]; lli f[maxn + 5], g[maxn + 5]; void read_input() { cin >> n; for (int i = 0; i < n; ++i) cin >> x[i] >> y[i] >> p[i]; } int bits(int x) { int res = 0; while (x > 0) { res += (x & 1); x >>= 1; } return res; } lli calc(vector<pii> &v) { pre[0] = v[0].se; for (int i = 1; i < sz(v); ++i) pre[i] = pre[i - 1] + v[i].se; su[sz(v) - 1] = v[sz(v) - 1].se; for (int i = sz(v) - 2; i >= 0; --i) su[i] = su[i + 1] + v[i].se; f[0] = 0; for (int i = 1; i < sz(v); ++i) f[i] = f[i - 1] + pre[i - 1] * 1LL * (v[i].fi - v[i - 1].fi); g[sz(v) - 1] = 0; for (int i = sz(v) - 2; i >= 0; --i) g[i] = g[i + 1] + su[i + 1] * 1LL * (v[i + 1].fi - v[i].fi); lli res = inf; for (int i = 0; i < sz(v); ++i) res = min(res, f[i] + g[i]); return res; } void solve() { fill_n(&dp[0][0], sizeof(dp) / sizeof(dp[0][0]), inf); for (int mask = 0; mask < (1 << n); ++mask) { dp[0][mask] = 0; for (int k = 0; k < n; ++k) if (mask >> k & 1) dp[0][mask] += min(abs(x[k]), abs(y[k])) * 1LL * p[k]; } for (int mask = 1; mask < (1 << n); ++mask) { if (bits(mask) == 1) { dp[1][mask] = 0; continue; } vector<pii> vx, vy; for (int k = 0; k < n; ++k) if (mask >> k & 1) { vx.push_back(pii(x[k], p[k])); vy.push_back(pii(y[k], p[k])); } sort(vx.begin(), vx.end()); sort(vy.begin(), vy.end()); dp[1][mask] = min(calc(vx), calc(vy)); } for (int i = 1; i <= n; ++i) for (int mask = 1; mask < (1 << n); ++mask) { if (bits(mask) <= i) { dp[i][mask] = 0; continue; } dp[i][mask] = min(dp[i][mask], dp[i - 1][mask]); for (int submask = mask; submask > 0; submask = (submask - 1) & mask) { if (submask == mask) continue; int omask = mask ^ submask; for (int j = 0; j <= 1; ++j) if (dp[i - j][submask] != inf && dp[i - 1][submask] != inf) dp[i][mask] = min(dp[i][mask], dp[i - j][submask] + dp[j][omask]); // dp[i][mask] = min(dp[i][mask], dp[i - 1][submask] + dp[1][omask]); } } for (int i = 0; i <= n; ++i) cout << dp[i][(1 << n) - 1] << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); read_input(); solve(); }
#define taskname "test" #include <bits/stdc++.h> using namespace std; #define sz(x) (int)x.size() #define fi first #define se second typedef long long lli; typedef pair<int, int> pii; const int maxn = 16; const lli inf = 1e18 + 7; int n; int x[maxn], y[maxn], p[maxn]; lli dp[maxn][(1 << maxn) + 5]; lli pre[maxn + 5], su[maxn + 5]; lli f[maxn + 5], g[maxn + 5]; void read_input() { cin >> n; for (int i = 0; i < n; ++i) cin >> x[i] >> y[i] >> p[i]; } int bits(int x) { int res = 0; while (x > 0) { res += (x & 1); x >>= 1; } return res; } lli calc(vector<pii> &v) { pre[0] = v[0].se; for (int i = 1; i < sz(v); ++i) pre[i] = pre[i - 1] + v[i].se; su[sz(v) - 1] = v[sz(v) - 1].se; for (int i = sz(v) - 2; i >= 0; --i) su[i] = su[i + 1] + v[i].se; f[0] = 0; for (int i = 1; i < sz(v); ++i) f[i] = f[i - 1] + pre[i - 1] * 1LL * (v[i].fi - v[i - 1].fi); g[sz(v) - 1] = 0; for (int i = sz(v) - 2; i >= 0; --i) g[i] = g[i + 1] + su[i + 1] * 1LL * (v[i + 1].fi - v[i].fi); lli res = inf; for (int i = 0; i < sz(v); ++i) res = min(res, f[i] + g[i]); return res; } void solve() { fill_n(&dp[0][0], sizeof(dp) / sizeof(dp[0][0]), inf); for (int mask = 0; mask < (1 << n); ++mask) { dp[0][mask] = 0; for (int k = 0; k < n; ++k) if (mask >> k & 1) dp[0][mask] += min(abs(x[k]), abs(y[k])) * 1LL * p[k]; } for (int mask = 1; mask < (1 << n); ++mask) { if (bits(mask) == 1) { dp[1][mask] = 0; continue; } vector<pii> vx, vy; for (int k = 0; k < n; ++k) if (mask >> k & 1) { vx.push_back(pii(x[k], p[k])); vy.push_back(pii(y[k], p[k])); } sort(vx.begin(), vx.end()); sort(vy.begin(), vy.end()); dp[1][mask] = min(calc(vx), calc(vy)); } for (int i = 1; i <= n; ++i) for (int mask = 1; mask < (1 << n); ++mask) { if (bits(mask) <= i) { dp[i][mask] = 0; continue; } dp[i][mask] = min(dp[i][mask], dp[i - 1][mask]); for (int submask = mask; submask > 0; submask = (submask - 1) & mask) { if (submask == mask) continue; int omask = mask ^ submask; for (int j = 0; j <= 1; ++j) if (dp[i - j][submask] != inf && dp[i - 1][submask] != inf) dp[i][mask] = min(dp[i][mask], dp[i - j][submask] + dp[j][omask]); // dp[i][mask] = min(dp[i][mask], dp[i - 1][submask] + dp[1][omask]); } } for (int i = 0; i <= n; ++i) cout << dp[i][(1 << n) - 1] << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); read_input(); solve(); }
replace
13
14
13
14
0
p02604
C++
Time Limit Exceeded
#include <stdio.h> short x[16], y[16]; int p[16]; long long ans[16]; short mi[16], m1[16]; short px[16][16], py[16][16]; int ppk, st; short cnt, now; int main(void) { char n; scanf("%hd", &n); for (char i = 0; i < n; i++) scanf("%hd%hd%d", &x[i], &y[i], &p[i]); int ma = 1; for (char i = 0; i <= n; ++i) ans[i] = 1000000000000000; for (char i = 0; i < n; ++i) ma *= 3; for (char i = 0; i < n; ++i) { short x1 = x[i] > 0 ? x[i] : -x[i], y1 = y[i] > 0 ? y[i] : -y[i]; m1[i] = x1 > y1 ? y1 : x1; } for (char i = 0; i < n; ++i) { for (char j = 0; j < n; ++j) { px[i][j] = x[i] - x[j]; py[i][j] = y[i] - y[j]; if (px[i][j] < 0) px[i][j] = -px[i][j]; if (py[i][j] < 0) py[i][j] = -py[i][j]; } } for (int zhu = 0; zhu < ma; ++zhu) { ppk = zhu, cnt = n, st = ma / 3; for (char i = 0; i < n; i++) mi[i] = m1[i]; for (char i = 0; i < n; i++, st /= 3) { now = ppk / st; switch (now) { case 2: for (char j = 0; j < n; ++j) if (mi[j] > px[i][j]) mi[j] = px[i][j]; break; case 1: for (char j = 0; j < n; ++j) if (mi[j] > py[i][j]) mi[j] = py[i][j]; break; case 0: cnt--; } ppk -= st * now; } long long sum = 0; for (char i = 0; i < n; ++i) sum += (long long)mi[i] * p[i]; if (ans[cnt] > sum) ans[cnt] = sum; } for (char i = 0; i <= n; i++) printf("%lld\n", ans[i]); }
#include <stdio.h> #pragma GCC optimize(2) short x[16], y[16]; int p[16]; long long ans[16]; short mi[16], m1[16]; short px[16][16], py[16][16]; int ppk, st; short cnt, now; int main(void) { char n; scanf("%hd", &n); for (char i = 0; i < n; i++) scanf("%hd%hd%d", &x[i], &y[i], &p[i]); int ma = 1; for (char i = 0; i <= n; ++i) ans[i] = 1000000000000000; for (char i = 0; i < n; ++i) ma *= 3; for (char i = 0; i < n; ++i) { short x1 = x[i] > 0 ? x[i] : -x[i], y1 = y[i] > 0 ? y[i] : -y[i]; m1[i] = x1 > y1 ? y1 : x1; } for (char i = 0; i < n; ++i) { for (char j = 0; j < n; ++j) { px[i][j] = x[i] - x[j]; py[i][j] = y[i] - y[j]; if (px[i][j] < 0) px[i][j] = -px[i][j]; if (py[i][j] < 0) py[i][j] = -py[i][j]; } } for (int zhu = 0; zhu < ma; ++zhu) { ppk = zhu, cnt = n, st = ma / 3; for (char i = 0; i < n; i++) mi[i] = m1[i]; for (char i = 0; i < n; i++, st /= 3) { now = ppk / st; switch (now) { case 2: for (char j = 0; j < n; ++j) if (mi[j] > px[i][j]) mi[j] = px[i][j]; break; case 1: for (char j = 0; j < n; ++j) if (mi[j] > py[i][j]) mi[j] = py[i][j]; break; case 0: cnt--; } ppk -= st * now; } long long sum = 0; for (char i = 0; i < n; ++i) sum += (long long)mi[i] * p[i]; if (ans[cnt] > sum) ans[cnt] = sum; } for (char i = 0; i <= n; i++) printf("%lld\n", ans[i]); }
insert
1
1
1
2
TLE
p02604
C++
Time Limit Exceeded
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #define PI 3.14159265359 using namespace std; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define bit(n, k) (((ll)n >> (ll)k) & 1) /*nのk bit目*/ #define pb push_back #define eb emplace_back #define SZ(x) ((ll)(x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() const long long INF = 1e+18 + 1; typedef long long ll; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> T; const ll MOD = 1000000007LL; // ll MOD=1000000007LL; // const ll MOD=998244353LL; // const ll MOD=1777777777LL; // const ll MAX_V=114514LL; // const ll MAX = 500010LL; const ll mod = MOD; string abc = "abcdefghijklmnopqrstuvwxyz"; string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; vl dx = {0, 0, 1, -1}; vl dy = {1, -1, 0, 0}; // 素因数分解O(√n) map<ll, ll> prime_factor(ll n) { map<ll, ll> res; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { res[i]++; n /= i; } } if (n != 1) res[n] = 1; return res; } const ll MAX = 510000; long long fac[MAX], finv[MAX], inv[MAX]; // finvが階乗の逆元 // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); cout << fixed << setprecision(10); /*--------------------------------*/ ll n; cin >> n; vl x(n), y(n), p(n); rep(i, n) cin >> x[i] >> y[i] >> p[i]; vvl bitx((1 << n), vl(n)), bity((1 << n), vl(n)); rep(bit, 1 << n) { rep(i, n) { bitx[bit][i] = min(abs(x[i]), abs(y[i])); bity[bit][i] = min(abs(x[i]), abs(y[i])); } } vl ans(n + 1, INF); vl pow(16); vl three(16); pow[0] = 1; three[0] = 1; rep(i, 15) pow[i + 1] = pow[i] * 2; rep(i, 15) three[i + 1] = three[i] * 3; rep(bit, (1 << n)) { rep(i, n) { rep(j, n) { if (bit(bit, j)) bitx[bit][i] = min(bitx[bit][i], abs(x[i] - x[j])); } } } rep(bit, (1 << n)) { rep(i, n) { rep(j, n) { if (bit(bit, j)) bity[bit][i] = min(bity[bit][i], abs(y[i] - y[j])); } } } // rep(bit,1<<n){ // rep(i,n)cout<<bitx[bit][i]<<" "; // cout<<endl; // } rep(bit, three[n]) { ll sumx = 0, sumy = 0; ll cnt = 0; ll tmp = bit; rep(i, n) { cnt++; if (tmp % 3 == 1) sumx += pow[i]; else if (tmp % 3 == 2) sumy += pow[i]; else cnt--; tmp /= 3; if (tmp == 0) break; } // cout<<bit<<" "<<sumx<<" "<<sumy<<endl; ll part = 0; rep(i, n) { part += p[i] * min(bitx[sumx][i], bity[sumy][i]); } ans[cnt] = min(ans[cnt], part); // cout<<bit<<" "<<part<<" "<<cnt<<endl; } rep(i, n + 1) cout << ans[i] << '\n'; }
// #define _GLIBCXX_DEBUG #include <bits/stdc++.h> #define PI 3.14159265359 using namespace std; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define bit(n, k) (((ll)n >> (ll)k) & 1) /*nのk bit目*/ #define pb push_back #define eb emplace_back #define SZ(x) ((ll)(x).size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() const long long INF = 1e+18 + 1; typedef long long ll; typedef vector<ll> vl; typedef vector<vector<ll>> vvl; typedef pair<ll, ll> P; typedef tuple<ll, ll, ll> T; const ll MOD = 1000000007LL; // ll MOD=1000000007LL; // const ll MOD=998244353LL; // const ll MOD=1777777777LL; // const ll MAX_V=114514LL; // const ll MAX = 500010LL; const ll mod = MOD; string abc = "abcdefghijklmnopqrstuvwxyz"; string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; vl dx = {0, 0, 1, -1}; vl dy = {1, -1, 0, 0}; // 素因数分解O(√n) map<ll, ll> prime_factor(ll n) { map<ll, ll> res; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { res[i]++; n /= i; } } if (n != 1) res[n] = 1; return res; } const ll MAX = 510000; long long fac[MAX], finv[MAX], inv[MAX]; // finvが階乗の逆元 // テーブルを作る前処理 void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // 二項係数計算 long long COM(ll n, ll k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } ll modpow(ll a, ll n, ll mod) { ll res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); cout << fixed << setprecision(10); /*--------------------------------*/ ll n; cin >> n; vl x(n), y(n), p(n); rep(i, n) cin >> x[i] >> y[i] >> p[i]; vvl bitx((1 << n), vl(n)), bity((1 << n), vl(n)); rep(bit, 1 << n) { rep(i, n) { bitx[bit][i] = min(abs(x[i]), abs(y[i])); bity[bit][i] = min(abs(x[i]), abs(y[i])); } } vl ans(n + 1, INF); vl pow(16); vl three(16); pow[0] = 1; three[0] = 1; rep(i, 15) pow[i + 1] = pow[i] * 2; rep(i, 15) three[i + 1] = three[i] * 3; rep(bit, (1 << n)) { rep(i, n) { rep(j, n) { if (bit(bit, j)) bitx[bit][i] = min(bitx[bit][i], abs(x[i] - x[j])); } } } rep(bit, (1 << n)) { rep(i, n) { rep(j, n) { if (bit(bit, j)) bity[bit][i] = min(bity[bit][i], abs(y[i] - y[j])); } } } // rep(bit,1<<n){ // rep(i,n)cout<<bitx[bit][i]<<" "; // cout<<endl; // } rep(bit, three[n]) { ll sumx = 0, sumy = 0; ll cnt = 0; ll tmp = bit; rep(i, n) { cnt++; if (tmp % 3 == 1) sumx += pow[i]; else if (tmp % 3 == 2) sumy += pow[i]; else cnt--; tmp /= 3; if (tmp == 0) break; } // cout<<bit<<" "<<sumx<<" "<<sumy<<endl; ll part = 0; rep(i, n) { part += p[i] * min(bitx[sumx][i], bity[sumy][i]); } ans[cnt] = min(ans[cnt], part); // cout<<bit<<" "<<part<<" "<<cnt<<endl; } rep(i, n + 1) cout << ans[i] << '\n'; }
replace
0
1
0
1
TLE
p02604
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define chmax(a, b) a = max(a, b); #define chmin(a, b) a = min(a, b); #define all(x) x.begin(), x.end() using namespace std; using ll = long long; using P = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; int n, x[15], y[15], p[15]; ll ans[16]; int main() { scanf("%d", &n); rep(i, n) { scanf("%d%d%d", &x[i], &y[i], &p[i]); } rep(i, 16) ans[i] = 1002003004005006001LL; int bitmx = 1; rep(i, n) bitmx *= 3; vi xordered(n), yordered(n); rep(i, n) xordered[i] = yordered[i] = i; sort(all(xordered), [](int a, int b) { return x[a] < x[b]; }); sort(all(yordered), [](int a, int b) { return y[a] < y[b]; }); rep(b, bitmx) { // 3 ^ 15 int xs[15], ys[15]; int xssize = 0, yssize = 0; int cnt = 0; int ybucket[15] = {}; { int t = b; rep(i, n) { if (t % 3 == 1) { xs[xssize++] = x[xordered[i]]; cnt++; } else if (t % 3 == 2) { ybucket[xordered[i]] = 1; cnt++; } t /= 3; } } rep(i, n) { int yi = yordered[i]; if (ybucket[yi]) ys[yssize++] = y[yi]; } int d[15]; rep(i, n) d[i] = min(abs(x[i]), abs(y[i])); if (xssize > 0) { int j = 0; for (int i : xordered) { while (j < xssize - 1 && xs[j + 1] < x[i]) j++; if (xs[j] >= x[i]) chmin(d[i], xs[j] - x[i]) else { chmin(d[i], x[i] - xs[j]); if (j < xssize - 1) chmin(d[i], xs[j + 1] - x[i]) } } } if (yssize > 0) { int j = 0; for (int i : yordered) { while (j < yssize - 1 && ys[j + 1] < y[i]) j++; if (ys[j] >= y[i]) chmin(d[i], ys[j] - y[i]) else { chmin(d[i], y[i] - ys[j]) if (j < yssize - 1) chmin(d[i], ys[j + 1] - y[i]) } } } ll s = 0; rep(i, n) s += (ll)d[i] * p[i]; chmin(ans[cnt], s); } rep(i, n + 1) printf("%lld\n", ans[i]); }
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) #define chmax(a, b) a = max(a, b); #define chmin(a, b) a = min(a, b); #define all(x) x.begin(), x.end() using namespace std; using ll = long long; using P = pair<int, int>; using vi = vector<int>; using vvi = vector<vi>; int n, x[15], y[15], p[15]; ll ans[16]; int main() { scanf("%d", &n); rep(i, n) { scanf("%d%d%d", &x[i], &y[i], &p[i]); } rep(i, 16) ans[i] = 1002003004005006001LL; int bitmx = 1; rep(i, n) bitmx *= 3; vi xordered(n), yordered(n); rep(i, n) xordered[i] = yordered[i] = i; sort(all(xordered), [](int a, int b) { return x[a] < x[b]; }); sort(all(yordered), [](int a, int b) { return y[a] < y[b]; }); rep(b, bitmx) { // 3 ^ 15 int xs[15], ys[15]; int xssize = 0, yssize = 0; int cnt = 0; int ybucket[15] = {}; { int t = b; rep(i, n) { if (t % 3 == 1) { xs[xssize++] = x[xordered[i]]; cnt++; } else if (t % 3 == 2) { ybucket[xordered[i]] = 1; cnt++; } t /= 3; } } rep(i, n) { int yi = yordered[i]; if (ybucket[yi]) ys[yssize++] = y[yi]; } int d[15]; rep(i, n) d[i] = min(abs(x[i]), abs(y[i])); if (xssize > 0) { int j = 0; for (int i : xordered) { while (j < xssize - 1 && xs[j + 1] < x[i]) j++; if (xs[j] >= x[i]) chmin(d[i], xs[j] - x[i]) else { chmin(d[i], x[i] - xs[j]); if (j < xssize - 1) chmin(d[i], xs[j + 1] - x[i]) } } } if (yssize > 0) { int j = 0; for (int i : yordered) { while (j < yssize - 1 && ys[j + 1] < y[i]) j++; if (ys[j] >= y[i]) chmin(d[i], ys[j] - y[i]) else { chmin(d[i], y[i] - ys[j]) if (j < yssize - 1) chmin(d[i], ys[j + 1] - y[i]) } } } ll s = 0; rep(i, n) s += (ll)d[i] * p[i]; chmin(ans[cnt], s); } rep(i, n + 1) printf("%lld\n", ans[i]); }
insert
0
0
0
4
TLE
p02605
C++
Runtime Error
#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 <utility> #include <vector> using namespace std; int X[100000]; int Y[100000]; char U[100000]; int dir_to_ind(char c) { if (c == 'U') { return 0; } else if (c == 'R') { return 1; } else if (c == 'D') { return 2; } return 3; } vector<int> dir_X_to_Y[4][200001]; vector<int> dir_Y_to_X[4][200001]; vector<int> dir_X_plus_Y_to_Y[4][400001]; vector<int> dir_X_plus_Y_to_X[4][400001]; vector<int> dir_X_minus_Y_to_Y[4][400001]; vector<int> dir_X_minus_Y_to_X[4][400001]; int main() { int N; cin >> N; int X_max = INT_MIN; int X_min = INT_MAX; int Y_max = INT_MIN; int Y_min = INT_MAX; int diff_max = INT_MIN; int diff_min = INT_MAX; for (int i = 0; i < N; i++) { cin >> X[i] >> Y[i] >> U[i]; X_max = max(X_max, X[i]); X_min = min(X_min, X[i]); Y_max = max(Y_max, Y[i]); Y_min = min(Y_min, Y[i]); diff_max = max(diff_max, X[i] - Y[i]); diff_min = min(diff_min, X[i] - Y[i]); } for (int i = 0; i < N; i++) { dir_X_to_Y[dir_to_ind(U[i])][X[i]].push_back(Y[i]); dir_Y_to_X[dir_to_ind(U[i])][Y[i]].push_back(X[i]); dir_X_plus_Y_to_X[dir_to_ind(U[i])][X[i] + Y[i]].push_back(X[i]); dir_X_plus_Y_to_Y[dir_to_ind(U[i])][X[i] + Y[i]].push_back(Y[i]); dir_X_minus_Y_to_X[dir_to_ind(U[i])][X[i] - Y[i] - diff_min].push_back( X[i]); dir_X_minus_Y_to_Y[dir_to_ind(U[i])][X[i] - Y[i] - diff_min].push_back( Y[i]); } for (int i = 0; i <= X_max; i++) { for (int j = 0; j < 4; j++) { sort(dir_Y_to_X[j][i].begin(), dir_Y_to_X[j][i].end()); dir_Y_to_X[j][i].erase( unique(dir_Y_to_X[j][i].begin(), dir_Y_to_X[j][i].end()), dir_Y_to_X[j][i].end()); } } for (int i = 0; i <= Y_max; i++) { for (int j = 0; j < 4; j++) { sort(dir_X_to_Y[j][i].begin(), dir_X_to_Y[j][i].end()); dir_X_to_Y[j][i].erase( unique(dir_X_to_Y[j][i].begin(), dir_X_to_Y[j][i].end()), dir_X_to_Y[j][i].end()); } } for (int i = 0; i <= X_max + Y_max; i++) { for (int j = 0; j < 4; j++) { sort(dir_X_plus_Y_to_X[j][i].begin(), dir_X_plus_Y_to_X[j][i].end()); dir_X_plus_Y_to_X[j][i].erase(unique(dir_X_plus_Y_to_X[j][i].begin(), dir_X_plus_Y_to_X[j][i].end()), dir_X_plus_Y_to_X[j][i].end()); sort(dir_X_plus_Y_to_Y[j][i].begin(), dir_X_plus_Y_to_Y[j][i].end()); dir_X_plus_Y_to_Y[j][i].erase(unique(dir_X_plus_Y_to_Y[j][i].begin(), dir_X_plus_Y_to_Y[j][i].end()), dir_X_plus_Y_to_Y[j][i].end()); } } for (int i = diff_min; i <= diff_max; i++) { for (int j = 0; j < 4; j++) { sort(dir_X_minus_Y_to_X[j][i - diff_min].begin(), dir_X_minus_Y_to_X[j][i - diff_min].end()); dir_X_minus_Y_to_X[j][i - diff_min].erase( unique(dir_X_minus_Y_to_X[j][i - diff_min].begin(), dir_X_minus_Y_to_X[j][i - diff_min].end()), dir_X_minus_Y_to_X[j][i - diff_min].end()); sort(dir_X_minus_Y_to_Y[j][i - diff_min].begin(), dir_X_minus_Y_to_Y[j][i - diff_min].end()); dir_X_minus_Y_to_Y[j][i - diff_min].erase( unique(dir_X_minus_Y_to_Y[j][i - diff_min].begin(), dir_X_minus_Y_to_Y[j][i - diff_min].end()), dir_X_minus_Y_to_Y[j][i - diff_min].end()); } } int ans = INT_MAX; for (int i = 0; i < N; i++) { int sum_XY = X[i] + Y[i]; int diff_XY = X[i] - Y[i]; if (U[i] == 'U') { vector<int> collidable = dir_X_to_Y[dir_to_ind('D')][X[i]]; auto it = upper_bound(collidable.begin(), collidable.end(), Y[i]); if (it != collidable.end()) { ans = min(ans, (*it - Y[i]) * 5); } collidable = dir_X_plus_Y_to_Y[dir_to_ind('R')][sum_XY]; it = upper_bound(collidable.begin(), collidable.end(), Y[i]); if (it != collidable.end()) { ans = min(ans, (*it - Y[i]) * 10); } collidable = dir_X_minus_Y_to_Y[dir_to_ind('L')][diff_XY - diff_min]; it = upper_bound(collidable.begin(), collidable.end(), Y[i]); if (it != collidable.end()) { ans = min(ans, (*it - Y[i]) * 10); } } else if (U[i] == 'R') { vector<int> collidable = dir_Y_to_X[dir_to_ind('L')][Y[i]]; auto it = upper_bound(collidable.begin(), collidable.end(), X[i]); if (it != collidable.end()) { ans = min(ans, (*it - X[i]) * 5); } collidable = dir_X_plus_Y_to_X[dir_to_ind('U')][sum_XY]; it = upper_bound(collidable.begin(), collidable.end(), X[i]); if (it != collidable.end()) { ans = min(ans, (*it - X[i]) * 10); } collidable = dir_X_minus_Y_to_X[dir_to_ind('D')][diff_XY - diff_min]; it = upper_bound(collidable.begin(), collidable.end(), X[i]); if (it != collidable.end()) { ans = min(ans, (*it - X[i]) * 10); } } else if (U[i] == 'D') { vector<int> collidable = dir_X_to_Y[dir_to_ind('U')][X[i]]; auto it = lower_bound(collidable.begin(), collidable.end(), Y[i]); if (it != collidable.begin()) { it--; ans = min(ans, (Y[i] - *it) * 5); } collidable = dir_X_plus_Y_to_Y[dir_to_ind('L')][sum_XY]; it = lower_bound(collidable.begin(), collidable.end(), Y[i]); if (it != collidable.begin()) { it--; ans = min(ans, (Y[i] - *it) * 10); } collidable = dir_X_minus_Y_to_Y[dir_to_ind('R')][diff_XY - diff_min]; it = lower_bound(collidable.begin(), collidable.end(), Y[i]); // cout << collidable.size() << endl; if (it != collidable.begin()) { it--; ans = min(ans, (Y[i] - *it) * 10); } } else if (U[i] == 'L') { vector<int> collidable = dir_Y_to_X[dir_to_ind('R')][Y[i]]; auto it = lower_bound(collidable.begin(), collidable.end(), X[i]); if (it != collidable.begin()) { it--; ans = min(ans, (X[i] - *it) * 5); } collidable = dir_X_plus_Y_to_X[dir_to_ind('D')][sum_XY]; it = lower_bound(collidable.begin(), collidable.end(), X[i]); if (it != collidable.begin()) { it--; ans = min(ans, (X[i] - *it) * 10); } collidable = dir_X_minus_Y_to_X[dir_to_ind('U')][diff_XY - diff_min]; it = lower_bound(collidable.begin(), collidable.end(), X[i]); if (it != collidable.begin()) { it--; ans = min(ans, (X[i] - *it) * 10); } } } if (ans == INT_MAX) { cout << "SAFE" << endl; } else { cout << ans << endl; } return 0; }
#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 <utility> #include <vector> using namespace std; int X[200000]; int Y[200000]; char U[200000]; int dir_to_ind(char c) { if (c == 'U') { return 0; } else if (c == 'R') { return 1; } else if (c == 'D') { return 2; } return 3; } vector<int> dir_X_to_Y[4][200001]; vector<int> dir_Y_to_X[4][200001]; vector<int> dir_X_plus_Y_to_Y[4][400001]; vector<int> dir_X_plus_Y_to_X[4][400001]; vector<int> dir_X_minus_Y_to_Y[4][400001]; vector<int> dir_X_minus_Y_to_X[4][400001]; int main() { int N; cin >> N; int X_max = INT_MIN; int X_min = INT_MAX; int Y_max = INT_MIN; int Y_min = INT_MAX; int diff_max = INT_MIN; int diff_min = INT_MAX; for (int i = 0; i < N; i++) { cin >> X[i] >> Y[i] >> U[i]; X_max = max(X_max, X[i]); X_min = min(X_min, X[i]); Y_max = max(Y_max, Y[i]); Y_min = min(Y_min, Y[i]); diff_max = max(diff_max, X[i] - Y[i]); diff_min = min(diff_min, X[i] - Y[i]); } for (int i = 0; i < N; i++) { dir_X_to_Y[dir_to_ind(U[i])][X[i]].push_back(Y[i]); dir_Y_to_X[dir_to_ind(U[i])][Y[i]].push_back(X[i]); dir_X_plus_Y_to_X[dir_to_ind(U[i])][X[i] + Y[i]].push_back(X[i]); dir_X_plus_Y_to_Y[dir_to_ind(U[i])][X[i] + Y[i]].push_back(Y[i]); dir_X_minus_Y_to_X[dir_to_ind(U[i])][X[i] - Y[i] - diff_min].push_back( X[i]); dir_X_minus_Y_to_Y[dir_to_ind(U[i])][X[i] - Y[i] - diff_min].push_back( Y[i]); } for (int i = 0; i <= X_max; i++) { for (int j = 0; j < 4; j++) { sort(dir_Y_to_X[j][i].begin(), dir_Y_to_X[j][i].end()); dir_Y_to_X[j][i].erase( unique(dir_Y_to_X[j][i].begin(), dir_Y_to_X[j][i].end()), dir_Y_to_X[j][i].end()); } } for (int i = 0; i <= Y_max; i++) { for (int j = 0; j < 4; j++) { sort(dir_X_to_Y[j][i].begin(), dir_X_to_Y[j][i].end()); dir_X_to_Y[j][i].erase( unique(dir_X_to_Y[j][i].begin(), dir_X_to_Y[j][i].end()), dir_X_to_Y[j][i].end()); } } for (int i = 0; i <= X_max + Y_max; i++) { for (int j = 0; j < 4; j++) { sort(dir_X_plus_Y_to_X[j][i].begin(), dir_X_plus_Y_to_X[j][i].end()); dir_X_plus_Y_to_X[j][i].erase(unique(dir_X_plus_Y_to_X[j][i].begin(), dir_X_plus_Y_to_X[j][i].end()), dir_X_plus_Y_to_X[j][i].end()); sort(dir_X_plus_Y_to_Y[j][i].begin(), dir_X_plus_Y_to_Y[j][i].end()); dir_X_plus_Y_to_Y[j][i].erase(unique(dir_X_plus_Y_to_Y[j][i].begin(), dir_X_plus_Y_to_Y[j][i].end()), dir_X_plus_Y_to_Y[j][i].end()); } } for (int i = diff_min; i <= diff_max; i++) { for (int j = 0; j < 4; j++) { sort(dir_X_minus_Y_to_X[j][i - diff_min].begin(), dir_X_minus_Y_to_X[j][i - diff_min].end()); dir_X_minus_Y_to_X[j][i - diff_min].erase( unique(dir_X_minus_Y_to_X[j][i - diff_min].begin(), dir_X_minus_Y_to_X[j][i - diff_min].end()), dir_X_minus_Y_to_X[j][i - diff_min].end()); sort(dir_X_minus_Y_to_Y[j][i - diff_min].begin(), dir_X_minus_Y_to_Y[j][i - diff_min].end()); dir_X_minus_Y_to_Y[j][i - diff_min].erase( unique(dir_X_minus_Y_to_Y[j][i - diff_min].begin(), dir_X_minus_Y_to_Y[j][i - diff_min].end()), dir_X_minus_Y_to_Y[j][i - diff_min].end()); } } int ans = INT_MAX; for (int i = 0; i < N; i++) { int sum_XY = X[i] + Y[i]; int diff_XY = X[i] - Y[i]; if (U[i] == 'U') { vector<int> collidable = dir_X_to_Y[dir_to_ind('D')][X[i]]; auto it = upper_bound(collidable.begin(), collidable.end(), Y[i]); if (it != collidable.end()) { ans = min(ans, (*it - Y[i]) * 5); } collidable = dir_X_plus_Y_to_Y[dir_to_ind('R')][sum_XY]; it = upper_bound(collidable.begin(), collidable.end(), Y[i]); if (it != collidable.end()) { ans = min(ans, (*it - Y[i]) * 10); } collidable = dir_X_minus_Y_to_Y[dir_to_ind('L')][diff_XY - diff_min]; it = upper_bound(collidable.begin(), collidable.end(), Y[i]); if (it != collidable.end()) { ans = min(ans, (*it - Y[i]) * 10); } } else if (U[i] == 'R') { vector<int> collidable = dir_Y_to_X[dir_to_ind('L')][Y[i]]; auto it = upper_bound(collidable.begin(), collidable.end(), X[i]); if (it != collidable.end()) { ans = min(ans, (*it - X[i]) * 5); } collidable = dir_X_plus_Y_to_X[dir_to_ind('U')][sum_XY]; it = upper_bound(collidable.begin(), collidable.end(), X[i]); if (it != collidable.end()) { ans = min(ans, (*it - X[i]) * 10); } collidable = dir_X_minus_Y_to_X[dir_to_ind('D')][diff_XY - diff_min]; it = upper_bound(collidable.begin(), collidable.end(), X[i]); if (it != collidable.end()) { ans = min(ans, (*it - X[i]) * 10); } } else if (U[i] == 'D') { vector<int> collidable = dir_X_to_Y[dir_to_ind('U')][X[i]]; auto it = lower_bound(collidable.begin(), collidable.end(), Y[i]); if (it != collidable.begin()) { it--; ans = min(ans, (Y[i] - *it) * 5); } collidable = dir_X_plus_Y_to_Y[dir_to_ind('L')][sum_XY]; it = lower_bound(collidable.begin(), collidable.end(), Y[i]); if (it != collidable.begin()) { it--; ans = min(ans, (Y[i] - *it) * 10); } collidable = dir_X_minus_Y_to_Y[dir_to_ind('R')][diff_XY - diff_min]; it = lower_bound(collidable.begin(), collidable.end(), Y[i]); // cout << collidable.size() << endl; if (it != collidable.begin()) { it--; ans = min(ans, (Y[i] - *it) * 10); } } else if (U[i] == 'L') { vector<int> collidable = dir_Y_to_X[dir_to_ind('R')][Y[i]]; auto it = lower_bound(collidable.begin(), collidable.end(), X[i]); if (it != collidable.begin()) { it--; ans = min(ans, (X[i] - *it) * 5); } collidable = dir_X_plus_Y_to_X[dir_to_ind('D')][sum_XY]; it = lower_bound(collidable.begin(), collidable.end(), X[i]); if (it != collidable.begin()) { it--; ans = min(ans, (X[i] - *it) * 10); } collidable = dir_X_minus_Y_to_X[dir_to_ind('U')][diff_XY - diff_min]; it = lower_bound(collidable.begin(), collidable.end(), X[i]); if (it != collidable.begin()) { it--; ans = min(ans, (X[i] - *it) * 10); } } } if (ans == INT_MAX) { cout << "SAFE" << endl; } else { cout << ans << endl; } return 0; }
replace
15
18
15
18
-11
p02605
C++
Runtime Error
#include <algorithm> #include <complex> #include <cstdint> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <math.h> #include <queue> #include <regex> #include <set> #include <stack> #include <stdio.h> #include <string> #include <time.h> #include <utility> #include <vector> using namespace std; using pii = pair<int, int>; using ll = long long; using ld = long double; #define pb push_back #define mp make_pair #define sc second #define fr first #define stpr setprecision #define cYES cout << "YES" << endl #define cNO cout << "NO" << endl #define cYes cout << "Yes" << endl #define cNo cout << "No" << endl #define rep(i, n) for (ll i = 0; i < (n); ++i) #define Rep(i, a, b) for (ll i = (a); i < (b); ++i) #define rrep(i, n) for (ll i = n - 1; i >= 0; i--) #define rRep(i, a, b) for (ll i = a; i >= b; i--) #define crep(i) for (char i = 'a'; i <= 'z'; ++i) #define psortsecond(A, N) \ sort(A, A + N, \ [](const pii &a, const pii &b) { return a.second < b.second; }); #define ALL(x) (x).begin(), (x).end() #define debug(v) \ cout << #v << ":"; \ for (auto x : v) { \ cout << x << ' '; \ } \ cout << endl; #define endl '\n' int ctoi(const char c) { if ('0' <= c && c <= '9') return (c - '0'); return -1; } ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } constexpr ll MOD = 1000000007; constexpr ll INF = 1000000011; constexpr ll MOD2 = 998244353; constexpr ll LINF = 1001002003004005006ll; constexpr ld EPS = 10e-8; template <class T, class U> inline bool chmax(T &lhs, const U &rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; } template <class T, class U> inline bool chmin(T &lhs, const U &rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &&x : v) is >> x; return is; } template <typename T, typename U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first; is >> p.second; return is; } template <typename T, typename U> ostream &operator>>(ostream &os, const pair<T, U> &p) { os << p.first << ' ' << p.second; return os; } template <class T> ostream &operator<<(ostream &os, vector<T> &v) { for (auto i = begin(v); i != end(v); ++i) { if (i != begin(v)) os << ' '; os << *i; } return os; } // modint template <std::uint_fast64_t Modulus> class modint { using u64 = std::uint_fast64_t; public: u64 a; constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; } constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; } constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; } constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; } constexpr modint &operator+=(const modint rhs) noexcept { a += rhs.a; if (a >= Modulus) { a -= Modulus; } return *this; } constexpr modint &operator-=(const modint rhs) noexcept { if (a < rhs.a) { a += Modulus; } a -= rhs.a; return *this; } constexpr modint &operator*=(const modint rhs) noexcept { a = a * rhs.a % Modulus; return *this; } constexpr modint &operator/=(modint rhs) noexcept { u64 exp = Modulus - 2; while (exp) { if (exp % 2) { *this *= rhs; } rhs *= rhs; exp /= 2; } return *this; } }; pair<pair<int, int>, char> P[20]; vector<set<int>> LU(800007), LD(800007), UL(800007), UR(800007), RU(800007), RD(800007), DL(800007), DR(800007), lU(800007), lD(800007), lL(800007), lR(800007); int main() { int N; cin >> N; rep(i, N) { cin >> P[i].fr.fr >> P[i].fr.sc >> P[i].sc; } ll K = 400000; ll ANS = INF; rep(i, N) { ll X = P[i].fr.fr, Y = P[i].fr.sc; if (P[i].sc == 'U') { UL[X - Y + K].insert(X); UR[X + Y + K].insert(X); lU[X + K].insert(Y); } if (P[i].sc == 'D') { DR[X - Y + K].insert(X); DL[X + Y + K].insert(X); lD[X + K].insert(Y); } if (P[i].sc == 'L') { LU[X - Y + K].insert(X); LD[X + Y + K].insert(X); lL[Y + K].insert(X); } if (P[i].sc == 'R') { RD[X - Y + K].insert(X); RU[X + Y + K].insert(X); lR[Y + K].insert(X); } if (P[i].sc == 'U') { set<int>::iterator it1, it2, it3; if (lD[X + K].size() > 0) { it1 = lD[X + K].upper_bound(Y); if (it1 != lD[X + K].end()) { ANS = min(ANS, (*it1 - Y) * 5); } } if (LU[X - Y + K].size() > 0) { it2 = LU[X - Y + K].upper_bound(X); if (it2 != LU[X - Y + K].end()) { ANS = min(ANS, (*it2 - X) * 10); } } if (RU[X + Y + K].size() > 0) { it3 = RU[X + Y + K].lower_bound(X); if (it3 != RU[X + Y + K].begin()) { advance(it3, -1); ANS = min(ANS, (X - *it3) * 10); } } } if (P[i].sc == 'D') { set<int>::iterator it1, it2, it3; if (lU[X + K].size() > 0) { it1 = lU[X + K].lower_bound(Y); if (it1 != lU[X + K].begin()) { advance(it1, -1); ANS = min(ANS, (Y - *it1) * 5); } } if (RD[X - Y + K].size() > 0) { it2 = RD[X - Y + K].lower_bound(X); if (it2 != RD[X - Y + K].begin()) { advance(it2, -1); ANS = min(ANS, (X - *it2) * 10); } } if (LD[X + Y + K].size() > 0) { it3 = LD[X + Y + K].upper_bound(X); if (it3 != LD[X + Y + K].end()) { ANS = min(ANS, (*it3 - X) * 10); } } } if (P[i].sc == 'R') { set<int>::iterator it1, it2, it3; if (lL[Y + K].size() > 0) { it1 = lL[Y + K].upper_bound(X); if (it1 != lL[Y + K].end()) { ANS = min(ANS, (*it1 - X) * 5); } } if (DR[X - Y + K].size() > 0) { it2 = DR[X - Y + K].upper_bound(X); if (it2 != DR[X - Y + K].end()) { ANS = min(ANS, (*it2 - X) * 10); } } if (UR[X + Y + K].size() > 0) { it3 = UR[X + Y + K].upper_bound(X); if (it3 != UR[X + Y + K].end()) { ANS = min(ANS, (*it3 - X) * 10); } } } if (P[i].sc == 'L') { set<int>::iterator it1, it2, it3; if (lR[Y + K].size() > 0) { it1 = lR[Y + K].lower_bound(X); if (it1 != lR[Y + K].begin()) { advance(it1, -1); ANS = min(ANS, (X - *it1) * 5); } } if (UL[X - Y + K].size() > 0) { it2 = UL[X - Y + K].lower_bound(X); if (it2 != UL[X - Y + K].begin()) { advance(it2, -1); ANS = min(ANS, (X - *it2) * 10); } } if (DL[X + Y + K].size() > 0) { it3 = DL[X + Y + K].lower_bound(X); if (it3 != DL[X + Y + K].begin()) { advance(it3, -1); ANS = min(ANS, (X - *it3) * 10); } } } // cout << ANS << endl; } if (ANS == INF) { cout << "SAFE" << endl; } else { cout << ANS << endl; } }
#include <algorithm> #include <complex> #include <cstdint> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <math.h> #include <queue> #include <regex> #include <set> #include <stack> #include <stdio.h> #include <string> #include <time.h> #include <utility> #include <vector> using namespace std; using pii = pair<int, int>; using ll = long long; using ld = long double; #define pb push_back #define mp make_pair #define sc second #define fr first #define stpr setprecision #define cYES cout << "YES" << endl #define cNO cout << "NO" << endl #define cYes cout << "Yes" << endl #define cNo cout << "No" << endl #define rep(i, n) for (ll i = 0; i < (n); ++i) #define Rep(i, a, b) for (ll i = (a); i < (b); ++i) #define rrep(i, n) for (ll i = n - 1; i >= 0; i--) #define rRep(i, a, b) for (ll i = a; i >= b; i--) #define crep(i) for (char i = 'a'; i <= 'z'; ++i) #define psortsecond(A, N) \ sort(A, A + N, \ [](const pii &a, const pii &b) { return a.second < b.second; }); #define ALL(x) (x).begin(), (x).end() #define debug(v) \ cout << #v << ":"; \ for (auto x : v) { \ cout << x << ' '; \ } \ cout << endl; #define endl '\n' int ctoi(const char c) { if ('0' <= c && c <= '9') return (c - '0'); return -1; } ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } constexpr ll MOD = 1000000007; constexpr ll INF = 1000000011; constexpr ll MOD2 = 998244353; constexpr ll LINF = 1001002003004005006ll; constexpr ld EPS = 10e-8; template <class T, class U> inline bool chmax(T &lhs, const U &rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; } template <class T, class U> inline bool chmin(T &lhs, const U &rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &&x : v) is >> x; return is; } template <typename T, typename U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first; is >> p.second; return is; } template <typename T, typename U> ostream &operator>>(ostream &os, const pair<T, U> &p) { os << p.first << ' ' << p.second; return os; } template <class T> ostream &operator<<(ostream &os, vector<T> &v) { for (auto i = begin(v); i != end(v); ++i) { if (i != begin(v)) os << ' '; os << *i; } return os; } // modint template <std::uint_fast64_t Modulus> class modint { using u64 = std::uint_fast64_t; public: u64 a; constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; } constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; } constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; } constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; } constexpr modint &operator+=(const modint rhs) noexcept { a += rhs.a; if (a >= Modulus) { a -= Modulus; } return *this; } constexpr modint &operator-=(const modint rhs) noexcept { if (a < rhs.a) { a += Modulus; } a -= rhs.a; return *this; } constexpr modint &operator*=(const modint rhs) noexcept { a = a * rhs.a % Modulus; return *this; } constexpr modint &operator/=(modint rhs) noexcept { u64 exp = Modulus - 2; while (exp) { if (exp % 2) { *this *= rhs; } rhs *= rhs; exp /= 2; } return *this; } }; pair<pair<int, int>, char> P[200000]; vector<set<int>> LU(800007), LD(800007), UL(800007), UR(800007), RU(800007), RD(800007), DL(800007), DR(800007), lU(800007), lD(800007), lL(800007), lR(800007); int main() { int N; cin >> N; rep(i, N) { cin >> P[i].fr.fr >> P[i].fr.sc >> P[i].sc; } ll K = 400000; ll ANS = INF; rep(i, N) { ll X = P[i].fr.fr, Y = P[i].fr.sc; if (P[i].sc == 'U') { UL[X - Y + K].insert(X); UR[X + Y + K].insert(X); lU[X + K].insert(Y); } if (P[i].sc == 'D') { DR[X - Y + K].insert(X); DL[X + Y + K].insert(X); lD[X + K].insert(Y); } if (P[i].sc == 'L') { LU[X - Y + K].insert(X); LD[X + Y + K].insert(X); lL[Y + K].insert(X); } if (P[i].sc == 'R') { RD[X - Y + K].insert(X); RU[X + Y + K].insert(X); lR[Y + K].insert(X); } if (P[i].sc == 'U') { set<int>::iterator it1, it2, it3; if (lD[X + K].size() > 0) { it1 = lD[X + K].upper_bound(Y); if (it1 != lD[X + K].end()) { ANS = min(ANS, (*it1 - Y) * 5); } } if (LU[X - Y + K].size() > 0) { it2 = LU[X - Y + K].upper_bound(X); if (it2 != LU[X - Y + K].end()) { ANS = min(ANS, (*it2 - X) * 10); } } if (RU[X + Y + K].size() > 0) { it3 = RU[X + Y + K].lower_bound(X); if (it3 != RU[X + Y + K].begin()) { advance(it3, -1); ANS = min(ANS, (X - *it3) * 10); } } } if (P[i].sc == 'D') { set<int>::iterator it1, it2, it3; if (lU[X + K].size() > 0) { it1 = lU[X + K].lower_bound(Y); if (it1 != lU[X + K].begin()) { advance(it1, -1); ANS = min(ANS, (Y - *it1) * 5); } } if (RD[X - Y + K].size() > 0) { it2 = RD[X - Y + K].lower_bound(X); if (it2 != RD[X - Y + K].begin()) { advance(it2, -1); ANS = min(ANS, (X - *it2) * 10); } } if (LD[X + Y + K].size() > 0) { it3 = LD[X + Y + K].upper_bound(X); if (it3 != LD[X + Y + K].end()) { ANS = min(ANS, (*it3 - X) * 10); } } } if (P[i].sc == 'R') { set<int>::iterator it1, it2, it3; if (lL[Y + K].size() > 0) { it1 = lL[Y + K].upper_bound(X); if (it1 != lL[Y + K].end()) { ANS = min(ANS, (*it1 - X) * 5); } } if (DR[X - Y + K].size() > 0) { it2 = DR[X - Y + K].upper_bound(X); if (it2 != DR[X - Y + K].end()) { ANS = min(ANS, (*it2 - X) * 10); } } if (UR[X + Y + K].size() > 0) { it3 = UR[X + Y + K].upper_bound(X); if (it3 != UR[X + Y + K].end()) { ANS = min(ANS, (*it3 - X) * 10); } } } if (P[i].sc == 'L') { set<int>::iterator it1, it2, it3; if (lR[Y + K].size() > 0) { it1 = lR[Y + K].lower_bound(X); if (it1 != lR[Y + K].begin()) { advance(it1, -1); ANS = min(ANS, (X - *it1) * 5); } } if (UL[X - Y + K].size() > 0) { it2 = UL[X - Y + K].lower_bound(X); if (it2 != UL[X - Y + K].begin()) { advance(it2, -1); ANS = min(ANS, (X - *it2) * 10); } } if (DL[X + Y + K].size() > 0) { it3 = DL[X + Y + K].lower_bound(X); if (it3 != DL[X + Y + K].begin()) { advance(it3, -1); ANS = min(ANS, (X - *it3) * 10); } } } // cout << ANS << endl; } if (ANS == INF) { cout << "SAFE" << endl; } else { cout << ANS << endl; } }
replace
154
155
154
155
-6
terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc
p02605
C++
Runtime Error
#include <algorithm> #include <array> #include <bitset> #include <cmath> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; #pragma region define #define M_PI 3.141592653589793238 #define upperbound(v, val) upper_bound(v.begin(), v.end(), val) - v.begin() #define lowerbound(v, val) lower_bound(v.begin(), v.end(), val) - v.begin() #define int long long #define vel vector<long long> #define vvel vector<vel> #define rep(i, n) for (int i = 0; i < n; i++) #define sor(v) sort(v.begin(), v.end()) #define mmax(a, b) a = max(a, b) #define mmin(a, b) a = min(a, b) #define mkp(a, b) make_pair(a, b) #define pin pair<int, int> #define qin pair<pin, int> #define V vector #define Endl endl #define veb vector<bool> #define fcout cout << fixed << setprecision(15) #define rev(s) reverse(s.begin(), s.end()) #define lower(h, val) (lower_bound(h.begin(), h.end(), val) - h.begin()) #define upper(h, val) (upper_bound(h.begin(), h.end(), val) - h.begin()) #define vveb V<veb> #define omajinai \ cin.tie(0); \ ios::sync_with_stdio(false); #define endl "\n" #define pb push_back #pragma endregion #pragma region Inner Class int root(int x, vel &pa) { if (pa[x] == -1) { return x; } int ans = root(pa[x], pa); pa[x] = ans; return ans; } bool mar(int x, int y, vel &pa) { x = root(x, pa); y = root(y, pa); if (x != y) { pa[x] = y; } return (x != y); } int gcd(int x, int y) { if (x < y) { return gcd(y, x); } if (y == 0) { return x; } return gcd(y, x % y); } int lcm(int x, int y) { x = abs(x); y = abs(y); return x * (y / gcd(x, y)); } long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } vel dijk(V<V<pin>> way, int st, int inf) { int n = way.size(); vel dist(n, inf); dist[st] = 0; priority_queue<pin, vector<pin>, greater<pin>> pq; pq.push(mkp(0, st)); veb is_checked(n, false); while (!pq.empty()) { pin x = pq.top(); pq.pop(); int pot = x.second; if (!is_checked[pot]) { is_checked[pot] = true; for (auto y : way[pot]) { int nex_dist = x.first + y.second; int nex_pot = y.first; if (dist[nex_pot] > nex_dist) { dist[nex_pot] = nex_dist; pq.push(mkp(nex_dist, y.first)); } } } } return dist; } V<V<pin>> make_w(vvel v) { int n = v.size(); V<V<pin>> ret(n); rep(i, n) { for (int x : v[i]) { ret[i].push_back(mkp(x, 1)); } } return ret; } void make_tree(vvel &chi, vel &par, int n, int st) { V<V<pin>> way(n); rep(i, n - 1) { int a, b; cin >> a >> b; a--; b--; way[a].push_back(mkp(b, 1)); way[b].push_back(mkp(a, 1)); } vel dist = dijk(way, st, n + 1); par = vel(n, -1); chi = vvel(n); rep(i, n) { for (auto nex : way[i]) { int pot = nex.first; if (dist[pot] > dist[i]) { chi[i].push_back(pot); } else { par[i] = pot; } } } } void pri(vel &v) { if (v.size() == 0) { return; } cout << v[0]; rep(i, v.size() - 1) { cout << " " << v[i + 1]; } cout << endl; return; } vvel disj_min(vel &v) { int n = v.size(); vvel ret(22, vel(n)); ret[0] = v; rep(i, 21) { rep(j, n) { int nex = j + (1 << i); if (nex < n) { ret[i + 1][j] = min(ret[i][j], ret[i][nex]); } else { ret[i + 1][j] = ret[i][j]; } } } return ret; } int find_min(vvel &dv, int l, int r) { int i = 21; while (l + (1 << i) > r) { i--; } while (i >= 0) { if (dv[i][l] > dv[i][r - (1 << i)]) { l = r - (1 << i); } else { r = l + (1 << i); } i--; } return l; } V<V<pin>> dbl(V<pin> &v) { V<V<pin>> ans(20, V<pin>(v)); int n = v.size(); rep(i, 19) { rep(j, n) { ans[i + 1][j].first = ans[i][ans[i][j].first].first; ans[i + 1][j].second = max(ans[i][j].second, ans[i][ans[i][j].first].second); } } return ans; } int lca(int s, int t, int diff, V<V<pin>> &pa) { if (diff < 0) { return lca(t, s, -diff, pa); } int ans = 0; rep(i, 19) { if ((diff & (1 << i)) != 0) { mmax(ans, pa[i][s].second); s = pa[i][s].first; } } for (int i = 19; i >= 0; i--) { if (pa[i][s] != pa[i][t]) { mmax(ans, pa[i][s].second); s = pa[i][s].first; mmax(ans, pa[i][t].second); t = pa[i][t].first; } } if (s != t) { mmax(ans, pa[0][s].second); mmax(ans, pa[0][t].second); } return ans; } void alp(int n, vel &pr) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) { pr.push_back(i); while (n % i == 0) { n /= i; } } } if (n != 1) { pr.push_back(n); } } vel dx = {0, 0, -1, 1, 1, -1}; vel dy = {1, -1, 0, 0, 1, 1}; #define all(a) a.begin(), a.end() template <typename T> void mk_uni(V<T> &a) { std::sort(a.begin(), a.end()); a.erase(std::unique(a.begin(), a.end()), a.end()); } template <std::uint_fast64_t Modulus> class modint { using u64 = std::uint_fast64_t; public: u64 a; constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; } constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; } constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; } constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; } constexpr modint &operator+=(const modint rhs) noexcept { a += rhs.a; if (a >= Modulus) { a -= Modulus; } return *this; } constexpr modint &operator-=(const modint rhs) noexcept { if (a < rhs.a) { a += Modulus; } a -= rhs.a; return *this; } constexpr modint &operator*=(const modint rhs) noexcept { a = a * rhs.a % Modulus; return *this; } constexpr modint &operator/=(modint rhs) noexcept { u64 exp = Modulus - 2; while (exp) { if (exp % 2) { *this *= rhs; } rhs *= rhs; exp /= 2; } return *this; } }; #pragma endregion // using mint = modint<998244353>; using mint = modint<1000000007>; using vem = vector<mint>; using vvem = vector<vem>; #pragma region mint mint mpow(mint a, int n) { mint ans = 1; while (n) { if (n & 1) { ans *= a; } a *= a; n /= 2; } return ans; } vem kai, inv_kai; void make_kai(int n) { kai = vem(n + 1, 1); inv_kai = vem(n + 1, 1); rep(i, n) { kai[i + 1] = kai[i] * (i + 1); } inv_kai[n] = (mint)1 / kai[n]; for (int i = n; i > 0; i--) { inv_kai[i - 1] = inv_kai[i] * i; } } mint com(int n, int r) { if (n < 0 || r < 0 || n < r) { return 0; } return kai[n] * inv_kai[r] * inv_kai[n - r]; } mint per(int n, int r) { if (n < 0 || r < 0 || n < r) { return 0; } return kai[n] * inv_kai[r]; } #pragma endregion int inf = 500001; int sol(vel &u, vel &d) { sor(u); sor(d); int ans = inf * inf; for (auto d1 : d) { auto itr = lower_bound(all(u), d1); if (itr != u.end()) { mmin(ans, (*itr) - d1); } } return ans; } int sol1(vel &x, vel &y, vel &u) { vvel mn(inf); vvel mx(inf); int n = x.size(); rep(i, n) { if (u[i] == 0) { mn[x[i]].push_back(y[i]); } if (u[i] == 2) { mx[x[i]].push_back(y[i]); } } int ans = inf * inf; rep(i, inf) { mmin(ans, sol(mx[i], mn[i])); } return ans; } int sol2(vel &x, vel &y, vel &u) { vvel mn(2 * inf); vvel mx(2 * inf); int n = x.size(); rep(i, n) { if (u[i] == 0) { mn[x[i] + y[i]].push_back(y[i]); } if (u[i] == 1) { mx[x[i] + y[i]].push_back(y[i]); } } int ans = inf * inf; rep(i, 2 * inf) { mmin(ans, sol(mx[i], mn[i])); } return 2 * ans; } signed main() { omajinai; int n; cin >> n; vel x(n), y(n), u(n); string s = "URDL"; rep(i, n) { cin >> x[i] >> y[i]; char c; cin >> c; rep(j, 4) { if (s[j] == c) { u[i] = j; } } } int ans = inf * inf; mmin(ans, sol1(x, y, u)); rep(i, n) { swap(x[i], y[i]); u[i] ^= 1; } mmin(ans, sol1(x, y, u)); mmin(ans, sol2(x, y, u)); rep(i, n) { y[i] *= -1; y[i] += 200000; if (u[i] % 2 == 0) { u[i] ^= 2; } } mmin(ans, sol2(x, y, u)); rep(i, n) { x[i] *= -1; x[i] += 200000; if (u[i] % 2 == 1) { u[i] ^= 2; } } mmin(ans, sol2(x, y, u)); rep(i, n) { y[i] *= -1; y[i] += 200000; if (u[i] % 2 == 0) { u[i] ^= 2; } } mmin(ans, sol2(x, y, u)); if (ans >= inf) { V<int> v(3, 0); cout << v.at(4) << endl; cout << "SAFE" << endl; return 0; } cout << ans * 5 << endl; return 0; }
#include <algorithm> #include <array> #include <bitset> #include <cmath> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; #pragma region define #define M_PI 3.141592653589793238 #define upperbound(v, val) upper_bound(v.begin(), v.end(), val) - v.begin() #define lowerbound(v, val) lower_bound(v.begin(), v.end(), val) - v.begin() #define int long long #define vel vector<long long> #define vvel vector<vel> #define rep(i, n) for (int i = 0; i < n; i++) #define sor(v) sort(v.begin(), v.end()) #define mmax(a, b) a = max(a, b) #define mmin(a, b) a = min(a, b) #define mkp(a, b) make_pair(a, b) #define pin pair<int, int> #define qin pair<pin, int> #define V vector #define Endl endl #define veb vector<bool> #define fcout cout << fixed << setprecision(15) #define rev(s) reverse(s.begin(), s.end()) #define lower(h, val) (lower_bound(h.begin(), h.end(), val) - h.begin()) #define upper(h, val) (upper_bound(h.begin(), h.end(), val) - h.begin()) #define vveb V<veb> #define omajinai \ cin.tie(0); \ ios::sync_with_stdio(false); #define endl "\n" #define pb push_back #pragma endregion #pragma region Inner Class int root(int x, vel &pa) { if (pa[x] == -1) { return x; } int ans = root(pa[x], pa); pa[x] = ans; return ans; } bool mar(int x, int y, vel &pa) { x = root(x, pa); y = root(y, pa); if (x != y) { pa[x] = y; } return (x != y); } int gcd(int x, int y) { if (x < y) { return gcd(y, x); } if (y == 0) { return x; } return gcd(y, x % y); } int lcm(int x, int y) { x = abs(x); y = abs(y); return x * (y / gcd(x, y)); } long long modinv(long long a, long long m) { long long b = m, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } vel dijk(V<V<pin>> way, int st, int inf) { int n = way.size(); vel dist(n, inf); dist[st] = 0; priority_queue<pin, vector<pin>, greater<pin>> pq; pq.push(mkp(0, st)); veb is_checked(n, false); while (!pq.empty()) { pin x = pq.top(); pq.pop(); int pot = x.second; if (!is_checked[pot]) { is_checked[pot] = true; for (auto y : way[pot]) { int nex_dist = x.first + y.second; int nex_pot = y.first; if (dist[nex_pot] > nex_dist) { dist[nex_pot] = nex_dist; pq.push(mkp(nex_dist, y.first)); } } } } return dist; } V<V<pin>> make_w(vvel v) { int n = v.size(); V<V<pin>> ret(n); rep(i, n) { for (int x : v[i]) { ret[i].push_back(mkp(x, 1)); } } return ret; } void make_tree(vvel &chi, vel &par, int n, int st) { V<V<pin>> way(n); rep(i, n - 1) { int a, b; cin >> a >> b; a--; b--; way[a].push_back(mkp(b, 1)); way[b].push_back(mkp(a, 1)); } vel dist = dijk(way, st, n + 1); par = vel(n, -1); chi = vvel(n); rep(i, n) { for (auto nex : way[i]) { int pot = nex.first; if (dist[pot] > dist[i]) { chi[i].push_back(pot); } else { par[i] = pot; } } } } void pri(vel &v) { if (v.size() == 0) { return; } cout << v[0]; rep(i, v.size() - 1) { cout << " " << v[i + 1]; } cout << endl; return; } vvel disj_min(vel &v) { int n = v.size(); vvel ret(22, vel(n)); ret[0] = v; rep(i, 21) { rep(j, n) { int nex = j + (1 << i); if (nex < n) { ret[i + 1][j] = min(ret[i][j], ret[i][nex]); } else { ret[i + 1][j] = ret[i][j]; } } } return ret; } int find_min(vvel &dv, int l, int r) { int i = 21; while (l + (1 << i) > r) { i--; } while (i >= 0) { if (dv[i][l] > dv[i][r - (1 << i)]) { l = r - (1 << i); } else { r = l + (1 << i); } i--; } return l; } V<V<pin>> dbl(V<pin> &v) { V<V<pin>> ans(20, V<pin>(v)); int n = v.size(); rep(i, 19) { rep(j, n) { ans[i + 1][j].first = ans[i][ans[i][j].first].first; ans[i + 1][j].second = max(ans[i][j].second, ans[i][ans[i][j].first].second); } } return ans; } int lca(int s, int t, int diff, V<V<pin>> &pa) { if (diff < 0) { return lca(t, s, -diff, pa); } int ans = 0; rep(i, 19) { if ((diff & (1 << i)) != 0) { mmax(ans, pa[i][s].second); s = pa[i][s].first; } } for (int i = 19; i >= 0; i--) { if (pa[i][s] != pa[i][t]) { mmax(ans, pa[i][s].second); s = pa[i][s].first; mmax(ans, pa[i][t].second); t = pa[i][t].first; } } if (s != t) { mmax(ans, pa[0][s].second); mmax(ans, pa[0][t].second); } return ans; } void alp(int n, vel &pr) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) { pr.push_back(i); while (n % i == 0) { n /= i; } } } if (n != 1) { pr.push_back(n); } } vel dx = {0, 0, -1, 1, 1, -1}; vel dy = {1, -1, 0, 0, 1, 1}; #define all(a) a.begin(), a.end() template <typename T> void mk_uni(V<T> &a) { std::sort(a.begin(), a.end()); a.erase(std::unique(a.begin(), a.end()), a.end()); } template <std::uint_fast64_t Modulus> class modint { using u64 = std::uint_fast64_t; public: u64 a; constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; } constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; } constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; } constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; } constexpr modint &operator+=(const modint rhs) noexcept { a += rhs.a; if (a >= Modulus) { a -= Modulus; } return *this; } constexpr modint &operator-=(const modint rhs) noexcept { if (a < rhs.a) { a += Modulus; } a -= rhs.a; return *this; } constexpr modint &operator*=(const modint rhs) noexcept { a = a * rhs.a % Modulus; return *this; } constexpr modint &operator/=(modint rhs) noexcept { u64 exp = Modulus - 2; while (exp) { if (exp % 2) { *this *= rhs; } rhs *= rhs; exp /= 2; } return *this; } }; #pragma endregion // using mint = modint<998244353>; using mint = modint<1000000007>; using vem = vector<mint>; using vvem = vector<vem>; #pragma region mint mint mpow(mint a, int n) { mint ans = 1; while (n) { if (n & 1) { ans *= a; } a *= a; n /= 2; } return ans; } vem kai, inv_kai; void make_kai(int n) { kai = vem(n + 1, 1); inv_kai = vem(n + 1, 1); rep(i, n) { kai[i + 1] = kai[i] * (i + 1); } inv_kai[n] = (mint)1 / kai[n]; for (int i = n; i > 0; i--) { inv_kai[i - 1] = inv_kai[i] * i; } } mint com(int n, int r) { if (n < 0 || r < 0 || n < r) { return 0; } return kai[n] * inv_kai[r] * inv_kai[n - r]; } mint per(int n, int r) { if (n < 0 || r < 0 || n < r) { return 0; } return kai[n] * inv_kai[r]; } #pragma endregion int inf = 500001; int sol(vel &u, vel &d) { sor(u); sor(d); int ans = inf * inf; for (auto d1 : d) { auto itr = lower_bound(all(u), d1); if (itr != u.end()) { mmin(ans, (*itr) - d1); } } return ans; } int sol1(vel &x, vel &y, vel &u) { vvel mn(inf); vvel mx(inf); int n = x.size(); rep(i, n) { if (u[i] == 0) { mn[x[i]].push_back(y[i]); } if (u[i] == 2) { mx[x[i]].push_back(y[i]); } } int ans = inf * inf; rep(i, inf) { mmin(ans, sol(mx[i], mn[i])); } return ans; } int sol2(vel &x, vel &y, vel &u) { vvel mn(2 * inf); vvel mx(2 * inf); int n = x.size(); rep(i, n) { if (u[i] == 0) { mn[x[i] + y[i]].push_back(y[i]); } if (u[i] == 1) { mx[x[i] + y[i]].push_back(y[i]); } } int ans = inf * inf; rep(i, 2 * inf) { mmin(ans, sol(mx[i], mn[i])); } return 2 * ans; } signed main() { omajinai; int n; cin >> n; vel x(n), y(n), u(n); string s = "URDL"; rep(i, n) { cin >> x[i] >> y[i]; char c; cin >> c; rep(j, 4) { if (s[j] == c) { u[i] = j; } } } int ans = inf * inf; mmin(ans, sol1(x, y, u)); rep(i, n) { swap(x[i], y[i]); u[i] ^= 1; } mmin(ans, sol1(x, y, u)); mmin(ans, sol2(x, y, u)); rep(i, n) { y[i] *= -1; y[i] += 200000; if (u[i] % 2 == 0) { u[i] ^= 2; } } mmin(ans, sol2(x, y, u)); rep(i, n) { x[i] *= -1; x[i] += 200000; if (u[i] % 2 == 1) { u[i] ^= 2; } } mmin(ans, sol2(x, y, u)); rep(i, n) { y[i] *= -1; y[i] += 200000; if (u[i] % 2 == 0) { u[i] ^= 2; } } mmin(ans, sol2(x, y, u)); if (ans >= inf) { cout << "SAFE" << endl; return 0; } cout << ans * 5 << endl; return 0; }
delete
434
436
434
434
0
p02605
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define NDEBUG #include <cassert> typedef long long ll; typedef long double Double; typedef unsigned long long ull; typedef pair<int, int> ii; typedef pair<ll, ll> llll; typedef pair<double, double> dd; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<ii> vii; typedef vector<vector<ii>> vvii; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef vector<llll> vllll; typedef vector<bool> vb; typedef vector<string> vs; typedef vector<double> vd; typedef vector<long double> vD; #define sz(a) int((a).size()) #define pb push_back #define eb emplace_back #define FOR(var, from, to) for (int var = (from); var <= (to); ++var) #define rep(var, n) for (int var = 0; var < (n); ++var) #define rep1(var, n) for (int var = 1; var <= (n); ++var) #define repC2(vari, varj, n) \ for (int vari = 0; vari < (n)-1; ++vari) \ for (int varj = vari + 1; varj < (n); ++varj) #define repC3(vari, varj, vark, n) \ for (int vari = 0; vari < (n)-2; ++vari) \ for (int varj = vari + 1; varj < (n)-1; ++varj) \ for (int vark = varj + 1; vark < (n); ++vark) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define tr(i, c) for (auto i = (c).begin(); i != (c).end(); ++i) #define found(s, e) ((s).find(e) != (s).end()) #define mset(arr, val) memset(arr, val, sizeof(arr)) #define mid(x, y) ((x) + ((y) - (x)) / 2) #define IN(x, a, b) ((a) <= (x) && (x) <= (b)) #define cons make_pair #define clamp(v, lo, hi) min(max(v, lo), hi) #define ABS(x) max((x), -(x)) #define PQ(T) priority_queue<T, vector<T>, greater<T>> template <typename T1, typename T2> inline void amin(T1 &a, T2 const &b) { if (a > b) a = b; } template <typename T1, typename T2> inline void amax(T1 &a, T2 const &b) { if (a < b) a = b; } template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); } template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); } inline ll square(ll x) { return x * x; } inline ll gcd(ll a, ll b) { while (a) swap(a, b %= a); return b; } inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } template <typename T> inline T mod(T a, T b) { return ((a % b) + b) % b; } template <typename T> int find_left(vector<T> &v, T elem) { return (int)(upper_bound(v.begin(), v.end(), elem) - v.begin()) - 1; } template <typename T> int find_right(vector<T> &v, T elem) { return (int)(lower_bound(v.begin(), v.end(), elem) - v.begin()); } const ll MOD = 1000000007LL; inline ll ADD(ll x, ll y) { return (x + y) % MOD; } inline ll SUB(ll x, ll y) { return (x - y + MOD) % MOD; } inline ll MUL(ll x, ll y) { return x * y % MOD; } inline ll POW(ll x, ll e) { ll v = 1; for (; e; x = MUL(x, x), e >>= 1) if (e & 1) v = MUL(v, x); return v; } inline ll INV(ll y) { /*assert(y%MOD!=0);*/ return POW(y, MOD - 2); } inline ll DIV(ll x, ll y) { return MUL(x, INV(y)); } #define INTSPACE 12 char _buf[INTSPACE * 1000000 + 3]; int loadint() { if (fgets(_buf, INTSPACE + 3, stdin) == NULL) return 0; return atoi(_buf); } int loadvec(vector<int> &v, int N = -1) { if (N == 0) { v.clear(); return 0; } if (N == -1) { N = loadint(); if (N == 0) return 0; } int bufsize = INTSPACE * N + 3; if (fgets(_buf, bufsize, stdin) == NULL) return 0; v.resize(N); int i = 0; bool last = false; for (char *p = &_buf[0];;) { char *q = p; while (*q > ' ') ++q; if (*q == 0x0D || *q == 0x0A) last = true; *q = 0; v[i++] = atoi(p); if (last || i == N) break; p = q + 1; } return i; } void read_cr() { fgets(_buf, 256, stdin); } void horizontal(vector<int> &v) { int L = v.size(); for (int i = 0; i < L; ++i) { printf("%d%c", v[i], (i == L - 1) ? '\n' : ' '); } } void horizontall(vector<long long> &v) { int L = v.size(); for (int i = 0; i < L; ++i) { printf("%lld%c", v[i], (i == L - 1) ? '\n' : ' '); } } int solve(int N, vi &xs, vi &ys, vector<char> &dir) { map<int, vi> r_h, l_h, u_v, d_v; map<int, vi> r_add, r_sub, l_add, l_sub, u_add, u_sub, d_add, d_sub; rep(i, N) { int x = xs[i], y = ys[i]; switch (dir[i]) { case 'R': r_h[y].pb(x); r_add[x + y].pb(x); r_sub[x - y].pb(x); break; case 'L': l_h[y].pb(x); l_add[x + y].pb(x); l_sub[x - y].pb(x); break; case 'U': u_v[x].pb(y); u_add[x + y].pb(x); u_sub[x - y].pb(x); break; case 'D': d_v[x].pb(y); d_add[x + y].pb(x); d_sub[x - y].pb(x); break; } } for (auto &p : r_h) { sort(ALL(p.second)); } for (auto &p : r_add) { sort(ALL(p.second)); } for (auto &p : r_sub) { sort(ALL(p.second)); } for (auto &p : l_h) { sort(ALL(p.second)); } for (auto &p : l_add) { sort(ALL(p.second)); } for (auto &p : l_sub) { sort(ALL(p.second)); } for (auto &p : u_v) { sort(ALL(p.second)); } for (auto &p : u_add) { sort(ALL(p.second)); } for (auto &p : u_sub) { sort(ALL(p.second)); } for (auto &p : d_v) { sort(ALL(p.second)); } for (auto &p : d_add) { sort(ALL(p.second)); } for (auto &p : d_sub) { sort(ALL(p.second)); } int bump = INT_MAX; for (auto &p : r_h) { int y = p.first; for (int x : p.second) { int add = x + y, sub = x - y; int S = l_h[y].size(); if (S > 0) { int ix = upper_bound(ALL(l_h[y]), x) - l_h[y].begin(); if (ix < S) { int x2 = l_h[y][ix]; amin(bump, 5 * (x2 - x)); } } S = u_add[add].size(); if (S > 0) { int ix = upper_bound(ALL(u_add[sub]), x) - u_add[add].begin(); if (ix < S) { int x2 = u_add[add][ix]; amin(bump, 10 * (x2 - x)); } } S = d_sub[sub].size(); if (S > 0) { int ix = upper_bound(ALL(d_sub[sub]), x) - d_sub[sub].begin(); if (ix < S) { int x2 = d_sub[sub][ix]; amin(bump, 10 * (x2 - x)); } } } } for (auto &p : u_v) { int x = p.first; for (int y : p.second) { int add = x + y, sub = x - y; int S = d_v[x].size(); if (S > 0) { int ix = upper_bound(ALL(d_v[x]), y) - d_v[x].begin(); if (ix < S) { int y2 = d_v[x][ix]; amin(bump, 5 * (y2 - y)); } } S = l_sub[sub].size(); if (S > 0) { int ix = upper_bound(ALL(l_sub[sub]), x) - l_sub[sub].begin(); if (ix < S) { int x2 = l_sub[sub][ix]; amin(bump, 10 * (x2 - x)); } } } } for (auto &p : d_v) { int x = p.first; for (int y : p.second) { int add = x + y, sub = x - y; int S = l_add[add].size(); if (S > 0) { int ix = upper_bound(ALL(l_add[add]), x) - l_add[add].begin(); if (ix < S) { int x2 = l_add[add][ix]; amin(bump, 10 * (x2 - x)); } } } } return bump; } int main() { int N; scanf("%d%*c", &N); vi x(N), y(N); vector<char> u(N); rep(i, N) { scanf("%d %d %c%*c", &x[i], &y[i], &u[i]); } int bump = solve(N, x, y, u); if (bump == INT_MAX) printf("SAFE\n"); else printf("%d\n", bump); return 0; }
#include <bits/stdc++.h> using namespace std; #define NDEBUG #include <cassert> typedef long long ll; typedef long double Double; typedef unsigned long long ull; typedef pair<int, int> ii; typedef pair<ll, ll> llll; typedef pair<double, double> dd; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<ii> vii; typedef vector<vector<ii>> vvii; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef vector<llll> vllll; typedef vector<bool> vb; typedef vector<string> vs; typedef vector<double> vd; typedef vector<long double> vD; #define sz(a) int((a).size()) #define pb push_back #define eb emplace_back #define FOR(var, from, to) for (int var = (from); var <= (to); ++var) #define rep(var, n) for (int var = 0; var < (n); ++var) #define rep1(var, n) for (int var = 1; var <= (n); ++var) #define repC2(vari, varj, n) \ for (int vari = 0; vari < (n)-1; ++vari) \ for (int varj = vari + 1; varj < (n); ++varj) #define repC3(vari, varj, vark, n) \ for (int vari = 0; vari < (n)-2; ++vari) \ for (int varj = vari + 1; varj < (n)-1; ++varj) \ for (int vark = varj + 1; vark < (n); ++vark) #define ALL(c) (c).begin(), (c).end() #define RALL(c) (c).rbegin(), (c).rend() #define tr(i, c) for (auto i = (c).begin(); i != (c).end(); ++i) #define found(s, e) ((s).find(e) != (s).end()) #define mset(arr, val) memset(arr, val, sizeof(arr)) #define mid(x, y) ((x) + ((y) - (x)) / 2) #define IN(x, a, b) ((a) <= (x) && (x) <= (b)) #define cons make_pair #define clamp(v, lo, hi) min(max(v, lo), hi) #define ABS(x) max((x), -(x)) #define PQ(T) priority_queue<T, vector<T>, greater<T>> template <typename T1, typename T2> inline void amin(T1 &a, T2 const &b) { if (a > b) a = b; } template <typename T1, typename T2> inline void amax(T1 &a, T2 const &b) { if (a < b) a = b; } template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); } template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); } inline ll square(ll x) { return x * x; } inline ll gcd(ll a, ll b) { while (a) swap(a, b %= a); return b; } inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } template <typename T> inline T mod(T a, T b) { return ((a % b) + b) % b; } template <typename T> int find_left(vector<T> &v, T elem) { return (int)(upper_bound(v.begin(), v.end(), elem) - v.begin()) - 1; } template <typename T> int find_right(vector<T> &v, T elem) { return (int)(lower_bound(v.begin(), v.end(), elem) - v.begin()); } const ll MOD = 1000000007LL; inline ll ADD(ll x, ll y) { return (x + y) % MOD; } inline ll SUB(ll x, ll y) { return (x - y + MOD) % MOD; } inline ll MUL(ll x, ll y) { return x * y % MOD; } inline ll POW(ll x, ll e) { ll v = 1; for (; e; x = MUL(x, x), e >>= 1) if (e & 1) v = MUL(v, x); return v; } inline ll INV(ll y) { /*assert(y%MOD!=0);*/ return POW(y, MOD - 2); } inline ll DIV(ll x, ll y) { return MUL(x, INV(y)); } #define INTSPACE 12 char _buf[INTSPACE * 1000000 + 3]; int loadint() { if (fgets(_buf, INTSPACE + 3, stdin) == NULL) return 0; return atoi(_buf); } int loadvec(vector<int> &v, int N = -1) { if (N == 0) { v.clear(); return 0; } if (N == -1) { N = loadint(); if (N == 0) return 0; } int bufsize = INTSPACE * N + 3; if (fgets(_buf, bufsize, stdin) == NULL) return 0; v.resize(N); int i = 0; bool last = false; for (char *p = &_buf[0];;) { char *q = p; while (*q > ' ') ++q; if (*q == 0x0D || *q == 0x0A) last = true; *q = 0; v[i++] = atoi(p); if (last || i == N) break; p = q + 1; } return i; } void read_cr() { fgets(_buf, 256, stdin); } void horizontal(vector<int> &v) { int L = v.size(); for (int i = 0; i < L; ++i) { printf("%d%c", v[i], (i == L - 1) ? '\n' : ' '); } } void horizontall(vector<long long> &v) { int L = v.size(); for (int i = 0; i < L; ++i) { printf("%lld%c", v[i], (i == L - 1) ? '\n' : ' '); } } int solve(int N, vi &xs, vi &ys, vector<char> &dir) { map<int, vi> r_h, l_h, u_v, d_v; map<int, vi> r_add, r_sub, l_add, l_sub, u_add, u_sub, d_add, d_sub; rep(i, N) { int x = xs[i], y = ys[i]; switch (dir[i]) { case 'R': r_h[y].pb(x); r_add[x + y].pb(x); r_sub[x - y].pb(x); break; case 'L': l_h[y].pb(x); l_add[x + y].pb(x); l_sub[x - y].pb(x); break; case 'U': u_v[x].pb(y); u_add[x + y].pb(x); u_sub[x - y].pb(x); break; case 'D': d_v[x].pb(y); d_add[x + y].pb(x); d_sub[x - y].pb(x); break; } } for (auto &p : r_h) { sort(ALL(p.second)); } for (auto &p : r_add) { sort(ALL(p.second)); } for (auto &p : r_sub) { sort(ALL(p.second)); } for (auto &p : l_h) { sort(ALL(p.second)); } for (auto &p : l_add) { sort(ALL(p.second)); } for (auto &p : l_sub) { sort(ALL(p.second)); } for (auto &p : u_v) { sort(ALL(p.second)); } for (auto &p : u_add) { sort(ALL(p.second)); } for (auto &p : u_sub) { sort(ALL(p.second)); } for (auto &p : d_v) { sort(ALL(p.second)); } for (auto &p : d_add) { sort(ALL(p.second)); } for (auto &p : d_sub) { sort(ALL(p.second)); } int bump = INT_MAX; for (auto &p : r_h) { int y = p.first; for (int x : p.second) { int add = x + y, sub = x - y; int S = l_h[y].size(); if (S > 0) { int ix = upper_bound(ALL(l_h[y]), x) - l_h[y].begin(); if (ix < S) { int x2 = l_h[y][ix]; amin(bump, 5 * (x2 - x)); } } S = u_add[add].size(); if (S > 0) { int ix = upper_bound(ALL(u_add[add]), x) - u_add[add].begin(); if (ix < S) { int x2 = u_add[add][ix]; amin(bump, 10 * (x2 - x)); } } S = d_sub[sub].size(); if (S > 0) { int ix = upper_bound(ALL(d_sub[sub]), x) - d_sub[sub].begin(); if (ix < S) { int x2 = d_sub[sub][ix]; amin(bump, 10 * (x2 - x)); } } } } for (auto &p : u_v) { int x = p.first; for (int y : p.second) { int add = x + y, sub = x - y; int S = d_v[x].size(); if (S > 0) { int ix = upper_bound(ALL(d_v[x]), y) - d_v[x].begin(); if (ix < S) { int y2 = d_v[x][ix]; amin(bump, 5 * (y2 - y)); } } S = l_sub[sub].size(); if (S > 0) { int ix = upper_bound(ALL(l_sub[sub]), x) - l_sub[sub].begin(); if (ix < S) { int x2 = l_sub[sub][ix]; amin(bump, 10 * (x2 - x)); } } } } for (auto &p : d_v) { int x = p.first; for (int y : p.second) { int add = x + y, sub = x - y; int S = l_add[add].size(); if (S > 0) { int ix = upper_bound(ALL(l_add[add]), x) - l_add[add].begin(); if (ix < S) { int x2 = l_add[add][ix]; amin(bump, 10 * (x2 - x)); } } } } return bump; } int main() { int N; scanf("%d%*c", &N); vi x(N), y(N); vector<char> u(N); rep(i, N) { scanf("%d %d %c%*c", &x[i], &y[i], &u[i]); } int bump = solve(N, x, y, u); if (bump == INT_MAX) printf("SAFE\n"); else printf("%d\n", bump); return 0; }
replace
240
241
240
241
0
p02605
C++
Runtime Error
#include <bits/stdc++.h> #define endl "\n" using namespace std; typedef long long ll; typedef vector<ll> vl; typedef pair<ll, ll> PP; #define rep(i, n) for (ll i = 0; i < ll(n); i++) #define rrep(i, n) for (ll i = n - 1; i > -1; i--) #define all(v) v.begin(), v.end() #define pb push_back #define fi first #define se second template <class X> void print(X x) { cout << x << endl; } void print(vl x) { for (ll i : x) { cout << i << " "; } cout << endl; } const ll INF = (1LL << 61) - 1; const ll MOD = 1000000007 /*998244353*/; const ll MAX_N = 500010; ll a, b, c, d, e, f, h, x, y, z, p, q, n, t, r, k, w, l, ans, i, j, u, v, m; ll codeforces = 1; string S, T; vl A, B; vector<tuple<ll, ll, ll>> UD, RL, UL, RD, UR, LD; void input() { cin >> n; rep(i, n) { cin >> x >> y; char C; cin >> C; if (C == 'U') { UD.pb({x, y, 1}); UL.pb({y - x, y + x, 1}); UR.pb({y + x, y - x, 1}); } if (C == 'D') { UD.pb({x, y, -1}); RD.pb({y - x, y + x, -1}); LD.pb({y + x, y - x, -1}); } if (C == 'L') { RL.pb({y, x, -1}); UL.pb({y - x, y + x, -1}); LD.pb({y + x, y - x, 1}); } if (C == 'R') { RL.pb({y, x, 1}); RD.pb({y - x, y + x, 1}); UR.pb({y + x, y - x, -1}); } } } void solve() { sort(all(UD)); sort(all(RL)); sort(all(UL)); sort(all(RD)); sort(all(UR)); sort(all(LD)); // tate a = INF; d = UD.size(); e = RL.size(); f = UL.size(); t = UD.size(); k = RL.size(); l = UL.size(); rep(i, d - 1) { auto [x, y, z] = UD[i]; auto [p, q, r] = UD[i + 1]; if (z == 1 && r == -1 && x == p) a = min(a, (q - y) * 5); } rep(i, e - 1) { auto [x, y, z] = RL[i]; auto [p, q, r] = RL[i + 1]; if (z == 1 && r == -1 && x == p) a = min(a, (q - y) * 5); } rep(i, f - 1) { auto [x, y, z] = UL[i]; auto [p, q, r] = UL[i + 1]; if (z == 1 && r == -1 && x == p) a = min(a, (q - y) * 5); } rep(i, t - 1) { auto [x, y, z] = RD[i]; auto [p, q, r] = RD[i + 1]; if (z == 1 && r == -1 && x == p) a = min(a, (q - y) * 5); } rep(i, k - 1) { auto [x, y, z] = UR[i]; auto [p, q, r] = UR[i + 1]; if (z == 1 && r == -1 && x == p) a = min(a, (q - y) * 5); } rep(i, l - 1) { auto [x, y, z] = LD[i]; auto [p, q, r] = LD[i + 1]; if (z == 1 && r == -1 && x == p) a = min(a, (q - y) * 5); } if (a == INF) print("SAFE"); else print(a); } int main() { // cout<<fixed<<setprecision(15); cin.tie(0); ios::sync_with_stdio(false); input(); while (codeforces--) { solve(); } }
#include <bits/stdc++.h> #define endl "\n" using namespace std; typedef long long ll; typedef vector<ll> vl; typedef pair<ll, ll> PP; #define rep(i, n) for (ll i = 0; i < ll(n); i++) #define rrep(i, n) for (ll i = n - 1; i > -1; i--) #define all(v) v.begin(), v.end() #define pb push_back #define fi first #define se second template <class X> void print(X x) { cout << x << endl; } void print(vl x) { for (ll i : x) { cout << i << " "; } cout << endl; } const ll INF = (1LL << 61) - 1; const ll MOD = 1000000007 /*998244353*/; const ll MAX_N = 500010; ll a, b, c, d, e, f, h, x, y, z, p, q, n, t, r, k, w, l, ans, i, j, u, v, m; ll codeforces = 1; string S, T; vl A, B; vector<tuple<ll, ll, ll>> UD, RL, UL, RD, UR, LD; void input() { cin >> n; rep(i, n) { cin >> x >> y; char C; cin >> C; if (C == 'U') { UD.pb({x, y, 1}); UL.pb({y - x, y + x, 1}); UR.pb({y + x, y - x, 1}); } if (C == 'D') { UD.pb({x, y, -1}); RD.pb({y - x, y + x, -1}); LD.pb({y + x, y - x, -1}); } if (C == 'L') { RL.pb({y, x, -1}); UL.pb({y - x, y + x, -1}); LD.pb({y + x, y - x, 1}); } if (C == 'R') { RL.pb({y, x, 1}); RD.pb({y - x, y + x, 1}); UR.pb({y + x, y - x, -1}); } } } void solve() { sort(all(UD)); sort(all(RL)); sort(all(UL)); sort(all(RD)); sort(all(UR)); sort(all(LD)); // tate a = INF; d = UD.size(); e = RL.size(); f = UL.size(); t = RD.size(); k = UR.size(); l = LD.size(); rep(i, d - 1) { auto [x, y, z] = UD[i]; auto [p, q, r] = UD[i + 1]; if (z == 1 && r == -1 && x == p) a = min(a, (q - y) * 5); } rep(i, e - 1) { auto [x, y, z] = RL[i]; auto [p, q, r] = RL[i + 1]; if (z == 1 && r == -1 && x == p) a = min(a, (q - y) * 5); } rep(i, f - 1) { auto [x, y, z] = UL[i]; auto [p, q, r] = UL[i + 1]; if (z == 1 && r == -1 && x == p) a = min(a, (q - y) * 5); } rep(i, t - 1) { auto [x, y, z] = RD[i]; auto [p, q, r] = RD[i + 1]; if (z == 1 && r == -1 && x == p) a = min(a, (q - y) * 5); } rep(i, k - 1) { auto [x, y, z] = UR[i]; auto [p, q, r] = UR[i + 1]; if (z == 1 && r == -1 && x == p) a = min(a, (q - y) * 5); } rep(i, l - 1) { auto [x, y, z] = LD[i]; auto [p, q, r] = LD[i + 1]; if (z == 1 && r == -1 && x == p) a = min(a, (q - y) * 5); } if (a == INF) print("SAFE"); else print(a); } int main() { // cout<<fixed<<setprecision(15); cin.tie(0); ios::sync_with_stdio(false); input(); while (codeforces--) { solve(); } }
replace
67
70
67
70
0
p02605
C++
Runtime Error
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; int n; vector<vector<long long>> points; void rotate() { for (auto &p : points) { int nx = p[1]; int ny = 202020 - p[0]; p[0] = nx; p[1] = ny; p[2]++; p[2] %= 4; } } signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; char dir; cin >> dir; if (dir == 'R') points.push_back({x, y, 0}); if (dir == 'D') points.push_back({x, y, 1}); if (dir == 'L') points.push_back({x, y, 2}); if (dir == 'U') points.push_back({x, y, 3}); } long long ans = 1 << 30; for (int u = 0; u < 4; u++) { vector<vector<pair<long long, long long>>> v(202020); for (auto &p : points) { if (p[2] == 0 || p[2] == 2) v[p[1]].emplace_back(p[0], p[2]); } for (auto &line : v) { long long l = -(1 << 30); sort(line.begin(), line.end()); for (auto &p : line) { if (p.second == 0) l = max(l, p.first); else ans = min(ans, p.first - l); } } v = vector<vector<pair<long long, long long>>>(404040); for (auto &p : points) { if (p[2] == 0 || p[2] == 3) v[p[0] + p[1]].emplace_back(p[0], p[2]); } for (auto &line : v) { sort(line.begin(), line.end()); long long l = -(1 << 30); for (auto &p : line) { if (p.second == 0) l = max(l, p.first); else ans = min(ans, 2LL * (p.first - l)); } } rotate(); } if (ans == 1 << 30) cout << "SAFE" << endl; else cout << ans * 5 << endl; return 0; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> using namespace std; int n; vector<vector<long long>> points; void rotate() { for (auto &p : points) { int nx = p[1]; int ny = 200005 - p[0]; p[0] = nx; p[1] = ny; p[2]++; p[2] %= 4; } } signed main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; char dir; cin >> dir; if (dir == 'R') points.push_back({x, y, 0}); if (dir == 'D') points.push_back({x, y, 1}); if (dir == 'L') points.push_back({x, y, 2}); if (dir == 'U') points.push_back({x, y, 3}); } long long ans = 1 << 30; for (int u = 0; u < 4; u++) { vector<vector<pair<long long, long long>>> v(202020); for (auto &p : points) { if (p[2] == 0 || p[2] == 2) v[p[1]].emplace_back(p[0], p[2]); } for (auto &line : v) { long long l = -(1 << 30); sort(line.begin(), line.end()); for (auto &p : line) { if (p.second == 0) l = max(l, p.first); else ans = min(ans, p.first - l); } } v = vector<vector<pair<long long, long long>>>(404040); for (auto &p : points) { if (p[2] == 0 || p[2] == 3) v[p[0] + p[1]].emplace_back(p[0], p[2]); } for (auto &line : v) { sort(line.begin(), line.end()); long long l = -(1 << 30); for (auto &p : line) { if (p.second == 0) l = max(l, p.first); else ans = min(ans, 2LL * (p.first - l)); } } rotate(); } if (ans == 1 << 30) cout << "SAFE" << endl; else cout << ans * 5 << endl; return 0; }
replace
8
9
8
9
0
p02605
C++
Time Limit Exceeded
#include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string.h> #include <string> #include <vector> #define SPBR(w, n) std::cout << (w + 1 == n ? '\n' : ' '); #define YES cout << "YES" << endl #define Yes cout << "Yes" << endl #define NO cout << "NO" << endl #define No cout << "No" << endl #define ALL(i) (i).begin(), (i).end() #define FOR(i, a, n) for (int i = (a); i < (n); ++i) #define RFOR(i, a, n) for (int i = (n)-1; i >= (a); --i) #define REP(i, n) for (int i = 0; i < int(n); ++i) #define RREP(i, n) for (int i = int(n) - 1; i >= 0; --i) #define IN(a, x, b) (a <= x && x < b) #define OUT(a, x, b) (x < a || b <= x) 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; } #define int ll using ll = long long; using ull = unsigned long long; using ld = long double; const int MOD = 1000000007; /* const int MOD = 998244353; */ const int INF = 1e8; const double PI = acos(-1); using namespace std; struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } INIT; int f(vector<pair<int, int>> &v) { sort(ALL(v)); int ret = INF; REP(i, v.size() - 1) { if (v[i].second == 0 && v[i + 1].second != 0) { chmin(ret, v[i + 1].first - v[i].first); } } return ret; } int f(map<int, vector<pair<int, int>>> &m) { int ret = INF; for (auto p : m) { chmin(ret, f(p.second)); } return ret; } signed main() { int N; cin >> N; vector<int> x(N), y(N), d(N); REP(i, N) { char c; cin >> x[i] >> y[i] >> c; if (c == 'U') d[i] = 0; if (c == 'R') d[i] = 1; if (c == 'D') d[i] = 2; if (c == 'L') d[i] = 3; } int ans = INF; REP(i, N) { { map<int, vector<pair<int, int>>> m; REP(i, N) { if (d[i] != 0 && d[i] != 2) continue; m[x[i]].emplace_back(y[i], d[i]); } chmin(ans, f(m) * 5); } { map<int, vector<pair<int, int>>> m; REP(i, N) { if (d[i] != 0 && d[i] != 1) continue; m[x[i] + y[i]].emplace_back(y[i], d[i]); } chmin(ans, f(m) * 10); } REP(i, N) { int px = x[i], py = y[i]; x[i] = py; y[i] = -px; d[i] = (d[i] + 1) % 4; } } if (ans == INF) cout << "SAFE" << "\n"; else cout << ans << "\n"; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string.h> #include <string> #include <vector> #define SPBR(w, n) std::cout << (w + 1 == n ? '\n' : ' '); #define YES cout << "YES" << endl #define Yes cout << "Yes" << endl #define NO cout << "NO" << endl #define No cout << "No" << endl #define ALL(i) (i).begin(), (i).end() #define FOR(i, a, n) for (int i = (a); i < (n); ++i) #define RFOR(i, a, n) for (int i = (n)-1; i >= (a); --i) #define REP(i, n) for (int i = 0; i < int(n); ++i) #define RREP(i, n) for (int i = int(n) - 1; i >= 0; --i) #define IN(a, x, b) (a <= x && x < b) #define OUT(a, x, b) (x < a || b <= x) 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; } #define int ll using ll = long long; using ull = unsigned long long; using ld = long double; const int MOD = 1000000007; /* const int MOD = 998244353; */ const int INF = 1e8; const double PI = acos(-1); using namespace std; struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } INIT; int f(vector<pair<int, int>> &v) { sort(ALL(v)); int ret = INF; REP(i, v.size() - 1) { if (v[i].second == 0 && v[i + 1].second != 0) { chmin(ret, v[i + 1].first - v[i].first); } } return ret; } int f(map<int, vector<pair<int, int>>> &m) { int ret = INF; for (auto p : m) { chmin(ret, f(p.second)); } return ret; } signed main() { int N; cin >> N; vector<int> x(N), y(N), d(N); REP(i, N) { char c; cin >> x[i] >> y[i] >> c; if (c == 'U') d[i] = 0; if (c == 'R') d[i] = 1; if (c == 'D') d[i] = 2; if (c == 'L') d[i] = 3; } int ans = INF; REP(i, 4) { { map<int, vector<pair<int, int>>> m; REP(i, N) { if (d[i] != 0 && d[i] != 2) continue; m[x[i]].emplace_back(y[i], d[i]); } chmin(ans, f(m) * 5); } { map<int, vector<pair<int, int>>> m; REP(i, N) { if (d[i] != 0 && d[i] != 1) continue; m[x[i] + y[i]].emplace_back(y[i], d[i]); } chmin(ans, f(m) * 10); } REP(i, N) { int px = x[i], py = y[i]; x[i] = py; y[i] = -px; d[i] = (d[i] + 1) % 4; } } if (ans == INF) cout << "SAFE" << "\n"; else cout << ans << "\n"; return 0; }
replace
98
99
98
99
TLE
p02605
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using i64 = long long; using u64 = unsigned long long; #define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i) #ifdef ENABLE_DEBUG template <typename T> void debug(T value) { cerr << value; } template <typename T, typename... Ts> void debug(T value, Ts... args) { cerr << value << ", "; debug(args...); } #define DEBUG(...) \ do { \ cerr << " \033[33m (L" << __LINE__ << ") "; \ cerr << #__VA_ARGS__ << ":\033[0m "; \ debug(__VA_ARGS__); \ cerr << endl; \ } while (0) #else #define debug(...) #define DEBUG(...) #endif const i64 INF = 1LL << 40; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector<tuple<i64, i64>> pu, pr, pd, pl; REP(i, N) { i64 x, y; char u; cin >> x >> y >> u; if (u == 'R') { pr.emplace_back(x, y); } else if (u == 'L') { pl.emplace_back(x, y); } else if (u == 'U') { pu.emplace_back(x, y); } else { assert(u == 'D'); pd.emplace_back(x, y); } } i64 ans = INF; int p = -1; { // U-D map<i64, set<i64>> t; for (auto [xu, yu] : pu) { t[xu].insert(yu); } for (auto [xd, yd] : pd) { auto &s = t[xd]; if (s.empty()) continue; auto it = s.lower_bound(yd); if (it == s.begin()) continue; i64 yu = *--it; assert(yu < yd); ans = min<i64>(ans, (yd - yu) * 5); } } { // L-R map<i64, set<i64>> t; for (auto [xr, yr] : pr) { t[yr].insert(xr); } for (auto [xl, yl] : pl) { auto &s = t[yl]; if (s.empty()) continue; auto it = s.lower_bound(yl); if (it == s.begin()) continue; i64 xr = *--it; assert(xr < xl); ans = min<i64>(ans, (xl - xr) * 5); } } { // D-R map<i64, set<i64>> t; for (auto [xd, yd] : pd) { t[yd - xd].insert(xd); } for (auto [xr, yr] : pr) { auto &s = t[yr - xr]; auto it = s.lower_bound(xr); if (it == s.end()) continue; i64 xd = *it; assert(xd > xr); ans = min<i64>(ans, 10 * (xd - xr)); } } { // D-L map<i64, set<i64>> t_minx; for (auto [xd, yd] : pd) { t_minx[xd + yd].insert(xd); } for (auto [xl, yl] : pl) { auto &s = t_minx[xl + yl]; auto it = s.lower_bound(xl); if (s.empty() || it == s.begin()) continue; --it; i64 xd = *it; if (xd < xl) { DEBUG(xl - xd, xl, yl); ans = min<i64>(ans, 10 * (xl - xd)); p = 4; } } } { // U-R map<i64, set<i64>> t_maxx; for (auto [xu, yu] : pu) { t_maxx[yu + xu].insert(xu); } for (auto [xr, yr] : pr) { auto &s = t_maxx[yr + xr]; auto it = s.lower_bound(xr); if (it == s.end()) continue; i64 xu = *it; if (xu > xr) { DEBUG(xu - xr, xr, yr); ans = min<i64>(ans, 10 * (xu - xr)); p = 5; } } } { // U-L map<i64, set<i64>> t_minx; for (auto [x, y] : pu) { t_minx[y - x].insert(x); } for (auto [xl, yl] : pl) { auto &s = t_minx[yl - xl]; auto it = s.lower_bound(xl); if (s.empty() || it == s.begin()) continue; --it; i64 xu = *it; if (xu < xl) { DEBUG(xl - xu, xl, yl); ans = min<i64>(ans, 10 * (xl - xu)); p = 6; } } } if (ans == INF) { cout << "SAFE" << endl; } else { cout << ans << endl; } }
#include <bits/stdc++.h> using namespace std; using i64 = long long; using u64 = unsigned long long; #define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i) #ifdef ENABLE_DEBUG template <typename T> void debug(T value) { cerr << value; } template <typename T, typename... Ts> void debug(T value, Ts... args) { cerr << value << ", "; debug(args...); } #define DEBUG(...) \ do { \ cerr << " \033[33m (L" << __LINE__ << ") "; \ cerr << #__VA_ARGS__ << ":\033[0m "; \ debug(__VA_ARGS__); \ cerr << endl; \ } while (0) #else #define debug(...) #define DEBUG(...) #endif const i64 INF = 1LL << 40; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; vector<tuple<i64, i64>> pu, pr, pd, pl; REP(i, N) { i64 x, y; char u; cin >> x >> y >> u; if (u == 'R') { pr.emplace_back(x, y); } else if (u == 'L') { pl.emplace_back(x, y); } else if (u == 'U') { pu.emplace_back(x, y); } else { assert(u == 'D'); pd.emplace_back(x, y); } } i64 ans = INF; int p = -1; { // U-D map<i64, set<i64>> t; for (auto [xu, yu] : pu) { t[xu].insert(yu); } for (auto [xd, yd] : pd) { auto &s = t[xd]; if (s.empty()) continue; auto it = s.lower_bound(yd); if (it == s.begin()) continue; i64 yu = *--it; assert(yu < yd); ans = min<i64>(ans, (yd - yu) * 5); } } { // L-R map<i64, set<i64>> t; for (auto [xr, yr] : pr) { t[yr].insert(xr); } for (auto [xl, yl] : pl) { auto &s = t[yl]; if (s.empty()) continue; auto it = s.lower_bound(xl); if (it == s.begin()) continue; i64 xr = *--it; assert(xr < xl); ans = min<i64>(ans, (xl - xr) * 5); } } { // D-R map<i64, set<i64>> t; for (auto [xd, yd] : pd) { t[yd - xd].insert(xd); } for (auto [xr, yr] : pr) { auto &s = t[yr - xr]; auto it = s.lower_bound(xr); if (it == s.end()) continue; i64 xd = *it; assert(xd > xr); ans = min<i64>(ans, 10 * (xd - xr)); } } { // D-L map<i64, set<i64>> t_minx; for (auto [xd, yd] : pd) { t_minx[xd + yd].insert(xd); } for (auto [xl, yl] : pl) { auto &s = t_minx[xl + yl]; auto it = s.lower_bound(xl); if (s.empty() || it == s.begin()) continue; --it; i64 xd = *it; if (xd < xl) { DEBUG(xl - xd, xl, yl); ans = min<i64>(ans, 10 * (xl - xd)); p = 4; } } } { // U-R map<i64, set<i64>> t_maxx; for (auto [xu, yu] : pu) { t_maxx[yu + xu].insert(xu); } for (auto [xr, yr] : pr) { auto &s = t_maxx[yr + xr]; auto it = s.lower_bound(xr); if (it == s.end()) continue; i64 xu = *it; if (xu > xr) { DEBUG(xu - xr, xr, yr); ans = min<i64>(ans, 10 * (xu - xr)); p = 5; } } } { // U-L map<i64, set<i64>> t_minx; for (auto [x, y] : pu) { t_minx[y - x].insert(x); } for (auto [xl, yl] : pl) { auto &s = t_minx[yl - xl]; auto it = s.lower_bound(xl); if (s.empty() || it == s.begin()) continue; --it; i64 xu = *it; if (xu < xl) { DEBUG(xl - xu, xl, yl); ans = min<i64>(ans, 10 * (xl - xu)); p = 6; } } } if (ans == INF) { cout << "SAFE" << endl; } else { cout << ans << endl; } }
replace
76
77
76
77
0
p02605
C++
Time Limit Exceeded
// #pragma GCC // target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,avx512f") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <functional> #include <immintrin.h> #include <iomanip> #include <iostream> #include <list> #include <map> #include <memory> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #ifdef DEBUG #include "./Lib/Timer.hpp" #include "./Lib/debug_VC.hpp" #include "./Lib/sample.hpp" #else #define dump(...) #endif /* macro */ #define FOR(i, b, e) for (ll i = (ll)(b); i < (ll)(e); ++i) #define RFOR(i, b, e) for (ll i = (ll)(e - 1); i >= (ll)(b); --i) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) RFOR(i, 0, n) #define REPC(x, c) for (const auto &x : (c)) #define REPI2(it, b, e) for (auto it = (b); it != (e); ++it) #define REPI(it, c) REPI2(it, (c).begin(), (c).end()) #define RREPI(it, c) REPI2(it, (c).rbegin(), (c).rend()) #define REPI_ERACE2(it, b, e) for (auto it = (b); it != (e);) #define REPI_ERACE(it, c) REPI_ERACE2(it, (c).begin(), (c).end()) #define ALL(x) (x).begin(), (x).end() #define cauto const auto & /* macro func */ template <class T> inline auto sort(T &t) { std::sort(ALL(t)); } template <class T> inline auto rsort(T &t) { std::sort((t).rbegin(), (t).rend()); } template <class T> inline auto unique(T &t) { (t).erase(unique((t).begin(), (t).end()), (t).end()); } template <class T, class S> inline auto chmax(T &t, const S &s) { if (s > t) { t = s; return true; } return false; } template <class T, class S> inline auto chmin(T &t, const S &s) { if (s < t) { t = s; return true; } return false; } inline auto BR() { std::cout << "\n"; } /* type define */ using ll = long long; using PAIR = std::pair<ll, ll>; using VS = std::vector<std::string>; using VL = std::vector<long long>; using VVL = std::vector<VL>; using VVVL = std::vector<VVL>; using VD = std::vector<double>; template <class T> using V = std::vector<T>; /* using std */ using std::cout; constexpr char endl = '\n'; using std::bitset; using std::cin; using std::list; using std::map; using std::multimap; using std::multiset; using std::pair; using std::priority_queue; using std::queue; using std::set; using std::stack; using std::string; using std::unordered_map; using std::unordered_multimap; using std::unordered_multiset; using std::unordered_set; using std::vector; /* Initial processing */ struct Preprocessing { Preprocessing() { std::cin.tie(0); std::ios::sync_with_stdio(0); }; } _Preprocessing; /* Remove the source of the bug */ signed pow(signed, signed) { assert(false); return -1; } /* define hash */ namespace std { template <> class hash<std::pair<ll, ll>> { public: size_t operator()(const std::pair<ll, ll> &x) const { return hash<ll>()(1000000000 * x.first + x.second); } }; } // namespace std /* input */ template <class T> std::istream &operator>>(std::istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } /* constant value */ constexpr ll MOD = 1000000007; // constexpr ll MOD = 998244353; //=============================================================================================; constexpr ll ubn = 200010; // constexpr ll ubn = 50; auto solve_head(const V<PAIR> &rv, const V<PAIR> &lv, bool b = true) { ll sz = rv.size() + lv.size(); V<pair<PAIR, ll>> v; v.reserve(sz); for (cauto[x, y] : rv) { v.emplace_back(b ? PAIR{x, y} : PAIR{y, x}, 0); } for (cauto[x, y] : lv) { v.emplace_back(b ? PAIR{x, y} : PAIR{y, x}, 1); } sort(v); ll ans = 1e10; VL mx(ubn + 10, -1); REPC(p, v) { auto [pp, b] = p; auto [x, y] = pp; if (b == 0) { mx[y] = x; continue; } if (mx[y] == -1) { continue; } chmin(ans, x - mx[y]); } return ans * 5; } auto solve_side(const V<PAIR> &av, const V<PAIR> &bv, bool b1 = true, bool b2 = true) { ll sz = av.size() + bv.size(); V<pair<PAIR, ll>> v; v.reserve(sz); for (cauto[x, y] : av) { v.emplace_back(PAIR{x, y}, 0); } for (cauto[x, y] : bv) { v.emplace_back(PAIR{x, y}, 1); } if (b2) { sort(v); } else { rsort(v); } auto diffMin = [](const set<ll> &s, ll x) { auto itr = s.lower_bound(x); ll ans = 1e11; if (itr != s.end()) { chmin(ans, std::abs(x - *itr)); } if (itr != s.begin()) { --itr; chmin(ans, std::abs(x - *itr)); } return ans; }; ll ans = 1e10; V<bool> exist(2 * ubn + 10); V<set<ll>> allX(2 * ubn + 10); V<set<ll>> allY(2 * ubn + 10); REPC(p, v) { auto [pp, b] = p; auto [x, y] = pp; ll key = (b1 ? x + y : x - y + ubn); if (b == 1) { exist[key] = true; allX[key].emplace(x); allY[key].emplace(y); } else { if (!exist[key]) { continue; } chmin(ans, diffMin(allX[key], x)); chmin(ans, diffMin(allY[key], y)); } } return ans * 10; } auto solve(ll n, const V<PAIR> &uv, const V<PAIR> &rv, const V<PAIR> &dv, const V<PAIR> &lv) { ll ans = 1e10; chmin(ans, solve_head(rv, lv)); chmin(ans, solve_head(uv, dv, false)); chmin(ans, solve_side(rv, dv, false, false)); chmin(ans, solve_side(rv, uv, true, false)); chmin(ans, solve_side(lv, dv, true, true)); chmin(ans, solve_side(lv, uv, false, true)); string ans_str = (ans > 1e9) ? "SAFE" : std::to_string(ans); return ans_str; } auto solve_c(ll n, const V<PAIR> &uv, const V<PAIR> &rv, const V<PAIR> &dv, const V<PAIR> &lv) { ll us = uv.size(); ll rs = rv.size(); ll ds = dv.size(); ll ls = lv.size(); ll ans = 1e10; for (cauto[x, y] : uv) for (cauto[s, t] : dv) { if (x == s && t > y) { chmin(ans, 5 * (t - y)); } } for (cauto[x, y] : rv) for (cauto[s, t] : lv) { if (y == t && s > x) { chmin(ans, 5 * (s - x)); } } for (cauto[x, y] : rv) for (cauto[s, t] : uv) { if (s > x && s - x == y - t) { chmin(ans, 10 * (y - t)); } } for (cauto[x, y] : rv) for (cauto[s, t] : dv) { if (s > x && s - x == t - y) { chmin(ans, 10 * (t - y)); } } for (cauto[x, y] : lv) for (cauto[s, t] : uv) { if (x > s && x - s == y - t) { chmin(ans, 10 * (y - t)); } } for (cauto[x, y] : lv) for (cauto[s, t] : dv) { if (x > s && x - s == t - y) { chmin(ans, 10 * (t - y)); } } string ans_str = (ans > 1e9) ? "SAFE" : std::to_string(ans); return ans_str; } signed main() { /**/ ll n; cin >> n; V<PAIR> uv, rv, dv, lv; uv.reserve(n); rv.reserve(n); dv.reserve(n); lv.reserve(n); REP(_, n) { ll x, y; char c; cin >> x >> y >> c; (c == 'U' ? uv : c == 'R' ? rv : c == 'D' ? dv : lv).emplace_back(x, y); } auto ans = solve(n, uv, rv, dv, lv); cout << ans << endl; auto ans_c = solve_c(n, uv, rv, dv, lv); dump(ans_c); /*/ auto gen = Sample::SampleGenerator(); REP(_, 100) { auto [nv] = gen.generate(V<PAIR>(4, PAIR{0,10})); ll n = 0; REPC(x, nv) { n += x; } auto [ux, rx, dx, lx] = gen.generate( V<PAIR>(nv[0], PAIR{0,10}), V<PAIR>(nv[1], PAIR{0,10}), V<PAIR>(nv[2], PAIR{0,10}), V<PAIR>(nv[3], PAIR{0,10}) ); auto [uy, ry, dy, ly] = gen.generate( V<PAIR>(nv[0], PAIR{0,10}), V<PAIR>(nv[1], PAIR{0,10}), V<PAIR>(nv[2], PAIR{0,10}), V<PAIR>(nv[3], PAIR{0,10}) ); V<PAIR> uv, rv, dv, lv; uv.reserve(nv[0]); REP(i, nv[0]) { uv.emplace_back(ux[i], uy[i]); } rv.reserve(nv[1]); REP(i, nv[1]) { rv.emplace_back(rx[i], ry[i]); } dv.reserve(nv[2]); REP(i, nv[2]) { dv.emplace_back(dx[i], dy[i]); } lv.reserve(nv[3]); REP(i, nv[3]) { lv.emplace_back(lx[i], ly[i]); } auto ans = solve(n, uv, rv, dv, lv); auto ans_c = solve_c(n, uv, rv, dv, lv); if (ans != ans_c) { cout << n << endl; for (cauto[x, y] : uv) { cout << x << " " << y << " U" << endl; } for (cauto[x, y] : rv) { cout << x << " " << y << " R" << endl; } for (cauto[x, y] : dv) { cout << x << " " << y << " D" << endl; } for (cauto[x, y] : lv) { cout << x << " " << y << " L" << endl; } dump(ans, ans_c); break; } } /**/ }
// #pragma GCC // target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,avx512f") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <functional> #include <immintrin.h> #include <iomanip> #include <iostream> #include <list> #include <map> #include <memory> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> #ifdef DEBUG #include "./Lib/Timer.hpp" #include "./Lib/debug_VC.hpp" #include "./Lib/sample.hpp" #else #define dump(...) #endif /* macro */ #define FOR(i, b, e) for (ll i = (ll)(b); i < (ll)(e); ++i) #define RFOR(i, b, e) for (ll i = (ll)(e - 1); i >= (ll)(b); --i) #define REP(i, n) FOR(i, 0, n) #define RREP(i, n) RFOR(i, 0, n) #define REPC(x, c) for (const auto &x : (c)) #define REPI2(it, b, e) for (auto it = (b); it != (e); ++it) #define REPI(it, c) REPI2(it, (c).begin(), (c).end()) #define RREPI(it, c) REPI2(it, (c).rbegin(), (c).rend()) #define REPI_ERACE2(it, b, e) for (auto it = (b); it != (e);) #define REPI_ERACE(it, c) REPI_ERACE2(it, (c).begin(), (c).end()) #define ALL(x) (x).begin(), (x).end() #define cauto const auto & /* macro func */ template <class T> inline auto sort(T &t) { std::sort(ALL(t)); } template <class T> inline auto rsort(T &t) { std::sort((t).rbegin(), (t).rend()); } template <class T> inline auto unique(T &t) { (t).erase(unique((t).begin(), (t).end()), (t).end()); } template <class T, class S> inline auto chmax(T &t, const S &s) { if (s > t) { t = s; return true; } return false; } template <class T, class S> inline auto chmin(T &t, const S &s) { if (s < t) { t = s; return true; } return false; } inline auto BR() { std::cout << "\n"; } /* type define */ using ll = long long; using PAIR = std::pair<ll, ll>; using VS = std::vector<std::string>; using VL = std::vector<long long>; using VVL = std::vector<VL>; using VVVL = std::vector<VVL>; using VD = std::vector<double>; template <class T> using V = std::vector<T>; /* using std */ using std::cout; constexpr char endl = '\n'; using std::bitset; using std::cin; using std::list; using std::map; using std::multimap; using std::multiset; using std::pair; using std::priority_queue; using std::queue; using std::set; using std::stack; using std::string; using std::unordered_map; using std::unordered_multimap; using std::unordered_multiset; using std::unordered_set; using std::vector; /* Initial processing */ struct Preprocessing { Preprocessing() { std::cin.tie(0); std::ios::sync_with_stdio(0); }; } _Preprocessing; /* Remove the source of the bug */ signed pow(signed, signed) { assert(false); return -1; } /* define hash */ namespace std { template <> class hash<std::pair<ll, ll>> { public: size_t operator()(const std::pair<ll, ll> &x) const { return hash<ll>()(1000000000 * x.first + x.second); } }; } // namespace std /* input */ template <class T> std::istream &operator>>(std::istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; } /* constant value */ constexpr ll MOD = 1000000007; // constexpr ll MOD = 998244353; //=============================================================================================; constexpr ll ubn = 200010; // constexpr ll ubn = 50; auto solve_head(const V<PAIR> &rv, const V<PAIR> &lv, bool b = true) { ll sz = rv.size() + lv.size(); V<pair<PAIR, ll>> v; v.reserve(sz); for (cauto[x, y] : rv) { v.emplace_back(b ? PAIR{x, y} : PAIR{y, x}, 0); } for (cauto[x, y] : lv) { v.emplace_back(b ? PAIR{x, y} : PAIR{y, x}, 1); } sort(v); ll ans = 1e10; VL mx(ubn + 10, -1); REPC(p, v) { auto [pp, b] = p; auto [x, y] = pp; if (b == 0) { mx[y] = x; continue; } if (mx[y] == -1) { continue; } chmin(ans, x - mx[y]); } return ans * 5; } auto solve_side(const V<PAIR> &av, const V<PAIR> &bv, bool b1 = true, bool b2 = true) { ll sz = av.size() + bv.size(); V<pair<PAIR, ll>> v; v.reserve(sz); for (cauto[x, y] : av) { v.emplace_back(PAIR{x, y}, 0); } for (cauto[x, y] : bv) { v.emplace_back(PAIR{x, y}, 1); } if (b2) { sort(v); } else { rsort(v); } auto diffMin = [](const set<ll> &s, ll x) { auto itr = s.lower_bound(x); ll ans = 1e11; if (itr != s.end()) { chmin(ans, std::abs(x - *itr)); } if (itr != s.begin()) { --itr; chmin(ans, std::abs(x - *itr)); } return ans; }; ll ans = 1e10; V<bool> exist(2 * ubn + 10); V<set<ll>> allX(2 * ubn + 10); V<set<ll>> allY(2 * ubn + 10); REPC(p, v) { auto [pp, b] = p; auto [x, y] = pp; ll key = (b1 ? x + y : x - y + ubn); if (b == 1) { exist[key] = true; allX[key].emplace(x); allY[key].emplace(y); } else { if (!exist[key]) { continue; } chmin(ans, diffMin(allX[key], x)); chmin(ans, diffMin(allY[key], y)); } } return ans * 10; } auto solve(ll n, const V<PAIR> &uv, const V<PAIR> &rv, const V<PAIR> &dv, const V<PAIR> &lv) { ll ans = 1e10; chmin(ans, solve_head(rv, lv)); chmin(ans, solve_head(uv, dv, false)); chmin(ans, solve_side(rv, dv, false, false)); chmin(ans, solve_side(rv, uv, true, false)); chmin(ans, solve_side(lv, dv, true, true)); chmin(ans, solve_side(lv, uv, false, true)); string ans_str = (ans > 1e9) ? "SAFE" : std::to_string(ans); return ans_str; } auto solve_c(ll n, const V<PAIR> &uv, const V<PAIR> &rv, const V<PAIR> &dv, const V<PAIR> &lv) { ll us = uv.size(); ll rs = rv.size(); ll ds = dv.size(); ll ls = lv.size(); ll ans = 1e10; for (cauto[x, y] : uv) for (cauto[s, t] : dv) { if (x == s && t > y) { chmin(ans, 5 * (t - y)); } } for (cauto[x, y] : rv) for (cauto[s, t] : lv) { if (y == t && s > x) { chmin(ans, 5 * (s - x)); } } for (cauto[x, y] : rv) for (cauto[s, t] : uv) { if (s > x && s - x == y - t) { chmin(ans, 10 * (y - t)); } } for (cauto[x, y] : rv) for (cauto[s, t] : dv) { if (s > x && s - x == t - y) { chmin(ans, 10 * (t - y)); } } for (cauto[x, y] : lv) for (cauto[s, t] : uv) { if (x > s && x - s == y - t) { chmin(ans, 10 * (y - t)); } } for (cauto[x, y] : lv) for (cauto[s, t] : dv) { if (x > s && x - s == t - y) { chmin(ans, 10 * (t - y)); } } string ans_str = (ans > 1e9) ? "SAFE" : std::to_string(ans); return ans_str; } signed main() { /**/ ll n; cin >> n; V<PAIR> uv, rv, dv, lv; uv.reserve(n); rv.reserve(n); dv.reserve(n); lv.reserve(n); REP(_, n) { ll x, y; char c; cin >> x >> y >> c; (c == 'U' ? uv : c == 'R' ? rv : c == 'D' ? dv : lv).emplace_back(x, y); } auto ans = solve(n, uv, rv, dv, lv); cout << ans << endl; // auto ans_c = solve_c(n, uv, rv, dv, lv); // dump(ans_c); /*/ auto gen = Sample::SampleGenerator(); REP(_, 100) { auto [nv] = gen.generate(V<PAIR>(4, PAIR{0,10})); ll n = 0; REPC(x, nv) { n += x; } auto [ux, rx, dx, lx] = gen.generate( V<PAIR>(nv[0], PAIR{0,10}), V<PAIR>(nv[1], PAIR{0,10}), V<PAIR>(nv[2], PAIR{0,10}), V<PAIR>(nv[3], PAIR{0,10}) ); auto [uy, ry, dy, ly] = gen.generate( V<PAIR>(nv[0], PAIR{0,10}), V<PAIR>(nv[1], PAIR{0,10}), V<PAIR>(nv[2], PAIR{0,10}), V<PAIR>(nv[3], PAIR{0,10}) ); V<PAIR> uv, rv, dv, lv; uv.reserve(nv[0]); REP(i, nv[0]) { uv.emplace_back(ux[i], uy[i]); } rv.reserve(nv[1]); REP(i, nv[1]) { rv.emplace_back(rx[i], ry[i]); } dv.reserve(nv[2]); REP(i, nv[2]) { dv.emplace_back(dx[i], dy[i]); } lv.reserve(nv[3]); REP(i, nv[3]) { lv.emplace_back(lx[i], ly[i]); } auto ans = solve(n, uv, rv, dv, lv); auto ans_c = solve_c(n, uv, rv, dv, lv); if (ans != ans_c) { cout << n << endl; for (cauto[x, y] : uv) { cout << x << " " << y << " U" << endl; } for (cauto[x, y] : rv) { cout << x << " " << y << " R" << endl; } for (cauto[x, y] : dv) { cout << x << " " << y << " D" << endl; } for (cauto[x, y] : lv) { cout << x << " " << y << " L" << endl; } dump(ans, ans_c); break; } } /**/ }
replace
304
306
304
306
TLE
p02605
C++
Runtime Error
#include <algorithm> #include <cassert> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <vector> #define syosu(x) fixed << setprecision(x) using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int, int> P; typedef pair<double, double> pdd; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<string> vs; typedef vector<P> vp; typedef vector<vp> vvp; typedef vector<pll> vpll; typedef pair<int, P> pip; typedef vector<pip> vip; const int inf = 1 << 28; const ll INF = 1ll << 60; const double pi = acos(-1); const double eps = 1e-8; const ll mod = 998244353; const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1}; const int M = 500001; int n; vi x, y, a; map<char, int> mp = { {'U', 0}, {'R', 1}, {'D', 2}, {'L', 3}, }; int main() { cin >> n; int res = inf; x = y = a = vi(n); for (int i = 0; i < n; i++) { char c; cin >> x[i] >> y[i] >> c; a[i] = mp[c]; } vvp b(M); for (int i = 0; i < n; i++) if (a[i] % 2 == 0) b[x[i]].push_back({y[i], a[i]}); for (int i = 0; i < M; i++) if (!b[i].empty()) { sort(b[i].begin(), b[i].end()); int tmp = -inf; for (auto p : b[i]) { if (p.second == 0) tmp = p.first; else res = min(res, p.first - tmp); } } b = vvp(M); for (int i = 0; i < n; i++) if (a[i] % 2 == 1) b[y[i]].push_back({x[i], a[i]}); for (int i = 0; i < M; i++) if (!b[i].empty()) { sort(b[i].begin(), b[i].end()); int tmp = -inf; for (auto p : b[i]) { if (p.second == 1) tmp = p.first; else res = min(res, p.first - tmp); } } b = vvp(M); for (int i = 0; i < n; i++) b[x[i] + y[i]].push_back({x[i], a[i]}); for (int i = 0; i < M; i++) if (!b[i].empty()) { sort(b[i].begin(), b[i].end()); int tmp = -inf; for (auto p : b[i]) { if (p.second == 1) tmp = p.first; if (p.second == 0) res = min(res, (p.first - tmp) * 2); } tmp = -inf; for (auto p : b[i]) { if (p.second == 2) tmp = p.first; if (p.second == 3) res = min(res, (p.first - tmp) * 2); } } b = vvp(M); for (int i = 0; i < n; i++) b[x[i] - y[i] + M].push_back({x[i], a[i]}); for (int i = 0; i < M; i++) if (!b[i].empty()) { sort(b[i].begin(), b[i].end()); int tmp = -inf; for (auto p : b[i]) { if (p.second == 0) tmp = p.first; if (p.second == 3) res = min(res, (p.first - tmp) * 2); } tmp = -inf; for (auto p : b[i]) { if (p.second == 1) tmp = p.first; if (p.second == 2) res = min(res, (p.first - tmp) * 2); } } if (res == inf) cout << "SAFE" << endl; else cout << res * 5 << endl; }
#include <algorithm> #include <cassert> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <vector> #define syosu(x) fixed << setprecision(x) using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int, int> P; typedef pair<double, double> pdd; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double> vd; typedef vector<vd> vvd; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<string> vs; typedef vector<P> vp; typedef vector<vp> vvp; typedef vector<pll> vpll; typedef pair<int, P> pip; typedef vector<pip> vip; const int inf = 1 << 28; const ll INF = 1ll << 60; const double pi = acos(-1); const double eps = 1e-8; const ll mod = 998244353; const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1}; const int M = 500001; int n; vi x, y, a; map<char, int> mp = { {'U', 0}, {'R', 1}, {'D', 2}, {'L', 3}, }; int main() { cin >> n; int res = inf; x = y = a = vi(n); for (int i = 0; i < n; i++) { char c; cin >> x[i] >> y[i] >> c; a[i] = mp[c]; } vvp b(M); for (int i = 0; i < n; i++) if (a[i] % 2 == 0) b[x[i]].push_back({y[i], a[i]}); for (int i = 0; i < M; i++) if (!b[i].empty()) { sort(b[i].begin(), b[i].end()); int tmp = -inf; for (auto p : b[i]) { if (p.second == 0) tmp = p.first; else res = min(res, p.first - tmp); } } b = vvp(M); for (int i = 0; i < n; i++) if (a[i] % 2 == 1) b[y[i]].push_back({x[i], a[i]}); for (int i = 0; i < M; i++) if (!b[i].empty()) { sort(b[i].begin(), b[i].end()); int tmp = -inf; for (auto p : b[i]) { if (p.second == 1) tmp = p.first; else res = min(res, p.first - tmp); } } b = vvp(M); for (int i = 0; i < n; i++) b[x[i] + y[i]].push_back({x[i], a[i]}); for (int i = 0; i < M; i++) if (!b[i].empty()) { sort(b[i].begin(), b[i].end()); int tmp = -inf; for (auto p : b[i]) { if (p.second == 1) tmp = p.first; if (p.second == 0) res = min(res, (p.first - tmp) * 2); } tmp = -inf; for (auto p : b[i]) { if (p.second == 2) tmp = p.first; if (p.second == 3) res = min(res, (p.first - tmp) * 2); } } b = vvp(M); for (int i = 0; i < n; i++) b[x[i] - y[i] + 200005].push_back({x[i], a[i]}); for (int i = 0; i < M; i++) if (!b[i].empty()) { sort(b[i].begin(), b[i].end()); int tmp = -inf; for (auto p : b[i]) { if (p.second == 0) tmp = p.first; if (p.second == 3) res = min(res, (p.first - tmp) * 2); } tmp = -inf; for (auto p : b[i]) { if (p.second == 1) tmp = p.first; if (p.second == 2) res = min(res, (p.first - tmp) * 2); } } if (res == inf) cout << "SAFE" << endl; else cout << res * 5 << endl; }
replace
109
110
109
110
0
p02605
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using LL = long long int; #define incID(i, l, r) for (int i = (l); i < (r); ++i) #define decID(i, l, r) for (int i = (r)-1; i >= (l); --i) #define incII(i, l, r) for (int i = (l); i <= (r); ++i) #define decII(i, l, r) for (int i = (r); i >= (l); --i) #define inc(i, n) incID(i, 0, n) #define dec(i, n) decID(i, 0, n) #define inc1(i, n) incII(i, 1, n) #define dec1(i, n) decII(i, 1, n) #define inID(v, l, r) ((l) <= (v) && (v) < (r)) #define inII(v, l, r) ((l) <= (v) && (v) <= (r)) #define PB push_back #define EB emplace_back #define MP make_pair #define MT make_tuple #define FI first #define SE second #define FR front() #define BA back() #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() auto setmin = [](auto &a, auto b) { return (b < a ? a = b, true : false); }; auto setmax = [](auto &a, auto b) { return (b > a ? a = b, true : false); }; auto setmineq = [](auto &a, auto b) { return (b <= a ? a = b, true : false); }; auto setmaxeq = [](auto &a, auto b) { return (b >= a ? a = b, true : false); }; #define SI(v) static_cast<int>(v.size()) #define RF(e, v) for (auto &e : v) #define until(e) while (!(e)) #define if_not(e) if (!(e)) #define ef else if #define UR assert(false) #define IN(T, ...) \ T __VA_ARGS__; \ IN_(__VA_ARGS__); void IN_(){}; template <typename T, typename... U> void IN_(T &a, U &...b) { cin >> a; IN_(b...); }; template <typename T> void OUT(T &&a) { cout << a << endl; } template <typename T, typename... U> void OUT(T &&a, U &&...b) { cout << a << " "; OUT(b...); } // ---- ---- template <typename T, typename I = LL> class Sequence { private: I mi = 1, ma = 0, n = 0; vector<T> s; public: Sequence() {} Sequence(I mi, I ma) : mi(mi), ma(ma), n(ma - mi + 1) { s = vector<T>(n); } Sequence(I mi, I ma, T v) : mi(mi), ma(ma), n(ma - mi + 1) { s = vector<T>(n, v); } T &operator[](I i) { assert(inII(i, mi, ma)); return s[i - mi]; } T &front() { return s.front(); } T &back() { return s.back(); } I size() { return n; } vector<T> &get() { return s; } }; template <typename T> class opt { private: bool f; T v; public: opt() { f = false; } opt(T v) : v(v) { f = true; } void reset() { f = false; } bool setmin(T a) { return (!f || a < v ? v = a, f = true : false); } bool setmax(T a) { return (!f || a > v ? v = a, f = true : false); } bool setmineq(T a) { return (!f || a <= v ? v = a, f = true : false); } bool setmaxeq(T a) { return (!f || a >= v ? v = a, f = true : false); } bool has_val() { return f; } bool is_null() { return !f; } T &val() { assert(f); return v; } friend T operator||(opt a, T e) { return (a.f ? a.v : e); } friend istream &operator>>(istream &s, opt<T> &a) { a.f = true; return (s >> a.v); } friend ostream &operator<<(ostream &s, opt<T> a) { return (a.f ? s << a.v : s << "[null]"); } }; int main() { const int M = 200'000; Sequence<map<int, char>> mx(0, M), my(0, M), ms(-M, +M), md(-M, +M); IN(int, n); inc(i, n) { IN(int, x, y); IN(string, s); char c = s[0]; mx[x][y] = c; my[y][x] = c; ms[x + y][x - y] = c; md[x - y][x + y] = c; } opt<int> ans; auto f = [&](auto &sm, char a, char b) { opt<int> mi; RF(m, sm.get()) { opt<int> p; for (auto [x, c] : m) { if (c == a) { p = x; } if (c == b) { if (p.has_val()) { mi.setmin(x - p.val()); } } } } if (mi.has_val()) { ans.setmin(mi.val()); } }; f(mx, 'U', 'D'); f(my, 'R', 'L'); f(ms, 'R', 'U'); f(ms, 'D', 'L'); f(md, 'U', 'L'); f(md, 'R', 'D'); if (ans.has_val()) { OUT(ans.val() * 5); } else { OUT("SAFE"); } }
#include <bits/stdc++.h> using namespace std; using LL = long long int; #define incID(i, l, r) for (int i = (l); i < (r); ++i) #define decID(i, l, r) for (int i = (r)-1; i >= (l); --i) #define incII(i, l, r) for (int i = (l); i <= (r); ++i) #define decII(i, l, r) for (int i = (r); i >= (l); --i) #define inc(i, n) incID(i, 0, n) #define dec(i, n) decID(i, 0, n) #define inc1(i, n) incII(i, 1, n) #define dec1(i, n) decII(i, 1, n) #define inID(v, l, r) ((l) <= (v) && (v) < (r)) #define inII(v, l, r) ((l) <= (v) && (v) <= (r)) #define PB push_back #define EB emplace_back #define MP make_pair #define MT make_tuple #define FI first #define SE second #define FR front() #define BA back() #define ALL(v) v.begin(), v.end() #define RALL(v) v.rbegin(), v.rend() auto setmin = [](auto &a, auto b) { return (b < a ? a = b, true : false); }; auto setmax = [](auto &a, auto b) { return (b > a ? a = b, true : false); }; auto setmineq = [](auto &a, auto b) { return (b <= a ? a = b, true : false); }; auto setmaxeq = [](auto &a, auto b) { return (b >= a ? a = b, true : false); }; #define SI(v) static_cast<int>(v.size()) #define RF(e, v) for (auto &e : v) #define until(e) while (!(e)) #define if_not(e) if (!(e)) #define ef else if #define UR assert(false) #define IN(T, ...) \ T __VA_ARGS__; \ IN_(__VA_ARGS__); void IN_(){}; template <typename T, typename... U> void IN_(T &a, U &...b) { cin >> a; IN_(b...); }; template <typename T> void OUT(T &&a) { cout << a << endl; } template <typename T, typename... U> void OUT(T &&a, U &&...b) { cout << a << " "; OUT(b...); } // ---- ---- template <typename T, typename I = LL> class Sequence { private: I mi = 1, ma = 0, n = 0; vector<T> s; public: Sequence() {} Sequence(I mi, I ma) : mi(mi), ma(ma), n(ma - mi + 1) { s = vector<T>(n); } Sequence(I mi, I ma, T v) : mi(mi), ma(ma), n(ma - mi + 1) { s = vector<T>(n, v); } T &operator[](I i) { assert(inII(i, mi, ma)); return s[i - mi]; } T &front() { return s.front(); } T &back() { return s.back(); } I size() { return n; } vector<T> &get() { return s; } }; template <typename T> class opt { private: bool f; T v; public: opt() { f = false; } opt(T v) : v(v) { f = true; } void reset() { f = false; } bool setmin(T a) { return (!f || a < v ? v = a, f = true : false); } bool setmax(T a) { return (!f || a > v ? v = a, f = true : false); } bool setmineq(T a) { return (!f || a <= v ? v = a, f = true : false); } bool setmaxeq(T a) { return (!f || a >= v ? v = a, f = true : false); } bool has_val() { return f; } bool is_null() { return !f; } T &val() { assert(f); return v; } friend T operator||(opt a, T e) { return (a.f ? a.v : e); } friend istream &operator>>(istream &s, opt<T> &a) { a.f = true; return (s >> a.v); } friend ostream &operator<<(ostream &s, opt<T> a) { return (a.f ? s << a.v : s << "[null]"); } }; int main() { const int M = 200'000; Sequence<map<int, char>> mx(0, M), my(0, M), ms(0, 2 * M), md(-M, +M); IN(int, n); inc(i, n) { IN(int, x, y); IN(string, s); char c = s[0]; mx[x][y] = c; my[y][x] = c; ms[x + y][x - y] = c; md[x - y][x + y] = c; } opt<int> ans; auto f = [&](auto &sm, char a, char b) { opt<int> mi; RF(m, sm.get()) { opt<int> p; for (auto [x, c] : m) { if (c == a) { p = x; } if (c == b) { if (p.has_val()) { mi.setmin(x - p.val()); } } } } if (mi.has_val()) { ans.setmin(mi.val()); } }; f(mx, 'U', 'D'); f(my, 'R', 'L'); f(ms, 'R', 'U'); f(ms, 'D', 'L'); f(md, 'U', 'L'); f(md, 'R', 'D'); if (ans.has_val()) { OUT(ans.val() * 5); } else { OUT("SAFE"); } }
replace
101
102
101
102
0
p02606
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define lvector vector<ll> #define P pair<ll, ll> #define ALL(a) a.begin(), a.end() #define YESNO(i) puts((i) ? "YES" : "NO"); #define YesNo(i) puts((i) ? "Yes" : "No"); #define yesno(i) puts((i) ? "yes" : "no"); #define rep(i, n) for (ll i = 0; i < n; ++i) #define print(a) cout << (a) << endl int main() { ios::sync_with_stdio(false); cin.tie(0); ll l, r, d, ans = 0; for (ll i = l; i <= r; i++) { if (i % d == 0) ans++; } print(ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define lvector vector<ll> #define P pair<ll, ll> #define ALL(a) a.begin(), a.end() #define YESNO(i) puts((i) ? "YES" : "NO"); #define YesNo(i) puts((i) ? "Yes" : "No"); #define yesno(i) puts((i) ? "yes" : "no"); #define rep(i, n) for (ll i = 0; i < n; ++i) #define print(a) cout << (a) << endl int main() { ios::sync_with_stdio(false); cin.tie(0); ll l, r, d, ans = 0; cin >> l >> r >> d; for (ll i = l; i <= r; i++) { if (i % d == 0) ans++; } print(ans); return 0; }
insert
16
16
16
17
0
p02606
C++
Time Limit Exceeded
#include <iostream> using namespace std; int main() { // your code goes here int l, r, d; cin >> l >> r >> d; int cnt = 0; while (l <= r) { if (l % d == 0) cnt++; } cout << cnt; return 0; }
#include <iostream> using namespace std; int main() { // your code goes here int l, r, d; cin >> l >> r >> d; int cnt = 0; while (l <= r) { if (l % d == 0) cnt++; l++; } cout << cnt; return 0; }
insert
11
11
11
12
TLE
p02606
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // #define int long long typedef pair<int, int> ii; typedef tuple<int, int, int> iii; #define ll long long #define iiMPQ priority_queue<ii, vector<ii>, greater<ii>> #define MPQ priority_queue<int, vector<int>, greater<int>> #define PQ priority_queue<int> #define iiPQ priority_queue<ii> #define US unordered_set<int> #define UMS unordered_multiset<int> #define UM unordered_map<int> #define iiUS unordered_set<ii> #define ST stack<int> #define MS multiset<int> #define scan1(n) cin >> n #define scan2(a, b) cin >> a >> b #define scan3(a, b, c) cin >> a >> b >> c #define print(n) cout << n #define println(n) cout << n << "\n" #define vi vector<int> #define vii vector<ii> #define viii vector<iii> #define fi first #define se second #define REP(i, n) for (int i = 0; i < n; ++i) #define REPR(i, s, e) for (int i = s; i < e; ++i) #define REPS(i, s, e, st) for (int i = s; i < e; i += st) #define rep(i, n) for (int i = n - 1; i >= 0; --i) #define repr(i, s, e) for (int i = s; i >= e; --i) #define reps(i, s, e, st) for (int i = s; i >= e; i -= st) #define SET(arr, k) memset(arr, k, sizeof arr) #define speed \ ios::sync_with_stdio(0); \ cin.tie(0); #define mp make_pair #define pb push_back #define Qu queue #define Vt vector #define Dq deque #define prints(n) cout << n << " "; void m1() { int l, r, d; int res = 0; for (int i = l; i <= r; ++i) { if (i % d == 0) ++res; } print(res); } /* void m2(){ int t; scan1(t); while(t--) m1(); } */ signed main() { speed; // freopen("in.txt","r",stdin); m1(); // m2(); }
#include <bits/stdc++.h> using namespace std; // #define int long long typedef pair<int, int> ii; typedef tuple<int, int, int> iii; #define ll long long #define iiMPQ priority_queue<ii, vector<ii>, greater<ii>> #define MPQ priority_queue<int, vector<int>, greater<int>> #define PQ priority_queue<int> #define iiPQ priority_queue<ii> #define US unordered_set<int> #define UMS unordered_multiset<int> #define UM unordered_map<int> #define iiUS unordered_set<ii> #define ST stack<int> #define MS multiset<int> #define scan1(n) cin >> n #define scan2(a, b) cin >> a >> b #define scan3(a, b, c) cin >> a >> b >> c #define print(n) cout << n #define println(n) cout << n << "\n" #define vi vector<int> #define vii vector<ii> #define viii vector<iii> #define fi first #define se second #define REP(i, n) for (int i = 0; i < n; ++i) #define REPR(i, s, e) for (int i = s; i < e; ++i) #define REPS(i, s, e, st) for (int i = s; i < e; i += st) #define rep(i, n) for (int i = n - 1; i >= 0; --i) #define repr(i, s, e) for (int i = s; i >= e; --i) #define reps(i, s, e, st) for (int i = s; i >= e; i -= st) #define SET(arr, k) memset(arr, k, sizeof arr) #define speed \ ios::sync_with_stdio(0); \ cin.tie(0); #define mp make_pair #define pb push_back #define Qu queue #define Vt vector #define Dq deque #define prints(n) cout << n << " "; void m1() { int l, r, d; cin >> l >> r >> d; int res = 0; for (int i = l; i <= r; ++i) { if (i % d == 0) ++res; } print(res); } /* void m2(){ int t; scan1(t); while(t--) m1(); } */ signed main() { speed; // freopen("in.txt","r",stdin); m1(); // m2(); }
insert
45
45
45
46
TLE
p02606
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int l, r, d; cin >> l, r, d; cout << r / d - l / d << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int l, r, d; cin >> l >> r >> d; cout << r / d - (l - 1) / d << endl; }
replace
4
6
4
6
0
p02606
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define IO \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); typedef long long ll; long long N = 1e+5; int solve() { int a, b, c; cin >> a >> b >> c; int cnt = 0; for (int i = a; i <= b; i++) { if (i % c == 0) { cnt++; } } cout << cnt << endl; } int main() { IO; solve(); return 0; }
#include <bits/stdc++.h> using namespace std; #define IO \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); typedef long long ll; long long N = 1e+5; void solve() { int a, b, c; cin >> a >> b >> c; int cnt = 0; for (int i = a; i <= b; i++) { if (i % c == 0) { cnt++; } } cout << cnt << endl; } int main() { IO; solve(); return 0; }
replace
10
11
10
11
TLE
p02606
C++
Runtime Error
// #include <tourist> #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> p; const ll INF = 1e9; const ll LINF = ll(1e18); const ll MOD = 1000000007; const ll dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; const ll Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl #define rep(i, n) for (ll i = 0; i < n; i++) #define ALL(v) v.begin(), v.end() #define debug(v) \ cout << #v << ":"; \ for (auto x : v) { \ cout << x << ' '; \ } \ cout << endl; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } // cout<<fixed<<setprecision(15);有効数字15桁 //-std=c++14 //-std=gnu++17 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; } int main() { cin.tie(0); ios::sync_with_stdio(false); int a, b, c; int ans = 0; for (int i = a; i <= b; i++) { if (i % c == 0) ans++; } cout << ans << "\n"; }
// #include <tourist> #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> p; const ll INF = 1e9; const ll LINF = ll(1e18); const ll MOD = 1000000007; const ll dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0}; const ll Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; #define yes cout << "Yes" << endl #define YES cout << "YES" << endl #define no cout << "No" << endl #define NO cout << "NO" << endl #define rep(i, n) for (ll i = 0; i < n; i++) #define ALL(v) v.begin(), v.end() #define debug(v) \ cout << #v << ":"; \ for (auto x : v) { \ cout << x << ' '; \ } \ cout << endl; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } // cout<<fixed<<setprecision(15);有効数字15桁 //-std=c++14 //-std=gnu++17 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; } int main() { cin.tie(0); ios::sync_with_stdio(false); int a, b, c; cin >> a >> b >> c; int ans = 0; for (int i = a; i <= b; i++) { if (i % c == 0) ans++; } cout << ans << "\n"; }
insert
46
46
46
47
0
p02606
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { ll l, r, d, cnt = 0; cin >> l >> r; for (ll i = l; i <= r; i++) { if (i % d == 0) cnt++; } cout << cnt << endl; return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { ll l, r, d, cnt = 0; cin >> l >> r >> d; for (ll i = l; i <= r; i++) { if (i % d == 0) cnt++; } cout << cnt << endl; return 0; }
replace
5
6
5
6
0
p02606
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { ll l, r, d, cnt = 0; cin >> l >> r; if (l % d == 0 || r % d == 0) cnt++; cnt += ((r - l) / d); cout << cnt << endl; return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; int main() { ll l, r, d, cnt = 0; cin >> l >> r >> d; if (l % d == 0 || r % d == 0) cnt++; cnt += ((r - l) / d); cout << cnt << endl; return 0; }
replace
5
6
5
6
0
p02606
C++
Runtime Error
#include <cstdint> #include <iostream> #include <string> int main(int argc, char *argv[]) { const int32_t L = std::atoi(argv[1]); const int32_t R = std::atoi(argv[2]); const int32_t d = std::atoi(argv[3]); std::cout << (R - L) / d << std::endl; return 0; }
#include <cstdint> #include <iostream> #include <string> int main(int argc, char *argv[]) { int32_t L, R, d; std::cin >> L; std::cin >> R; std::cin >> d; int cnt = 0; for (int i = L; i <= R; ++i) { cnt += (i % d == 0) ? 1 : 0; } std::cout << cnt << std::endl; return 0; }
replace
6
10
6
16
-11
p02606
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, N) for (int i = 0; i < N; i++) typedef long long ll; #define dump(x) cerr << #x << "=" << x << endl using P = pair<int, int>; int main() { int l, r, d; cin >> l >> r, d; int cnt = 0; for (int i = l; i <= r; i++) { if (i % d == 0) cnt++; } cout << cnt << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, N) for (int i = 0; i < N; i++) typedef long long ll; #define dump(x) cerr << #x << "=" << x << endl using P = pair<int, int>; int main() { int l, r, d; cin >> l >> r >> d; int cnt = 0; for (int i = l; i <= r; i++) { if (i % d == 0) cnt++; } cout << cnt << endl; return 0; }
replace
9
10
9
10
0
p02606
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { long long l, r, d; l--; long long ans = 0; ans += r / d; ans -= l / d; cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { long long l, r, d; cin >> l >> r >> d; l--; long long ans = 0; ans += r / d; ans -= l / d; cout << ans << endl; }
insert
6
6
6
7
0
p02606
C++
Time Limit Exceeded
#include <bits/stdc++.h> // #include <boost/functional/hash.hpp> using namespace std; typedef long long ll; // typedef int long long int; typedef unsigned long long ull; typedef map<int, int> mii; typedef map<ll, ll> mll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; #define f(i, n) for (i = 0; i < n; i++) #define f1(i, n) for (i = 1; i < n; i++) #define fr(i, n) for (i = n - 1; i >= 0; i--) #define em emplace_back #define mp make_pair #define in insert #define fi first #define sc second #define b begin #define e end #define er erase #define l length #define c clear #define si size #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(0); const double pi = 3.141592653; const ll MOD = 1000000007; const ll mod = 998244353; const string no = "NO\n", yes = "YES\n"; // ll gcd(ll a,ll b){ // if(a==0) return b; // gcd(b%a,a); // } // void dfs(vl v[],ll node,ll hai[]){ // hai[node]=1; // for(auto i:v[node]){ // if(hai[i]==0){ // dfs(v,i,hai); // } // } // } // ll con(vl v[],ll hai[],ll sz){ // ll count=0; // for(int i=1;i<sz;i++){ // if(hai[i]==0){ // count++; // dfs(v,i,hai); // } // } // return count; // } // void gcde(int a,int b,int *x,int *y){ // if(a==0){ // *x=0; // *y=1; // return; // } // int x1,y1; // gcde(b%a,a,&x1,&y1); // *x=y1-(b/a)*x1; // *y=x1; // } // ll recur(vl v,ll in,ll m,ll n){ // if(in==-1) return 1000000000001; // ll d,e,c; // d=max(m/v[in],n*v[in]); // c=recur(v,in-1,m/v[in],n*v[in]); // e=recur(v,in-1,m,n); // return min(c,min(e,d)); // } // ll bexpo(ll a,ll p){ // ll x=1; // while(p){ // if(p&1){ // x=(x*a)%mod; // } // a=(a*a)%mod; // p>>=1; // } // return x; // } // ll fact[500001],invf[500001]; int main() { fastio int t = 1; // cin>>t; ull n, m, a, b, i, l, r, d, ans; while (t--) { ans = 0; cin >> l >> r >> d; i = 1; while (i < 101) { if (d * i >= l && d * i <= r) ans++; } cout << ans; } return 0; }
#include <bits/stdc++.h> // #include <boost/functional/hash.hpp> using namespace std; typedef long long ll; // typedef int long long int; typedef unsigned long long ull; typedef map<int, int> mii; typedef map<ll, ll> mll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; #define f(i, n) for (i = 0; i < n; i++) #define f1(i, n) for (i = 1; i < n; i++) #define fr(i, n) for (i = n - 1; i >= 0; i--) #define em emplace_back #define mp make_pair #define in insert #define fi first #define sc second #define b begin #define e end #define er erase #define l length #define c clear #define si size #define fastio \ ios_base::sync_with_stdio(false); \ cin.tie(0); const double pi = 3.141592653; const ll MOD = 1000000007; const ll mod = 998244353; const string no = "NO\n", yes = "YES\n"; // ll gcd(ll a,ll b){ // if(a==0) return b; // gcd(b%a,a); // } // void dfs(vl v[],ll node,ll hai[]){ // hai[node]=1; // for(auto i:v[node]){ // if(hai[i]==0){ // dfs(v,i,hai); // } // } // } // ll con(vl v[],ll hai[],ll sz){ // ll count=0; // for(int i=1;i<sz;i++){ // if(hai[i]==0){ // count++; // dfs(v,i,hai); // } // } // return count; // } // void gcde(int a,int b,int *x,int *y){ // if(a==0){ // *x=0; // *y=1; // return; // } // int x1,y1; // gcde(b%a,a,&x1,&y1); // *x=y1-(b/a)*x1; // *y=x1; // } // ll recur(vl v,ll in,ll m,ll n){ // if(in==-1) return 1000000000001; // ll d,e,c; // d=max(m/v[in],n*v[in]); // c=recur(v,in-1,m/v[in],n*v[in]); // e=recur(v,in-1,m,n); // return min(c,min(e,d)); // } // ll bexpo(ll a,ll p){ // ll x=1; // while(p){ // if(p&1){ // x=(x*a)%mod; // } // a=(a*a)%mod; // p>>=1; // } // return x; // } // ll fact[500001],invf[500001]; int main() { fastio int t = 1; // cin>>t; ull n, m, a, b, i, l, r, d, ans; while (t--) { ans = 0; cin >> l >> r >> d; i = 1; while (i < 101) { if (d * i >= l && d * i <= r) ans++; i++; } cout << ans; } return 0; }
insert
106
106
106
107
TLE
p02606
C++
Runtime Error
#include <iostream> using namespace std; int main() { int x, y, z; cin >> x >> y; int cntr = 0; for (int i = x; i <= y; i++) { if (i % z == 0) cntr++; } cout << cntr; }
#include <iostream> using namespace std; int main() { int x, y, z; cin >> x >> y >> z; int cntr = 0; for (int i = x; i <= y; i++) { if (i % z == 0) cntr++; } cout << cntr; }
replace
6
7
6
7
0
p02606
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int L, R, d; int ans = 0; for (int i = L; i <= R; i++) { if (i % d == 0) ans++; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int L, R, d; cin >> L >> R >> d; int ans = 0; for (int i = L; i <= R; i++) { if (i % d == 0) ans++; } cout << ans << endl; }
insert
4
4
4
5
0
p02606
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int l, r, d; int sum = 0; for (int i = l; i <= r; i++) { if (i % d == 0) { sum++; } } cout << sum << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int l, r, d; cin >> l >> r >> d; int sum = 0; for (int i = l; i <= r; i++) { if (i % d == 0) { sum++; } } cout << sum << endl; return 0; }
insert
4
4
4
5
0
p02606
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define loop(i, x, z) for (int i = x; i < z; i++) int cnt = 0, l, r, d; int main() { cin >> l >> r; loop(i, l, r + 1) { if (i % d == 0) cnt++; } cout << cnt; }
#include <bits/stdc++.h> using namespace std; #define loop(i, x, z) for (int i = x; i < z; i++) int cnt = 0, l, r, d; int main() { cin >> l >> r >> d; loop(i, l, r + 1) { if (i % d == 0) cnt++; } cout << cnt; }
replace
5
6
5
6
-8
p02606
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; #define fi first #define se second #define mp make_pair #define rep(i, n) for (int i = 0; i < n; ++i) #define rrep(i, n) for (int i = n; i >= 0; --i) const int inf = 1e9 + 7; const ll mod = 1e9 + 7; const ll mod1 = 998244353; const ll big = 1e18; const double PI = 2 * asin(1); int main() { int L, R, D; int ans = 0; for (int i = L; i <= R; ++i) { if (i % D == 0) ans++; } cout << ans << endl; }
#include <algorithm> #include <cmath> #include <cstring> #include <iomanip> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; #define fi first #define se second #define mp make_pair #define rep(i, n) for (int i = 0; i < n; ++i) #define rrep(i, n) for (int i = n; i >= 0; --i) const int inf = 1e9 + 7; const ll mod = 1e9 + 7; const ll mod1 = 998244353; const ll big = 1e18; const double PI = 2 * asin(1); int main() { int L, R, D; cin >> L >> R >> D; int ans = 0; for (int i = L; i <= R; ++i) { if (i % D == 0) ans++; } cout << ans << endl; }
insert
27
27
27
28
0
p02606
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define repi(i, a, b) for (int i = (a); i <= (b); i++) #define repA(i, n) for (int i = n; i >= 0; i--) #define all(x) x.begin(), x.end() #define pb push_back #define mp make_pair #define ff first #define ss second #define sz(a) (int)(a.size()) typedef long long ll; typedef long double ld; const ll mod = (ll)(1e9 + 7); // 998244353; const int N = (int)(1e6 + 5); void pre() {} void solve() { ll l, r, d; cin >> l >> r >> d; int cnt = 0; repi(i, l, r) if (i % d == 0) cnt++; cout << cnt; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); // freopen("output.txt","w",stdout); #endif int t = 1; pre(); cin >> t; rep(i, t) { // cout<<"\nCase #"<<(i+1)<<"\n"; solve(); cout << '\n'; } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (n); i++) #define repi(i, a, b) for (int i = (a); i <= (b); i++) #define repA(i, n) for (int i = n; i >= 0; i--) #define all(x) x.begin(), x.end() #define pb push_back #define mp make_pair #define ff first #define ss second #define sz(a) (int)(a.size()) typedef long long ll; typedef long double ld; const ll mod = (ll)(1e9 + 7); // 998244353; const int N = (int)(1e6 + 5); void pre() {} void solve() { ll l, r, d; cin >> l >> r >> d; int cnt = 0; repi(i, l, r) if (i % d == 0) cnt++; cout << cnt; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); // freopen("output.txt","w",stdout); #endif int t = 1; pre(); // cin>>t; rep(i, t) { // cout<<"\nCase #"<<(i+1)<<"\n"; solve(); cout << '\n'; } return 0; }
replace
38
39
38
39
0
p02606
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int l, r, d; cin >> l >> r >> d; int ans = 0; for (int i = l; i <= r; i = i++) { if (i % d == 0) ans++; } cout << ans; }
#include <bits/stdc++.h> using namespace std; int main() { int l, r, d; cin >> l >> r >> d; cout << r / d - (l - 1) / d; }
replace
6
12
6
7
TLE
p02606
C++
Runtime Error
#include <iostream> using namespace std; int main() { int L, R, d; int ans = 0; for (int i = L; i <= R; ++i) if (i % d == 0) ans++; cout << ans << "\n"; }
#include <iostream> using namespace std; int main() { int L, R, d; cin >> L >> R >> d; int ans = 0; for (int i = L; i <= R; ++i) if (i % d == 0) ans++; cout << ans << "\n"; }
insert
4
4
4
5
TLE
p02606
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; int main() { int l, r, d; int ans = 0; for (int i = l; i <= r; i++) { if (i % d == 0) ans++; } cout << ans; }
#include <iostream> #include <vector> using namespace std; int main() { int l, r, d; int ans = 0; cin >> l >> r >> d; for (int i = l; i <= r; i++) { if (i % d == 0) ans++; } cout << ans; }
insert
8
8
8
9
0
p02606
C++
Runtime Error
#include <iostream> using namespace std; int main() { int L, R, d; cout << R / d - (L - 1) / d; return 0; }
#include <iostream> using namespace std; int main() { int L, R, d; cin >> L >> R >> d; cout << R / d - (L - 1) / d; return 0; }
insert
6
6
6
7
0
p02606
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; int main() { int l, r, d; cin >> l >> r >> d; int ans = 0; for (int i = l; l <= r; ++i) { if (i % d == 0) ans++; } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int l, r, d; cin >> l >> r >> d; int ans = 0; for (int i = l; i <= r; ++i) { if (i % d == 0) ans++; } cout << ans << '\n'; return 0; }
replace
8
9
8
9
TLE