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
p02555
C++
Runtime Error
#include <bits/stdc++.h> #define all(a) a.begin(), a.end() #define db(a) cout << fixed << #a << " = " << a << endl; using namespace std; typedef long long ll; typedef pair<int, int> pii; const ll MOD = 1e9 + 7; const int MAXN = 20 + 5; vector<vector<ll>> dp(MAXN, vector<ll>(MAXN, 0)); int main() { ios_base::sync_with_stdio(false); cin.tie(0); for (int k = 1; k < MAXN; k++) { dp[1][k] = k; } for (int s = 1; s < MAXN; s++) { dp[s][1] = 1; } for (int s = 2; s < MAXN; s++) { for (int k = 2; k < MAXN; k++) { dp[s][k] = (dp[s][k - 1] + dp[s - 1][k]) % MOD; } } int S; cin >> S; ll ans = 0; for (int i = 1; i < S; i++) { ans += dp[max(S - 3 * i, 0)][i]; if (S - 3 * i == 0) ans += 1; // cout << i << " " << S - 3*i << " = " << dp[max(S - 3*i, 0)][i] << endl; ans %= MOD; } cout << ans << endl; }
#include <bits/stdc++.h> #define all(a) a.begin(), a.end() #define db(a) cout << fixed << #a << " = " << a << endl; using namespace std; typedef long long ll; typedef pair<int, int> pii; const ll MOD = 1e9 + 7; const int MAXN = 2000 + 5; vector<vector<ll>> dp(MAXN, vector<ll>(MAXN, 0)); int main() { ios_base::sync_with_stdio(false); cin.tie(0); for (int k = 1; k < MAXN; k++) { dp[1][k] = k; } for (int s = 1; s < MAXN; s++) { dp[s][1] = 1; } for (int s = 2; s < MAXN; s++) { for (int k = 2; k < MAXN; k++) { dp[s][k] = (dp[s][k - 1] + dp[s - 1][k]) % MOD; } } int S; cin >> S; ll ans = 0; for (int i = 1; i < S; i++) { ans += dp[max(S - 3 * i, 0)][i]; if (S - 3 * i == 0) ans += 1; // cout << i << " " << S - 3*i << " = " << dp[max(S - 3*i, 0)][i] << endl; ans %= MOD; } cout << ans << endl; }
replace
9
10
9
10
0
p02555
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <climits> using namespace std; #define debug(x, y) \ cout << (#x) << " " << (#y) << " is " << (x) << " " << (y) << endl #define watch(x) cout << (#x) << " is " << (x) << endl #define fast ios_base::sync_with_stdio(false) #define fie(i, a, b) for (i = a; i < b; i++) #define MOD 1000000007 #define mod 998244353 #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define ll long long #define lld long long int #define ALL(x) (x).begin(), (x).end() typedef vector<lld> vi; typedef vector<vector<lld>> vii; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<pair<lld, lld>> vpi; typedef long long LL; lld dp[2001][2001]; lld solve(lld n, lld l) { if (n < 0 || n == 1 || n == 2 || l < 0) return 0; if ((l == 0 && n != 0) || (n == 0 && l != 0)) return dp[n][l] = 0; if (n == 0 && l == 0) { return dp[n][l] = 1; } lld c = 0; if (dp[n][l] != -1) return dp[n][l]; for (lld i = 3; i <= n; i++) { c += solve(n - i, l - 1); c %= MOD; } return dp[n][l] = c; } int main() { fast; cin.tie(0); lld n; cin >> n; if (n == 1 || n == 2) cout << "0" << endl; else { memset(dp, -1, sizeof(dp)); lld cnt = 0; for (lld i = 1; i <= (n / 3) + 1; i++) { cnt += solve(n, i); cnt %= MOD; } cout << cnt << endl; } }
#include <bits/stdc++.h> #include <climits> using namespace std; #define debug(x, y) \ cout << (#x) << " " << (#y) << " is " << (x) << " " << (y) << endl #define watch(x) cout << (#x) << " is " << (x) << endl #define fast ios_base::sync_with_stdio(false) #define fie(i, a, b) for (i = a; i < b; i++) #define MOD 1000000007 #define mod 998244353 #define PB push_back #define EB emplace_back #define MP make_pair #define FI first #define SE second #define ll long long #define lld long long int #define ALL(x) (x).begin(), (x).end() typedef vector<lld> vi; typedef vector<vector<lld>> vii; typedef vector<string> vs; typedef vector<bool> vb; typedef vector<pair<lld, lld>> vpi; typedef long long LL; lld dp[2001][2001]; lld solve(lld n, lld l) { if (n < 0 || n == 1 || n == 2 || l < 0) return 0; if ((l == 0 && n != 0) || (n == 0 && l != 0)) return dp[n][l] = 0; if (n == 0 && l == 0) { return dp[n][l] = 1; } lld c = 0; if (dp[n][l] != -1) return dp[n][l]; c += solve(n - 1, l); c %= MOD; c += solve(n - 3, l - 1); c %= MOD; return dp[n][l] = c; } int main() { fast; cin.tie(0); lld n; cin >> n; if (n == 1 || n == 2) cout << "0" << endl; else { memset(dp, -1, sizeof(dp)); lld cnt = 0; for (lld i = 1; i <= (n / 3) + 1; i++) { cnt += solve(n, i); cnt %= MOD; } cout << cnt << endl; } }
replace
41
45
41
45
TLE
p02555
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define sync \ { \ ios_base ::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); \ } #define ll long long int #define mod 1000000007 void solve() { int s; cin >> s; ll dp[s + 1]; dp[0] = dp[1] = dp[2] = 0; dp[3] = 1; for (int i = 4; i <= s; i++) { dp[i] = 0; for (int j = i - 3; j >= 3; j--) { dp[i] += (dp[j]) % mod; dp[i] %= mod; } dp[i] = (dp[i] + 1) % mod; } cout << dp[s]; } int main() { sync; int t = 1; // cin>>t; while (t--) { solve(); cout << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; #define sync \ { \ ios_base ::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); \ } #define ll long long int #define mod 1000000007 void solve() { int s; cin >> s; ll dp[s + 1]; if (s == 1 or s == 2) { cout << 0; return; } else if (s == 3) { cout << 1; return; } dp[0] = dp[1] = dp[2] = 0; dp[3] = 1; for (int i = 4; i <= s; i++) { dp[i] = 0; for (int j = i - 3; j >= 3; j--) { dp[i] += (dp[j]) % mod; dp[i] %= mod; } dp[i] = (dp[i] + 1) % mod; } cout << dp[s]; } int main() { sync; int t = 1; // cin>>t; while (t--) { solve(); cout << "\n"; } return 0; }
insert
17
17
17
27
0
p02555
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double mt19937 gen(chrono::steady_clock::now().time_since_epoch().count()); ll INF = (ll)1e20; int iINF = (int)1e20; ll mod = (ll)1e9 + 7; signed main() { ll n; cin >> n; ll dp[n + 1]; fill(&dp[0], &dp[0] + n + 1, 0); dp[3] = 1; for (int i = 4; i <= n; ++i) { dp[i] = 1; for (int j = 3; j < i; ++j) { if (i - j >= 3) { dp[i] += dp[j]; dp[i] %= mod; } } } cout << dp[n]; }
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double mt19937 gen(chrono::steady_clock::now().time_since_epoch().count()); ll INF = (ll)1e20; int iINF = (int)1e20; ll mod = (ll)1e9 + 7; signed main() { ll n; cin >> n; vector<ll> dp(n + 100, 0); if (n < 3) { cout << 0; return 0; } dp[3] = 1; for (int i = 4; i <= n; ++i) { dp[i] = 1; for (int j = 3; j < i; ++j) { if (i - j >= 3) { dp[i] += dp[j]; dp[i] %= mod; } } } cout << dp[n]; }
replace
16
18
16
21
0
p02555
C++
Runtime Error
#include <bits/stdc++.h> #define x first #define y second #define pb push_back #define mk make_pair #define all(a) a.begin(), a.end() #define len(a) (int)a.size() using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; vector<ll> dp; ll ans = 0; ll mod = 1e9 + 7; int solve(int v) { // cout << v << endl; if (dp[v] > 1) return dp[v]; for (int i = 3; v - i >= 0; i++) dp[v] = (dp[v] + solve(v - i)) % mod; return dp[v]; } int main() { int n; cin >> n; dp.resize(n + 1, 1); dp[0] = 0, dp[1] = 0, dp[2] = 0, dp[3] = 1; cout << solve(n) % mod << endl; return 0; }
#include <bits/stdc++.h> #define x first #define y second #define pb push_back #define mk make_pair #define all(a) a.begin(), a.end() #define len(a) (int)a.size() using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; vector<ll> dp; ll ans = 0; ll mod = 1e9 + 7; int solve(int v) { // cout << v << endl; if (dp[v] > 1) return dp[v]; for (int i = 3; v - i >= 0; i++) dp[v] = (dp[v] + solve(v - i)) % mod; return dp[v]; } int main() { int n; cin >> n; if (n < 3) return cout << 0 << endl, 0; dp.resize(n + 1, 1); dp[0] = 0, dp[1] = 0, dp[2] = 0, dp[3] = 1; cout << solve(n) % mod << endl; return 0; }
insert
31
31
31
33
0
p02555
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int64_t mod = 1000000007; int64_t f(int n, vector<int64_t> &a) { if (a.at(n) != -1) return a.at(n); else { a.at(n) = (f(n - 1, a) + f(n - 3, a)); a.at(n) %= mod; return a.at(n); } } int main() { int s; cin >> s; vector<int64_t> a(s + 1, -1); if (s < 3) { cout << 0 << endl; return 0; } a.at(0) = 0, a.at(1) = 0, a.at(2) = 0; a.at(3) = 1, a.at(4) = 1, a.at(5) = 1; int64_t ans; ans = f(s, a); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int64_t mod = 1000000007; int64_t f(int n, vector<int64_t> &a) { if (a.at(n) != -1) return a.at(n); else { a.at(n) = (f(n - 1, a) + f(n - 3, a)); a.at(n) %= mod; return a.at(n); } } int main() { int s; cin >> s; vector<int64_t> a(s + 1, -1); if (s < 3) { cout << 0 << endl; return 0; } a.at(0) = 0, a.at(1) = 0, a.at(2) = 0; a.at(3) = 1; int64_t ans; ans = f(s, a); cout << ans << endl; }
replace
24
25
24
25
0
p02555
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define irep(i, n) for (int i = (n); i >= 0; i--) using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 1 << 25; const int MOD = 1e9 + 7; ll dp[1000]; int main() { int s; cin >> s; dp[0] = 1; for (int i = 3; i <= s; i++) { dp[i] = dp[i - 1] + dp[i - 3]; dp[i] %= MOD; } cout << dp[s] << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define irep(i, n) for (int i = (n); i >= 0; i--) using namespace std; using ll = long long; using P = pair<int, int>; const int INF = 1 << 25; const int MOD = 1e9 + 7; int dp[2050]; int main() { int s; cin >> s; dp[0] = 1; for (int i = 3; i <= s; i++) { dp[i] = dp[i - 1] + dp[i - 3]; dp[i] %= MOD; } cout << dp[s] << endl; return 0; }
replace
8
9
8
9
0
p02555
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int mod = 1e9 + 7; int n; cin >> n; long long int dp[n + 1]; dp[1] = 0; dp[2] = 0; dp[3] = 1; dp[4] = 1; dp[5] = 1; dp[6] = 2; for (int i = 7; i <= n; i++) dp[i] = (dp[i - 3] * 2 + dp[i - 4] + dp[i - 5]) % mod; cout << dp[n]; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int mod = 1e9 + 7; int n; cin >> n; long long int dp[n + 7]; dp[1] = 0; dp[2] = 0; dp[3] = 1; dp[4] = 1; dp[5] = 1; dp[6] = 2; for (int i = 7; i <= n; i++) dp[i] = (dp[i - 3] * 2 + dp[i - 4] + dp[i - 5]) % mod; cout << dp[n]; return 0; }
replace
7
8
7
8
0
p02555
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define int long long int #define pb push_back const int mod = 1e9 + 7; #define all(x) x.begin(), x.end() #define endl '\n' #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) int dp[2010]; int solve(int n) { if (n == 0) return 1; if (n == 1 and n == 2) return 0; if (n >= 3 and n <= 5) return 1; if (dp[n] != -1) return dp[n]; int ans = 0; for (int i = 3; i <= n; i++) { if (n - i >= 0) { int temp = (solve(n - i)) % mod; ans = (ans + temp) % mod; } } return ans; } int32_t main() { IOS; int n; cin >> n; memset(dp, -1, sizeof dp); cout << solve(n) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long int #define pb push_back const int mod = 1e9 + 7; #define all(x) x.begin(), x.end() #define endl '\n' #define IOS \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0) int dp[2010]; int solve(int n) { if (n == 0) return 1; if (n == 1 and n == 2) return 0; if (n >= 3 and n <= 5) return 1; if (dp[n] != -1) return dp[n]; int ans = 0; for (int i = 3; i <= n; i++) { if (n - i >= 0) { int temp = (solve(n - i)) % mod; ans = (ans + temp) % mod; } } return dp[n] = ans; } int32_t main() { IOS; int n; cin >> n; memset(dp, -1, sizeof dp); cout << solve(n) << endl; return 0; }
replace
28
29
28
29
TLE
p02555
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define int long long int #define fi first #define se second #define pb push_back #define soo(v) sort(v.rbegin(), v.rend()) #define so(v) sort(v.begin(), v.end()) #define lb(v, x) lower_bound(v.begin(), v.end(), x) #define ub(v, x) upper_bound(v.begin(), v.end(), x) #define endl '\n' #define dbv(v) \ cout << endl; \ cout << #v << "-->> "; \ for (auto it : v) { \ cout << it << " "; \ } \ cout << endl; #define dbm(m) \ cout << endl; \ cout << #m << "-->> "; \ for (auto it : m) { \ cout << it.fi << " " << it.se.fi << " " << it.se.se << endl; \ } #define dbs(s) \ cout << endl; \ cout << #s << "-->> "; \ for (auto it : s) { \ cout << it << " "; \ } \ cout << endl; #define mod 1000000007 #define db1(x) cout << #x << "=" << x << endl; #define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl; #define db3(x, y, z) \ cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \ << endl; #define mx 1e18 #define mxe(v) *max_element(v.begin(), v.end()) #define mne(v) *min_element(v.begin(), v.end()) #define double long double #define io \ std::ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define re(s) reverse(s.begin(), s.end()) int powe(int x, int n) { if (n == 0) return 1; if (n % 2 == 0) return powe((x % mod * x % mod) % mod, n / 2) % mod; return (x % mod * powe((x % mod * x % mod) % mod, (n - 1) / 2) % mod) % mod; } int fun(int s, vector<int> &dp) { if (s < 0) return 0; if (dp[s] != -1) return dp[s]; if (s == 0) return dp[s] = 1; int pp = 0; for (int i = 3; i <= s; i++) { pp += fun(s - i, dp); pp %= mod; } dp[s] = pp; } int32_t main() { io int n; cin >> n; vector<int> dp(n + 1, -1); cout << fun(n, dp); }
#include <bits/stdc++.h> using namespace std; #define int long long int #define fi first #define se second #define pb push_back #define soo(v) sort(v.rbegin(), v.rend()) #define so(v) sort(v.begin(), v.end()) #define lb(v, x) lower_bound(v.begin(), v.end(), x) #define ub(v, x) upper_bound(v.begin(), v.end(), x) #define endl '\n' #define dbv(v) \ cout << endl; \ cout << #v << "-->> "; \ for (auto it : v) { \ cout << it << " "; \ } \ cout << endl; #define dbm(m) \ cout << endl; \ cout << #m << "-->> "; \ for (auto it : m) { \ cout << it.fi << " " << it.se.fi << " " << it.se.se << endl; \ } #define dbs(s) \ cout << endl; \ cout << #s << "-->> "; \ for (auto it : s) { \ cout << it << " "; \ } \ cout << endl; #define mod 1000000007 #define db1(x) cout << #x << "=" << x << endl; #define db2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl; #define db3(x, y, z) \ cout << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \ << endl; #define mx 1e18 #define mxe(v) *max_element(v.begin(), v.end()) #define mne(v) *min_element(v.begin(), v.end()) #define double long double #define io \ std::ios::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define re(s) reverse(s.begin(), s.end()) int powe(int x, int n) { if (n == 0) return 1; if (n % 2 == 0) return powe((x % mod * x % mod) % mod, n / 2) % mod; return (x % mod * powe((x % mod * x % mod) % mod, (n - 1) / 2) % mod) % mod; } int fun(int s, vector<int> &dp) { if (s < 0) return 0; if (dp[s] != -1) return dp[s]; if (s == 0) return dp[s] = 1; int pp = 0; for (int i = 3; i <= s; i++) { pp += fun(s - i, dp); pp %= mod; } return dp[s] = pp; } int32_t main() { io int n; cin >> n; vector<int> dp(n + 1, -1); cout << fun(n, dp); }
replace
65
66
65
66
TLE
p02555
C++
Runtime Error
// 177 #include <algorithm> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <numeric> #include <queue> #include <string> #include <vector> using namespace std; using ll = long long int; #define NUM 1000000007 int main() { int s; ll ans = 0; cin >> s; vector<vector<ll>> v(s - 2, vector<ll>(s - 1, 0)); for (int i = 0; i < v.size(); i++) { v.at(i).at(0) = 1; } for (int i = 1; i < v.size(); i++) { for (int j = 1; j < i + 1; j++) { v.at(i).at(j) = (v.at(i - 1).at(j - 1) + v.at(i - 1).at(j)) % NUM; } } for (int i = 1; s >= 3 * i; i++) { ans += v.at(s - i * 2 - 1).at(i - 1); ans %= NUM; } cout << ans << endl; return 0; }
// 177 #include <algorithm> #include <climits> #include <cmath> #include <iomanip> #include <iostream> #include <numeric> #include <queue> #include <string> #include <vector> using namespace std; using ll = long long int; #define NUM 1000000007 int main() { int s; ll ans = 0; cin >> s; vector<vector<ll>> v(s, vector<ll>(s + 1, 0)); for (int i = 0; i < v.size(); i++) { v.at(i).at(0) = 1; } for (int i = 1; i < v.size(); i++) { for (int j = 1; j < i + 1; j++) { v.at(i).at(j) = (v.at(i - 1).at(j - 1) + v.at(i - 1).at(j)) % NUM; } } for (int i = 1; s >= 3 * i; i++) { ans += v.at(s - i * 2 - 1).at(i - 1); ans %= NUM; } cout << ans << endl; return 0; }
replace
20
21
20
21
0
p02555
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MOD = 1000000007; int main() { ll s; cin >> s; ll dp[s + 1]; // oooo|ooooooo i番目の右に仕切り dp[0] = dp[1] = dp[2] = 0; // 数列なし dp[3] = dp[4] = dp[5] = 1; // 数列はひとつだけ(仕切りが右端) dp[6] = dp[3] + 1; // dp[7] = dp[4] + dp[3] = dp[4] + dp[6]; // dp[8] = dp[5] + dp[4] + dp[3] = dp[5] + dp[7]; // dp[n] = dp[n-3] + dp[n-1]; if (s >= 7) { for (int i = 7; i <= s; i++) { dp[i] = dp[i - 3] + dp[i - 1]; dp[i] %= MOD; } } cout << dp[s] << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const int MOD = 1000000007; int main() { ll s; cin >> s; ll dp[2001]; // oooo|ooooooo i番目の右に仕切り dp[0] = dp[1] = dp[2] = 0; // 数列なし dp[3] = dp[4] = dp[5] = 1; // 数列はひとつだけ(仕切りが右端) dp[6] = dp[3] + 1; // dp[7] = dp[4] + dp[3] = dp[4] + dp[6]; // dp[8] = dp[5] + dp[4] + dp[3] = dp[5] + dp[7]; // dp[n] = dp[n-3] + dp[n-1]; if (s >= 7) { for (int i = 7; i <= s; i++) { dp[i] = dp[i - 3] + dp[i - 1]; dp[i] %= MOD; } } cout << dp[s] << endl; }
replace
9
10
9
10
0
p02555
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pii; typedef tuple<ll, ll, ll> ti; #define REP(a, b, c) for (ll a = b; a < (c); a++) #define PER(a, b, c) for (ll a = b; a >= (c); a--) inline ll ii() { ll x; cin >> x; return x; } inline string is() { string x; cin >> x; return x; } inline ld id() { ld x; cin >> x; return x; } inline void oi(ll x) { cout << x; } inline void od(ld x) { cout << fixed << setprecision(10) << x; } inline void os(string x) { cout << x; } inline void oe() { cout << endl; } inline void oie(ll x) { oi(x); oe(); } inline void ode(ld x) { od(x); oe(); } inline void ose(string x) { os(x); oe(); } inline void maxin(ll &a, ll b) { a = max(a, b); } inline void minin(ll &a, ll b) { a = min(a, b); } ll m[1123][2123]; ll mod = 1e9 + 7; int main() { ll S = ii(); ll ret = 0; m[0][0] = 1; REP(i, 0, 667) { REP(k, 0, S) { if (m[i][k] == 0) continue; for (ll j = 3; k + j <= S; j++) { if (k + j == S) { ret += m[i][k]; ret %= mod; } else { m[i + 1][k + j] += m[i][k]; m[i + 1][k + j] %= mod; } } } } oie(ret); return 0; }
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ull; typedef long long ll; typedef long double ld; typedef pair<ll, ll> pii; typedef tuple<ll, ll, ll> ti; #define REP(a, b, c) for (ll a = b; a < (c); a++) #define PER(a, b, c) for (ll a = b; a >= (c); a--) inline ll ii() { ll x; cin >> x; return x; } inline string is() { string x; cin >> x; return x; } inline ld id() { ld x; cin >> x; return x; } inline void oi(ll x) { cout << x; } inline void od(ld x) { cout << fixed << setprecision(10) << x; } inline void os(string x) { cout << x; } inline void oe() { cout << endl; } inline void oie(ll x) { oi(x); oe(); } inline void ode(ld x) { od(x); oe(); } inline void ose(string x) { os(x); oe(); } inline void maxin(ll &a, ll b) { a = max(a, b); } inline void minin(ll &a, ll b) { a = min(a, b); } ll m[1123][2123]; ll mod = 1e9 + 7; int main() { ll S = ii(); ll ret = 0; m[0][0] = 1; REP(i, 0, 667) { ll s = 0; REP(k, 0, S - 3 + 1) { s += m[i][k]; if (k + 3 == S) { ret += s; ret %= mod; } else { m[i + 1][k + 3] += s; m[i + 1][k + 3] %= mod; } } } oie(ret); return 0; }
replace
53
64
53
62
TLE
p02555
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep_(i, n, m) for (int i = n; i < (int)(m); i++) #define all(v) v.begin(), v.end() #define int long long #define stoi stoll // #define _GLIBCXX_DEBUG const int mod = 1000000007; int a(vector<int> &dp, int S) { if (S <= 2) return 0; if (S <= 5) return 1; if (dp[S] >= 0) return dp[S]; int ans = 0; for (int i = 3; i < S; i++) { ans += a(dp, S - i); ans %= mod; } ans++; dp[S] = ans; return ans; } signed main() { int S; cin >> S; vector<int> dp(S + 1, -1); dp[3] = 1; dp[4] = 1; dp[5] = 1; cout << a(dp, S) << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep_(i, n, m) for (int i = n; i < (int)(m); i++) #define all(v) v.begin(), v.end() #define int long long #define stoi stoll // #define _GLIBCXX_DEBUG const int mod = 1000000007; int a(vector<int> &dp, int S) { if (S <= 2) return 0; if (S <= 5) return 1; if (dp[S] >= 0) return dp[S]; int ans = 0; for (int i = 3; i < S; i++) { ans += a(dp, S - i); ans %= mod; } ans++; dp[S] = ans; return ans; } signed main() { int S; cin >> S; vector<int> dp(S + 1, -1); if (S <= 2) { cout << 0 << endl; return 0; } if (S <= 5) { cout << 1 << endl; return 0; } dp[3] = 1; dp[4] = 1; dp[5] = 1; cout << a(dp, S) << endl; }
insert
33
33
33
42
0
p02555
Python
Runtime Error
S = int(input()) MOD = 10**9 + 7 A = [0] * (S + 1) A[0] = 1 A[1] = 0 A[2] = 0 cumsum = 1 for i in range(3, len(A)): A[i] = cumsum cumsum += A[i - 2] cumsum %= MOD print(A[-1])
S = int(input()) if S == 1: print(0) exit() MOD = 10**9 + 7 A = [0] * (S + 1) A[0] = 1 A[1] = 0 A[2] = 0 cumsum = 1 for i in range(3, len(A)): A[i] = cumsum cumsum += A[i - 2] cumsum %= MOD print(A[-1])
insert
1
1
1
4
0
p02555
C++
Runtime Error
#include <bits/stdc++.h> #include <iostream> using namespace std; #define ll long long int #define ld long double #define MAX 100005 #define MOD 1000000007 #define fast \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define pi 3.14159265358979323846 #define Q \ ll _; \ cin >> _; \ while (_--) #define endl "\n" #define flush fflush(stdout); int main() { fast ll i, j, n; cin >> n; ll dp[n + 1]; for (i = 0; i <= n; i++) { dp[i] = 0; } dp[0] = 1; dp[1] = 0; dp[2] = 0; dp[3] = 1; dp[4] = 1; dp[5] = 1; for (i = 6; i <= n; i++) { for (j = 0; j <= i - 3; j++) { dp[i] = (dp[j] % MOD) + (dp[i] % MOD); dp[i] = dp[i] % MOD; } } ll ans = dp[n] % MOD; cout << ans % MOD << endl; } // cout << fixed << setprecision(12);
#include <bits/stdc++.h> #include <iostream> using namespace std; #define ll long long int #define ld long double #define MAX 100005 #define MOD 1000000007 #define fast \ ios::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define pi 3.14159265358979323846 #define Q \ ll _; \ cin >> _; \ while (_--) #define endl "\n" #define flush fflush(stdout); int main() { fast ll i, j, n; cin >> n; ll dp[2001]; for (i = 0; i <= n; i++) { dp[i] = 0; } dp[0] = 1; dp[1] = 0; dp[2] = 0; dp[3] = 1; dp[4] = 1; dp[5] = 1; for (i = 6; i <= n; i++) { for (j = 0; j <= i - 3; j++) { dp[i] = (dp[j] % MOD) + (dp[i] % MOD); dp[i] = dp[i] % MOD; } } ll ans = dp[n] % MOD; cout << ans % MOD << endl; } // cout << fixed << setprecision(12);
replace
28
29
28
29
0
p02555
Python
Runtime Error
S = int(input()) if S < 3: print(0) exit() x = [0] * (S + 1) x[3] = x[4] = x[5] = 1 for i in range(6, S + 1): x[i] += 1 for j in range(3, i - 3 + 1): x[i] += x[i - j] print(x[S] % (10**9 + 7))
S = int(input()) if S < 3: print(0) exit() if S < 6: print(1) exit() x = [0] * (S + 1) x[3] = x[4] = x[5] = 1 for i in range(6, S + 1): x[i] += 1 for j in range(3, i - 3 + 1): x[i] += x[i - j] print(x[S] % (10**9 + 7))
insert
4
4
4
8
0
p02555
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long struct listnode { int val; listnode *next; }; vector<int> func(vector<int> a, vector<int> l, int sum) { vector<int> k, val; for (int i = 0; i < l.size(); i++) if (l[i] == 0) { k.push_back(i); val.push_back(a[i]); } if (sum < 0) return a; else { sort(val.rbegin(), val.rend()); for (int i = 0; i < k.size(); i++) a[k[i]] = val[i]; } return a; } int32_t main() { int m = 1000000007; int n; cin >> n; int dp[2001]; dp[0] = 1; dp[1] = 0; dp[2] = 0; dp[3] = 1; dp[4] = 1; dp[5] = 1; dp[6] = 2; dp[7] = 3; for (int i = 8; i <= n + 1; i++) dp[i] = (dp[i - 3] + dp[i - 1]) % m; cout << dp[n] % m << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long struct listnode { int val; listnode *next; }; vector<int> func(vector<int> a, vector<int> l, int sum) { vector<int> k, val; for (int i = 0; i < l.size(); i++) if (l[i] == 0) { k.push_back(i); val.push_back(a[i]); } if (sum < 0) return a; else { sort(val.rbegin(), val.rend()); for (int i = 0; i < k.size(); i++) a[k[i]] = val[i]; } return a; } int32_t main() { int m = 1000000007; int n; cin >> n; int dp[2001]; dp[0] = 1; dp[1] = 0; dp[2] = 0; dp[3] = 1; dp[4] = 1; dp[5] = 1; dp[6] = 2; dp[7] = 3; for (int i = 8; i < n + 1; i++) dp[i] = (dp[i - 3] + dp[i - 1]) % m; cout << dp[n] % m << endl; return 0; }
replace
39
40
39
40
0
p02555
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 1e5 + 10; const int mod = 1e9 + 7; ll c[2010][2010]; void init(int n) { for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { if (!j) c[i][j] = 1; else c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod; } } } int main() { ios::sync_with_stdio(false); cout.tie(0), cin.tie(0); int s; cin >> s; init(2005); ll ans = 0; for (int i = 1; i * 2 <= s; i++) { ans = (ans + c[s - 2 * i - 1][i - 1]) % mod; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MAXN = 1e5 + 10; const int mod = 1e9 + 7; ll c[2010][2010]; void init(int n) { for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { if (!j) c[i][j] = 1; else c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod; } } } int main() { ios::sync_with_stdio(false); cout.tie(0), cin.tie(0); int s; cin >> s; init(2005); ll ans = 0; for (int i = 1; i * 2 <= s - 1; i++) { ans = (ans + c[s - 2 * i - 1][i - 1]) % mod; } cout << ans << endl; return 0; }
replace
23
24
23
24
0
p02556
C++
Runtime Error
#include <stdio.h> int main(void) { static double p[100000][2]; double min[32], max[32]; int n; int i, j, k; double dat; double ans; scanf("%d", &n); for (i = 0; i < n; i++) { for (j = 0; j < 2; j++) { scanf("%lf", &p[i][j]); } } ans = 0; for (i = 0; i < 1 << 2; i++) { for (j = 0; j < n; j++) { dat = 0; for (k = 0; k < 2; k++) { if ((i >> k) & 1) { dat += p[j][k]; } else { dat -= p[j][k]; } } if (j == 0) { min[i] = max[i] = dat; } else { if (dat < min[i]) { min[i] = dat; } if (dat > max[i]) { max[i] = dat; } } } ans = ans > max[i] - min[i] ? ans : max[i] - min[i]; } printf("%.0f\n", ans); return (0); }
#include <stdio.h> int main(void) { static double p[220000][2]; double min[32], max[32]; int n; int i, j, k; double dat; double ans; scanf("%d", &n); for (i = 0; i < n; i++) { for (j = 0; j < 2; j++) { scanf("%lf", &p[i][j]); } } ans = 0; for (i = 0; i < 1 << 2; i++) { for (j = 0; j < n; j++) { dat = 0; for (k = 0; k < 2; k++) { if ((i >> k) & 1) { dat += p[j][k]; } else { dat -= p[j][k]; } } if (j == 0) { min[i] = max[i] = dat; } else { if (dat < min[i]) { min[i] = dat; } if (dat > max[i]) { max[i] = dat; } } } ans = ans > max[i] - min[i] ? ans : max[i] - min[i]; } printf("%.0f\n", ans); return (0); }
replace
3
4
3
4
0
p02556
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v1, v2; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; v1.push_back(x + y); v2.push_back(x - y); } sort(v1.begin(), v2.end()); sort(v2.begin(), v2.end()); cout << max(v1[n - 1] - v1[0], v2[n - 1] - v2[0]); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> v1, v2; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; v1.push_back(x + y); v2.push_back(x - y); } sort(v1.begin(), v1.end()); sort(v2.begin(), v2.end()); cout << max(v1[n - 1] - v1[0], v2[n - 1] - v2[0]); return 0; }
replace
12
13
12
13
-6
double free or corruption (out)
p02556
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; #define inf 1e200 typedef long long ll; ll a[100001][2]; ll n; ll GetManhattan(ll p[][2], ll n, ll dem) { ll ans = 0, Min, Max; ll i, j, k; for (i = 0; i < (1 << (dem)); i++) { // 用二进制形式遍历所有可能的运算情况 Min = inf, Max = -inf; for (j = 0; j < n; j++) { // 遍历每一个点 ll sum = 0; for (k = 0; k < 2; k++) { // 因为是五维的,所以有4个运算符 // 提取当前运算符 ll t = i & 1 << k; // 1为+,0为- if (t) sum += p[j][k]; else sum -= p[j][k]; } if (sum > Max) Max = sum; if (sum < Min) Min = sum; } if (Max - Min > ans) ans = Max - Min; } return ans; } #pragma warning(disable : 4996) int main() { scanf("%d", &n); { for (ll i = 0; i < n; i++) for (ll j = 0; j < 2; j++) scanf("%lld", &a[i][j]); ll ans = GetManhattan(a, n, 2); printf("%lld\n", ans); } return 0; }
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> using namespace std; #define inf 1e200 typedef long long ll; ll a[200003][2]; ll n; ll GetManhattan(ll p[][2], ll n, ll dem) { ll ans = 0, Min, Max; ll i, j, k; for (i = 0; i < (1 << (dem)); i++) { // 用二进制形式遍历所有可能的运算情况 Min = inf, Max = -inf; for (j = 0; j < n; j++) { // 遍历每一个点 ll sum = 0; for (k = 0; k < 2; k++) { // 因为是五维的,所以有4个运算符 // 提取当前运算符 ll t = i & 1 << k; // 1为+,0为- if (t) sum += p[j][k]; else sum -= p[j][k]; } if (sum > Max) Max = sum; if (sum < Min) Min = sum; } if (Max - Min > ans) ans = Max - Min; } return ans; } #pragma warning(disable : 4996) int main() { scanf("%d", &n); { for (ll i = 0; i < n; i++) for (ll j = 0; j < 2; j++) scanf("%lld", &a[i][j]); ll ans = GetManhattan(a, n, 2); printf("%lld\n", ans); } return 0; }
replace
7
8
7
8
0
p02556
C++
Runtime Error
#include <map> #include <math.h> #include <stdio.h> #include <string.h> #define N 60060 #define ll long long using namespace std; map<ll, int> mp[33]; typedef map<ll, int>::iterator iter; int seq[N][5]; int n, m; void del(int pos, int val) { iter t1 = mp[pos].find(val); t1->second--; if (t1->second == 0) mp[pos].erase(t1); return; } int mm; int myabs(int x) { return x < 0 ? -x : x; } ll get_ans() { ll res = 0; for (int i = 0; i < mm; i++) { iter l = mp[i].begin(); iter r = mp[i].end(); r--; ll tmp = myabs((l->first) - (r->first)); if (tmp > res) res = tmp; } return res; } void dfs(int deep, int val, int root, int pos, int id) { if (deep >= m) { if (id == 0) { mp[root][val]++; } else { del(root, val); } return; } dfs(deep + 1, val + seq[pos][deep], root * 2, pos, id); dfs(deep + 1, val - seq[pos][deep], root * 2 + 1, pos, id); return; } signed main() { scanf("%d", &n); m = 2; mm = 1 << m; for (int i = 0; i < mm; i++) mp[i].clear(); for (int i = 1; i <= n; i++) { for (int j = 0; j < m; j++) scanf("%d", &seq[i][j]); dfs(0, 0, 0, i, 0); // puts("d"); } printf("%lld\n", get_ans()); }
#include <map> #include <math.h> #include <stdio.h> #include <string.h> #define N 200060 #define ll long long using namespace std; map<ll, int> mp[33]; typedef map<ll, int>::iterator iter; int seq[N][5]; int n, m; void del(int pos, int val) { iter t1 = mp[pos].find(val); t1->second--; if (t1->second == 0) mp[pos].erase(t1); return; } int mm; int myabs(int x) { return x < 0 ? -x : x; } ll get_ans() { ll res = 0; for (int i = 0; i < mm; i++) { iter l = mp[i].begin(); iter r = mp[i].end(); r--; ll tmp = myabs((l->first) - (r->first)); if (tmp > res) res = tmp; } return res; } void dfs(int deep, int val, int root, int pos, int id) { if (deep >= m) { if (id == 0) { mp[root][val]++; } else { del(root, val); } return; } dfs(deep + 1, val + seq[pos][deep], root * 2, pos, id); dfs(deep + 1, val - seq[pos][deep], root * 2 + 1, pos, id); return; } signed main() { scanf("%d", &n); m = 2; mm = 1 << m; for (int i = 0; i < mm; i++) mp[i].clear(); for (int i = 1; i <= n; i++) { for (int j = 0; j < m; j++) scanf("%d", &seq[i][j]); dfs(0, 0, 0, i, 0); // puts("d"); } printf("%lld\n", get_ans()); }
replace
4
5
4
5
0
p02556
C++
Runtime Error
#include <bits/stdc++.h> /* #include <atcoder/all> using namespace atcoder; */ #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") // #include <boost/multiprecision/cpp_int.hpp> using namespace std; using dou = long double; string yes = "yes"; string Yes = "Yes"; string YES = "YES"; string no = "no"; string No = "No"; string NO = "NO"; 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; } typedef long long ll; typedef pair<int, int> P; typedef pair<ll, ll> PL; const ll mod = 1000000007ll; // const ll mod = 10000000000ll; // const ll mod = 10000; 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; } #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define brep(n) for (int bit = 0; bit < (1 << n); bit++) #define bbrep(n) for (int bbit = 0; bbit < (1 << n); bbit++) #define erep(i, container) for (auto &i : container) #define itrep(i, container) for (auto i : container) #define irep(i, n) for (ll i = n - 1; i >= (ll)0ll; i--) #define rrep(i, m, n) for (ll i = m; i < (ll)(n); i++) #define reprep(i, j, h, w) rep(i, h) rep(j, w) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define VEC(type, name, n) \ std::vector<type> name(n); \ rep(i, n) std::cin >> name[i]; #define pb push_back #define pf push_front #define query \ int qq; \ std::cin >> qq; \ rep(qqq, qq) #define lb lower_bound #define ub upper_bound #define fi first #define se second #define itn int #define mp make_pair // #define sum(a) accumulate(all(a),0ll) #define keta fixed << setprecision #define vout(a) \ erep(qxqxqx, a) std::cout << qxqxqx << ' '; \ std::cout << std::endl; #define vvector(name, typ, m, n, a) \ vector<vector<typ>> name(m, vector<typ>(n, a)) // #define vvector(name,typ,m,n)vector<vector<typ> > name(m,vector<typ> (n)) #define vvvector(name, t, l, m, n, a) \ vector<vector<vector<t>>> name(l, vector<vector<t>>(m, vector<t>(n, a))); #define vvvvector(name, t, k, l, m, n, a) \ vector<vector<vector<vector<t>>>> name( \ k, vector<vector<vector<t>>>(l, vector<vector<t>>(m, vector<t>(n, a)))); #define case std::cout << "Case #" << qqq + 1 << ":" #define RES(a, i, j) \ a.resize(i); \ rep(ii, i) a[ii].resize(j); #define RESRES(a, i, j, k) \ a.resize(i); \ rep(ii, i) a[ii].resize(j); \ reprep(ii, jj, i, j){dp[ii][jj].resize(k)}; #define res resize #define as assign #define ffor for (;;) #define ppri(a, b) std::cout << a << " " << b << std::endl #define pppri(a, b, c) std::cout << a << " " << b << " " << c << std::endl #define ppppri(a, b, c, d) \ std::cout << a << " " << b << " " << c << ' ' << d << std::endl #define aall(x, n) (x).begin(), (x).begin() + (n) #define SUM(a) accumulate(all(a), 0ll) #define stirng string #define gin(a, b) \ int a, b; \ std::cin >> a >> b; \ a--; \ b--; #define popcount __builtin_popcount #define permu(a) next_permutation(all(a)) // #define grid_input(a,type) int h,w;std::cin >> // h>>w;vvector(a,type,h,w,0);reprep(i,j,h,w)std::cin >> a[i][j]; // typedef long long T; ll ceil(ll a, ll b) { return ((a + b - 1) / b); } const int INF = 2000000000; // const ll INF64 =3223372036854775807ll; // const ll INF64 = 9223372036854775807ll; const ll INF64 = 243000000000001ll; ; ; const ll MOD = 1000000007ll; // const ll MOD = 1000003ll; const ll OD = 1000000000000007ll; const dou pi = 3.141592653589793; long long modpow(long long a, long long n) { // 累乗の余剰 long long res = 1; while (n > 0) { if (n & 1) res = res * a % MOD; a = a * a % MOD; n >>= 1; } return res; } // メモ // ゲーム(Grundy数とか)の復習をする // 群論の勉強をする? // ドツボにハマったら頑張って今までの思考をリセットする // 学会のスライドを作る(水曜日まで) // 周期性の実験をする // リスニング力をどうにかする // GT学会の会費を払う /* #include <atcoder/all> using namespace atcoder; */ /* #include <atcoder/all> using namespace atcoder; */ int main() { int n; std::cin >> n; // std::vector<ll> x(n),y(n); std::vector<ll> p(8); rep(i, n) { if (i % 2 == 1) p[i] = INF64; else p[i] = -INF64; } rep(i, n) { ll x, y; std::cin >> x >> y; chmax(p[0], x + y); chmin(p[1], x + y); chmax(p[2], x - y); chmin(p[3], x - y); chmax(p[4], -x + y); chmin(p[5], -x + y); chmax(p[6], -x - y); chmin(p[7], -x - y); } ll ans = 0; chmax(ans, p[0] - p[1]); chmax(ans, -p[2] + p[3]); chmax(ans, p[2] - p[3]); chmax(ans, -p[0] + p[1]); std::cout << ans << std::endl; }
#include <bits/stdc++.h> /* #include <atcoder/all> using namespace atcoder; */ #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") // #include <boost/multiprecision/cpp_int.hpp> using namespace std; using dou = long double; string yes = "yes"; string Yes = "Yes"; string YES = "YES"; string no = "no"; string No = "No"; string NO = "NO"; 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; } typedef long long ll; typedef pair<int, int> P; typedef pair<ll, ll> PL; const ll mod = 1000000007ll; // const ll mod = 10000000000ll; // const ll mod = 10000; 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; } #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define brep(n) for (int bit = 0; bit < (1 << n); bit++) #define bbrep(n) for (int bbit = 0; bbit < (1 << n); bbit++) #define erep(i, container) for (auto &i : container) #define itrep(i, container) for (auto i : container) #define irep(i, n) for (ll i = n - 1; i >= (ll)0ll; i--) #define rrep(i, m, n) for (ll i = m; i < (ll)(n); i++) #define reprep(i, j, h, w) rep(i, h) rep(j, w) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define VEC(type, name, n) \ std::vector<type> name(n); \ rep(i, n) std::cin >> name[i]; #define pb push_back #define pf push_front #define query \ int qq; \ std::cin >> qq; \ rep(qqq, qq) #define lb lower_bound #define ub upper_bound #define fi first #define se second #define itn int #define mp make_pair // #define sum(a) accumulate(all(a),0ll) #define keta fixed << setprecision #define vout(a) \ erep(qxqxqx, a) std::cout << qxqxqx << ' '; \ std::cout << std::endl; #define vvector(name, typ, m, n, a) \ vector<vector<typ>> name(m, vector<typ>(n, a)) // #define vvector(name,typ,m,n)vector<vector<typ> > name(m,vector<typ> (n)) #define vvvector(name, t, l, m, n, a) \ vector<vector<vector<t>>> name(l, vector<vector<t>>(m, vector<t>(n, a))); #define vvvvector(name, t, k, l, m, n, a) \ vector<vector<vector<vector<t>>>> name( \ k, vector<vector<vector<t>>>(l, vector<vector<t>>(m, vector<t>(n, a)))); #define case std::cout << "Case #" << qqq + 1 << ":" #define RES(a, i, j) \ a.resize(i); \ rep(ii, i) a[ii].resize(j); #define RESRES(a, i, j, k) \ a.resize(i); \ rep(ii, i) a[ii].resize(j); \ reprep(ii, jj, i, j){dp[ii][jj].resize(k)}; #define res resize #define as assign #define ffor for (;;) #define ppri(a, b) std::cout << a << " " << b << std::endl #define pppri(a, b, c) std::cout << a << " " << b << " " << c << std::endl #define ppppri(a, b, c, d) \ std::cout << a << " " << b << " " << c << ' ' << d << std::endl #define aall(x, n) (x).begin(), (x).begin() + (n) #define SUM(a) accumulate(all(a), 0ll) #define stirng string #define gin(a, b) \ int a, b; \ std::cin >> a >> b; \ a--; \ b--; #define popcount __builtin_popcount #define permu(a) next_permutation(all(a)) // #define grid_input(a,type) int h,w;std::cin >> // h>>w;vvector(a,type,h,w,0);reprep(i,j,h,w)std::cin >> a[i][j]; // typedef long long T; ll ceil(ll a, ll b) { return ((a + b - 1) / b); } const int INF = 2000000000; // const ll INF64 =3223372036854775807ll; // const ll INF64 = 9223372036854775807ll; const ll INF64 = 243000000000001ll; ; ; const ll MOD = 1000000007ll; // const ll MOD = 1000003ll; const ll OD = 1000000000000007ll; const dou pi = 3.141592653589793; long long modpow(long long a, long long n) { // 累乗の余剰 long long res = 1; while (n > 0) { if (n & 1) res = res * a % MOD; a = a * a % MOD; n >>= 1; } return res; } // メモ // ゲーム(Grundy数とか)の復習をする // 群論の勉強をする? // ドツボにハマったら頑張って今までの思考をリセットする // 学会のスライドを作る(水曜日まで) // 周期性の実験をする // リスニング力をどうにかする // GT学会の会費を払う /* #include <atcoder/all> using namespace atcoder; */ /* #include <atcoder/all> using namespace atcoder; */ int main() { int n; std::cin >> n; // std::vector<ll> x(n),y(n); std::vector<ll> p(8); rep(i, 8) { if (i % 2 == 1) p[i] = INF64; else p[i] = -INF64; } rep(i, n) { ll x, y; std::cin >> x >> y; chmax(p[0], x + y); chmin(p[1], x + y); chmax(p[2], x - y); chmin(p[3], x - y); chmax(p[4], -x + y); chmin(p[5], -x + y); chmax(p[6], -x - y); chmin(p[7], -x - y); } ll ans = 0; chmax(ans, p[0] - p[1]); chmax(ans, -p[2] + p[3]); chmax(ans, p[2] - p[3]); chmax(ans, -p[0] + p[1]); std::cout << ans << std::endl; }
replace
189
190
189
190
0
p02556
C++
Runtime Error
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; const int M = 2e4 + 5; int a[M], b[M]; int n, ans = 0; int main() { int i; scanf("%d", &n); for (i = 1; i <= n; i++) { int x, y; cin >> x >> y; a[i] = x + y; b[i] = y - x; } sort(a + 1, a + n + 1); sort(b + 1, b + n + 1); ans = max(a[n] - a[1], b[n] - b[1]); printf("%d\n", ans); return 0; }
#include <algorithm> #include <cstdio> #include <iostream> using namespace std; const int M = 2e5 + 5; int a[M], b[M]; int n, ans = 0; int main() { int i; scanf("%d", &n); for (i = 1; i <= n; i++) { int x, y; cin >> x >> y; a[i] = x + y; b[i] = y - x; } sort(a + 1, a + n + 1); sort(b + 1, b + n + 1); ans = max(a[n] - a[1], b[n] - b[1]); printf("%d\n", ans); return 0; }
replace
5
6
5
6
0
p02556
C++
Runtime Error
#include <bits/stdc++.h> #define in(x) freopen(x, "r", stdin) #define out(x) freopen(x, "w", stdout) using namespace std; const int N = (int)(1e5 + 500); int x[N], y[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef _LOCAL #endif // _LOCAL int n; int mx1, mx2, mx3, mx4; mx1 = mx2 = mx3 = mx4 = -2e9; cin >> n; for (int i = 0; i < n; ++i) { cin >> x[i] >> y[i]; mx1 = max(mx1, -x[i] - y[i]); mx2 = max(mx2, -x[i] + y[i]); mx3 = max(mx3, x[i] - y[i]); mx4 = max(mx4, x[i] + y[i]); } int ans = -2e9; for (int i = 0; i < n; ++i) { ans = max(ans, x[i] + y[i] + mx1); ans = max(ans, x[i] - y[i] + mx2); ans = max(ans, -x[i] + y[i] + mx3); ans = max(ans, -x[i] - y[i] + mx4); } cout << ans << "\n"; return 0; }
#include <bits/stdc++.h> #define in(x) freopen(x, "r", stdin) #define out(x) freopen(x, "w", stdout) using namespace std; const int N = (int)(2e5 + 500); int x[N], y[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifndef _LOCAL #endif // _LOCAL int n; int mx1, mx2, mx3, mx4; mx1 = mx2 = mx3 = mx4 = -2e9; cin >> n; for (int i = 0; i < n; ++i) { cin >> x[i] >> y[i]; mx1 = max(mx1, -x[i] - y[i]); mx2 = max(mx2, -x[i] + y[i]); mx3 = max(mx3, x[i] - y[i]); mx4 = max(mx4, x[i] + y[i]); } int ans = -2e9; for (int i = 0; i < n; ++i) { ans = max(ans, x[i] + y[i] + mx1); ans = max(ans, x[i] - y[i] + mx2); ans = max(ans, -x[i] + y[i] + mx3); ans = max(ans, -x[i] - y[i] + mx4); } cout << ans << "\n"; return 0; }
replace
5
6
5
6
0
p02556
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define re register #define ls (o << 1) #define rs (o << 1 | 1) #define pb push_back const double PI = acos(-1.0); const int M = 1e5 + 7; /* int head[M],cnt=1; void init(int n){cnt=1;for(int i=0;i<=n;i++)head[i]=0;} struct EDGE{int to,nxt,w;}ee[M*2]; void add(int x,int y,int w){ee[++cnt].nxt=head[x],ee[cnt].w=w,ee[cnt].to=y,head[x]=cnt;} */ int x[M], y[M]; int p[4][M]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> x[i] >> y[i]; p[0][i] = x[i] + y[i]; p[1][i] = -x[i] + y[i]; p[2][i] = x[i] - y[i]; p[3][i] = -x[i] - y[i]; } for (int i = 0; i < 4; i++) sort(p[i] + 1, p[i] + 1 + n); int mx = 0; for (int i = 0; i < 4; i++) { mx = max(mx, p[i][n] - p[i][1]); // cout<<i<<" "<<p[i][n]<<" "<<p[i][1]<<endl; } cout << mx << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define re register #define ls (o << 1) #define rs (o << 1 | 1) #define pb push_back const double PI = acos(-1.0); const int M = 2e5 + 7; /* int head[M],cnt=1; void init(int n){cnt=1;for(int i=0;i<=n;i++)head[i]=0;} struct EDGE{int to,nxt,w;}ee[M*2]; void add(int x,int y,int w){ee[++cnt].nxt=head[x],ee[cnt].w=w,ee[cnt].to=y,head[x]=cnt;} */ int x[M], y[M]; int p[4][M]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 1; i <= n; i++) { cin >> x[i] >> y[i]; p[0][i] = x[i] + y[i]; p[1][i] = -x[i] + y[i]; p[2][i] = x[i] - y[i]; p[3][i] = -x[i] - y[i]; } for (int i = 0; i < 4; i++) sort(p[i] + 1, p[i] + 1 + n); int mx = 0; for (int i = 0; i < 4; i++) { mx = max(mx, p[i][n] - p[i][1]); // cout<<i<<" "<<p[i][n]<<" "<<p[i][1]<<endl; } cout << mx << endl; return 0; }
replace
8
9
8
9
0
p02556
C++
Runtime Error
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; using namespace std; #define pb push_back #define mp make_pair #define mt make_tuple #define ff first #define ss second #define null 0 #define pi 3.14159265358979323846 #define all(x) x.begin(), x.end() #define d0(x) cout << x << " "; #define d1(x) cout << x << "\n"; #define d2(x, y) cout << x << " " << y << "\n"; #define d3(x, y, z) cout << x << " " << y << " " << z << "\n"; #define d4(x, y, z, w) cout << x << " " << y << " " << z << " " << w << "\n"; // #define ordered_set tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, // rb_tree_tag,tree_order_statistics_node_update> #define ordered_set tree<int, // null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> template <typename T, typename U> static inline void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> static inline void amax(T &x, U y) { if (y > x) x = y; } typedef long long int ll; typedef unsigned long long int ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const ll mod = 1000000007; const long long inf = (ll)1e18 + 17; const int inff = 1500000000; const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; ll tree[100010], aa[200010]; void build(int node, int start, int end) { if (start == end) { tree[node] = aa[start]; } else { int mid = (start + end) / 2; build(2 * node, start, mid); build(2 * node + 1, mid + 1, end); tree[node] = max(tree[2 * node], tree[2 * node + 1]); } } void update(int node, int start, int end, int idx, int val) { if (start == end) { aa[idx] = val; tree[node] = val; } else { int mid = (start + end) / 2; if (start <= idx and idx <= mid) { update(2 * node, start, mid, idx, val); } else { update(2 * node + 1, mid + 1, end, idx, val); } tree[node] = max(tree[2 * node], tree[2 * node + 1]); } } ll query(int node, int start, int end, int l, int r) { if (r < start or end < l) { return -1; } if (l <= start and end <= r) { return tree[node]; } int mid = (start + end) / 2; ll p1 = query(2 * node, start, mid, l, r); ll p2 = query(2 * node + 1, mid + 1, end, l, r); return max(p1, p2); } ll n; pair<pair<ll, ll>, ll> a[200010], b[200010]; int test_case = 0; void solve() { cin >> n; vector<pll> ok; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; ok.pb({x, y}); a[i] = {{x, y}, i}; b[i] = {{y, x}, i}; } int ai[n + 10], bi[n + 10]; sort(a, a + n); sort(b, b + n); for (int i = 0; i < n; i++) ai[a[i].ss] = i, bi[a[i].ss] = i; for (int i = 0; i < n; i++) aa[i] = a[i].ff.ff + a[i].ff.ss; build(1, 0, n - 1); ll ans = 0; for (int i = 0; i < n; i++) { int j = b[i].ss; j = ai[j]; ll op = query(1, 0, n - 1, j, n - 1); amax(ans, op - b[i].ff.ff - b[i].ff.ss); update(1, 0, n - 1, j, -1); } for (int i = 0; i < n; i++) { int x = ok[i].ff, y = ok[i].ss; y = 1000000001 - y; a[i] = {{x, y}, i}; b[i] = {{y, x}, i}; } sort(a, a + n); sort(b, b + n); for (int i = 0; i < n; i++) ai[a[i].ss] = i, bi[a[i].ss] = i; for (int i = 0; i < n; i++) aa[i] = a[i].ff.ff + a[i].ff.ss; build(1, 0, n - 1); for (int i = 0; i < n; i++) { int j = b[i].ss; j = ai[j]; ll op = query(1, 0, n - 1, j, n - 1); amax(ans, op - b[i].ff.ff - b[i].ff.ss); update(1, 0, n - 1, j, -1); } cout << ans << endl; } int main() { clock_t tt; tt = clock(); // ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int t = 1; if (test_case == 1) cin >> t; // pre(); for (int i = 1; i <= t; i++) { // cout<<"Case #"<<i<<": "; solve(); } tt = clock() - tt; double time_taken = ((double)tt) / CLOCKS_PER_SEC; // printf("code took %f seconds to execute \n", time_taken); return 0; } // ============== Notes =============== // // common bugs // - remove ios_base for interactive problems // - int overflow (especially intermediate expressionns) // - array bounds (indices bigger than MAXN?) // - special cases (n=1? graph not connected?) // - re-initialize efficiently between test cases
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; using namespace std; #define pb push_back #define mp make_pair #define mt make_tuple #define ff first #define ss second #define null 0 #define pi 3.14159265358979323846 #define all(x) x.begin(), x.end() #define d0(x) cout << x << " "; #define d1(x) cout << x << "\n"; #define d2(x, y) cout << x << " " << y << "\n"; #define d3(x, y, z) cout << x << " " << y << " " << z << "\n"; #define d4(x, y, z, w) cout << x << " " << y << " " << z << " " << w << "\n"; // #define ordered_set tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, // rb_tree_tag,tree_order_statistics_node_update> #define ordered_set tree<int, // null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> template <typename T, typename U> static inline void amin(T &x, U y) { if (y < x) x = y; } template <typename T, typename U> static inline void amax(T &x, U y) { if (y > x) x = y; } typedef long long int ll; typedef unsigned long long int ull; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const ll mod = 1000000007; const long long inf = (ll)1e18 + 17; const int inff = 1500000000; const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; ll tree[1000010], aa[200010]; void build(int node, int start, int end) { if (start == end) { tree[node] = aa[start]; } else { int mid = (start + end) / 2; build(2 * node, start, mid); build(2 * node + 1, mid + 1, end); tree[node] = max(tree[2 * node], tree[2 * node + 1]); } } void update(int node, int start, int end, int idx, int val) { if (start == end) { aa[idx] = val; tree[node] = val; } else { int mid = (start + end) / 2; if (start <= idx and idx <= mid) { update(2 * node, start, mid, idx, val); } else { update(2 * node + 1, mid + 1, end, idx, val); } tree[node] = max(tree[2 * node], tree[2 * node + 1]); } } ll query(int node, int start, int end, int l, int r) { if (r < start or end < l) { return -1; } if (l <= start and end <= r) { return tree[node]; } int mid = (start + end) / 2; ll p1 = query(2 * node, start, mid, l, r); ll p2 = query(2 * node + 1, mid + 1, end, l, r); return max(p1, p2); } ll n; pair<pair<ll, ll>, ll> a[200010], b[200010]; int test_case = 0; void solve() { cin >> n; vector<pll> ok; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; ok.pb({x, y}); a[i] = {{x, y}, i}; b[i] = {{y, x}, i}; } int ai[n + 10], bi[n + 10]; sort(a, a + n); sort(b, b + n); for (int i = 0; i < n; i++) ai[a[i].ss] = i, bi[a[i].ss] = i; for (int i = 0; i < n; i++) aa[i] = a[i].ff.ff + a[i].ff.ss; build(1, 0, n - 1); ll ans = 0; for (int i = 0; i < n; i++) { int j = b[i].ss; j = ai[j]; ll op = query(1, 0, n - 1, j, n - 1); amax(ans, op - b[i].ff.ff - b[i].ff.ss); update(1, 0, n - 1, j, -1); } for (int i = 0; i < n; i++) { int x = ok[i].ff, y = ok[i].ss; y = 1000000001 - y; a[i] = {{x, y}, i}; b[i] = {{y, x}, i}; } sort(a, a + n); sort(b, b + n); for (int i = 0; i < n; i++) ai[a[i].ss] = i, bi[a[i].ss] = i; for (int i = 0; i < n; i++) aa[i] = a[i].ff.ff + a[i].ff.ss; build(1, 0, n - 1); for (int i = 0; i < n; i++) { int j = b[i].ss; j = ai[j]; ll op = query(1, 0, n - 1, j, n - 1); amax(ans, op - b[i].ff.ff - b[i].ff.ss); update(1, 0, n - 1, j, -1); } cout << ans << endl; } int main() { clock_t tt; tt = clock(); // ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int t = 1; if (test_case == 1) cin >> t; // pre(); for (int i = 1; i <= t; i++) { // cout<<"Case #"<<i<<": "; solve(); } tt = clock() - tt; double time_taken = ((double)tt) / CLOCKS_PER_SEC; // printf("code took %f seconds to execute \n", time_taken); return 0; } // ============== Notes =============== // // common bugs // - remove ios_base for interactive problems // - int overflow (especially intermediate expressionns) // - array bounds (indices bigger than MAXN?) // - special cases (n=1? graph not connected?) // - re-initialize efficiently between test cases
replace
44
45
44
45
0
p02556
C++
Runtime Error
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; // mannhattan distance => 45 degree rotation // max( abs(x1-x2) + abs(y1-y2) ) // abs(x1-x2) = max( x1-x2, x2-x1) // => max( abs(x1-x2) + abs(y1-y2) ) = max( x1-x2+y1-y2, x1-x2+y2-y1, // x2-x1+y1-y2, x2-x1+y2-y1 ) X = x+y, Y = x-y max( abs(x1-x2) + abs(y1-y2) ) = // max( X1-X2, Y1-Y2, Y2-Y1, X2-X1 ) = max( abs(X1-X2), abs(Y1-Y2) ) // int main() { int N; cin >> N; vector<int> x45(N), y45(N); rep(i, N) { int x, y; cin >> x >> y; x45[i] = x + y; y45[i] = x - y; } sort(x45.begin(), x45.end()); sort(x45.begin(), y45.end()); cout << max(abs(x45[N - 1] - x45[0]), abs(y45[N - 1] - y45[0])); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<int, int>; // mannhattan distance => 45 degree rotation // max( abs(x1-x2) + abs(y1-y2) ) // abs(x1-x2) = max( x1-x2, x2-x1) // => max( abs(x1-x2) + abs(y1-y2) ) = max( x1-x2+y1-y2, x1-x2+y2-y1, // x2-x1+y1-y2, x2-x1+y2-y1 ) X = x+y, Y = x-y max( abs(x1-x2) + abs(y1-y2) ) = // max( X1-X2, Y1-Y2, Y2-Y1, X2-X1 ) = max( abs(X1-X2), abs(Y1-Y2) ) // int main() { int N; cin >> N; vector<int> x45(N), y45(N); rep(i, N) { int x, y; cin >> x >> y; x45[i] = x + y; y45[i] = x - y; } sort(x45.begin(), x45.end()); sort(y45.begin(), y45.end()); cout << max(abs(x45[N - 1] - x45[0]), abs(y45[N - 1] - y45[0])); return 0; }
replace
24
25
24
25
-6
double free or corruption (out)
p02556
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(ver, n) rep2(ver, 0, n) #define rep2(ver, m, n) for (int ver = m; ver < (n); ver++) #define loop while (true) #define dup(x, y) (((x) + (y)-1) / (y)) #define all(v) (v).begin(), (v).end() #define debug(x) std::cerr << #x << ": " << x << "\n" #define debug2(x, y) \ std::cerr << #x << ": " << x << ", " << #y << ": " << y << "\n" #define debug3(x, y, z) \ std::cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z \ << ": " << z << "\n" typedef long long ll; typedef pair<int, int> P; 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; } ll n, x[30000] = {}, y[300000] = {}, sum1[300000] = {}, sum2[300000] = {}; int main() { scanf("%d", &n); rep(i, n) { int tx, ty; scanf("%d %d", &tx, &ty); x[i] = tx; y[i] = ty; sum1[i] = tx + ty; sum2[i] = tx - ty; } sort(sum1, sum1 + n); sort(sum2, sum2 + n); cout << max(abs(sum1[n - 1] - sum1[0]), abs(sum2[n - 1] - sum2[0])); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(ver, n) rep2(ver, 0, n) #define rep2(ver, m, n) for (int ver = m; ver < (n); ver++) #define loop while (true) #define dup(x, y) (((x) + (y)-1) / (y)) #define all(v) (v).begin(), (v).end() #define debug(x) std::cerr << #x << ": " << x << "\n" #define debug2(x, y) \ std::cerr << #x << ": " << x << ", " << #y << ": " << y << "\n" #define debug3(x, y, z) \ std::cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z \ << ": " << z << "\n" typedef long long ll; typedef pair<int, int> P; 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; } ll n, x[300000] = {}, y[300000] = {}, sum1[300000] = {}, sum2[300000] = {}; int main() { scanf("%d", &n); rep(i, n) { int tx, ty; scanf("%d %d", &tx, &ty); x[i] = tx; y[i] = ty; sum1[i] = tx + ty; sum2[i] = tx - ty; } sort(sum1, sum1 + n); sort(sum2, sum2 + n); cout << max(abs(sum1[n - 1] - sum1[0]), abs(sum2[n - 1] - sum2[0])); return 0; }
replace
33
34
33
34
0
p02556
C++
Runtime Error
#include <algorithm> #include <complex> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <memory> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define REP(i, m, n) for (int i = int(m); i < int(n); i++) #define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i) #define EACH(i, c) for (auto &(i) : c) #define all(c) begin(c), end(c) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort(begin(c), end(c)) #define pb emplace_back #define MP make_pair #define SZ(a) int((a).size()) // #define int long long #ifdef LOCAL #define DEBUG(s) cout << (s) << endl #define dump(x) cerr << #x << " = " << (x) << endl #define BR cout << endl; #else #define DEBUG(s) \ do { \ } while (0) #define dump(x) \ do { \ } while (0) #define BR #endif using namespace std; using UI = unsigned int; using UL = unsigned long; using LL = long long; using ULL = unsigned long long; using VI = vector<int>; using VVI = vector<VI>; using VLL = vector<LL>; using VVLL = vector<VLL>; using VS = vector<string>; using PII = pair<int, int>; using VP = vector<PII>; 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; } // constexpr double EPS = 1e-10; // constexpr double PI = acos(-1.0); // constexpr int INF = INT_MAX; // constexpr int MOD = 1'000'000'007; // inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;} template <class T> inline T sqr(T x) { return x * x; } void solve() { int n; cin >> n; VP ps(n); REP(i, 0, n) { cin >> ps[i].first >> ps[i].second; } set<int> us, ds; REP(i, 0, n) { us.insert(ps[i].first + ps[i].second); ds.insert(ps[i].first - ps[i].second); } sort(all(ps), [](auto &l, auto &r) { return l.first < r.first; }); int ans = 0; REP(i, 0, n - 1) { int d = *us.rbegin() - ps[i].first - ps[i].second; // dump(d); chmax(d, *ds.rbegin() - ps[i].first + ps[i].second); chmax(ans, d); us.erase(ps[i].first + ps[i].second); ds.erase(ps[i].first - ps[i].second); } cout << ans << endl; } signed main() { solve(); return 0; }
#include <algorithm> #include <complex> #include <cstdio> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <memory> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define REP(i, m, n) for (int i = int(m); i < int(n); i++) #define RREP(i, m, n) for (int i = int(n) - 1; i >= int(m); --i) #define EACH(i, c) for (auto &(i) : c) #define all(c) begin(c), end(c) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort(begin(c), end(c)) #define pb emplace_back #define MP make_pair #define SZ(a) int((a).size()) // #define int long long #ifdef LOCAL #define DEBUG(s) cout << (s) << endl #define dump(x) cerr << #x << " = " << (x) << endl #define BR cout << endl; #else #define DEBUG(s) \ do { \ } while (0) #define dump(x) \ do { \ } while (0) #define BR #endif using namespace std; using UI = unsigned int; using UL = unsigned long; using LL = long long; using ULL = unsigned long long; using VI = vector<int>; using VVI = vector<VI>; using VLL = vector<LL>; using VVLL = vector<VLL>; using VS = vector<string>; using PII = pair<int, int>; using VP = vector<PII>; 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; } // constexpr double EPS = 1e-10; // constexpr double PI = acos(-1.0); // constexpr int INF = INT_MAX; // constexpr int MOD = 1'000'000'007; // inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;} template <class T> inline T sqr(T x) { return x * x; } void solve() { int n; cin >> n; VP ps(n); REP(i, 0, n) { cin >> ps[i].first >> ps[i].second; } set<int> us, ds; REP(i, 0, n) { us.insert(ps[i].first + ps[i].second); ds.insert(ps[i].first - ps[i].second); } sort(all(ps), [](auto &l, auto &r) { return l.first < r.first; }); int ans = 0; REP(i, 0, n - 1) { if (us.empty()) break; int d = *us.rbegin() - ps[i].first - ps[i].second; // dump(d); chmax(d, *ds.rbegin() - ps[i].first + ps[i].second); chmax(ans, d); us.erase(ps[i].first + ps[i].second); ds.erase(ps[i].first - ps[i].second); } cout << ans << endl; } signed main() { solve(); return 0; }
insert
90
90
90
92
0
p02556
C++
Runtime Error
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") #include <algorithm> #include <array> #include <bitset> #include <chrono> #include <cmath> #include <cstring> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <vector> #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define make_unique(x) \ sort(all((x))); \ (x).resize(unique(all((x))) - (x).begin()) typedef long long ll; typedef long double ld; using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ll N = 1e5 + 42; ll n, m; struct ppolls { pair<ll, ll> mns; pair<ll, ll> mxs; pair<ll, ll> mnd; pair<ll, ll> mxd; }; ppolls emp; ppolls comb(ppolls a, ppolls b) { ppolls res; res.mns = (a.mns.fi + a.mns.se < b.mns.fi + b.mns.se ? a.mns : b.mns); res.mxs = (a.mxs.fi + a.mxs.se > b.mxs.fi + b.mxs.se ? a.mxs : b.mxs); res.mnd = (a.mnd.fi - a.mnd.se < b.mnd.fi - b.mnd.se ? a.mnd : b.mnd); res.mxd = (a.mxd.fi - a.mxd.se > b.mxd.fi - b.mxd.se ? a.mxd : b.mxd); return res; } ppolls st[4 * N]; vector<pair<ll, ll>> a; void build(ll v, ll tl, ll tr) { if (tl == tr) { st[v].mns = a[tl]; st[v].mxs = a[tl]; st[v].mnd = a[tl]; st[v].mxd = a[tl]; return; } ll tm = ((tl + tr) >> 1); build((v << 1), tl, tm); build((v << 1) + 1, tm + 1, tr); st[v] = comb(st[(v << 1)], st[(v << 1) + 1]); } ppolls get(ll v, ll tl, ll tr, ll l, ll r) { if (l > r) { ppolls emp; emp.mns = mp(1e9 + 42, 1e9 + 42); emp.mxs = mp(-1e9 + 42, -1e9 + 42); emp.mnd = mp(1e9 + 42, 0); emp.mxd = mp(0, 1e9 + 42); return emp; } if (l == tl && r == tr) return st[v]; ll tm = ((tl + tr) >> 1); return comb(get((v << 1), tl, tm, l, min(r, tm)), get((v << 1) + 1, tm + 1, tr, max(l, tm + 1), r)); } void upd(ll v, ll tl, ll tr, ll pos, pair<ll, ll> new_v) { if (tl == tr) { st[v].mns = new_v; st[v].mxs = new_v; st[v].mnd = new_v; st[v].mxd = new_v; return; } ll tm = ((tl + tr) >> 1); if (pos <= tm) upd((v << 1), tl, tm, pos, new_v); else upd((v << 1) + 1, tm + 1, tr, pos, new_v); st[v] = comb(st[(v << 1)], st[(v << 1) + 1]); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; // yay a.resize(n); for (ll i = 0; i < n; i++) cin >> a[i].fi >> a[i].se; build(1, 0, n - 1); auto ans = st[1]; cout << max(ans.mxs.fi + ans.mxs.se - (ans.mns.fi + ans.mns.se), ans.mxd.fi - ans.mxd.se - (ans.mnd.fi - ans.mnd.se)) << endl; return 0; } /* */
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") #include <algorithm> #include <array> #include <bitset> #include <chrono> #include <cmath> #include <cstring> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <vector> #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define make_unique(x) \ sort(all((x))); \ (x).resize(unique(all((x))) - (x).begin()) typedef long long ll; typedef long double ld; using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const ll N = 2e5 + 42; ll n, m; struct ppolls { pair<ll, ll> mns; pair<ll, ll> mxs; pair<ll, ll> mnd; pair<ll, ll> mxd; }; ppolls emp; ppolls comb(ppolls a, ppolls b) { ppolls res; res.mns = (a.mns.fi + a.mns.se < b.mns.fi + b.mns.se ? a.mns : b.mns); res.mxs = (a.mxs.fi + a.mxs.se > b.mxs.fi + b.mxs.se ? a.mxs : b.mxs); res.mnd = (a.mnd.fi - a.mnd.se < b.mnd.fi - b.mnd.se ? a.mnd : b.mnd); res.mxd = (a.mxd.fi - a.mxd.se > b.mxd.fi - b.mxd.se ? a.mxd : b.mxd); return res; } ppolls st[4 * N]; vector<pair<ll, ll>> a; void build(ll v, ll tl, ll tr) { if (tl == tr) { st[v].mns = a[tl]; st[v].mxs = a[tl]; st[v].mnd = a[tl]; st[v].mxd = a[tl]; return; } ll tm = ((tl + tr) >> 1); build((v << 1), tl, tm); build((v << 1) + 1, tm + 1, tr); st[v] = comb(st[(v << 1)], st[(v << 1) + 1]); } ppolls get(ll v, ll tl, ll tr, ll l, ll r) { if (l > r) { ppolls emp; emp.mns = mp(1e9 + 42, 1e9 + 42); emp.mxs = mp(-1e9 + 42, -1e9 + 42); emp.mnd = mp(1e9 + 42, 0); emp.mxd = mp(0, 1e9 + 42); return emp; } if (l == tl && r == tr) return st[v]; ll tm = ((tl + tr) >> 1); return comb(get((v << 1), tl, tm, l, min(r, tm)), get((v << 1) + 1, tm + 1, tr, max(l, tm + 1), r)); } void upd(ll v, ll tl, ll tr, ll pos, pair<ll, ll> new_v) { if (tl == tr) { st[v].mns = new_v; st[v].mxs = new_v; st[v].mnd = new_v; st[v].mxd = new_v; return; } ll tm = ((tl + tr) >> 1); if (pos <= tm) upd((v << 1), tl, tm, pos, new_v); else upd((v << 1) + 1, tm + 1, tr, pos, new_v); st[v] = comb(st[(v << 1)], st[(v << 1) + 1]); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; // yay a.resize(n); for (ll i = 0; i < n; i++) cin >> a[i].fi >> a[i].se; build(1, 0, n - 1); auto ans = st[1]; cout << max(ans.mxs.fi + ans.mxs.se - (ans.mns.fi + ans.mns.se), ans.mxd.fi - ans.mxd.se - (ans.mnd.fi - ans.mnd.se)) << endl; return 0; } /* */
replace
32
33
32
33
0
p02556
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<string> vs; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef vector<vpii> vvpii; typedef vector<vpll> vvpll; typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ms; #define all(v) (v).begin(), (v).end() #define srt(v) sort(all(v)) #define pb push_back // #define mp make_pair #define fill (x, y) memset(x, y, sizeof(x)) #define clr(a) fill(a, 0) // #define endl '\n' #define PI 3.14159265358979323 const int Maxn = 2e5 + 3; const ll Mod = 1e9 + 7; #define trace1(x1) cerr << #x1 << ": " << x1 << endl; #define trace2(x1, x2) \ cerr << #x1 << ": " << x1 << " | " << #x2 << ": " << x2 << endl; #define trace3(x1, x2, x3) \ cerr << #x1 << ": " << x1 << " | " << #x2 << ": " << x2 << " | " << #x3 \ << ": " << x3 << endl; #define FAST_IO \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) const ll MOD = 1000000007LL; const ll MAX = 100010LL; template <typename T> T power(T x, T y, ll m = MOD) { T ans = 1; x %= m; while (y > 0) { if (y & 1ll) ans = (ans * x) % m; y >>= 1ll; x = (x * x) % m; } return ans % m; } // template<typename T, typename T1> // T mod(T x, T1 p) { // x %= p; // if (x < 0) // x += p; // return x; // } // ll inv[Maxn], ifact[Maxn], fact[Maxn]; // template<typename T> // T inverse(T x, T p) // { // x = mod(x, p); // if (x == 1) // return x; // return mod((1LL * (-p / x) * (inv[p % x] % p)) , p); // // Since inverse of p % x is already calculated. // } // ll NcR(ll n, ll r) // { // int ret = (1LL * ifact[n - r] * ifact[r]) % Mod ; // ret = (1LL * ret * fact[n]) % Mod; // return ret; // } // ll NpR(ll n, ll r) // { // int ret = (1LL * ifact[n - r]) % Mod ; // ret = (1LL * ret * fact[n]) % Mod; // return ret; // } void leastPrimeFactor(vector<int> &least_prime, int n) { least_prime[1] = 1; for (int i = 2; i <= n; i++) { if (least_prime[i] == 0) { least_prime[i] = i; for (int j = 2 * i; j <= n; j += i) if (least_prime[j] == 0) least_prime[j] = i; } } } // ifact[0] = 1; // for(ll i = 1; i < Maxn; i++) // { // inv[i] = inverse(i, Mod); // ifact[i] = (1LL * ifact[i - 1] * inv[i]) % Mod; // } // fact[0] = 1; // for(ll i = 1; i < Maxn; i++) // { // fact[i] = (1LL * fact[i - 1] * i) % Mod; // // cout << fact[i] << endl; // } // struct dat { // ll sum, pref, suff, ans; // }; // dat make_dat(ll val) { // dat res; // res.sum = val; // res.pref = res.suff = res.ans = val; // return res; // } // dat t[4*Maxn]; // dat combine(dat l, dat r) // { // dat res; // res.sum = l.sum + r.sum; // res.pref = max(l.pref, l.sum + r.pref); // res.suff = max(r.suff, r.sum + l.suff); // res.ans = max(max(l.ans, r.ans), l.suff + r.pref); // return res; // } // void build(vector<ll>& a, int v, int tl, int tr) // { // if (tl == tr) // t[v] = make_dat((ll)a[tl]); // else // { // int tm = (tl + tr) / 2; // build(a, v*2, tl, tm); // build(a, v*2+1, tm+1, tr); // t[v] = combine(t[v*2], t[v*2+1]); // } // } // void update(int v, int tl, int tr, int pos, ll new_val) // { // if (tl == tr) // t[v] = make_dat(new_val); // else // { // int tm = (tl + tr) / 2; // if (pos <= tm) // update(v*2, tl, tm, pos, new_val); // else // update(v*2+1, tm+1, tr, pos, new_val); // t[v] = combine(t[v*2], t[v*2+1]); // } // } // dat query(int v, int tl, int tr, int l, int r) // { // // cout << l << " " << r << " " << tl << " " << tr << endl; // if (l > r) // return make_dat(INT_MIN); // if (l == tl && r == tr) // return t[v]; // int tm = (tl + tr) / 2; // return combine(query(v*2, tl, tm, l, min(r, tm)), // query(v*2+1, tm+1, tr, max(l, tm+1), r)); // } // void push(ll v) // { // t[v*2] += lazy[v]; // lazy[v*2] += lazy[v]; // t[v*2+1] += lazy[v]; // lazy[v*2+1] += lazy[v]; // lazy[v] = 0; // } // void update(int v, int tl, int tr, int l, int r, ll addend) // { // if (l > r) // return; // if (l == tl && tr == r) // { // t[v] += addend; // lazy[v] += addend; // } // else // { // push(v); // int tm = (tl + tr) / 2; // update(v*2, tl, tm, l, min(r, tm), addend); // update(v*2+1, tm+1, tr, max(l, tm+1), r, addend); // t[v] = combine(t[v*2], t[v*2+1]); // } // } // ll query(int v, int tl, int tr, int l, int r) // { // // cout << l << " " << r << " " << tl << " " << tr << endl; // if (l > r) // return make_dat(0); // if (l <= tl && r >= tr) // return t[v]; // push(v); // int tm = (tl + tr) / 2; // return combine(query(v*2, tl, tm, l, min(r, tm)), // query(v*2+1, tm+1, tr, max(l, tm+1), r)); // } int main() { FAST_IO; // int nt; // cin >> nt; // // vvi dir = {{-1,0},{1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,-1},{-1,1}}; // for(int ze = 0 ; ze < nt ; ze++) // { int n; cin >> n; vpll a; set<pll> s; ll x, y; for (int i = 0; i < n; i++) { cin >> x >> y; if (s.find({x, y}) == s.end()) s.insert({x, y}), a.pb({x, y}); } ll max1 = 0, max2 = 0, min1 = LLONG_MAX, min2 = LLONG_MAX; for (int i = 0; i < n; i++) { max1 = max(max1, a[i].first + a[i].second); max2 = max(max2, a[i].first - a[i].second); min1 = min(min1, a[i].first + a[i].second); min2 = min(min2, a[i].first - a[i].second); } cout << max(abs(max1 - min1), abs(max2 - min2)) << endl; // } }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef long long int ll; typedef unsigned long long int ull; typedef long double ld; typedef vector<int> vi; typedef vector<ll> vll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<string> vs; typedef vector<vi> vvi; typedef vector<vll> vvll; typedef vector<vpii> vvpii; typedef vector<vpll> vvpll; typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ms; #define all(v) (v).begin(), (v).end() #define srt(v) sort(all(v)) #define pb push_back // #define mp make_pair #define fill (x, y) memset(x, y, sizeof(x)) #define clr(a) fill(a, 0) // #define endl '\n' #define PI 3.14159265358979323 const int Maxn = 2e5 + 3; const ll Mod = 1e9 + 7; #define trace1(x1) cerr << #x1 << ": " << x1 << endl; #define trace2(x1, x2) \ cerr << #x1 << ": " << x1 << " | " << #x2 << ": " << x2 << endl; #define trace3(x1, x2, x3) \ cerr << #x1 << ": " << x1 << " | " << #x2 << ": " << x2 << " | " << #x3 \ << ": " << x3 << endl; #define FAST_IO \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) const ll MOD = 1000000007LL; const ll MAX = 100010LL; template <typename T> T power(T x, T y, ll m = MOD) { T ans = 1; x %= m; while (y > 0) { if (y & 1ll) ans = (ans * x) % m; y >>= 1ll; x = (x * x) % m; } return ans % m; } // template<typename T, typename T1> // T mod(T x, T1 p) { // x %= p; // if (x < 0) // x += p; // return x; // } // ll inv[Maxn], ifact[Maxn], fact[Maxn]; // template<typename T> // T inverse(T x, T p) // { // x = mod(x, p); // if (x == 1) // return x; // return mod((1LL * (-p / x) * (inv[p % x] % p)) , p); // // Since inverse of p % x is already calculated. // } // ll NcR(ll n, ll r) // { // int ret = (1LL * ifact[n - r] * ifact[r]) % Mod ; // ret = (1LL * ret * fact[n]) % Mod; // return ret; // } // ll NpR(ll n, ll r) // { // int ret = (1LL * ifact[n - r]) % Mod ; // ret = (1LL * ret * fact[n]) % Mod; // return ret; // } void leastPrimeFactor(vector<int> &least_prime, int n) { least_prime[1] = 1; for (int i = 2; i <= n; i++) { if (least_prime[i] == 0) { least_prime[i] = i; for (int j = 2 * i; j <= n; j += i) if (least_prime[j] == 0) least_prime[j] = i; } } } // ifact[0] = 1; // for(ll i = 1; i < Maxn; i++) // { // inv[i] = inverse(i, Mod); // ifact[i] = (1LL * ifact[i - 1] * inv[i]) % Mod; // } // fact[0] = 1; // for(ll i = 1; i < Maxn; i++) // { // fact[i] = (1LL * fact[i - 1] * i) % Mod; // // cout << fact[i] << endl; // } // struct dat { // ll sum, pref, suff, ans; // }; // dat make_dat(ll val) { // dat res; // res.sum = val; // res.pref = res.suff = res.ans = val; // return res; // } // dat t[4*Maxn]; // dat combine(dat l, dat r) // { // dat res; // res.sum = l.sum + r.sum; // res.pref = max(l.pref, l.sum + r.pref); // res.suff = max(r.suff, r.sum + l.suff); // res.ans = max(max(l.ans, r.ans), l.suff + r.pref); // return res; // } // void build(vector<ll>& a, int v, int tl, int tr) // { // if (tl == tr) // t[v] = make_dat((ll)a[tl]); // else // { // int tm = (tl + tr) / 2; // build(a, v*2, tl, tm); // build(a, v*2+1, tm+1, tr); // t[v] = combine(t[v*2], t[v*2+1]); // } // } // void update(int v, int tl, int tr, int pos, ll new_val) // { // if (tl == tr) // t[v] = make_dat(new_val); // else // { // int tm = (tl + tr) / 2; // if (pos <= tm) // update(v*2, tl, tm, pos, new_val); // else // update(v*2+1, tm+1, tr, pos, new_val); // t[v] = combine(t[v*2], t[v*2+1]); // } // } // dat query(int v, int tl, int tr, int l, int r) // { // // cout << l << " " << r << " " << tl << " " << tr << endl; // if (l > r) // return make_dat(INT_MIN); // if (l == tl && r == tr) // return t[v]; // int tm = (tl + tr) / 2; // return combine(query(v*2, tl, tm, l, min(r, tm)), // query(v*2+1, tm+1, tr, max(l, tm+1), r)); // } // void push(ll v) // { // t[v*2] += lazy[v]; // lazy[v*2] += lazy[v]; // t[v*2+1] += lazy[v]; // lazy[v*2+1] += lazy[v]; // lazy[v] = 0; // } // void update(int v, int tl, int tr, int l, int r, ll addend) // { // if (l > r) // return; // if (l == tl && tr == r) // { // t[v] += addend; // lazy[v] += addend; // } // else // { // push(v); // int tm = (tl + tr) / 2; // update(v*2, tl, tm, l, min(r, tm), addend); // update(v*2+1, tm+1, tr, max(l, tm+1), r, addend); // t[v] = combine(t[v*2], t[v*2+1]); // } // } // ll query(int v, int tl, int tr, int l, int r) // { // // cout << l << " " << r << " " << tl << " " << tr << endl; // if (l > r) // return make_dat(0); // if (l <= tl && r >= tr) // return t[v]; // push(v); // int tm = (tl + tr) / 2; // return combine(query(v*2, tl, tm, l, min(r, tm)), // query(v*2+1, tm+1, tr, max(l, tm+1), r)); // } int main() { FAST_IO; // int nt; // cin >> nt; // // vvi dir = {{-1,0},{1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,-1},{-1,1}}; // for(int ze = 0 ; ze < nt ; ze++) // { int n; cin >> n; vpll a; set<pll> s; ll x, y; for (int i = 0; i < n; i++) { cin >> x >> y; a.pb({x, y}); } ll max1 = a[0].first + a[0].second, max2 = a[0].first - a[0].second, min1 = a[0].first + a[0].second, min2 = a[0].first - a[0].second; for (int i = 0; i < n; i++) { max1 = max(max1, a[i].first + a[i].second); max2 = max(max2, a[i].first - a[i].second); min1 = min(min1, a[i].first + a[i].second); min2 = min(min2, a[i].first - a[i].second); } cout << max(abs(max1 - min1), abs(max2 - min2)) << endl; // } }
replace
246
250
246
250
0
p02556
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using vl = vector<ll>; template <class T> using vc = vector<T>; template <class T> using vvc = vector<vector<T>>; #define eb emplace_back #define all(x) (x).begin(), (x).end() #define rep(i, n) for (ll i = 0; i < (n); i++) #define repr(i, n) for (ll i = (n)-1; i >= 0; i--) #define repe(i, l, r) for (ll i = (l); i < (r); i++) #define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--) #define repa(i, n) for (auto &i : n) template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } struct init { init() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } init_; #ifdef DEBUG template <class T, class N> void verr(const T &a, const N &n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; } ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; } template <class H, class... T> void err(H &&h, T &&...t) { cerr << h << (sizeof...(t) ? " " : "\n") << flush; if (sizeof...(t) > 0) err(forward<T>(t)...); } #endif const ll INF = 4e18; const ld EPS = 1e-11; const ld PI = acos(-1.0L); const ll MOD = 1e9 + 7; // const ll MOD = 998244353; //--------------------------------------------------------------------------------// struct p { ll x, y; p() {} p(ll x, ll y) : x(x), y(y) {} }; ll dist(p a, p b) { return max(abs(a.x - b.x), abs(a.y - b.y)); } int main() { ll N; cin >> N; vc<p> P(N); rep(i, N) cin >> P[i].x >> P[i].y; vc<p> Q(N); rep(i, N) Q[i].x = P[i].x - P[i].y, Q[i].y = P[i].x + P[i].y; ll ans = 0; sort(all(Q), [](p a, p b) { return a.x < a.y; }); p xmin = Q.front(), xmax = Q.back(); chmax(ans, dist(xmax, xmin)); sort(all(Q), [](p a, p b) { return a.y < b.y; }); p ymin = Q.front(), ymax = Q.back(); chmax(ans, dist(ymax, ymin)); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using vl = vector<ll>; template <class T> using vc = vector<T>; template <class T> using vvc = vector<vector<T>>; #define eb emplace_back #define all(x) (x).begin(), (x).end() #define rep(i, n) for (ll i = 0; i < (n); i++) #define repr(i, n) for (ll i = (n)-1; i >= 0; i--) #define repe(i, l, r) for (ll i = (l); i < (r); i++) #define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--) #define repa(i, n) for (auto &i : n) template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } struct init { init() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } init_; #ifdef DEBUG template <class T, class N> void verr(const T &a, const N &n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; } ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; } template <class H, class... T> void err(H &&h, T &&...t) { cerr << h << (sizeof...(t) ? " " : "\n") << flush; if (sizeof...(t) > 0) err(forward<T>(t)...); } #endif const ll INF = 4e18; const ld EPS = 1e-11; const ld PI = acos(-1.0L); const ll MOD = 1e9 + 7; // const ll MOD = 998244353; //--------------------------------------------------------------------------------// struct p { ll x, y; p() {} p(ll x, ll y) : x(x), y(y) {} }; ll dist(p a, p b) { return max(abs(a.x - b.x), abs(a.y - b.y)); } int main() { ll N; cin >> N; vc<p> P(N); rep(i, N) cin >> P[i].x >> P[i].y; vc<p> Q(N); rep(i, N) Q[i].x = P[i].x - P[i].y, Q[i].y = P[i].x + P[i].y; ll ans = 0; sort(all(Q), [](p a, p b) { return a.x < b.x; }); p xmin = Q.front(), xmax = Q.back(); chmax(ans, dist(xmax, xmin)); sort(all(Q), [](p a, p b) { return a.y < b.y; }); p ymin = Q.front(), ymax = Q.back(); chmax(ans, dist(ymax, ymin)); cout << ans << endl; }
replace
77
78
77
78
TLE
p02556
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int maxn = 100000 + 10; const int dem = 2; const long long INF = 1e18; struct Point { long long x[dem]; } p[maxn]; int n; long long minx[1 << dem], maxx[1 << dem]; long long solve() { int tmp = (1 << dem); for (int i = 0; i < tmp; i++) { minx[i] = INF; maxx[i] = -INF; } for (int i = 0; i < n; i++) { for (int j = 0; j < tmp; j++) { int t = j; long long s = 0; for (int k = 0; k < dem; k++) { if (t & 1) s += p[i].x[k]; else s -= p[i].x[k]; t >>= 1; } if (maxx[j] < s) maxx[j] = s; if (minx[j] > s) minx[j] = s; } } long long ans = -INF; for (int i = 0; i < tmp; i++) { if (maxx[i] - minx[i] > ans) ans = maxx[i] - minx[i]; } return ans; } int main() { while (scanf("%d", &n) != EOF) { for (int i = 0; i < n; i++) { for (int j = 0; j < dem; j++) { scanf("%lld", &p[i].x[j]); } } printf("%lld\n", solve()); return 0; } }
#include <bits/stdc++.h> using namespace std; const int maxn = 200000 + 10; const int dem = 2; const long long INF = 1e18; struct Point { long long x[dem]; } p[maxn]; int n; long long minx[1 << dem], maxx[1 << dem]; long long solve() { int tmp = (1 << dem); for (int i = 0; i < tmp; i++) { minx[i] = INF; maxx[i] = -INF; } for (int i = 0; i < n; i++) { for (int j = 0; j < tmp; j++) { int t = j; long long s = 0; for (int k = 0; k < dem; k++) { if (t & 1) s += p[i].x[k]; else s -= p[i].x[k]; t >>= 1; } if (maxx[j] < s) maxx[j] = s; if (minx[j] > s) minx[j] = s; } } long long ans = -INF; for (int i = 0; i < tmp; i++) { if (maxx[i] - minx[i] > ans) ans = maxx[i] - minx[i]; } return ans; } int main() { while (scanf("%d", &n) != EOF) { for (int i = 0; i < n; i++) { for (int j = 0; j < dem; j++) { scanf("%lld", &p[i].x[j]); } } printf("%lld\n", solve()); return 0; } }
replace
2
3
2
3
0
p02556
C++
Runtime Error
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = 1e5 + 100; struct Node { ll x, y; ll num1, num2; } p[N]; ll n; bool cmp1(const Node &a, const Node &b) { return a.num1 < b.num1; } bool cmp2(const Node &a, const Node &b) { return a.num2 < b.num2; } int main() { cin >> n; for (ll i = 1; i <= n; i++) { cin >> p[i].x >> p[i].y; p[i].num1 = p[i].x - p[i].y; p[i].num2 = p[i].x + p[i].y; } ll ans = 0; sort(p + 1, p + n + 1, cmp1); ans = max(ans, p[n].num1 - p[1].num1); sort(p + 1, p + n + 1, cmp2); ans = max(ans, p[n].num2 - p[1].num2); cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = 2e5 + 100; struct Node { ll x, y; ll num1, num2; } p[N]; ll n; bool cmp1(const Node &a, const Node &b) { return a.num1 < b.num1; } bool cmp2(const Node &a, const Node &b) { return a.num2 < b.num2; } int main() { cin >> n; for (ll i = 1; i <= n; i++) { cin >> p[i].x >> p[i].y; p[i].num1 = p[i].x - p[i].y; p[i].num2 = p[i].x + p[i].y; } ll ans = 0; sort(p + 1, p + n + 1, cmp1); ans = max(ans, p[n].num1 - p[1].num1); sort(p + 1, p + n + 1, cmp2); ans = max(ans, p[n].num2 - p[1].num2); cout << ans << endl; return 0; }
replace
3
4
3
4
0
p02556
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define deb(x) cout << "> " << #x << " : " << x << endl; #define deb2(x, y) \ cout << "> " << #x << "->" << x << " " << #y << "->" << y << endl; #define LINE cout << "--- LINE NO : " << __LINE__ << " ---" << endl; #define pnr(a) \ for (auto x : a) { \ cout << x << " "; \ } \ cout << endl; #define pnr2(a) \ for (auto x : a) { \ cout << x.first << " " << x.second << endl; \ } #define pi 2 * acos(0.0) #define inf (int)1e18 const int mod = 1e9 + 7, mxn = 2e5 + 5; #define vt vector #define ff first #define ss second #define int long long #define db long double #define pii pair<int, int> #define Maxpq(x) priority_queue<x> #define Minpq(x) priority_queue<x, vt<x>, greater<x>> #define pb push_back #define si(x) (int)x.size() #define all(x) x.begin(), x.end() #define mem(a, x) memset(a, x, sizeof(a)) #define rep(n) for (int i = 0; i < n; i++) #define forr(i, n) for (int i = 0; i < n; i++) #define FOR(a) for (auto &x : a) int mainx() { int n; cin >> n; int sum[n], sub[n], a, b; for (int i = 0; i < n; i++) { cin >> a >> b; sum[i] = a + b; sub[i] = a - b; } sort(sum, sum + n); sort(sub, sub + n); cout << max(abs(sum[0] - sum[n - 1]), abs(sub[n - 1] - sub[0])) << endl; } bool cmp(pii &a, pii &b) { if (a.ff < b.ff) return true; if (a.ff == b.ff) return a.ss < b.ss; return false; } inline void INCLUDE() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); // freopen("out.txt","w",stdout); #endif } int32_t main() { // INCLUDE(); ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); // cout << fixed << setprecision(20); int tt = 1; // cin>>tt; for (int t = 1; t <= tt; t++) { // cout<<"Case #"<<t<<": "; mainx(); } return 0; }
#include <bits/stdc++.h> using namespace std; #define deb(x) cout << "> " << #x << " : " << x << endl; #define deb2(x, y) \ cout << "> " << #x << "->" << x << " " << #y << "->" << y << endl; #define LINE cout << "--- LINE NO : " << __LINE__ << " ---" << endl; #define pnr(a) \ for (auto x : a) { \ cout << x << " "; \ } \ cout << endl; #define pnr2(a) \ for (auto x : a) { \ cout << x.first << " " << x.second << endl; \ } #define pi 2 * acos(0.0) #define inf (int)1e18 const int mod = 1e9 + 7, mxn = 2e5 + 5; #define vt vector #define ff first #define ss second #define int long long #define db long double #define pii pair<int, int> #define Maxpq(x) priority_queue<x> #define Minpq(x) priority_queue<x, vt<x>, greater<x>> #define pb push_back #define si(x) (int)x.size() #define all(x) x.begin(), x.end() #define mem(a, x) memset(a, x, sizeof(a)) #define rep(n) for (int i = 0; i < n; i++) #define forr(i, n) for (int i = 0; i < n; i++) #define FOR(a) for (auto &x : a) int mainx() { int n; cin >> n; int sum[n], sub[n], a, b; for (int i = 0; i < n; i++) { cin >> a >> b; sum[i] = a + b; sub[i] = a - b; } sort(sum, sum + n); sort(sub, sub + n); cout << max(abs(sum[0] - sum[n - 1]), abs(sub[n - 1] - sub[0])) << endl; return 0; } bool cmp(pii &a, pii &b) { if (a.ff < b.ff) return true; if (a.ff == b.ff) return a.ss < b.ss; return false; } inline void INCLUDE() { #ifndef ONLINE_JUDGE freopen("in.txt", "r", stdin); // freopen("out.txt","w",stdout); #endif } int32_t main() { // INCLUDE(); ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); // cout << fixed << setprecision(20); int tt = 1; // cin>>tt; for (int t = 1; t <= tt; t++) { // cout<<"Case #"<<t<<": "; mainx(); } return 0; }
insert
49
49
49
50
0
p02556
C++
Runtime Error
#include "bits/stdc++.h" using namespace std; #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(0); #define pb push_back #define eb emplace_back #define ins insert #define f first #define s second #define cbr cerr << "hi\n" #define mmst(x, v) memset((x), v, sizeof((x))) #define siz(x) ll(x.size()) #define all(x) (x).begin(), (x).end() #define lbd(x, y) (lower_bound(all(x), y) - x.begin()) #define ubd(x, y) (upper_bound(all(x), y) - x.begin()) mt19937 rng(chrono::steady_clock::now() .time_since_epoch() .count()); // can be used by calling rng() or shuffle(A, A+n, rng) inline long long rand(long long x, long long y) { return rng() % (y + 1 - x) + x; } // inclusivesss string inline to_string(char c) { string s(1, c); return s; } template <typename T> inline T gcd(T a, T b) { return a == 0 ? llabs(b) : gcd(b % a, a); } using ll = long long; using ld = long double; #define FOR(i, s, e) for (ll i = s; i <= ll(e); ++i) #define DEC(i, s, e) for (ll i = s; i >= ll(e); --i) using pi = pair<ll, ll>; using spi = pair<ll, pi>; using dpi = pair<pi, pi>; #define LLINF ((long long)1e18) #define INF int(1e9 + 1e6) #define MAXN (200006) ll n, ans, tmp; pi A[MAXN]; multiset<pi> h, l; ll dist(ll x, ll y) { return abs(A[x].f - A[y].f) + abs(A[x].s - A[y].s); } int main() { FAST cin >> n; FOR(i, 1, n) cin >> A[i].f >> A[i].s; tmp = -LLINF; FOR(i, 1, n) tmp = max(tmp, A[i].s); ans = tmp, tmp = LLINF; FOR(i, 1, n) tmp = min(tmp, A[i].s); ans -= tmp; sort(A + 1, A + n + 1); FOR(i, 1, n) { auto tmp = h.lower_bound(pi(A[i].s, 0)); if (tmp != h.end()) ans = max(ans, dist(tmp->s, i)); tmp = l.upper_bound(pi(A[i].s, LLINF)); if (tmp != l.begin()) --tmp, ans = max(ans, dist(tmp->s, i)); if (h.empty() || (--h.end())->f < A[i].s) { while (h.size()) { auto tmp = (--h.end())->s; if (A[i].s - A[tmp].s < A[i].f - A[tmp].f) break; h.erase(--h.end()); } h.ins(pi(A[i].s, i)); } if (l.empty() || l.begin()->f > A[i].s) { while (l.size()) { auto tmp = l.begin()->f; if (A[tmp].s - A[i].s < A[i].f - A[tmp].f) break; l.erase(l.begin()); } l.ins(pi(A[i].s, i)); } } cout << ans << '\n'; }
#include "bits/stdc++.h" using namespace std; #define FAST \ ios_base::sync_with_stdio(false); \ cin.tie(0); #define pb push_back #define eb emplace_back #define ins insert #define f first #define s second #define cbr cerr << "hi\n" #define mmst(x, v) memset((x), v, sizeof((x))) #define siz(x) ll(x.size()) #define all(x) (x).begin(), (x).end() #define lbd(x, y) (lower_bound(all(x), y) - x.begin()) #define ubd(x, y) (upper_bound(all(x), y) - x.begin()) mt19937 rng(chrono::steady_clock::now() .time_since_epoch() .count()); // can be used by calling rng() or shuffle(A, A+n, rng) inline long long rand(long long x, long long y) { return rng() % (y + 1 - x) + x; } // inclusivesss string inline to_string(char c) { string s(1, c); return s; } template <typename T> inline T gcd(T a, T b) { return a == 0 ? llabs(b) : gcd(b % a, a); } using ll = long long; using ld = long double; #define FOR(i, s, e) for (ll i = s; i <= ll(e); ++i) #define DEC(i, s, e) for (ll i = s; i >= ll(e); --i) using pi = pair<ll, ll>; using spi = pair<ll, pi>; using dpi = pair<pi, pi>; #define LLINF ((long long)1e18) #define INF int(1e9 + 1e6) #define MAXN (200006) ll n, ans, tmp; pi A[MAXN]; multiset<pi> h, l; ll dist(ll x, ll y) { return abs(A[x].f - A[y].f) + abs(A[x].s - A[y].s); } int main() { FAST cin >> n; FOR(i, 1, n) cin >> A[i].f >> A[i].s; tmp = -LLINF; FOR(i, 1, n) tmp = max(tmp, A[i].s); ans = tmp, tmp = LLINF; FOR(i, 1, n) tmp = min(tmp, A[i].s); ans -= tmp; sort(A + 1, A + n + 1); FOR(i, 1, n) { auto tmp = h.lower_bound(pi(A[i].s, 0)); if (tmp != h.end()) ans = max(ans, dist(tmp->s, i)); tmp = l.upper_bound(pi(A[i].s, LLINF)); if (tmp != l.begin()) --tmp, ans = max(ans, dist(tmp->s, i)); if (h.empty() || (--h.end())->f < A[i].s) { while (h.size()) { auto tmp = (--h.end())->s; if (A[i].s - A[tmp].s < A[i].f - A[tmp].f) break; h.erase(--h.end()); } h.ins(pi(A[i].s, i)); } if (l.empty() || l.begin()->f > A[i].s) { while (l.size()) { auto tmp = l.begin()->s; if (A[tmp].s - A[i].s < A[i].f - A[tmp].f) break; l.erase(l.begin()); } l.ins(pi(A[i].s, i)); } } cout << ans << '\n'; }
replace
74
75
74
75
0
p02556
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define all(a) (a).begin(), (a).end() #define sz(x) (int)x.size() #define F first #define S second #define endl "\n" #define inf (long long)1000000007 #define FOR(i, a, b) for (int i = a; i < b; i++) #define bigint 1e18 mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); #define SHUF(v) shuffle(aint(v), RNG); // Use mt19937_64 for 64 bit random numbers. template <typename T> T ceil(T a, T b) { return (a + b - 1) / b; } template <typename T> T binpow(T a, T b, T m) { a %= m; T res = 1; while (b > 0) { if (b & 1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } class Solution { int M = 3e9 + 7; public: Solution() {} int solve() { int n; cin >> n; int mx1 = 0, mn1 = M, mx2 = -M, mn2 = M; FOR(i, 0, n) { int x, y; cin >> x >> y; mx1 = max(mx1, x + y); mn1 = min(mn1, x + y); mx2 = max(mx2, x - y); mn2 = min(mn2, x - y); } cout << max(abs(mx1 - mn1), abs(mx2 - mn2)); } }; // abs(x1 - x2) + abs(y1 - y2) // (x1 - x2) + (y1-y2) -- both +ve // (x1 + y1) - ( x2 + y2) -- (1) // OR // -(x1 - x2) - (y1 - y2) -- both -ve // -x1 + x2 - y1 + y2 -- Same as (1) (?) // OR // x1 - x2 - y1 + y2 -- second -ve // (x1 - y1) - (x2 - y2) -- (2) // OR // -x1 + x2 + y1 - y2 // -(x1 - y1) + (x2 - y2) -- Same as (2) () void solve() { Solution sol; sol.solve(); } signed main() { ios::sync_with_stdio(false); cin.tie(0); int t = 1; // cin>>t; FOR(i, 1, t + 1) { // cout<<"Case #"<<i<<": "; solve(); } cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define all(a) (a).begin(), (a).end() #define sz(x) (int)x.size() #define F first #define S second #define endl "\n" #define inf (long long)1000000007 #define FOR(i, a, b) for (int i = a; i < b; i++) #define bigint 1e18 mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); #define SHUF(v) shuffle(aint(v), RNG); // Use mt19937_64 for 64 bit random numbers. template <typename T> T ceil(T a, T b) { return (a + b - 1) / b; } template <typename T> T binpow(T a, T b, T m) { a %= m; T res = 1; while (b > 0) { if (b & 1) res = res * a % m; a = a * a % m; b >>= 1; } return res; } class Solution { int M = 3e9 + 7; public: Solution() {} void solve() { int n; cin >> n; int mx1 = 0, mn1 = M, mx2 = -M, mn2 = M; FOR(i, 0, n) { int x, y; cin >> x >> y; mx1 = max(mx1, x + y); mn1 = min(mn1, x + y); mx2 = max(mx2, x - y); mn2 = min(mn2, x - y); } cout << max(abs(mx1 - mn1), abs(mx2 - mn2)); } }; // abs(x1 - x2) + abs(y1 - y2) // (x1 - x2) + (y1-y2) -- both +ve // (x1 + y1) - ( x2 + y2) -- (1) // OR // -(x1 - x2) - (y1 - y2) -- both -ve // -x1 + x2 - y1 + y2 -- Same as (1) (?) // OR // x1 - x2 - y1 + y2 -- second -ve // (x1 - y1) - (x2 - y2) -- (2) // OR // -x1 + x2 + y1 - y2 // -(x1 - y1) + (x2 - y2) -- Same as (2) () void solve() { Solution sol; sol.solve(); } signed main() { ios::sync_with_stdio(false); cin.tie(0); int t = 1; // cin>>t; FOR(i, 1, t + 1) { // cout<<"Case #"<<i<<": "; solve(); } cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; }
replace
34
35
34
35
0
Time elapsed: 23ms
p02556
C++
Runtime Error
/*input 2 1 1 1 1 */ // Nihesh Anderson - knandy #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef long double ld; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key ll MOD = 1000000007; #define endl '\n' #define fast_cin() \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define pb push_back ll INF = 2000000000000000001; long double EPS = 1e-9; ll power(ll a, ll n, ll md) { if (n == 0) { return 1; } else { ll res = power(a, n / 2, md); res = (res * res) % md; if (n % 2 != 0) { res = (res * a) % md; } return res; } } random_device rndm; mt19937 grndm(rndm()); void mix(ll *a, ll *b) { shuffle(a, b, grndm); } const ll MX = 1000000000; int main() { fast_cin(); // freopen("input.in","r",stdin); // freopen("output.out","w",stdout); ll n; cin >> n; vector<ll> v[4]; for (ll i = 0; i < n; i++) { ll x, y; cin >> x >> y; v[0].push_back(y - 1 + x - 1); v[1].push_back(x - 1 + MX - y); v[2].push_back(MX - x + y - 1); v[3].push_back(MX - x + MX - y); } for (ll i = 0; i < n; i++) { sort(v[i].begin(), v[i].end()); } ll ans = 0; for (ll i = 0; i < 4; i++) { ans = max(ans, v[i][n - 1] - v[i][0]); } cout << ans << endl; return 0; }
/*input 2 1 1 1 1 */ // Nihesh Anderson - knandy #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef long double ld; typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key ll MOD = 1000000007; #define endl '\n' #define fast_cin() \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define pb push_back ll INF = 2000000000000000001; long double EPS = 1e-9; ll power(ll a, ll n, ll md) { if (n == 0) { return 1; } else { ll res = power(a, n / 2, md); res = (res * res) % md; if (n % 2 != 0) { res = (res * a) % md; } return res; } } random_device rndm; mt19937 grndm(rndm()); void mix(ll *a, ll *b) { shuffle(a, b, grndm); } const ll MX = 1000000000; int main() { fast_cin(); // freopen("input.in","r",stdin); // freopen("output.out","w",stdout); ll n; cin >> n; vector<ll> v[4]; for (ll i = 0; i < n; i++) { ll x, y; cin >> x >> y; v[0].push_back(y - 1 + x - 1); v[1].push_back(x - 1 + MX - y); v[2].push_back(MX - x + y - 1); v[3].push_back(MX - x + MX - y); } for (ll i = 0; i < 4; i++) { sort(v[i].begin(), v[i].end()); } ll ans = 0; for (ll i = 0; i < 4; i++) { ans = max(ans, v[i][n - 1] - v[i][0]); } cout << ans << endl; return 0; }
replace
63
64
63
64
0
p02556
C++
Runtime Error
#include <bits/stdc++.h> #define f first #define s second #define mp make_pair using namespace std; typedef long long ll; const int nax = 1e5 + 5; int xx[nax]; int yy[nax]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; xx[i] = a + b; yy[i] = b - a; } sort(xx, xx + n); sort(yy, yy + n); cout << max(abs(xx[0] - xx[n - 1]), abs(yy[0] - yy[n - 1])); }
#include <bits/stdc++.h> #define f first #define s second #define mp make_pair using namespace std; typedef long long ll; const int nax = 2e5 + 5; int xx[nax]; int yy[nax]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; xx[i] = a + b; yy[i] = b - a; } sort(xx, xx + n); sort(yy, yy + n); cout << max(abs(xx[0] - xx[n - 1]), abs(yy[0] - yy[n - 1])); }
replace
9
10
9
10
0
p02556
C++
Runtime Error
#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <queue> #include <stack> using namespace std; const int maxn = 100000 + 10; const int dem = 2; // 维数 const double INF = (1e200); struct Point { double x[dem]; } p[maxn]; int n; double minx[1 << dem], maxx[1 << dem]; long long solve() { int tmp = 1 << dem; for (int i = 0; i < tmp; i++) { minx[i] = INF; maxx[i] = -INF; } for (int i = 0; i < n; i++) { for (int j = 0; j < tmp; j++) { int t = j; double s = 0; for (int k = 0; k < dem; k++) { if (t & 1) s += p[i].x[k]; else s -= p[i].x[k]; t >>= 1; } if (maxx[j] < s) maxx[j] = s; if (minx[j] > s) minx[j] = s; } } double ans = -INF; for (int i = 0; i < tmp; i++) { if (maxx[i] - minx[i] > ans) ans = maxx[i] - minx[i]; } return ans; } int main() { cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < dem; j++) { scanf("%lf", &p[i].x[j]); } } cout << solve() << endl; return 0; }
#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <queue> #include <stack> using namespace std; const int maxn = 400000 + 10; const int dem = 2; // 维数 const double INF = (1e200); struct Point { double x[dem]; } p[maxn]; int n; double minx[1 << dem], maxx[1 << dem]; long long solve() { int tmp = 1 << dem; for (int i = 0; i < tmp; i++) { minx[i] = INF; maxx[i] = -INF; } for (int i = 0; i < n; i++) { for (int j = 0; j < tmp; j++) { int t = j; double s = 0; for (int k = 0; k < dem; k++) { if (t & 1) s += p[i].x[k]; else s -= p[i].x[k]; t >>= 1; } if (maxx[j] < s) maxx[j] = s; if (minx[j] > s) minx[j] = s; } } double ans = -INF; for (int i = 0; i < tmp; i++) { if (maxx[i] - minx[i] > ans) ans = maxx[i] - minx[i]; } return ans; } int main() { cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < dem; j++) { scanf("%lf", &p[i].x[j]); } } cout << solve() << endl; return 0; }
replace
9
10
9
10
0
p02556
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int mod = 1e9; int main() { int N; scanf("%d", &N); int Max1 = mod * -1, Min1 = mod; int Max0 = mod * -1, Min0 = mod; for (int i = 1; i <= N; ++i) { int x, y; scanf("%d%d", &x, &y); Max1 = max(Max1, x + y); Min1 = min(Min1, x + y); Max0 = max(Max0, x - y); Min0 = min(Min0, x - y); } int ans = max((Max1 - Min1), (Max0 - Min0)); return printf("%d", ans); }
#include <bits/stdc++.h> using namespace std; const int mod = 1e9; int main() { int N; scanf("%d", &N); int Max1 = mod * -1, Min1 = mod; int Max0 = mod * -1, Min0 = mod; for (int i = 1; i <= N; ++i) { int x, y; scanf("%d%d", &x, &y); Max1 = max(Max1, x + y); Min1 = min(Min1, x + y); Max0 = max(Max0, x - y); Min0 = min(Min0, x - y); } int ans = max((Max1 - Min1), (Max0 - Min0)); return printf("%d", ans), 0; }
replace
20
21
20
21
1
p02556
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int n; vector<int> x(n); vector<int> y(n); for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; } vector<int> rect(4, 0); for (int i = 0; i < n; i++) { if (x[i] + y[i] > x[rect[0]] + y[rect[0]]) { rect[0] = i; } if (x[i] - y[i] > x[rect[1]] - y[rect[1]]) { rect[1] = i; } if (y[i] - x[i] > y[rect[2]] - x[rect[2]]) { rect[2] = i; } if (x[i] + y[i] < x[rect[3]] + y[rect[3]]) { rect[3] = i; } } cout << max(abs(x[rect[0]] - x[rect[3]]) + abs(y[rect[0]] - y[rect[3]]), abs(x[rect[1]] - x[rect[2]]) + abs(y[rect[1]] - y[rect[2]])) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> x(n); vector<int> y(n); for (int i = 0; i < n; i++) { cin >> x[i] >> y[i]; } vector<int> rect(4, 0); for (int i = 0; i < n; i++) { if (x[i] + y[i] > x[rect[0]] + y[rect[0]]) { rect[0] = i; } if (x[i] - y[i] > x[rect[1]] - y[rect[1]]) { rect[1] = i; } if (y[i] - x[i] > y[rect[2]] - x[rect[2]]) { rect[2] = i; } if (x[i] + y[i] < x[rect[3]] + y[rect[3]]) { rect[3] = i; } } cout << max(abs(x[rect[0]] - x[rect[3]]) + abs(y[rect[0]] - y[rect[3]]), abs(x[rect[1]] - x[rect[2]]) + abs(y[rect[1]] - y[rect[2]])) << endl; }
insert
4
4
4
5
-11
p02556
C++
Runtime Error
#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 DINF = 1e100; const double pi = acos(-1.0); const double eps = 1e-7; 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> class Mint { private: int x; public: 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()() { return x; } Mint operator-() const { return Mint(x == 0 ? x : 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)); } }; 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; inline bool is_digit() const { return '0' <= *ptr && *ptr <= '9'; } inline bool is_blank() const { return *ptr == ' ' || *ptr == '\n' || *ptr == '\t' || *ptr == '\0'; } template <typename T> inline void read_i(T &x) { bool f = false; x = 0; while (ptr < tail && !is_digit()) { if (*ptr == '-') f = true; ptr++; } while (ptr < tail && is_digit()) { x = (x << 1) + (x << 3) + (*ptr & 0xf); ptr++; } if (f) x = -x; } template <typename T> inline void read_f(T &x) { static char t_buff[1 << 6]; read(t_buff); x = atof(t_buff); } public: fast_reader() : buff_size(0), buff_ptr(nullptr), ptr(nullptr), tail(nullptr), is_open(false) {} ~fast_reader() { if (is_open) free(buff_ptr); } template <typename T> fast_reader &operator>>(T &x) { read(x); return *this; } 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, typename... Args> inline void read(T &x, Args &...args) { read(x); read(args...); } 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); } inline void read(float &x) { read_f(x); } inline void read(double &x) { read_f(x); } 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 } inline bool is_end() { while (ptr < tail && is_blank()) ptr++; return ptr >= tail; } } reader; const int maxn = (int)2e5 + 5; const int maxm = (int)5e6 + 5; int n; pii p[maxn]; int hs[maxn], hscnt; struct SGT { LL T[maxn << 2]; void build(int l, int r, int id) { T[id] = INT_MIN; if (l == r) return; int mid = MID(l, r); build(lson); build(rson); } void update(LL v, int p, int l, int r, int id) { if (l == r) { T[id] = max(T[id], v); return; } int mid = MID(l, r); if (p <= mid) update(v, p, lson); else update(v, p, rson); T[id] = max(T[ls], T[rs]); } LL query(int L, int R, int l, int r, int id) { if (L <= l && r <= R) return T[id]; int mid = MID(l, r); if (R <= mid) return query(L, R, lson); if (mid < L) return query(L, R, rson); return max(query(L, R, lson), query(L, R, rson)); } } sgt[2]; void work() { reader >> n; for (int i = 0; i < n; i++) { reader >> p[i].fi >> p[i].se; hs[i] = p[i].se; } sort(hs, hs + n); hscnt = unique(hs, hs + n) - hs; sort(p, p + n); for (int i = 0; i < n; i++) sgt[i].build(0, hscnt - 1, 1); LL ans = 0; for (int i = 0; i < n; i++) { int x = p[i].fi; int y = p[i].se; int yy = lower_bound(hs, hs + hscnt, y) - hs; sgt[0].update(-x - y, yy, 0, hscnt - 1, 1); sgt[1].update(-x + y, yy, 0, hscnt - 1, 1); get_max(ans, sgt[0].query(0, yy, 0, hscnt - 1, 1) + x + y); get_max(ans, sgt[1].query(yy, hscnt - 1, 0, hscnt - 1, 1) + x - y); } cout << ans << endl; } int main() { #ifdef yukihana0416 freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #endif // yukihana0416 reader.open_alter(1 << 24); int tc = 1; // reader >> 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 DINF = 1e100; const double pi = acos(-1.0); const double eps = 1e-7; 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> class Mint { private: int x; public: 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()() { return x; } Mint operator-() const { return Mint(x == 0 ? x : 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)); } }; 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; inline bool is_digit() const { return '0' <= *ptr && *ptr <= '9'; } inline bool is_blank() const { return *ptr == ' ' || *ptr == '\n' || *ptr == '\t' || *ptr == '\0'; } template <typename T> inline void read_i(T &x) { bool f = false; x = 0; while (ptr < tail && !is_digit()) { if (*ptr == '-') f = true; ptr++; } while (ptr < tail && is_digit()) { x = (x << 1) + (x << 3) + (*ptr & 0xf); ptr++; } if (f) x = -x; } template <typename T> inline void read_f(T &x) { static char t_buff[1 << 6]; read(t_buff); x = atof(t_buff); } public: fast_reader() : buff_size(0), buff_ptr(nullptr), ptr(nullptr), tail(nullptr), is_open(false) {} ~fast_reader() { if (is_open) free(buff_ptr); } template <typename T> fast_reader &operator>>(T &x) { read(x); return *this; } 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, typename... Args> inline void read(T &x, Args &...args) { read(x); read(args...); } 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); } inline void read(float &x) { read_f(x); } inline void read(double &x) { read_f(x); } 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 } inline bool is_end() { while (ptr < tail && is_blank()) ptr++; return ptr >= tail; } } reader; const int maxn = (int)2e5 + 5; const int maxm = (int)5e6 + 5; int n; pii p[maxn]; int hs[maxn], hscnt; struct SGT { LL T[maxn << 2]; void build(int l, int r, int id) { T[id] = INT_MIN; if (l == r) return; int mid = MID(l, r); build(lson); build(rson); } void update(LL v, int p, int l, int r, int id) { if (l == r) { T[id] = max(T[id], v); return; } int mid = MID(l, r); if (p <= mid) update(v, p, lson); else update(v, p, rson); T[id] = max(T[ls], T[rs]); } LL query(int L, int R, int l, int r, int id) { if (L <= l && r <= R) return T[id]; int mid = MID(l, r); if (R <= mid) return query(L, R, lson); if (mid < L) return query(L, R, rson); return max(query(L, R, lson), query(L, R, rson)); } } sgt[2]; void work() { reader >> n; for (int i = 0; i < n; i++) { reader >> p[i].fi >> p[i].se; hs[i] = p[i].se; } sort(hs, hs + n); hscnt = unique(hs, hs + n) - hs; sort(p, p + n); for (int i = 0; i < 2; i++) sgt[i].build(0, hscnt - 1, 1); LL ans = 0; for (int i = 0; i < n; i++) { int x = p[i].fi; int y = p[i].se; int yy = lower_bound(hs, hs + hscnt, y) - hs; sgt[0].update(-x - y, yy, 0, hscnt - 1, 1); sgt[1].update(-x + y, yy, 0, hscnt - 1, 1); get_max(ans, sgt[0].query(0, yy, 0, hscnt - 1, 1) + x + y); get_max(ans, sgt[1].query(yy, hscnt - 1, 0, hscnt - 1, 1) + x - y); } cout << ans << endl; } int main() { #ifdef yukihana0416 freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); #endif // yukihana0416 reader.open_alter(1 << 24); int tc = 1; // reader >> tc; for (int ca = 1; ca <= tc; ca++) { // printf("Case #%d: ", ca); // printf("Case #%d:\n", ca); work(); } return 0; }
replace
307
308
307
308
0
p02556
C++
Time Limit Exceeded
#include <bits/stdc++.h> typedef long long int ll; typedef long double ld; #define sync \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define input(arr, n) \ for (ll i1 = 0; i1 < n; i1++) \ cin >> arr[i1] #define mod 1000000007 #define F first #define S second #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") using namespace __gnu_pbds; #define ordered_set \ tree<ll, null_type, less_equal<ll>, rb_tree_tag, \ tree_order_statistics_node_update> // s.order_of_key(val) // *s.find_by_order(ind) using namespace std; const int N = 1e6 + 5; int main() { sync; ll n; cin >> n; vector<pair<ll, ll>> v(n); for (ll i = 0; i < n; i++) cin >> v[i].F >> v[i].S; ll ans = 0; for (ll i = 0; i < n; i++) for (ll j = 0; j < n; j++) ans = max(ans, abs(v[i].F - v[j].F) + abs(v[i].S - v[j].S)); cout << ans; }
#include <bits/stdc++.h> typedef long long int ll; typedef long double ld; #define sync \ ios_base::sync_with_stdio(false); \ cin.tie(NULL) #define input(arr, n) \ for (ll i1 = 0; i1 < n; i1++) \ cin >> arr[i1] #define mod 1000000007 #define F first #define S second #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") using namespace __gnu_pbds; #define ordered_set \ tree<ll, null_type, less_equal<ll>, rb_tree_tag, \ tree_order_statistics_node_update> // s.order_of_key(val) // *s.find_by_order(ind) using namespace std; const int N = 1e6 + 5; int main() { sync; ll n; cin >> n; vector<pair<ll, ll>> v(n); for (ll i = 0; i < n; i++) cin >> v[i].F >> v[i].S; ll ans = 0, minm = 1e18, maxm = -1e18; for (ll i = 0; i < n; i++) { minm = min(minm, v[i].F + v[i].S); maxm = max(maxm, v[i].F + v[i].S); } ans = maxm - minm; minm = 1e18, maxm = -1e18; for (ll i = 0; i < n; i++) { minm = min(minm, v[i].F - v[i].S); maxm = max(maxm, v[i].F - v[i].S); } ans = max(ans, maxm - minm); cout << ans; }
replace
34
38
34
46
TLE
p02556
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < n; i++) #define pii pair<int, int> int N; int X[100010], Y[100010]; signed main() { cin >> N; rep(i, N) { int x, y; cin >> x >> y; X[i] = x + y; Y[i] = x - y; } sort(X, X + N); sort(Y, Y + N); cout << max(X[N - 1] - X[0], Y[N - 1] - Y[0]) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i, n) for (int i = 0; i < n; i++) #define pii pair<int, int> int N; int X[200010], Y[200010]; signed main() { cin >> N; rep(i, N) { int x, y; cin >> x >> y; X[i] = x + y; Y[i] = x - y; } sort(X, X + N); sort(Y, Y + N); cout << max(X[N - 1] - X[0], Y[N - 1] - Y[0]) << endl; return 0; }
replace
8
9
8
9
0
p02556
C++
Runtime Error
#include <iostream> #include <stdio.h> #include <string.h> using namespace std; const int N = 100005; const double INF = 1e100; int a[N][3]; int n; int main() { while (~scanf("%d", &n)) { for (int i = 0; i < n; i++) for (int j = 0; j < 2; j++) scanf("%d", &a[i][j]); int ans = 0, mi, mx, t; for (int s = 1; s < (1 << 2); s++) { mi = INF; mx = -INF; for (int i = 0; i < n; i++) { t = 0; for (int j = 0; j < 2; j++) { if ((1 << j) & s) t += a[i][j]; else t -= a[i][j]; } mi = min(mi, t); mx = max(mx, t); } ans = max(ans, mx - mi); } printf("%d\n", ans); } return 0; }
#include <iostream> #include <stdio.h> #include <string.h> using namespace std; const int N = 200005; const double INF = 1e100; int a[N][3]; int n; int main() { while (~scanf("%d", &n)) { for (int i = 0; i < n; i++) for (int j = 0; j < 2; j++) scanf("%d", &a[i][j]); int ans = 0, mi, mx, t; for (int s = 1; s < (1 << 2); s++) { mi = INF; mx = -INF; for (int i = 0; i < n; i++) { t = 0; for (int j = 0; j < 2; j++) { if ((1 << j) & s) t += a[i][j]; else t -= a[i][j]; } mi = min(mi, t); mx = max(mx, t); } ans = max(ans, mx - mi); } printf("%d\n", ans); } return 0; }
replace
5
6
5
6
0
p02556
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i) namespace IO { #define gc getchar() template <typename T> inline void read(T &x) { x = 0; bool f = 1; char ch; for (ch = gc; ch < '0' || '9' < ch; ch = gc) if (ch == '-') f ^= 1; for (; '0' <= ch && ch <= '9'; ch = gc) x = (x << 3) + (x << 1) + (ch ^ 48); x = f ? x : -x; } #undef gc } // namespace IO typedef long long ll; typedef pair<ll, ll> pii; const int MAXN = 2e5 + 10; int n; ll ans, tmp[MAXN], num[MAXN]; pii arr[MAXN]; struct BIT { ll bit[MAXN + 100]; void chkmin(ll &a, ll b) { if (a < b) a = b; } BIT() { rep(i, 0, MAXN) bit[i] = -INT_MAX; } void clear() { rep(i, 0, MAXN) bit[i] = -INT_MAX; } void add(int x, ll val) { for (; x < MAXN; x += x & -x) chkmin(bit[x], val); } ll query(int x) { ll ret = -INT_MAX; for (; x; x -= x & -x) chkmin(ret, bit[x]); return ret; } void radd(int x, ll val) { for (; x; x -= x & -x) chkmin(bit[x], val); } ll rquery(int x) { ll ret = -INT_MAX; for (; x < MAXN; x += x & -x) chkmin(ret, bit[x]); return ret; } } bit1, bit2; int main() { IO::read(n); rep(i, 1, n) IO::read(arr[i].first), IO::read(arr[i].second), tmp[i] = arr[i].second; sort(arr + 1, arr + n + 1), sort(tmp + 1, tmp + n + 1); int _n = unique(tmp + 1, tmp + n + 1) - tmp - 1; rep(i, 1, n) num[i] = *lower_bound(tmp + 1, tmp + _n + 1, arr[i].second); rep(i, 1, n) { if (i > 1) ans = max(ans, arr[i].first + max(arr[i].second + bit1.query(num[i]), bit2.rquery(num[i]) - arr[i].second)); bit1.add(num[i], -(arr[i].first + arr[i].second)), bit2.radd(num[i], -arr[i].first + arr[i].second); } bit1.clear(), bit2.clear(); per(i, n, 1) { if (i < n) ans = max(ans, -arr[i].first + max(arr[i].second + bit1.query(num[i]), bit2.rquery(num[i]) - arr[i].second)); bit1.add(num[i], -(-arr[i].first + arr[i].second)), bit2.radd(num[i], arr[i].first + arr[i].second); } printf("%lld\n", ans); return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i) #define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i) namespace IO { #define gc getchar() template <typename T> inline void read(T &x) { x = 0; bool f = 1; char ch; for (ch = gc; ch < '0' || '9' < ch; ch = gc) if (ch == '-') f ^= 1; for (; '0' <= ch && ch <= '9'; ch = gc) x = (x << 3) + (x << 1) + (ch ^ 48); x = f ? x : -x; } #undef gc } // namespace IO typedef long long ll; typedef pair<ll, ll> pii; const int MAXN = 2e5 + 10; int n; ll ans, tmp[MAXN], num[MAXN]; pii arr[MAXN]; struct BIT { ll bit[MAXN + 100]; void chkmin(ll &a, ll b) { if (a < b) a = b; } BIT() { rep(i, 0, MAXN) bit[i] = -INT_MAX; } void clear() { rep(i, 0, MAXN) bit[i] = -INT_MAX; } void add(int x, ll val) { for (; x < MAXN; x += x & -x) chkmin(bit[x], val); } ll query(int x) { ll ret = -INT_MAX; for (; x; x -= x & -x) chkmin(ret, bit[x]); return ret; } void radd(int x, ll val) { for (; x; x -= x & -x) chkmin(bit[x], val); } ll rquery(int x) { ll ret = -INT_MAX; for (; x < MAXN; x += x & -x) chkmin(ret, bit[x]); return ret; } } bit1, bit2; int main() { IO::read(n); rep(i, 1, n) IO::read(arr[i].first), IO::read(arr[i].second), tmp[i] = arr[i].second; sort(arr + 1, arr + n + 1), sort(tmp + 1, tmp + n + 1); int _n = unique(tmp + 1, tmp + n + 1) - tmp - 1; rep(i, 1, n) num[i] = lower_bound(tmp + 1, tmp + _n + 1, arr[i].second) - tmp; rep(i, 1, n) { if (i > 1) ans = max(ans, arr[i].first + max(arr[i].second + bit1.query(num[i]), bit2.rquery(num[i]) - arr[i].second)); bit1.add(num[i], -(arr[i].first + arr[i].second)), bit2.radd(num[i], -arr[i].first + arr[i].second); } bit1.clear(), bit2.clear(); per(i, n, 1) { if (i < n) ans = max(ans, -arr[i].first + max(arr[i].second + bit1.query(num[i]), bit2.rquery(num[i]) - arr[i].second)); bit1.add(num[i], -(-arr[i].first + arr[i].second)), bit2.radd(num[i], arr[i].first + arr[i].second); } printf("%lld\n", ans); return 0; }
replace
67
68
67
68
0
p02556
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define INF 9999999999999 #define D 2 // 空间维数 #define M 100005 // 坐标个数 struct Point { int x[D]; } pt[M]; int dis[1 << D][M], minx[1 << D], maxx[1 << D]; // 去掉绝对值后有2^D种可能 void Get(int N) // 取得所有点在指定状态(S)下的“本点有效距离” { int tot = (1 << D); for (int s = 0; s < tot; s++) // 遍历所有维数正负状态 { int coe[D]; for (int i = 0; i < D; i++) // 设定当前状态的具体正负参数 if (s & (1 << i)) coe[i] = -1.0; else coe[i] = 1.0; for (int i = 0; i < N; i++) // 遍历所有点,确定每个点在当前状态下的“本点有效距离” { dis[s][i] = 0.0; for (int j = 0; j < D; j++) dis[s][i] = dis[s][i] + coe[j] * pt[i].x[j]; } } } // 取每种可能中的最大差距 void Solve(int N) { int tot = (1 << D); int tmp, ans; for (int s = 0; s < tot; s++) { minx[s] = INF; maxx[s] = -INF; for (int i = 0; i < N; i++) { if (minx[s] > dis[s][i]) minx[s] = dis[s][i]; if (maxx[s] < dis[s][i]) maxx[s] = dis[s][i]; } } ans = 0; for (int s = 0; s < tot; s++) { tmp = maxx[s] - minx[s]; if (tmp > ans) ans = tmp; } cout << ans << endl; } int main() { int n; while (scanf("%d", &n) != EOF) { for (int i = 0; i < n; i++) cin >> pt[i].x[0] >> pt[i].x[1]; Get(n); Solve(n); } return 0; }
#include <bits/stdc++.h> using namespace std; #define INF 9999999999999 #define D 2 // 空间维数 #define M 200005 // 坐标个数 struct Point { int x[D]; } pt[M]; int dis[1 << D][M], minx[1 << D], maxx[1 << D]; // 去掉绝对值后有2^D种可能 void Get(int N) // 取得所有点在指定状态(S)下的“本点有效距离” { int tot = (1 << D); for (int s = 0; s < tot; s++) // 遍历所有维数正负状态 { int coe[D]; for (int i = 0; i < D; i++) // 设定当前状态的具体正负参数 if (s & (1 << i)) coe[i] = -1.0; else coe[i] = 1.0; for (int i = 0; i < N; i++) // 遍历所有点,确定每个点在当前状态下的“本点有效距离” { dis[s][i] = 0.0; for (int j = 0; j < D; j++) dis[s][i] = dis[s][i] + coe[j] * pt[i].x[j]; } } } // 取每种可能中的最大差距 void Solve(int N) { int tot = (1 << D); int tmp, ans; for (int s = 0; s < tot; s++) { minx[s] = INF; maxx[s] = -INF; for (int i = 0; i < N; i++) { if (minx[s] > dis[s][i]) minx[s] = dis[s][i]; if (maxx[s] < dis[s][i]) maxx[s] = dis[s][i]; } } ans = 0; for (int s = 0; s < tot; s++) { tmp = maxx[s] - minx[s]; if (tmp > ans) ans = tmp; } cout << ans << endl; } int main() { int n; while (scanf("%d", &n) != EOF) { for (int i = 0; i < n; i++) cin >> pt[i].x[0] >> pt[i].x[1]; Get(n); Solve(n); } return 0; }
replace
4
5
4
5
0
p02556
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define int long long #define ar array<int, 2> #define inf 1000000000000000000 int mod = 1e9 + 7; int min(int a, int b) { return (a < b) ? a : b; } int max(int a, int b) { return (a > b) ? a : b; } int fp(int a, int b) { if (b == 0) return 1; int x = fp(a, b / 2); x = (x * x) % mod; if (b & 1) x = (x * a) % mod; return x; } const int N = 2e5 + 5; void solve() { int n, x, y; cin >> n; vector<int> tmp(1ll << 2, -inf); int ans = -inf; for (int i = 1; i <= n; i++) { cin >> x >> y; for (int j = 0; j < (1ll << 2); j++) { if (tmp[i] == -inf) break; int z = tmp[j]; if (j & 1) z -= y; else z += y; if ((j >> 1) & 1) z -= x; else z += x; ans = max(ans, z); } for (int j = 0; j < (1ll << 2); j++) { int z = 0; if (j & 1) z += y; else z -= y; if ((j >> 1) & 1) z += x; else z -= x; tmp[j] = max(tmp[j], z); // cout<<tmp[j]<<endl; } } cout << ans << endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); srand(time(0)); int t = 1; // cin>>t; for (int i = 1; i <= t; i++) { solve(); } }
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define int long long #define ar array<int, 2> #define inf 1000000000000000000 int mod = 1e9 + 7; int min(int a, int b) { return (a < b) ? a : b; } int max(int a, int b) { return (a > b) ? a : b; } int fp(int a, int b) { if (b == 0) return 1; int x = fp(a, b / 2); x = (x * x) % mod; if (b & 1) x = (x * a) % mod; return x; } const int N = 2e5 + 5; void solve() { int n, x, y; cin >> n; vector<int> tmp(1ll << 2, -inf); int ans = -inf; for (int i = 1; i <= n; i++) { cin >> x >> y; for (int j = 0; j < (1ll << 2); j++) { if (tmp[j] == -inf) break; int z = tmp[j]; if (j & 1) z -= y; else z += y; if ((j >> 1) & 1) z -= x; else z += x; ans = max(ans, z); } for (int j = 0; j < (1ll << 2); j++) { int z = 0; if (j & 1) z += y; else z -= y; if ((j >> 1) & 1) z += x; else z -= x; tmp[j] = max(tmp[j], z); // cout<<tmp[j]<<endl; } } cout << ans << endl; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); srand(time(0)); int t = 1; // cin>>t; for (int i = 1; i <= t; i++) { solve(); } }
replace
29
30
29
30
0
p02556
C++
Time Limit Exceeded
#define _overload(_1, _2, _3, _4, name, ...) name #define _rep1(Itr, N) _rep3(Itr, 0, N, 1) #define _rep2(Itr, a, b) _rep3(Itr, a, b, 1) #define _rep3(Itr, a, b, step) for (i64(Itr) = a; (Itr) < b; (Itr) += step) #define repeat(...) _overload(__VA_ARGS__, _rep3, _rep2, _rep1)(__VA_ARGS__) #include "bits/stdc++.h" using i64 = long long; using namespace std; // beet san arigatou // BEGIN CUT HERE struct FullyIndexableDictionary { int len, blk; vector<unsigned> bit; vector<int> sum; FullyIndexableDictionary() {} FullyIndexableDictionary(int len) : len(len), blk((len + 31) >> 5), bit(blk, 0), sum(blk, 0) {} void set(int k) { bit[k >> 5] |= 1u << (k & 31); } void build() { sum[0] = 0; for (int i = 1; i < blk; i++) sum[i] = sum[i - 1] + __builtin_popcount(bit[i - 1]); } bool operator[](int k) const { return bool((bit[k >> 5] >> (k & 31)) & 1); } int rank(int k) { return sum[k >> 5] + __builtin_popcount(bit[k >> 5] & ((1u << (k & 31)) - 1)); } int rank(bool v, int k) { return (v ? rank(k) : k - rank(k)); } int select(bool v, int k) { if (k < 0 || rank(v, len) <= k) return -1; int l = 0, r = len; while (l + 1 < r) { int m = (l + r) >> 1; if (rank(v, m) >= k + 1) r = m; else l = m; } return r - 1; } int select(bool v, int i, int l) { return select(v, i + rank(v, l)); } }; template <class T, int MAXLOG> struct WaveletMatrix { int len; FullyIndexableDictionary mat[MAXLOG]; int zs[MAXLOG], buff1[MAXLOG], buff2[MAXLOG]; static const T npos = -1; WaveletMatrix(vector<T> data) { len = data.size(); vector<T> ls(len), rs(len); for (int dep = 0; dep < MAXLOG; dep++) { mat[dep] = FullyIndexableDictionary(len + 1); int p = 0, q = 0; for (int i = 0; i < len; i++) { bool k = (data[i] >> (MAXLOG - (dep + 1))) & 1; if (k) rs[q++] = data[i], mat[dep].set(i); else ls[p++] = data[i]; } zs[dep] = p; mat[dep].build(); swap(ls, data); for (int i = 0; i < q; i++) data[p + i] = rs[i]; } } T access(int k) { T res = 0; for (int dep = 0; dep < MAXLOG; dep++) { bool bit = mat[dep][k]; res = (res << 1) | bit; k = mat[dep].rank(bit, k) + zs[dep] * dep; } return res; } // return the number of v in [0,k) int rank(T v, int k) { int l = 0, r = k; for (int dep = 0; dep < MAXLOG; dep++) { buff1[dep] = l; buff2[dep] = r; bool bit = (v >> (MAXLOG - (dep + 1))) & 1; l = mat[dep].rank(bit, l) + zs[dep] * bit; r = mat[dep].rank(bit, r) + zs[dep] * bit; } return r - l; } // return the position of k-th v int select(T v, int k) { rank(v, len); for (int dep = MAXLOG - 1; dep >= 0; dep--) { bool bit = (v >> (MAXLOG - (dep + 1))) & 1; k = mat[dep].select(bit, k, buff1[dep]); if (k >= buff2[dep] || k < 0) return -1; k -= buff1[dep]; } return k; } int select(T v, int k, int l) { return select(v, k + rank(v, l)); } // return k-th largest value in [l,r) T quantile(int l, int r, int k) { if (r - l <= k || k < 0) return -1; T res = 0; for (int dep = 0; dep < MAXLOG; dep++) { int p = mat[dep].rank(1, l); int q = mat[dep].rank(1, r); if (q - p > k) { l = p + zs[dep]; r = q + zs[dep]; res |= T(1) << (MAXLOG - (dep + 1)); } else { k -= (q - p); l -= p; r -= q; } } return res; } T rquantile(int l, int r, int k) { return quantile(l, r, r - l - k - 1); } int freq_dfs(int d, int l, int r, T val, T a, T b) { if (l == r) return 0; if (d == MAXLOG) return (a <= val && val < b) ? r - l : 0; T nv = T(1) << (MAXLOG - d - 1) | val; T nnv = ((T(1) << (MAXLOG - d - 1)) - 1) | nv; if (nnv < a || b <= val) return 0; if (a <= val && nnv < b) return r - l; int lc = mat[d].rank(1, l), rc = mat[d].rank(1, r); return freq_dfs(d + 1, l - lc, r - rc, val, a, b) + freq_dfs(d + 1, lc + zs[d], rc + zs[d], nv, a, b); } // return number of points in [left, right) * [lower, upper) int rangefreq(int left, int right, T lower, T upper) { return freq_dfs(0, left, right, 0, lower, upper); } pair<int, int> ll(int l, int r, T v) { int res = 0; for (int dep = 0; dep < MAXLOG; dep++) { buff1[dep] = l; buff2[dep] = r; bool bit = (v >> (MAXLOG - (dep + 1))) & 1; if (bit) res += r - l + mat[dep].rank(bit, l) - mat[dep].rank(bit, r); l = mat[dep].rank(bit, l) + zs[dep] * bit; r = mat[dep].rank(bit, r) + zs[dep] * bit; } return make_pair(res, r - l); } int lt(int l, int r, T v) { auto p = ll(l, r, v); return p.first; } int le(int l, int r, T v) { auto p = ll(l, r, v); return p.first + p.second; } T succ(int l, int r, T v) { int k = le(l, r, v); return k == r - l ? npos : rquantile(l, r, k); } T pred(int l, int r, T v) { int k = lt(l, r, v); return k ? rquantile(l, r, k - 1) : npos; } }; // END CUT HERE int main() { using u64 = unsigned long long; using P = pair<i64, i64>; const i64 INF = 1ll << 60; i64 n; vector<i64> x, y; vector<P> p; cin >> n; x.resize(n); y.resize(n); p.resize(n); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; x[i] = a - b; y[i] = a + b; p[i] = {x[i], y[i]}; } sort(p.begin(), p.end()); vector<u64> dat(n); for (int i = 0; i < n; i++) dat[i] = p[i].second; WaveletMatrix<u64, 32> wm(dat); auto f = [&](int i, i64 d) { int l = lower_bound(p.begin(), p.end(), P(p[i].first - d, -1 * INF)) - p.begin(); int r = lower_bound(p.begin(), p.end(), P(p[i].first + d + 1, -1 * INF)) - p.begin(); return n - wm.rangefreq(l, r, max(p[i].second - d, 0ll), p[i].second + d + 1); }; i64 ans = 0; for (int i = 0; i < n; i++) { i64 valid = INF; i64 invalid = -1; i64 mid; while (valid - invalid > 1) { mid = (valid + invalid) / 2; if (f(i, mid) == 0) valid = mid; else invalid = mid; } ans = max(ans, valid); } cout << ans << endl; return 0; };
#define _overload(_1, _2, _3, _4, name, ...) name #define _rep1(Itr, N) _rep3(Itr, 0, N, 1) #define _rep2(Itr, a, b) _rep3(Itr, a, b, 1) #define _rep3(Itr, a, b, step) for (i64(Itr) = a; (Itr) < b; (Itr) += step) #define repeat(...) _overload(__VA_ARGS__, _rep3, _rep2, _rep1)(__VA_ARGS__) #include "bits/stdc++.h" using i64 = long long; using namespace std; // beet san arigatou // BEGIN CUT HERE struct FullyIndexableDictionary { int len, blk; vector<unsigned> bit; vector<int> sum; FullyIndexableDictionary() {} FullyIndexableDictionary(int len) : len(len), blk((len + 31) >> 5), bit(blk, 0), sum(blk, 0) {} void set(int k) { bit[k >> 5] |= 1u << (k & 31); } void build() { sum[0] = 0; for (int i = 1; i < blk; i++) sum[i] = sum[i - 1] + __builtin_popcount(bit[i - 1]); } bool operator[](int k) const { return bool((bit[k >> 5] >> (k & 31)) & 1); } int rank(int k) { return sum[k >> 5] + __builtin_popcount(bit[k >> 5] & ((1u << (k & 31)) - 1)); } int rank(bool v, int k) { return (v ? rank(k) : k - rank(k)); } int select(bool v, int k) { if (k < 0 || rank(v, len) <= k) return -1; int l = 0, r = len; while (l + 1 < r) { int m = (l + r) >> 1; if (rank(v, m) >= k + 1) r = m; else l = m; } return r - 1; } int select(bool v, int i, int l) { return select(v, i + rank(v, l)); } }; template <class T, int MAXLOG> struct WaveletMatrix { int len; FullyIndexableDictionary mat[MAXLOG]; int zs[MAXLOG], buff1[MAXLOG], buff2[MAXLOG]; static const T npos = -1; WaveletMatrix(vector<T> data) { len = data.size(); vector<T> ls(len), rs(len); for (int dep = 0; dep < MAXLOG; dep++) { mat[dep] = FullyIndexableDictionary(len + 1); int p = 0, q = 0; for (int i = 0; i < len; i++) { bool k = (data[i] >> (MAXLOG - (dep + 1))) & 1; if (k) rs[q++] = data[i], mat[dep].set(i); else ls[p++] = data[i]; } zs[dep] = p; mat[dep].build(); swap(ls, data); for (int i = 0; i < q; i++) data[p + i] = rs[i]; } } T access(int k) { T res = 0; for (int dep = 0; dep < MAXLOG; dep++) { bool bit = mat[dep][k]; res = (res << 1) | bit; k = mat[dep].rank(bit, k) + zs[dep] * dep; } return res; } // return the number of v in [0,k) int rank(T v, int k) { int l = 0, r = k; for (int dep = 0; dep < MAXLOG; dep++) { buff1[dep] = l; buff2[dep] = r; bool bit = (v >> (MAXLOG - (dep + 1))) & 1; l = mat[dep].rank(bit, l) + zs[dep] * bit; r = mat[dep].rank(bit, r) + zs[dep] * bit; } return r - l; } // return the position of k-th v int select(T v, int k) { rank(v, len); for (int dep = MAXLOG - 1; dep >= 0; dep--) { bool bit = (v >> (MAXLOG - (dep + 1))) & 1; k = mat[dep].select(bit, k, buff1[dep]); if (k >= buff2[dep] || k < 0) return -1; k -= buff1[dep]; } return k; } int select(T v, int k, int l) { return select(v, k + rank(v, l)); } // return k-th largest value in [l,r) T quantile(int l, int r, int k) { if (r - l <= k || k < 0) return -1; T res = 0; for (int dep = 0; dep < MAXLOG; dep++) { int p = mat[dep].rank(1, l); int q = mat[dep].rank(1, r); if (q - p > k) { l = p + zs[dep]; r = q + zs[dep]; res |= T(1) << (MAXLOG - (dep + 1)); } else { k -= (q - p); l -= p; r -= q; } } return res; } T rquantile(int l, int r, int k) { return quantile(l, r, r - l - k - 1); } int freq_dfs(int d, int l, int r, T val, T a, T b) { if (l == r) return 0; if (d == MAXLOG) return (a <= val && val < b) ? r - l : 0; T nv = T(1) << (MAXLOG - d - 1) | val; T nnv = ((T(1) << (MAXLOG - d - 1)) - 1) | nv; if (nnv < a || b <= val) return 0; if (a <= val && nnv < b) return r - l; int lc = mat[d].rank(1, l), rc = mat[d].rank(1, r); return freq_dfs(d + 1, l - lc, r - rc, val, a, b) + freq_dfs(d + 1, lc + zs[d], rc + zs[d], nv, a, b); } // return number of points in [left, right) * [lower, upper) int rangefreq(int left, int right, T lower, T upper) { return freq_dfs(0, left, right, 0, lower, upper); } pair<int, int> ll(int l, int r, T v) { int res = 0; for (int dep = 0; dep < MAXLOG; dep++) { buff1[dep] = l; buff2[dep] = r; bool bit = (v >> (MAXLOG - (dep + 1))) & 1; if (bit) res += r - l + mat[dep].rank(bit, l) - mat[dep].rank(bit, r); l = mat[dep].rank(bit, l) + zs[dep] * bit; r = mat[dep].rank(bit, r) + zs[dep] * bit; } return make_pair(res, r - l); } int lt(int l, int r, T v) { auto p = ll(l, r, v); return p.first; } int le(int l, int r, T v) { auto p = ll(l, r, v); return p.first + p.second; } T succ(int l, int r, T v) { int k = le(l, r, v); return k == r - l ? npos : rquantile(l, r, k); } T pred(int l, int r, T v) { int k = lt(l, r, v); return k ? rquantile(l, r, k - 1) : npos; } }; // END CUT HERE int main() { using u64 = unsigned long long; using P = pair<i64, i64>; const i64 INF = 1ll << 60; i64 n; vector<i64> x, y; vector<P> p; cin >> n; x.resize(n); y.resize(n); p.resize(n); for (int i = 0; i < n; i++) { int a, b; cin >> a >> b; x[i] = a - b; y[i] = a + b; p[i] = {x[i], y[i]}; } sort(p.begin(), p.end()); vector<u64> dat(n); for (int i = 0; i < n; i++) dat[i] = p[i].second; WaveletMatrix<u64, 32> wm(dat); auto f = [&](int i, i64 d) { int l = lower_bound(p.begin(), p.end(), P(p[i].first - d, -1 * INF)) - p.begin(); int r = lower_bound(p.begin(), p.end(), P(p[i].first + d + 1, -1 * INF)) - p.begin(); return n - wm.rangefreq(l, r, max(p[i].second - d, 0ll), p[i].second + d + 1); }; i64 ans = 0; for (int i = 0; i < n; i++) { i64 valid = 1ll << 32; i64 invalid = -1; i64 mid; while (valid - invalid > 1) { mid = (valid + invalid) / 2; if (f(i, mid) == 0) valid = mid; else invalid = mid; } ans = max(ans, valid); } cout << ans << endl; return 0; };
replace
238
239
238
239
TLE
p02556
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<vi> vvi; typedef vector<vii> vvii; #define fi first #define se second #define ALL(x) (x).begin(), (x).end() #define RALL(x) (x).rbegin(), (x).rend() #define eb emplace_back #define pb push_back #define mp make_pair #define mt make_tuple #define SZ(x) (int)(x).size() #define endl '\n' #define FOR(a, b, c) for (auto a = (b); (a) < (c); ++(a)) #define F0R(a, b) FOR(a, 0, (b)) #define CEIL(a, b) ((a) + (b)-1) / (b) template <class T> bool ckmin(T &a, const T &b) { return a > b ? a = b, true : false; } template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, true : false; } #ifndef DEBUG #define DEBUG 0 #endif #define dout \ if (DEBUG) \ std::cerr #define dvar(...) " [" << #__VA_ARGS__ ": " << mt(__VA_ARGS__) << "] " template <typename T> struct IsC { template <typename C> static char test(typename C::const_iterator *); template <typename C> static int test(...); static const bool value = sizeof(test<T>(0)) == sizeof(char); }; template <> struct IsC<string> { static const bool value = false; }; template <typename C> typename enable_if<IsC<C>::value, ostream &>::type operator<<(ostream &, const C &); template <typename T1, typename T2> ostream &operator<<(ostream &, const pair<T1, T2> &); template <typename... T> using TS = tuple_size<tuple<T...>>; template <size_t idx, typename... T> typename enable_if<TS<T...>::value == idx + 1, ostream &>::type operator<<(ostream &o, const tuple<T...> &t) { return o << ", " << get<idx>(t) << ')'; } template <size_t idx, typename... T> typename enable_if<0 < idx && idx + 1 < TS<T...>::value, ostream &>::type operator<<(ostream &o, const tuple<T...> &t) { return operator<< <idx + 1>(o << ", " << get<idx>(t), t); } template <size_t idx = 0, typename... T> typename enable_if<1 < TS<T...>::value && !idx, ostream &>::type operator<<(ostream &o, const tuple<T...> &t) { return operator<< <idx + 1>(o << '(' << get<idx>(t), t); } template <typename T> ostream &operator<<(ostream &o, const tuple<T> &t) { return o << get<0>(t); } template <typename T1, typename T2> ostream &operator<<(ostream &o, const pair<T1, T2> &p) { return o << mt(p.fi, p.se); } template <typename C> typename enable_if<IsC<C>::value, ostream &>::type operator<<(ostream &o, const C &c) { o << '['; for (auto it = c.cbegin(); it != c.cend(); ++it) o << *it << (next(it) != c.cend() ? ", " : ""); return o << ']'; } template <typename T> void tprint(vector<vector<T>> &v, size_t width = 0, ostream &o = cerr) { if (!DEBUG) return; for (const auto &vv : v) { for (const auto &i : vv) o << setw(width) << i; o << endl; } } #define xx real() #define yy imag() const double EPS = 1e-9; const double INF = numeric_limits<double>::max(); using pt = complex<double>; struct Line { double a, b, c; }; // ax + by + c = 0 double dot(pt a, pt b) { return a.xx * b.xx + a.yy * b.yy; } double cross(pt a, pt b) { return a.xx * b.yy - a.yy * b.xx; } double dir(pt a, pt b, pt c) { return cross(b - a, c - a); } bool cw(pt a, pt b, pt c) { return dir(a, b, c) < 0; } bool ccw(pt a, pt b, pt c) { return dir(a, b, c) > 0; } bool collinear(pt a, pt b, pt c) { return abs(dir(a, b, c)) < EPS; } // Angle between a and b with o as origin (ccw). // Return value in [0, 2PI) double angle(pt a, pt b) { double ang = arg(a) - arg(b); return ang < 0 ? ang + 2 * M_PI : ang; } double angle(pt a, pt b, pt o) { return angle(b - o, a - o); } // Theta in radiens pt rotate(pt a, double theta) { return a * polar(1.0, theta); } Line ptToLine(pt p1, pt p2) { if (abs(real(p1) - real(p2)) < EPS) { return {1.0, 0.0, -real(p1)}; } else { double a = -(imag(p1) - imag(p2)) / (real(p1) - real(p2)), c = -(a * real(p1)) - imag(p2); return {a, 1.0, c}; } } bool areParallel(Line l1, Line l2) { return abs(l1.a - l2.a) < EPS && abs(l1.b - l2.b) < EPS; } bool areSame(Line l1, Line l2) { return areParallel(l1, l2) && abs(l1.c - l2.c) < EPS; } pt intersectPt(Line l1, Line l2) { // Does not handle if same or parrallel if (areParallel(l1, l2)) return pt(-INF, -INF); double x = (l2.b * l1.c - l1.b * l2.c) / (l2.a * l1.b - l1.a * l2.b); double y; if (abs(l1.b) < EPS) y = -(l1.a * x + l1.c); else y = -(l2.a * x + l2.c); return pt(x, y); } double distToLine(pt p, pt a, pt b, bool segment = false) { pt ap = p - a, ab = b - a; double u = dot(ap, ab) / (abs(ab) * abs(ab)); if (segment) { if (u < 0.0) return abs(p - a); // a is closest if (u > 1.0) return abs(p - b); // b is closest } return abs(p - a - ab * u); // closest is in segment. } // careful with inputs for n < 2 vector<pt> convexHull(vector<pt> &pts) { int n = SZ(pts); sort(ALL(pts), [](pt a, pt b) { return mp(a.xx, a.yy) < mp(b.xx, b.yy); }); vector<pt> up, down; up.eb(pts[0]); down.eb(pts[0]); FOR(i, 1, n) { if (i == n - 1 || ccw(pts[0], pts[n - 1], pts[i])) { while (SZ(up) > 1 && ccw(up[SZ(up) - 2], up[SZ(up) - 1], pts[i])) up.pop_back(); up.eb(pts[i]); } if (i == n - 1 || cw(pts[0], pts[n - 1], pts[i])) { while (SZ(down) > 1 && cw(down[SZ(down) - 2], down[SZ(down) - 1], pts[i])) down.pop_back(); down.eb(pts[i]); } } vector<pt> ans(up); ans.insert(ans.end(), 1 + RALL(down)); return ans; } ll dist(pt a, pt b) { return abs(a.xx - b.xx) + abs(a.yy - b.yy); } ll findForInd(int i, vector<pt> &hull) { int l = 0; int r = SZ(hull) - 2; dout << "Startign for ind " << i << ", pt=" << hull[i] << endl; int x = 0; while (l < r) { int m1 = l + (r - l) / 3; int m2 = r - (r - l) / 3; pt elem1 = hull[(i + 1 + m1) % SZ(hull)]; pt elem2 = hull[(i + 1 + m2) % SZ(hull)]; ll d1 = dist(hull[i], elem1); ll d2 = dist(hull[i], elem2); dout << dvar(l, r, m1, m2, elem1, elem2) << endl; assert(++x < 10); if (d1 < d2) { l = m1 + 1; } else { r = m2 - 1; } } return dist(hull[i], hull[(i + 1 + l) % SZ(hull)]); } void solve() { int n; cin >> n; set<ii> seen; vector<pt> pts; F0R(i, n) { int x, y; cin >> x >> y; if (!seen.count(mp(x, y))) { seen.emplace(x, y); pts.eb(x, y); } } if (SZ(pts) < 2) { cout << 0 << endl; return; } vector<pt> hull = convexHull(pts); hull.pop_back(); dout << dvar(hull) << endl; ll res = 0; F0R(i, SZ(hull)) { ll r = findForInd(i, hull); dout << dvar(i, r) << endl; ckmax(res, r); } cout << res << endl; } int main() { cin.tie(0); ios_base::sync_with_stdio(0); int tc = 1; FOR(i, 1, tc + 1) { // cout << "Case #" << i << ": "; solve(); } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; typedef vector<vi> vvi; typedef vector<vii> vvii; #define fi first #define se second #define ALL(x) (x).begin(), (x).end() #define RALL(x) (x).rbegin(), (x).rend() #define eb emplace_back #define pb push_back #define mp make_pair #define mt make_tuple #define SZ(x) (int)(x).size() #define endl '\n' #define FOR(a, b, c) for (auto a = (b); (a) < (c); ++(a)) #define F0R(a, b) FOR(a, 0, (b)) #define CEIL(a, b) ((a) + (b)-1) / (b) template <class T> bool ckmin(T &a, const T &b) { return a > b ? a = b, true : false; } template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, true : false; } #ifndef DEBUG #define DEBUG 0 #endif #define dout \ if (DEBUG) \ std::cerr #define dvar(...) " [" << #__VA_ARGS__ ": " << mt(__VA_ARGS__) << "] " template <typename T> struct IsC { template <typename C> static char test(typename C::const_iterator *); template <typename C> static int test(...); static const bool value = sizeof(test<T>(0)) == sizeof(char); }; template <> struct IsC<string> { static const bool value = false; }; template <typename C> typename enable_if<IsC<C>::value, ostream &>::type operator<<(ostream &, const C &); template <typename T1, typename T2> ostream &operator<<(ostream &, const pair<T1, T2> &); template <typename... T> using TS = tuple_size<tuple<T...>>; template <size_t idx, typename... T> typename enable_if<TS<T...>::value == idx + 1, ostream &>::type operator<<(ostream &o, const tuple<T...> &t) { return o << ", " << get<idx>(t) << ')'; } template <size_t idx, typename... T> typename enable_if<0 < idx && idx + 1 < TS<T...>::value, ostream &>::type operator<<(ostream &o, const tuple<T...> &t) { return operator<< <idx + 1>(o << ", " << get<idx>(t), t); } template <size_t idx = 0, typename... T> typename enable_if<1 < TS<T...>::value && !idx, ostream &>::type operator<<(ostream &o, const tuple<T...> &t) { return operator<< <idx + 1>(o << '(' << get<idx>(t), t); } template <typename T> ostream &operator<<(ostream &o, const tuple<T> &t) { return o << get<0>(t); } template <typename T1, typename T2> ostream &operator<<(ostream &o, const pair<T1, T2> &p) { return o << mt(p.fi, p.se); } template <typename C> typename enable_if<IsC<C>::value, ostream &>::type operator<<(ostream &o, const C &c) { o << '['; for (auto it = c.cbegin(); it != c.cend(); ++it) o << *it << (next(it) != c.cend() ? ", " : ""); return o << ']'; } template <typename T> void tprint(vector<vector<T>> &v, size_t width = 0, ostream &o = cerr) { if (!DEBUG) return; for (const auto &vv : v) { for (const auto &i : vv) o << setw(width) << i; o << endl; } } #define xx real() #define yy imag() const double EPS = 1e-9; const double INF = numeric_limits<double>::max(); using pt = complex<double>; struct Line { double a, b, c; }; // ax + by + c = 0 double dot(pt a, pt b) { return a.xx * b.xx + a.yy * b.yy; } double cross(pt a, pt b) { return a.xx * b.yy - a.yy * b.xx; } double dir(pt a, pt b, pt c) { return cross(b - a, c - a); } bool cw(pt a, pt b, pt c) { return dir(a, b, c) < 0; } bool ccw(pt a, pt b, pt c) { return dir(a, b, c) > 0; } bool collinear(pt a, pt b, pt c) { return abs(dir(a, b, c)) < EPS; } // Angle between a and b with o as origin (ccw). // Return value in [0, 2PI) double angle(pt a, pt b) { double ang = arg(a) - arg(b); return ang < 0 ? ang + 2 * M_PI : ang; } double angle(pt a, pt b, pt o) { return angle(b - o, a - o); } // Theta in radiens pt rotate(pt a, double theta) { return a * polar(1.0, theta); } Line ptToLine(pt p1, pt p2) { if (abs(real(p1) - real(p2)) < EPS) { return {1.0, 0.0, -real(p1)}; } else { double a = -(imag(p1) - imag(p2)) / (real(p1) - real(p2)), c = -(a * real(p1)) - imag(p2); return {a, 1.0, c}; } } bool areParallel(Line l1, Line l2) { return abs(l1.a - l2.a) < EPS && abs(l1.b - l2.b) < EPS; } bool areSame(Line l1, Line l2) { return areParallel(l1, l2) && abs(l1.c - l2.c) < EPS; } pt intersectPt(Line l1, Line l2) { // Does not handle if same or parrallel if (areParallel(l1, l2)) return pt(-INF, -INF); double x = (l2.b * l1.c - l1.b * l2.c) / (l2.a * l1.b - l1.a * l2.b); double y; if (abs(l1.b) < EPS) y = -(l1.a * x + l1.c); else y = -(l2.a * x + l2.c); return pt(x, y); } double distToLine(pt p, pt a, pt b, bool segment = false) { pt ap = p - a, ab = b - a; double u = dot(ap, ab) / (abs(ab) * abs(ab)); if (segment) { if (u < 0.0) return abs(p - a); // a is closest if (u > 1.0) return abs(p - b); // b is closest } return abs(p - a - ab * u); // closest is in segment. } // careful with inputs for n < 2 vector<pt> convexHull(vector<pt> &pts) { int n = SZ(pts); sort(ALL(pts), [](pt a, pt b) { return mp(a.xx, a.yy) < mp(b.xx, b.yy); }); vector<pt> up, down; up.eb(pts[0]); down.eb(pts[0]); FOR(i, 1, n) { if (i == n - 1 || ccw(pts[0], pts[n - 1], pts[i])) { while (SZ(up) > 1 && ccw(up[SZ(up) - 2], up[SZ(up) - 1], pts[i])) up.pop_back(); up.eb(pts[i]); } if (i == n - 1 || cw(pts[0], pts[n - 1], pts[i])) { while (SZ(down) > 1 && cw(down[SZ(down) - 2], down[SZ(down) - 1], pts[i])) down.pop_back(); down.eb(pts[i]); } } vector<pt> ans(up); ans.insert(ans.end(), 1 + RALL(down)); return ans; } ll dist(pt a, pt b) { return abs(a.xx - b.xx) + abs(a.yy - b.yy); } ll findForInd(int i, vector<pt> &hull) { int l = 0; int r = SZ(hull) - 2; dout << "Startign for ind " << i << ", pt=" << hull[i] << endl; int x = 0; while (l < r) { int m1 = l + (r - l) / 3; int m2 = r - (r - l) / 3; pt elem1 = hull[(i + 1 + m1) % SZ(hull)]; pt elem2 = hull[(i + 1 + m2) % SZ(hull)]; ll d1 = dist(hull[i], elem1); ll d2 = dist(hull[i], elem2); dout << dvar(l, r, m1, m2, elem1, elem2) << endl; if (d1 < d2) { l = m1 + 1; } else { r = m2 - 1; } } return dist(hull[i], hull[(i + 1 + l) % SZ(hull)]); } void solve() { int n; cin >> n; set<ii> seen; vector<pt> pts; F0R(i, n) { int x, y; cin >> x >> y; if (!seen.count(mp(x, y))) { seen.emplace(x, y); pts.eb(x, y); } } if (SZ(pts) < 2) { cout << 0 << endl; return; } vector<pt> hull = convexHull(pts); hull.pop_back(); dout << dvar(hull) << endl; ll res = 0; F0R(i, SZ(hull)) { ll r = findForInd(i, hull); dout << dvar(i, r) << endl; ckmax(res, r); } cout << res << endl; } int main() { cin.tie(0); ios_base::sync_with_stdio(0); int tc = 1; FOR(i, 1, tc + 1) { // cout << "Case #" << i << ": "; solve(); } }
delete
190
191
190
190
0
p02556
C++
Runtime Error
#include <cstdio> #ifdef _MSC_VER #define GC getchar #else #define GC getchar_unlocked #endif int input() { int x = 0; char c; bool minus = false; for (;;) { c = GC(); if (c == '-') { minus = true; continue; } if (c == ' ' || c == '\n') if (minus) return -x; else return x; x = 10 * x + c - '0'; } } void fix() { char c; for (;;) { c = GC(); if (c == -1 || c != ' ' && c != '\n') break; } if (c != -1) ungetc(c, stdin); } int main() { int N, i, j, k, d; int a[6]; int m[32]; int M[32]; for (i = 0; i < 32; i++) { m[i] = 1000000000; M[i] = -1000000000; } scanf("%d %d", &N, &d); fix(); for (i = 0; i < N; i++) { for (j = 0; j < d; j++) a[j] = input(); //,fix(); for (j = 0; j < 1 << (d - 1); j++) { int x = a[0]; for (k = 0; k < d - 1; k++) if (j & (1 << k)) x += a[k + 1]; else x -= a[k + 1]; if (m[j] > x) m[j] = x; if (M[j] < x) M[j] = x; } } int ans = 0; for (i = 0; i < 1 << (d - 1); i++) if (ans < M[i] - m[i]) ans = M[i] - m[i]; printf("%d\n", ans); return 0; }
#include <cstdio> #ifdef _MSC_VER #define GC getchar #else #define GC getchar_unlocked #endif int input() { int x = 0; char c; bool minus = false; for (;;) { c = GC(); if (c == '-') { minus = true; continue; } if (c == ' ' || c == '\n') if (minus) return -x; else return x; x = 10 * x + c - '0'; } } void fix() { char c; for (;;) { c = GC(); if (c == -1 || c != ' ' && c != '\n') break; } if (c != -1) ungetc(c, stdin); } int main() { int N, i, j, k, d; int a[6]; int m[32]; int M[32]; for (i = 0; i < 32; i++) { m[i] = 1000000000; M[i] = -1000000000; } scanf("%d", &N); d = 2; fix(); for (i = 0; i < N; i++) { for (j = 0; j < d; j++) a[j] = input(); //,fix(); for (j = 0; j < 1 << (d - 1); j++) { int x = a[0]; for (k = 0; k < d - 1; k++) if (j & (1 << k)) x += a[k + 1]; else x -= a[k + 1]; if (m[j] > x) m[j] = x; if (M[j] < x) M[j] = x; } } int ans = 0; for (i = 0; i < 1 << (d - 1); i++) if (ans < M[i] - m[i]) ans = M[i] - m[i]; printf("%d\n", ans); return 0; }
replace
43
44
43
45
0
p02556
C++
Runtime Error
#include <bits/stdc++.h> #include <math.h> using namespace std; typedef long long int lli; typedef unsigned long long int uli; typedef long double Lf; typedef pair<int, int> pii; typedef vector<int> vi; #define fastIO \ std::ios::sync_with_stdio(false); \ cin.tie(NULL) #define mod 1000000007 #define N 205 #define NN 2005 #define SZ(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define loop(i, s, n) for (int i = (s); i < (n); i++) #define loopr(i, n, s) for (int i = (n)-1; i >= (s); i--) #define pb push_back #define o2(a, b) cout << (a) << " " << (b) << endl #define o3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl #define o4(a, b, c, d) \ cout << (a) << " " << (b) << " " << (c) << " " << (d) << endl #define cl cout << endl #define r0 return 0 #define e0 exit(0) #define x first #define y second inline lli modadd(lli n, lli m, lli p = mod) { return ((n + m) % p + p) % p; } inline lli modsub(lli n, lli m, lli p = mod) { return ((n - m + p) % p + p) % p; } inline lli modpro(lli n, lli m, lli p = mod) { return (((n % p) * (m % p)) % p + p) % p; } uli powe(lli x, lli y) { uli res = 1; while (y > 0) { if (y & 1) res = res * x; y = y >> 1; x = x * x; } return res; } lli modpow(lli x, lli y, lli p = mod) { lli res = 1; while (y > 0) { if (y & 1) res = modpro(res, x, p); y = y >> 1; x = modpro(x, x, p); } return res; } inline lli modInverse(lli n, lli p = mod) { if (n == 1) return 1; return modpow(n, p - 2, p); } inline lli moddiv(lli n, lli m, lli p = mod) { return modpro(n, modInverse(m, p), p); } inline lli modadd3(lli x, lli y, lli z, lli p = mod) { return modadd(modadd(x, y, p), z, p); } inline lli modadd4(lli x, lli y, lli z, lli w, lli p = mod) { return modadd(modadd(x, y, p), modadd(z, w, p), p); } inline lli modnCr(lli fac[], int n, int r, lli p = mod) { if (r == 0) return 1; return modpro(fac[n], modInverse(modpro(fac[r], fac[n - r], p), p), p); } template <typename T> void printArr(T *arr, int s, int n) { for (int i = s; i <= n; i++) { cout << arr[i] << " "; } cout << endl; } // template<class X, class Y, class Z> // struct triple { // X x; // Y y; // Z z; // // friend bool operator<(triple a, triple b) // { // if(a.x!=b.x) return a.x<b.x; // else if(a.y!=b.y) return a.y<b.y; // else return a.z<=b.z; // } // }; // // // template<class X, class Y, class Z, class W> // class quad { // public: // X x; // Y y; // Z z; // W w; // // friend bool operator<(quad a, quad b) // { // if(a.x!=b.x) return a.x<b.x; // else if(a.y!=b.y) return a.y<b.y; // else if(a.z!=b.z)return a.z<b.z; // else return a.w<b.w; // } // }; // // uli choose(uli n, uli k){ // uli res = 1; // // // Since C(n, k) = C(n, n-k) // if ( k > n - k ) // k = n - k; // // // Calculate value of // // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1] // for (uli i = 0; i < k; ++i) // { // res *= (n - i); // res /= (i + 1); // } // // return res; //} // // // vector<vector<pii>> adj; // //vector<int> dist; // vector<int> d; //// vector<bool> visited; //// vector<int> pa; // //queue<int> q; // // class Graph{ // // public: // int V; // // Graph(int V){ // this->V = V; // adj.resize(V); //// visited.resize(V); // //color.resize(V); // //dist.resize(V); // d.resize(V); // //// dist.resize(V); //// pa.resize(V); // // } // // ~Graph(){ // adj.clear(); // //visited.clear(); // // color.clear(); // // dist.clear(); //// pa.clear(); // //dist.clear(); //// visited.clear(); // d.clear(); // // // } // // // void addEdge(int a, int b) // { // adj[a].pb(b); // adj[b].pb(a); // //adj[b].pb({a,in}); // } // // // void dfs(int x){ // // // color[x]=1; // // visited[x]=1; // // for(auto u: adj[x]){ // // if(visited[u]) continue; // // // // dfs(u); // // } // // // // } // // // // // // // // // // // // void dfsTree(int x, int p){ // // for(auto u: adj[x]){ // // if(u==p) {continue;} // // dfsTree(u,x); // // } // // } // // // void dijkstra(int s) { // d.assign(n, INF); // d[s] = 0; // set<pair<int, int>> q; // q.insert({0, s}); // while (!q.empty()) { // int v = q.begin()->second; // q.erase(q.begin()); // for (auto edge : adj[v]) { // int to = edge.first; // int len = edge.second; // if (d[v] + len < d[to]) { // q.erase({d[to], to}); // d[to] = d[v] + len; // q.insert({d[to], to}); // } // } // } // } // // //// void bfs(int x){ //// queue<int> q; //// visited[x]=1; //// q.push(x); //// //dist[x]=0; //// while(!q.empty()){ //// int s = q.front(); //// q.pop(); //// //// for(auto u : adj[s]){ //// //// if(visited[u]) continue; //// pa[u]=s; //// visited[u]=1; //// //dist[u.x]=dist[s]+1; //// q.push(u); //// } //// } //// } // // //pair<int,int> farthest(int start){ // // vector<int> dist(V,INT_MAX); // // // // q.push(start); // // dist[start]=0; // // while(!q.empty()){ // // int u = q.front(); // // q.pop(); // // for(int child: adj[u]){ // // //if(keep[child]) // // if(dist[child] > dist[u]+1) { // // dist[child] = dist[u]+1; // // q.push(child); // // } // // } // // } // // int big=-1,mi=-1; // // for(int i=1;i<n+1;i++){ // // //if(keep[i]) // // { // // if(dist[i]>big){ // // big=dist[i];mi=i; // // } // // } // // } // // return make_pair(big,mi); // //} // // // // int connectedcomponents(int n){ // // int ans=0; // // loop(i,1,n+1){ // // if(!visited[i]){ // // ans++; // // dfs(i); // // } // // // // } // // return ans; // // } // // }; // template <typename T> // T findpowerfactorial(T n,T p) //{ // T x = 0; // while (n) // { // n /= p; // x += n; // } // return x; // } // // vector<pair<lli,int>> v; // void primeFactors(lli n) //{ // v.clear(); // int c=0; // while (n % 2 == 0) // { // n = n/2; // c++; // } // if(c>0) v.pb({2,c}); // // // for (lli i = 3; i*i <= n; i = i + 2) // { c=0; // // while (n % i == 0) // { // n = n/i; // c++; // } // if(c>0)v.pb({i,c}); // // } // if (n > 2) // v.pb({n,1}); // } // lli fac_[N]; // void fac_init(int n){ // fac_[0]=1; // loop(i,1,n+1)fac_[i]=modpro(fac_[i-1],i); // } // /*BITMASK for( int inum = 0 ; inum < ( 1 << n ) ; ++ inum ) { for ( int pos = 0; pos < n ; ++pos ) { if ( inum & ( 1 << pos ) ){ results[inum] += s [pos] ; //DO SOMETHING } } } */ lli a[N][2], mx[4], mn[4]; int main() { // fastIO; int erer = 1; // cin>>erer; loop(erer2, 1, erer + 1) { int n; cin >> n; loop(i, 0, n) loop(j, 0, 2) cin >> a[i][j]; loop(i, 0, 4) mx[i] = INT_MIN, mn[i] = INT_MAX; loop(i, 0, n) { loop(j, 0, 4) { lli temp = 0; loop(k, 0, 2) { if (j & (1 << k)) temp += a[i][k]; else temp -= a[i][k]; } mx[j] = max(mx[j], temp); mn[j] = min(mn[j], temp); } } lli big = -1; loop(i, 0, 4) big = max(big, mx[i] - mn[i]); cout << big << endl; } return 0; }
#include <bits/stdc++.h> #include <math.h> using namespace std; typedef long long int lli; typedef unsigned long long int uli; typedef long double Lf; typedef pair<int, int> pii; typedef vector<int> vi; #define fastIO \ std::ios::sync_with_stdio(false); \ cin.tie(NULL) #define mod 1000000007 #define N 200005 #define NN 2005 #define SZ(x) ((int)(x).size()) #define all(x) (x).begin(), (x).end() #define loop(i, s, n) for (int i = (s); i < (n); i++) #define loopr(i, n, s) for (int i = (n)-1; i >= (s); i--) #define pb push_back #define o2(a, b) cout << (a) << " " << (b) << endl #define o3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl #define o4(a, b, c, d) \ cout << (a) << " " << (b) << " " << (c) << " " << (d) << endl #define cl cout << endl #define r0 return 0 #define e0 exit(0) #define x first #define y second inline lli modadd(lli n, lli m, lli p = mod) { return ((n + m) % p + p) % p; } inline lli modsub(lli n, lli m, lli p = mod) { return ((n - m + p) % p + p) % p; } inline lli modpro(lli n, lli m, lli p = mod) { return (((n % p) * (m % p)) % p + p) % p; } uli powe(lli x, lli y) { uli res = 1; while (y > 0) { if (y & 1) res = res * x; y = y >> 1; x = x * x; } return res; } lli modpow(lli x, lli y, lli p = mod) { lli res = 1; while (y > 0) { if (y & 1) res = modpro(res, x, p); y = y >> 1; x = modpro(x, x, p); } return res; } inline lli modInverse(lli n, lli p = mod) { if (n == 1) return 1; return modpow(n, p - 2, p); } inline lli moddiv(lli n, lli m, lli p = mod) { return modpro(n, modInverse(m, p), p); } inline lli modadd3(lli x, lli y, lli z, lli p = mod) { return modadd(modadd(x, y, p), z, p); } inline lli modadd4(lli x, lli y, lli z, lli w, lli p = mod) { return modadd(modadd(x, y, p), modadd(z, w, p), p); } inline lli modnCr(lli fac[], int n, int r, lli p = mod) { if (r == 0) return 1; return modpro(fac[n], modInverse(modpro(fac[r], fac[n - r], p), p), p); } template <typename T> void printArr(T *arr, int s, int n) { for (int i = s; i <= n; i++) { cout << arr[i] << " "; } cout << endl; } // template<class X, class Y, class Z> // struct triple { // X x; // Y y; // Z z; // // friend bool operator<(triple a, triple b) // { // if(a.x!=b.x) return a.x<b.x; // else if(a.y!=b.y) return a.y<b.y; // else return a.z<=b.z; // } // }; // // // template<class X, class Y, class Z, class W> // class quad { // public: // X x; // Y y; // Z z; // W w; // // friend bool operator<(quad a, quad b) // { // if(a.x!=b.x) return a.x<b.x; // else if(a.y!=b.y) return a.y<b.y; // else if(a.z!=b.z)return a.z<b.z; // else return a.w<b.w; // } // }; // // uli choose(uli n, uli k){ // uli res = 1; // // // Since C(n, k) = C(n, n-k) // if ( k > n - k ) // k = n - k; // // // Calculate value of // // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1] // for (uli i = 0; i < k; ++i) // { // res *= (n - i); // res /= (i + 1); // } // // return res; //} // // // vector<vector<pii>> adj; // //vector<int> dist; // vector<int> d; //// vector<bool> visited; //// vector<int> pa; // //queue<int> q; // // class Graph{ // // public: // int V; // // Graph(int V){ // this->V = V; // adj.resize(V); //// visited.resize(V); // //color.resize(V); // //dist.resize(V); // d.resize(V); // //// dist.resize(V); //// pa.resize(V); // // } // // ~Graph(){ // adj.clear(); // //visited.clear(); // // color.clear(); // // dist.clear(); //// pa.clear(); // //dist.clear(); //// visited.clear(); // d.clear(); // // // } // // // void addEdge(int a, int b) // { // adj[a].pb(b); // adj[b].pb(a); // //adj[b].pb({a,in}); // } // // // void dfs(int x){ // // // color[x]=1; // // visited[x]=1; // // for(auto u: adj[x]){ // // if(visited[u]) continue; // // // // dfs(u); // // } // // // // } // // // // // // // // // // // // void dfsTree(int x, int p){ // // for(auto u: adj[x]){ // // if(u==p) {continue;} // // dfsTree(u,x); // // } // // } // // // void dijkstra(int s) { // d.assign(n, INF); // d[s] = 0; // set<pair<int, int>> q; // q.insert({0, s}); // while (!q.empty()) { // int v = q.begin()->second; // q.erase(q.begin()); // for (auto edge : adj[v]) { // int to = edge.first; // int len = edge.second; // if (d[v] + len < d[to]) { // q.erase({d[to], to}); // d[to] = d[v] + len; // q.insert({d[to], to}); // } // } // } // } // // //// void bfs(int x){ //// queue<int> q; //// visited[x]=1; //// q.push(x); //// //dist[x]=0; //// while(!q.empty()){ //// int s = q.front(); //// q.pop(); //// //// for(auto u : adj[s]){ //// //// if(visited[u]) continue; //// pa[u]=s; //// visited[u]=1; //// //dist[u.x]=dist[s]+1; //// q.push(u); //// } //// } //// } // // //pair<int,int> farthest(int start){ // // vector<int> dist(V,INT_MAX); // // // // q.push(start); // // dist[start]=0; // // while(!q.empty()){ // // int u = q.front(); // // q.pop(); // // for(int child: adj[u]){ // // //if(keep[child]) // // if(dist[child] > dist[u]+1) { // // dist[child] = dist[u]+1; // // q.push(child); // // } // // } // // } // // int big=-1,mi=-1; // // for(int i=1;i<n+1;i++){ // // //if(keep[i]) // // { // // if(dist[i]>big){ // // big=dist[i];mi=i; // // } // // } // // } // // return make_pair(big,mi); // //} // // // // int connectedcomponents(int n){ // // int ans=0; // // loop(i,1,n+1){ // // if(!visited[i]){ // // ans++; // // dfs(i); // // } // // // // } // // return ans; // // } // // }; // template <typename T> // T findpowerfactorial(T n,T p) //{ // T x = 0; // while (n) // { // n /= p; // x += n; // } // return x; // } // // vector<pair<lli,int>> v; // void primeFactors(lli n) //{ // v.clear(); // int c=0; // while (n % 2 == 0) // { // n = n/2; // c++; // } // if(c>0) v.pb({2,c}); // // // for (lli i = 3; i*i <= n; i = i + 2) // { c=0; // // while (n % i == 0) // { // n = n/i; // c++; // } // if(c>0)v.pb({i,c}); // // } // if (n > 2) // v.pb({n,1}); // } // lli fac_[N]; // void fac_init(int n){ // fac_[0]=1; // loop(i,1,n+1)fac_[i]=modpro(fac_[i-1],i); // } // /*BITMASK for( int inum = 0 ; inum < ( 1 << n ) ; ++ inum ) { for ( int pos = 0; pos < n ; ++pos ) { if ( inum & ( 1 << pos ) ){ results[inum] += s [pos] ; //DO SOMETHING } } } */ lli a[N][2], mx[4], mn[4]; int main() { // fastIO; int erer = 1; // cin>>erer; loop(erer2, 1, erer + 1) { int n; cin >> n; loop(i, 0, n) loop(j, 0, 2) cin >> a[i][j]; loop(i, 0, 4) mx[i] = INT_MIN, mn[i] = INT_MAX; loop(i, 0, n) { loop(j, 0, 4) { lli temp = 0; loop(k, 0, 2) { if (j & (1 << k)) temp += a[i][k]; else temp -= a[i][k]; } mx[j] = max(mx[j], temp); mn[j] = min(mn[j], temp); } } lli big = -1; loop(i, 0, 4) big = max(big, mx[i] - mn[i]); cout << big << endl; } return 0; }
replace
12
13
12
13
0
p02557
C++
Runtime Error
/////////////////////////////////////////////////////////////////////////////// #include <bits/stdc++.h> #include <sys/time.h> #include <time.h> #include <unistd.h> using namespace std; /////////////////////////////////////////////////////////////////////////////// #define DEBUG 0 #define pb push_back #define V vector #define M unordered_map #define S static #define rep(i, n) for (ll i = 0LL; i < n; ++i) #define srep(i, s, n) for (ll i = s; i < n; ++i) #define rrep(i, n) for (ll i = n - 1LL; i >= 0LL; --i) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define CIN(x) \ do { \ assert(!cin.eof()); \ cin >> x; \ assert(!cin.fail()); \ } while (0); #if DEBUG #define debug_print(...) _debug_print(__VA_ARGS__) #define debug_printf(...) printf(__VA_ARGS__) #define debug_print_time _debug_print_time #else // DEBUG #define debug_print(...) #define debug_printf(...) #define debug_print_time #endif // DEBUG typedef long long ll; typedef unsigned long long ull; typedef tuple<ll, ll> t2; typedef tuple<ll, ll, ll> t3; typedef tuple<ll, ll, ll, ll> t4; typedef tuple<ll, ll, ll, ll, ll> t5; template <typename T> using priority_queue_incr = priority_queue<T, V<T>, greater<T>>; /////////////////////////////////////////////////////////////////////////////// template <typename TT, typename T> T get_m(M<TT, T> &m, TT k, T default_value) { if (m.find(k) == m.end()) return m[k] = default_value; return m[k]; } template <typename TT, typename T> void incr_m(M<TT, T> &m, TT k) { if (m.find(k) == m.end()) m[k] = 0; m[k]++; } template <typename TT, typename T> void incr_m(map<TT, T> &m, TT k) { if (m.find(k) == m.end()) m[k] = 0; m[k]++; } void llin(ll &a) { CIN(a); } void llinl1(V<ll> &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a; CIN(a); v.push_back(a); } } void llinl2(V<t2> &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a, b; CIN(a >> b); v.push_back(t2(a, b)); } } void llinl3(V<t3> &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a, b, c; CIN(a >> b >> c); v.push_back(t3(a, b, c)); } } void llinl4(V<t4> &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a, b, c, d; CIN(a >> b >> c >> d); v.push_back(t4(a, b, c, d)); } } void llina(V<ll> &v, ll count) { llinl1(v, count); } template <typename T> void sort(V<T> &v) { sort(v.begin(), v.end()); } template <typename T> void sort_reverse(V<T> &v) { sort(v.begin(), v.end(), greater<T>()); } template <typename T> void _debug_print(T x) { cout << x << endl; } void _debug_print(const t2 &x) { ll x1 = get<0>(x); ll x2 = get<1>(x); cout << "-- " << x1 << " -- " << x2 << endl; } void _debug_print(const t3 &x) { ll x1 = get<0>(x); ll x2 = get<1>(x); ll x3 = get<2>(x); cout << "-- " << x1 << " -- " << x2 << " -- " << x3 << endl; } void _debug_print(const t4 &x) { ll x1 = get<0>(x); ll x2 = get<1>(x); ll x3 = get<2>(x); ll x4 = get<3>(x); cout << "-- " << x1 << " -- " << x2 << " -- " << x3 << " -- " << x4 << endl; } template <typename T> void _debug_print(T xarray[], ll n) { rep(i, n) _debug_print(xarray[i]); } template <typename T> void _debug_print(const V<T> &xlist) { for (auto x : xlist) { cout << "-- "; _debug_print(x); } } template <typename T> void _debug_print(const set<T> &xset) { for (auto x : xset) { cout << "-- "; _debug_print(x); } } template <typename TT, typename T> void _debug_print(const M<TT, T> &xlist) { for (auto x : xlist) { TT k = x.first; T v = x.second; cout << "====" << endl; cout << "K="; _debug_print(k); cout << "V="; _debug_print(v); } } template <typename TT, typename T> void _debug_print(const map<TT, T> &xlist) { for (auto x : xlist) { TT k = x.first; T v = x.second; cout << "====" << endl; cout << "K="; _debug_print(k); cout << "V="; _debug_print(v); } } void _debug_print_time(const char *prefix) { struct timeval tv; gettimeofday(&tv, NULL); #if DEBUG struct tm *tm = localtime(&tv.tv_sec); #endif debug_printf("-- %s %02d:%02d:%02d.%06ld\n", prefix, tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec); } /////////////////////////////////////////////////////////////////////////////// void _main(); int main() { cout << setprecision(12); #if !DEBUG ios::sync_with_stdio(false); cin.tie(0); #endif _main(); return 0; } void _main() { ll n; llin(n); S V<ll> alist; llina(alist, n); S V<ll> blist; llina(blist, n); S ll cnts_a[200005] = {}; S ll cnts_b[200005] = {}; for (auto a : alist) cnts_a[a]++; for (auto b : blist) cnts_b[b]++; rep(i, n + 1) { if (cnts_a[i] + cnts_b[i] > n) { cout << "No" << endl; return; } } cout << "Yes" << endl; set<t2> bset; rep(i, n) bset.insert(t2(blist[i], i)); V<ll> anslist; rep(i, n) { ll a = alist[i]; auto iter = bset.upper_bound(t2(a, 1e18)); if (iter == bset.end()) iter = bset.begin(); ll b = get<0>(*iter); if (a == b) break; anslist.pb(b); bset.erase(iter); } if (anslist.size() == n) { for (auto ans : anslist) cout << ans << " "; cout << endl; return; } ll bmax = -1e18; for (auto b : blist) bmax = max(bmax, b); anslist.clear(); rep(i, cnts_b[bmax]) anslist.pb(bmax); bset.clear(); rep(i, n) if (blist[i] != bmax) bset.insert(t2(blist[i], i)); srep(i, cnts_b[bmax], n) { ll a = alist[i]; auto iter = bset.upper_bound(t2(a, 1e18)); if (iter == bset.end()) iter = bset.begin(); ll b = get<0>(*iter); if (a == b) break; anslist.pb(b); bset.erase(iter); } if (anslist.size() == n) { for (auto ans : anslist) cout << ans << " "; cout << endl; return; } assert(false); } ///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////// #include <bits/stdc++.h> #include <sys/time.h> #include <time.h> #include <unistd.h> using namespace std; /////////////////////////////////////////////////////////////////////////////// #define DEBUG 0 #define pb push_back #define V vector #define M unordered_map #define S static #define rep(i, n) for (ll i = 0LL; i < n; ++i) #define srep(i, s, n) for (ll i = s; i < n; ++i) #define rrep(i, n) for (ll i = n - 1LL; i >= 0LL; --i) #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define CIN(x) \ do { \ assert(!cin.eof()); \ cin >> x; \ assert(!cin.fail()); \ } while (0); #if DEBUG #define debug_print(...) _debug_print(__VA_ARGS__) #define debug_printf(...) printf(__VA_ARGS__) #define debug_print_time _debug_print_time #else // DEBUG #define debug_print(...) #define debug_printf(...) #define debug_print_time #endif // DEBUG typedef long long ll; typedef unsigned long long ull; typedef tuple<ll, ll> t2; typedef tuple<ll, ll, ll> t3; typedef tuple<ll, ll, ll, ll> t4; typedef tuple<ll, ll, ll, ll, ll> t5; template <typename T> using priority_queue_incr = priority_queue<T, V<T>, greater<T>>; /////////////////////////////////////////////////////////////////////////////// template <typename TT, typename T> T get_m(M<TT, T> &m, TT k, T default_value) { if (m.find(k) == m.end()) return m[k] = default_value; return m[k]; } template <typename TT, typename T> void incr_m(M<TT, T> &m, TT k) { if (m.find(k) == m.end()) m[k] = 0; m[k]++; } template <typename TT, typename T> void incr_m(map<TT, T> &m, TT k) { if (m.find(k) == m.end()) m[k] = 0; m[k]++; } void llin(ll &a) { CIN(a); } void llinl1(V<ll> &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a; CIN(a); v.push_back(a); } } void llinl2(V<t2> &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a, b; CIN(a >> b); v.push_back(t2(a, b)); } } void llinl3(V<t3> &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a, b, c; CIN(a >> b >> c); v.push_back(t3(a, b, c)); } } void llinl4(V<t4> &v, ll count) { for (ll i = 0LL; i < count; ++i) { ll a, b, c, d; CIN(a >> b >> c >> d); v.push_back(t4(a, b, c, d)); } } void llina(V<ll> &v, ll count) { llinl1(v, count); } template <typename T> void sort(V<T> &v) { sort(v.begin(), v.end()); } template <typename T> void sort_reverse(V<T> &v) { sort(v.begin(), v.end(), greater<T>()); } template <typename T> void _debug_print(T x) { cout << x << endl; } void _debug_print(const t2 &x) { ll x1 = get<0>(x); ll x2 = get<1>(x); cout << "-- " << x1 << " -- " << x2 << endl; } void _debug_print(const t3 &x) { ll x1 = get<0>(x); ll x2 = get<1>(x); ll x3 = get<2>(x); cout << "-- " << x1 << " -- " << x2 << " -- " << x3 << endl; } void _debug_print(const t4 &x) { ll x1 = get<0>(x); ll x2 = get<1>(x); ll x3 = get<2>(x); ll x4 = get<3>(x); cout << "-- " << x1 << " -- " << x2 << " -- " << x3 << " -- " << x4 << endl; } template <typename T> void _debug_print(T xarray[], ll n) { rep(i, n) _debug_print(xarray[i]); } template <typename T> void _debug_print(const V<T> &xlist) { for (auto x : xlist) { cout << "-- "; _debug_print(x); } } template <typename T> void _debug_print(const set<T> &xset) { for (auto x : xset) { cout << "-- "; _debug_print(x); } } template <typename TT, typename T> void _debug_print(const M<TT, T> &xlist) { for (auto x : xlist) { TT k = x.first; T v = x.second; cout << "====" << endl; cout << "K="; _debug_print(k); cout << "V="; _debug_print(v); } } template <typename TT, typename T> void _debug_print(const map<TT, T> &xlist) { for (auto x : xlist) { TT k = x.first; T v = x.second; cout << "====" << endl; cout << "K="; _debug_print(k); cout << "V="; _debug_print(v); } } void _debug_print_time(const char *prefix) { struct timeval tv; gettimeofday(&tv, NULL); #if DEBUG struct tm *tm = localtime(&tv.tv_sec); #endif debug_printf("-- %s %02d:%02d:%02d.%06ld\n", prefix, tm->tm_hour, tm->tm_min, tm->tm_sec, tv.tv_usec); } /////////////////////////////////////////////////////////////////////////////// void _main(); int main() { cout << setprecision(12); #if !DEBUG ios::sync_with_stdio(false); cin.tie(0); #endif _main(); return 0; } void _main() { ll n; llin(n); S V<ll> alist; llina(alist, n); S V<ll> blist; llina(blist, n); S ll cnts_a[200005] = {}; S ll cnts_b[200005] = {}; for (auto a : alist) cnts_a[a]++; for (auto b : blist) cnts_b[b]++; rep(i, n + 1) { if (cnts_a[i] + cnts_b[i] > n) { cout << "No" << endl; return; } } cout << "Yes" << endl; set<t2> bset; rep(i, n) bset.insert(t2(blist[i], i)); V<ll> anslist; rep(i, n) { ll a = alist[i]; auto iter = bset.upper_bound(t2(a, 1e18)); if (iter == bset.end()) iter = bset.begin(); ll b = get<0>(*iter); if (a == b) break; anslist.pb(b); bset.erase(iter); } if (anslist.size() == n) { for (auto ans : anslist) cout << ans << " "; cout << endl; return; } ll bmax = -1e18; for (auto b : blist) bmax = max(bmax, b); anslist.clear(); rep(i, cnts_b[bmax]) anslist.pb(bmax); bset.clear(); rep(i, n) if (blist[i] != bmax) bset.insert(t2(blist[i], i)); srep(i, cnts_b[bmax], n) { ll a = alist[i]; auto iter = bset.upper_bound(t2(a, 1e18)); if (iter == bset.end()) iter = bset.begin(); ll b = get<0>(*iter); if (a == b) break; anslist.pb(b); bset.erase(iter); } if (anslist.size() == n) { for (auto ans : anslist) cout << ans << " "; cout << endl; return; } anslist.clear(); srep(i, n / 2LL, n) { anslist.pb(blist[i]); } bset.clear(); rep(i, n / 2LL) bset.insert(t2(blist[i], i)); srep(i, n / 2LL, n) { ll a = alist[i]; auto iter = bset.upper_bound(t2(a, 1e18)); if (iter == bset.end()) iter = bset.begin(); ll b = get<0>(*iter); if (a == b) break; anslist.pb(b); bset.erase(iter); } if (anslist.size() == n) { for (auto ans : anslist) cout << ans << " "; cout << endl; return; } } ///////////////////////////////////////////////////////////////////////////////
replace
276
280
276
303
0
p02557
C++
Runtime Error
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <string> #include <time.h> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define all(a) a.begin(), a.end() #define rep(i, n) for (ll i = 0; i < (n); i++) #define pb push_back #define debug(x) cerr << __LINE__ << ' ' << #x << ':' << x << '\n' #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> P; typedef complex<ld> com; template <class T> using pque = priority_queue<T, vector<T>, greater<T>>; constexpr int inf = 1000000010; constexpr ll INF = 1000000000000000010; constexpr int mod1e9 = 1000000007; constexpr int mod998 = 998244353; constexpr ld eps = 1e-12; constexpr ld pi = 3.141592653589793238; constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; }; int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}; int dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; void fail() { cout << "-1\n"; exit(0); } template <class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template <class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; } template <class T> istream &operator>>(istream &s, vector<T> &v) { for (auto &e : v) s >> e; return s; } template <class T> ostream &operator<<(ostream &s, const vector<T> &v) { for (auto &e : v) s << e << ' '; return s; } struct fastio { fastio() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); cerr << fixed << setprecision(20); } } fastio_; int main() { int n; cin >> n; vector<int> a(n), b(n), ca(n), cb(n), cnt(n); multiset<int> sta, stb; rep(i, n) { cin >> a[i]; a[i]--; ca[a[i]]++; cnt[a[i]]++; sta.insert(a[i]); } rep(i, n) { cin >> b[i]; b[i]--; cb[b[i]]++; cnt[b[i]]++; stb.insert(b[i]); } multiset<P, greater<P>> st; rep(i, n) st.insert({cnt[i], i}); if ((*st.begin()).first > n) { cout << "No\n"; return 0; } vector<vector<int>> match(n); for (int i = n; i >= 1; i--) { P p = *st.begin(); st.erase(st.find(p)); P q = *st.begin(); st.erase(st.find(q)); if (p.first == i && q.first == i) { match[p.second].pb(q.second); sta.erase(sta.find(p.second)); stb.erase(stb.find(q.second)); cnt[p.second]--; cnt[q.second]--; ca[p.second]--; cb[q.second]--; p.first--; q.first--; st.insert(p); st.insert(q); } else if (p.first == i && ca[p.second] != 0) { int v = *stb.begin(); if (v == p.second) v = *stb.rbegin(); match[p.second].pb(v); st.insert(q); q = {cnt[v], v}; st.erase(st.find(q)); sta.erase(sta.find(p.second)); stb.erase(stb.find(q.second)); cnt[p.second]--; cnt[q.second]--; ca[p.second]--; cb[q.second]--; p.first--; q.first--; st.insert(p); st.insert(q); } else if (p.first == i && cb[p.second] != 0) { int v = *sta.begin(); if (v == p.second) v = *sta.rbegin(); match[v].pb(p.second); st.insert(q); q = {cnt[v], v}; st.erase(st.find(q)); sta.erase(sta.find(q.second)); stb.erase(stb.find(p.second)); cnt[p.second]--; cnt[q.second]--; ca[q.second]--; cb[p.second]--; p.first--; q.first--; st.insert(p); st.insert(q); } else { int v = *sta.begin(); int w = *stb.begin(); if (v == w) w = *stb.rbegin(); st.insert(p); st.insert(q); p = {cnt[v], v}; q = {cnt[w], w}; st.erase(st.find(p)); st.erase(st.find(q)); match[p.second].pb(q.second); sta.erase(sta.find(p.second)); stb.erase(stb.find(q.second)); cnt[p.second]--; cnt[q.second]--; ca[p.second]--; cb[q.second]--; p.first--; q.first--; st.insert(p); st.insert(q); } } cout << "Yes\n"; rep(i, n) { for (int j : match[i]) { cout << j + 1 << ' '; } } cout << '\n'; }
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <string> #include <time.h> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define all(a) a.begin(), a.end() #define rep(i, n) for (ll i = 0; i < (n); i++) #define pb push_back #define debug(x) cerr << __LINE__ << ' ' << #x << ':' << x << '\n' #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef long double ld; typedef pair<ll, ll> P; typedef complex<ld> com; template <class T> using pque = priority_queue<T, vector<T>, greater<T>>; constexpr int inf = 1000000010; constexpr ll INF = 1000000000000000010; constexpr int mod1e9 = 1000000007; constexpr int mod998 = 998244353; constexpr ld eps = 1e-12; constexpr ld pi = 3.141592653589793238; constexpr ll ten(int n) { return n ? 10 * ten(n - 1) : 1; }; int dx[] = {1, 0, -1, 0, 1, 1, -1, -1}; int dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; void fail() { cout << "-1\n"; exit(0); } template <class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; } template <class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; } template <class T> istream &operator>>(istream &s, vector<T> &v) { for (auto &e : v) s >> e; return s; } template <class T> ostream &operator<<(ostream &s, const vector<T> &v) { for (auto &e : v) s << e << ' '; return s; } struct fastio { fastio() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); cerr << fixed << setprecision(20); } } fastio_; int main() { int n; cin >> n; vector<int> a(n), b(n), ca(n), cb(n), cnt(n); multiset<int> sta, stb; rep(i, n) { cin >> a[i]; a[i]--; ca[a[i]]++; cnt[a[i]]++; sta.insert(a[i]); } rep(i, n) { cin >> b[i]; b[i]--; cb[b[i]]++; cnt[b[i]]++; stb.insert(b[i]); } multiset<P, greater<P>> st; rep(i, n) st.insert({cnt[i], i}); if ((*st.begin()).first > n) { cout << "No\n"; return 0; } vector<vector<int>> match(n); for (int i = n; i >= 1; i--) { P p = *st.begin(); st.erase(st.find(p)); P q = *st.begin(); st.erase(st.find(q)); if (p.first == i && q.first == i) { if (ca[p.second] == 0) swap(p, q); match[p.second].pb(q.second); sta.erase(sta.find(p.second)); stb.erase(stb.find(q.second)); cnt[p.second]--; cnt[q.second]--; ca[p.second]--; cb[q.second]--; p.first--; q.first--; st.insert(p); st.insert(q); } else if (p.first == i && ca[p.second] != 0) { int v = *stb.begin(); if (v == p.second) v = *stb.rbegin(); match[p.second].pb(v); st.insert(q); q = {cnt[v], v}; st.erase(st.find(q)); sta.erase(sta.find(p.second)); stb.erase(stb.find(q.second)); cnt[p.second]--; cnt[q.second]--; ca[p.second]--; cb[q.second]--; p.first--; q.first--; st.insert(p); st.insert(q); } else if (p.first == i && cb[p.second] != 0) { int v = *sta.begin(); if (v == p.second) v = *sta.rbegin(); match[v].pb(p.second); st.insert(q); q = {cnt[v], v}; st.erase(st.find(q)); sta.erase(sta.find(q.second)); stb.erase(stb.find(p.second)); cnt[p.second]--; cnt[q.second]--; ca[q.second]--; cb[p.second]--; p.first--; q.first--; st.insert(p); st.insert(q); } else { int v = *sta.begin(); int w = *stb.begin(); if (v == w) w = *stb.rbegin(); st.insert(p); st.insert(q); p = {cnt[v], v}; q = {cnt[w], w}; st.erase(st.find(p)); st.erase(st.find(q)); match[p.second].pb(q.second); sta.erase(sta.find(p.second)); stb.erase(stb.find(q.second)); cnt[p.second]--; cnt[q.second]--; ca[p.second]--; cb[q.second]--; p.first--; q.first--; st.insert(p); st.insert(q); } } cout << "Yes\n"; rep(i, n) { for (int j : match[i]) { cout << j + 1 << ' '; } } cout << '\n'; }
insert
116
116
116
118
0
p02557
C++
Runtime Error
// #define _GLIBCXX_DEBUG // for STL debug (optional) #include <algorithm> #include <bitset> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long int; using int64 = long long int; template <typename T> void chmax(T &a, T b) { a = max(a, b); } template <typename T> void chmin(T &a, T b) { a = min(a, b); } template <typename T> void chadd(T &a, T b) { a = a + b; } int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; const int INF = 1LL << 29; const ll LONGINF = 1LL << 60; const ll MOD = 1000000007LL; int main() { int N; scanf("%d", &N); vector<int> cnt(N + 1), cntB(N + 1); vector<int> A(N), B(N); vector<set<int>> idx(N + 1); for (int i = 0; i < N; i++) { scanf("%d", &A[i]); cnt[A[i]]++; idx[A[i]].emplace(i); } for (int i = 0; i < N; i++) { scanf("%d", &B[i]); cnt[B[i]]++; cntB[B[i]]++; } for (int i = 0; i <= N; i++) { if (cnt[i] > N) { puts("No"); return 0; } } vector<int> ord(N); iota(ord.begin(), ord.end(), 0); sort(ord.begin(), ord.end(), [&](auto x, auto y) { return cnt[x] > cnt[y]; }); vector<int> ans(N, -1); set<int> S; for (int i = 0; i < N; i++) S.emplace(i); for (int i = 0; i < N; i++) { // for(int j=0; j<N; j++) fprintf(stderr, "%d%c", ans[j], " \n"[j + 1 == // N]); if (i == 0 or B[i - 1] != B[i]) { for (auto j : idx[B[i]]) { S.erase(j); } } if (S.empty()) { assert(idx[B[i]].size() > 0); int k = *idx[B[i]].begin(); // fprintf(stderr, "same %d %d\n", i, k); ans[k] = B[i]; S.erase(k); } else { int k = *S.rbegin(); ans[k] = B[i]; idx[A[k]].erase(k); S.erase(k); } if (i == N - 1 or B[i] != B[i + 1]) { for (auto j : idx[B[i]]) { if (ans[j] == -1) S.emplace(j); } } } set<int> match; for (int i = 0; i < N; i++) { assert(ans[i] != -1); if (A[i] == ans[i]) { match.emplace(i); } } while (match.size()) { if (match.size() == 1) break; int x = *match.begin(), y = *match.rbegin(); if (A[x] == A[y]) break; swap(ans[x], ans[y]); match.erase(x); match.erase(y); } while (match.size()) { int x = *match.begin(); int y = rand() % N; if (ans[x] == A[y]) continue; if (ans[y] == A[x]) continue; swap(ans[x], ans[y]); match.erase(x); } puts("Yes"); for (int i = 0; i < N; i++) printf("%d%c", ans[i], " \n"[i + 1 == N]); return 0; }
// #define _GLIBCXX_DEBUG // for STL debug (optional) #include <algorithm> #include <bitset> #include <cassert> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <ctime> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; using ll = long long int; using int64 = long long int; template <typename T> void chmax(T &a, T b) { a = max(a, b); } template <typename T> void chmin(T &a, T b) { a = min(a, b); } template <typename T> void chadd(T &a, T b) { a = a + b; } int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; const int INF = 1LL << 29; const ll LONGINF = 1LL << 60; const ll MOD = 1000000007LL; int main() { int N; scanf("%d", &N); vector<int> cnt(N + 1), cntB(N + 1); vector<int> A(N), B(N); vector<set<int>> idx(N + 1); for (int i = 0; i < N; i++) { scanf("%d", &A[i]); cnt[A[i]]++; idx[A[i]].emplace(i); } for (int i = 0; i < N; i++) { scanf("%d", &B[i]); cnt[B[i]]++; cntB[B[i]]++; } for (int i = 0; i <= N; i++) { if (cnt[i] > N) { puts("No"); return 0; } } vector<int> ord(N); iota(ord.begin(), ord.end(), 0); sort(ord.begin(), ord.end(), [&](auto x, auto y) { return cnt[x] > cnt[y]; }); vector<int> ans(N, -1); set<int> S; for (int i = 0; i < N; i++) S.emplace(i); for (int i = 0; i < N; i++) { // for(int j=0; j<N; j++) fprintf(stderr, "%d%c", ans[j], " \n"[j + 1 == // N]); if (i == 0 or B[i - 1] != B[i]) { for (auto j : idx[B[i]]) { S.erase(j); } } if (S.empty()) { assert(idx[B[i]].size() > 0); int k = *idx[B[i]].begin(); // fprintf(stderr, "same %d %d\n", i, k); ans[k] = B[i]; idx[B[i]].erase(k); S.erase(k); } else { int k = *S.rbegin(); ans[k] = B[i]; idx[A[k]].erase(k); S.erase(k); } if (i == N - 1 or B[i] != B[i + 1]) { for (auto j : idx[B[i]]) { if (ans[j] == -1) S.emplace(j); } } } set<int> match; for (int i = 0; i < N; i++) { assert(ans[i] != -1); if (A[i] == ans[i]) { match.emplace(i); } } while (match.size()) { if (match.size() == 1) break; int x = *match.begin(), y = *match.rbegin(); if (A[x] == A[y]) break; swap(ans[x], ans[y]); match.erase(x); match.erase(y); } while (match.size()) { int x = *match.begin(); int y = rand() % N; if (ans[x] == A[y]) continue; if (ans[y] == A[x]) continue; swap(ans[x], ans[y]); match.erase(x); } puts("Yes"); for (int i = 0; i < N; i++) printf("%d%c", ans[i], " \n"[i + 1 == N]); return 0; }
insert
90
90
90
91
0
p02557
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // typedef //------------------------------------------ typedef long long LL; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<LL> VLL; typedef vector<VLL> VVLL; typedef vector<bool> VB; typedef vector<VB> VVB; typedef vector<double> VD; typedef vector<VD> VVD; typedef vector<string> VS; typedef vector<VS> VVS; typedef vector<char> VC; typedef vector<VC> VVC; typedef vector<PII> VPII; typedef vector<PLL> VPLL; typedef priority_queue<int> PQGI; // 大きい順 typedef priority_queue<int, VI, greater<int>> PQLI; typedef priority_queue<PII> PQGP; typedef priority_queue<PII, VPII, greater<PII>> PQLP; // priority_queue<T,vector<T>,decltype(f)> pq{f}; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define EB emplace_back #define EF emplace_front #define PB push_back #define PF push_front #define POB pop_back #define POF pop_front #define MP make_pair #define SZ(a) int((a).size()) #define SQ(a) ((a) * (a)) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) #define SORTR(c) sort((c).rbegin(), (c).rend()) #define LB lower_bound #define UB upper_bound #define NEXP next_permutation #define FI first #define SE second #define Vmin(a) *min_element((a).begin(), (a).end()) #define Vmax(a) *max_element((a).begin(), (a).end()) // repetition //------------------------------------------ #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define FORR(i, a, b) for (int i = (b - 1); i >= (a); i--) #define REPR(i, n) FORR(i, 0, n) #define CFOR(i, a, b) for (int i = (a); i <= (b); ++i) #define CREP(i, n) CFOR(i, 0, n) #define CFORR(i, a, b) for (int i = (b); i >= (a); i--) #define CREPR(i, n) CFORR(i, 0, n) #define BFOR(bit, a, b) for (int bit = (a); bit < (1 << (b)); ++bit) #define BREP(bit, n) BFOR(bit, 0, n) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = INT_MAX / 2; const LL LINF = LLONG_MAX / 3; const int RINF = INT_MIN / 2; const LL RLINF = LLONG_MIN / 3; const LL MOD = 1e9 + 7; const LL MODD = 998244353; const int MAX = 510000; inline bool Eq(double a, double b) { return fabs(b - a) < EPS; } // other //------------------------------------------- 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; } #define COUT(x) cout << (x) << endl #define COUT2(x, y) cout << (x) << " " << (y) << endl #define COUT3(x, y, z) cout << (x) << " " << (y) << " " << (z) << endl #define PR(x) cout << (x) #define ENDL cout << endl #define SPACE cout << " " #define BC(x) __builtin_popcountll(x) VI dx = {1, 0, -1, 0, 1, 1, -1, -1}; VI dy = {0, 1, 0, -1, 1, -1, 1, -1}; LL Gcd(LL a, LL b) { return __gcd(a, b); } LL Lcm(LL a, LL b) { return a / Gcd(a, b) * b; } LL ModPow(LL A, LL N, LL M = MOD) { LL res = 1; while (N > 0) { if (N & 1) res = res * A % M; A = A * A % M; N >>= 1; } return res; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "{" << p.first << " " << p.second << "}"; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < (int)v.size(); i++) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } int main() { // cin.tie(0); // ios::sync_with_stdio(false); cout << fixed << setprecision(12); int N; cin >> N; VI A(N), B(N); cin >> A; cin >> B; using P = pair<PII, PII>; VPII C(N * 2); REP(i, N) C.at(i) = MP(A.at(i), 0); REP(i, N) C.at(i + N) = MP(B.at(i), 1); SORT(C); vector<P> D(N), E, F, G; REP(i, N) { D.at(i) = MP(C.at(i), C.at(i + N)); if (C.at(i).FI == C.at(i + N).FI) { COUT("No"); return 0; } if (C.at(i).SE == C.at(i + N).SE) { if (C.at(i).SE == 0) E.EB(D.at(i)); if (C.at(i).SE == 1) F.EB(D.at(i)); } else { G.EB(D.at(i)); } } COUT("Yes"); int M = SZ(E); REP(i, M) { if (E.at(i).FI.FI == F.at(i).FI.FI) { swap(E.at(i).FI, F.at(i).FI); } else { swap(E.at(i).FI, F.at(i).SE); } G.EB(E.at(i)); G.EB(F.at(i)); } VI ans, res; ans.reserve(N); REP(i, N) { if (G.at(i).SE.SE == 0) { swap(G.at(i).FI, G.at(i).SE); } } SORT(G); REP(i, N) ans.PB(G.at(i).SE.FI); REP(i, N) { assert(A.at(i) == G.at(i).FI.FI); assert(G.at(i).FI.FI != G.at(i).SE.FI); } // COUT(G); COUT(ans); return 0; }
#include <bits/stdc++.h> using namespace std; // conversion //------------------------------------------ inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } // math //------------------------------------------- template <class T> inline T sqr(T x) { return x * x; } // typedef //------------------------------------------ typedef long long LL; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<LL> VLL; typedef vector<VLL> VVLL; typedef vector<bool> VB; typedef vector<VB> VVB; typedef vector<double> VD; typedef vector<VD> VVD; typedef vector<string> VS; typedef vector<VS> VVS; typedef vector<char> VC; typedef vector<VC> VVC; typedef vector<PII> VPII; typedef vector<PLL> VPLL; typedef priority_queue<int> PQGI; // 大きい順 typedef priority_queue<int, VI, greater<int>> PQLI; typedef priority_queue<PII> PQGP; typedef priority_queue<PII, VPII, greater<PII>> PQLP; // priority_queue<T,vector<T>,decltype(f)> pq{f}; // container util //------------------------------------------ #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define EB emplace_back #define EF emplace_front #define PB push_back #define PF push_front #define POB pop_back #define POF pop_front #define MP make_pair #define SZ(a) int((a).size()) #define SQ(a) ((a) * (a)) #define EACH(i, c) \ for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define EXIST(s, e) ((s).find(e) != (s).end()) #define SORT(c) sort((c).begin(), (c).end()) #define SORTR(c) sort((c).rbegin(), (c).rend()) #define LB lower_bound #define UB upper_bound #define NEXP next_permutation #define FI first #define SE second #define Vmin(a) *min_element((a).begin(), (a).end()) #define Vmax(a) *max_element((a).begin(), (a).end()) // repetition //------------------------------------------ #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define FORR(i, a, b) for (int i = (b - 1); i >= (a); i--) #define REPR(i, n) FORR(i, 0, n) #define CFOR(i, a, b) for (int i = (a); i <= (b); ++i) #define CREP(i, n) CFOR(i, 0, n) #define CFORR(i, a, b) for (int i = (b); i >= (a); i--) #define CREPR(i, n) CFORR(i, 0, n) #define BFOR(bit, a, b) for (int bit = (a); bit < (1 << (b)); ++bit) #define BREP(bit, n) BFOR(bit, 0, n) // constant //-------------------------------------------- const double EPS = 1e-10; const double PI = acos(-1.0); const int INF = INT_MAX / 2; const LL LINF = LLONG_MAX / 3; const int RINF = INT_MIN / 2; const LL RLINF = LLONG_MIN / 3; const LL MOD = 1e9 + 7; const LL MODD = 998244353; const int MAX = 510000; inline bool Eq(double a, double b) { return fabs(b - a) < EPS; } // other //------------------------------------------- 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; } #define COUT(x) cout << (x) << endl #define COUT2(x, y) cout << (x) << " " << (y) << endl #define COUT3(x, y, z) cout << (x) << " " << (y) << " " << (z) << endl #define PR(x) cout << (x) #define ENDL cout << endl #define SPACE cout << " " #define BC(x) __builtin_popcountll(x) VI dx = {1, 0, -1, 0, 1, 1, -1, -1}; VI dy = {0, 1, 0, -1, 1, -1, 1, -1}; LL Gcd(LL a, LL b) { return __gcd(a, b); } LL Lcm(LL a, LL b) { return a / Gcd(a, b) * b; } LL ModPow(LL A, LL N, LL M = MOD) { LL res = 1; while (N > 0) { if (N & 1) res = res * A % M; A = A * A % M; N >>= 1; } return res; } template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; } template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "{" << p.first << " " << p.second << "}"; return os; } template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i = 0; i < (int)v.size(); i++) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } int main() { // cin.tie(0); // ios::sync_with_stdio(false); cout << fixed << setprecision(12); int N; cin >> N; VI A(N), B(N); cin >> A; cin >> B; using P = pair<PII, PII>; VPII C(N * 2); REP(i, N) C.at(i) = MP(A.at(i), 0); REP(i, N) C.at(i + N) = MP(B.at(i), 1); SORT(C); vector<P> D(N), E, F, G; REP(i, N) { D.at(i) = MP(C.at(i), C.at(i + N)); if (C.at(i).FI == C.at(i + N).FI) { COUT("No"); return 0; } if (C.at(i).SE == C.at(i + N).SE) { if (C.at(i).SE == 0) E.EB(D.at(i)); if (C.at(i).SE == 1) F.EB(D.at(i)); } else { G.EB(D.at(i)); } } COUT("Yes"); int M = SZ(E); REP(i, M) { if (E.at(i).FI.FI == F.at(i).FI.FI) { swap(E.at(i).FI, F.at(i).FI); } else if (E.at(i).SE.FI == F.at(i).SE.FI) { swap(E.at(i).SE, F.at(i).SE); } else { swap(E.at(i).FI, F.at(i).SE); } G.EB(E.at(i)); G.EB(F.at(i)); } VI ans, res; ans.reserve(N); REP(i, N) { if (G.at(i).SE.SE == 0) { swap(G.at(i).FI, G.at(i).SE); } } SORT(G); REP(i, N) ans.PB(G.at(i).SE.FI); REP(i, N) { assert(A.at(i) == G.at(i).FI.FI); assert(G.at(i).FI.FI != G.at(i).SE.FI); } // COUT(G); COUT(ans); return 0; }
insert
220
220
220
222
0
p02557
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define ll long long #define P pair<int, int> #define fi first #define se second #define rep(i, n) for (int i = 0; i < n; i++) #define all(v) v.begin(), v.end() #define pb push_back #define eb emplace_back template <class T> void chmax(T &a, T b) { if (a < b) a = b; } template <class T> void chmin(T &a, T b) { if (a > b) a = b; } constexpr int INF = 1000000000000000000; constexpr int mod = 1000000007; constexpr double eps = 1e-8; const double pi = acos(-1); int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; int Random(int mi, int ma) { random_device rnd; mt19937 mt(rnd()); // 32bit //[mi,ma] uniform_int_distribution<int> engine(mi, ma); return engine(mt); } int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int lcm(int a, int b) { return a / gcd(a, b) * b; } bool prime(int a) { if (a == 1) return false; for (int i = 2; i * i <= a; i++) { if (a % i == 0) return false; } return true; } int modpow(int a, int b) { if (b == 0) return 1; if (b % 2) return modpow(a, b - 1) * a % mod; int memo = modpow(a, b / 2); return memo * memo % mod; } vector<int> kaijo, invkaijo; void init_fact(int n) { kaijo.resize(n + 1); invkaijo.resize(n + 1); kaijo[0] = 1; for (int i = 1; i <= n; i++) { kaijo[i] = kaijo[i - 1] * i; kaijo[i] %= mod; } rep(i, n + 1) invkaijo[i] = modpow(kaijo[i], mod - 2); } int comb(int a, int b) { if (a < b) return 0; if (a < 0 || b < 0) return 0; return kaijo[a] * invkaijo[a - b] % mod * invkaijo[b] % mod; } int inv(int x) { x = modpow(x, mod - 2); return x; } int n, a[200010], b[200010], ans[200010]; set<int> st; signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n; rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; reverse(b, b + n); rep(i, n) { if (a[i] == b[i]) { int l = i, r = i, x = a[i], pos = l; for (int j = l; j < n; j++) { if (a[j] == b[j]) r = j; } rep(k, n) { if (pos > r) break; if (a[k] != x && b[k] != x) { swap(b[pos], b[k]); pos++; } } } } rep(i, n) { if (a[i] == b[i]) { puts("No"); return 0; } } cout << "Yes" << endl; rep(i, n) cout << b[i] << " "; cout << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define ll long long #define P pair<int, int> #define fi first #define se second #define rep(i, n) for (int i = 0; i < n; i++) #define all(v) v.begin(), v.end() #define pb push_back #define eb emplace_back template <class T> void chmax(T &a, T b) { if (a < b) a = b; } template <class T> void chmin(T &a, T b) { if (a > b) a = b; } constexpr int INF = 1000000000000000000; constexpr int mod = 1000000007; constexpr double eps = 1e-8; const double pi = acos(-1); int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; int Random(int mi, int ma) { random_device rnd; mt19937 mt(rnd()); // 32bit //[mi,ma] uniform_int_distribution<int> engine(mi, ma); return engine(mt); } int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } int lcm(int a, int b) { return a / gcd(a, b) * b; } bool prime(int a) { if (a == 1) return false; for (int i = 2; i * i <= a; i++) { if (a % i == 0) return false; } return true; } int modpow(int a, int b) { if (b == 0) return 1; if (b % 2) return modpow(a, b - 1) * a % mod; int memo = modpow(a, b / 2); return memo * memo % mod; } vector<int> kaijo, invkaijo; void init_fact(int n) { kaijo.resize(n + 1); invkaijo.resize(n + 1); kaijo[0] = 1; for (int i = 1; i <= n; i++) { kaijo[i] = kaijo[i - 1] * i; kaijo[i] %= mod; } rep(i, n + 1) invkaijo[i] = modpow(kaijo[i], mod - 2); } int comb(int a, int b) { if (a < b) return 0; if (a < 0 || b < 0) return 0; return kaijo[a] * invkaijo[a - b] % mod * invkaijo[b] % mod; } int inv(int x) { x = modpow(x, mod - 2); return x; } int n, a[200010], b[200010], ans[200010]; set<int> st; signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n; rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; reverse(b, b + n); rep(i, n) { if (a[i] == b[i]) { int l = i, r = i, x = a[i], pos = l; for (int j = l; j < n; j++) { if (a[j] == b[j]) r = j; } rep(k, n) { if (pos > r) break; if (a[k] != x && b[k] != x) { swap(b[pos], b[k]); pos++; } } break; } } rep(i, n) { if (a[i] == b[i]) { puts("No"); return 0; } } cout << "Yes" << endl; rep(i, n) cout << b[i] << " "; cout << endl; return 0; }
insert
101
101
101
102
TLE
p02557
C++
Runtime Error
#include <bits/stdc++.h> #define maxn 200086 using namespace std; int n; int a[maxn], b[maxn]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) scanf("%d", &b[i]); reverse(b + 1, b + 1 + n); int l = n, r = 1; for (int i = 1; i <= n; i++) { if (a[i] == b[i]) l = min(l, i), r = max(r, i); } for (int i = 1; i <= n && l <= r; i++) { if (a[i] != a[l] && b[i] != a[l]) swap(b[i], b[l++]); } if (l <= r) return printf("No"); puts("Yes"); for (int i = 1; i <= n; i++) printf("%d ", b[i]); }
#include <bits/stdc++.h> #define maxn 200086 using namespace std; int n; int a[maxn], b[maxn]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) scanf("%d", &b[i]); reverse(b + 1, b + 1 + n); int l = n, r = 1; for (int i = 1; i <= n; i++) { if (a[i] == b[i]) l = min(l, i), r = max(r, i); } for (int i = 1; i <= n && l <= r; i++) { if (a[i] != a[l] && b[i] != a[l]) swap(b[i], b[l++]); } if (l <= r) return printf("No"), 0; puts("Yes"); for (int i = 1; i <= n; i++) printf("%d ", b[i]); }
replace
25
26
25
26
0
p02557
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <tuple> #include <vector> #define mkp make_pair #define mkt make_tuple #define rep(i, n) for (int i = 0; i < (n); ++i) #define all(v) v.begin(), v.end() using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; template <class T> void chmin(T &a, const T &b) { if (a > b) a = b; } template <class T> void chmax(T &a, const T &b) { if (a < b) a = b; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<int> A(N), B(N); rep(i, N) cin >> A[i]; rep(i, N) cin >> B[i]; rep(i, N) { A[i]--; B[i]--; } vector<ll> an(N, 0), bn(N, 0); rep(i, N) an[A[i]]++; rep(i, N) bn[B[i]]++; rep(i, N) { if (min(an[i], bn[i]) > N / 2) { cout << "No" << endl; return 0; } } vector<int> ord(N, 0); rep(i, N) ord[i] = i; sort(all(ord), [&](int a, int b) { if (an[A[a]] == an[A[b]]) { if (bn[A[a]] == bn[A[b]]) return a < b; else bn[A[a]] > bn[A[b]]; } else an[A[a]] > an[A[b]]; }); vector<int> ans(N, -1); vector<int> deg(N, 0); rep(i, N) deg[i] = an[i]; set<tuple<int, int, int>> se; rep(i, N) { if (bn[i] == 0) continue; se.insert(mkt(-deg[i], -bn[i], i)); } for (auto i : ord) { auto itr = se.begin(); int ft = get<2>(*itr); int tval = A[i]; if (tval == ft) { ++itr; int st = get<2>(*itr); ans[i] = st; se.erase(itr); bn[st]--; if (bn[st] > 0) se.insert(mkt(-deg[st], -bn[st], st)); if (bn[tval]) { se.erase(mkt(-deg[tval], -bn[tval], tval)); deg[tval]--; se.insert(mkt(-deg[tval], -bn[tval], tval)); } } else { ans[i] = ft; se.erase(itr); bn[ft]--; if (bn[ft] > 0) se.insert(mkt(-deg[ft], -bn[ft], ft)); if (bn[tval]) { se.erase(mkt(-deg[tval], -bn[tval], tval)); deg[tval]--; se.insert(mkt(-deg[tval], -bn[tval], tval)); } } } cout << "Yes" << endl; rep(i, N) cout << ans[i] + 1 << " "; cout << endl; return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <string> #include <tuple> #include <vector> #define mkp make_pair #define mkt make_tuple #define rep(i, n) for (int i = 0; i < (n); ++i) #define all(v) v.begin(), v.end() using namespace std; typedef long long ll; const ll MOD = 1e9 + 7; template <class T> void chmin(T &a, const T &b) { if (a > b) a = b; } template <class T> void chmax(T &a, const T &b) { if (a < b) a = b; } int main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin >> N; vector<int> A(N), B(N); rep(i, N) cin >> A[i]; rep(i, N) cin >> B[i]; rep(i, N) { A[i]--; B[i]--; } vector<ll> an(N, 0), bn(N, 0); rep(i, N) an[A[i]]++; rep(i, N) bn[B[i]]++; rep(i, N) { if (N - an[i] < bn[i]) { cout << "No" << endl; return 0; } } vector<int> ord(N, 0); rep(i, N) ord[i] = i; sort(all(ord), [&](int a, int b) { if (an[A[a]] == an[A[b]]) { if (bn[A[a]] == bn[A[b]]) return a < b; else bn[A[a]] > bn[A[b]]; } else an[A[a]] > an[A[b]]; }); vector<int> ans(N, -1); vector<int> deg(N, 0); rep(i, N) deg[i] = an[i]; set<tuple<int, int, int>> se; rep(i, N) { if (bn[i] == 0) continue; se.insert(mkt(-deg[i], -bn[i], i)); } for (auto i : ord) { auto itr = se.begin(); int ft = get<2>(*itr); int tval = A[i]; if (tval == ft) { ++itr; int st = get<2>(*itr); ans[i] = st; se.erase(itr); bn[st]--; if (bn[st] > 0) se.insert(mkt(-deg[st], -bn[st], st)); if (bn[tval]) { se.erase(mkt(-deg[tval], -bn[tval], tval)); deg[tval]--; se.insert(mkt(-deg[tval], -bn[tval], tval)); } } else { ans[i] = ft; se.erase(itr); bn[ft]--; if (bn[ft] > 0) se.insert(mkt(-deg[ft], -bn[ft], ft)); if (bn[tval]) { se.erase(mkt(-deg[tval], -bn[tval], tval)); deg[tval]--; se.insert(mkt(-deg[tval], -bn[tval], tval)); } } } cout << "Yes" << endl; rep(i, N) cout << ans[i] + 1 << " "; cout << endl; return 0; }
replace
46
47
46
47
0
p02557
C++
Runtime Error
#include <algorithm> #include <cmath> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; map<int, int> a; for (int i = 0; i < n; ++i) { int j; cin >> j; a[j]++; } map<int, int> b; for (int i = 0; i < n; ++i) { int j; cin >> j; b[j]++; } set<pair<int, int>, greater<pair<int, int>>> s; for (auto &it : a) { if (b.count(it.first) > 0) { int cnt = it.second; s.insert({cnt + b[it.first], it.first}); } } vector<pair<int, int>> res; while (!s.empty()) { auto it = begin(s); int cnt = it->first; int num = it->second; if (cnt > n) { cout << "No\n"; return 0; } if (s.size() > 1) { auto it2 = ++begin(s); int num2 = it2->second; int cnt2 = it2->first; a[num]--; b[num2]--; res.emplace_back(num, num2); s.erase(it); s.erase(it2); if (a[num] != 0) { s.insert({cnt - 1, num}); } else { a.erase(num); } if (b[num2] != 0) { s.insert({cnt2 - 1, num2}); } else { b.erase(num2); } } else { auto it2 = begin(b); if (it2->first == num) { ++it2; } int num2 = it2->second; int cnt2 = it2->first; a[num]--; b[num2]--; res.emplace_back(num, num2); s.erase(it); if (a[num] != 0) { s.insert({cnt - 1, num}); } else { a.erase(num); } if (b[num2] == 0) { b.erase(num2); } } } int c = res.size(); for (auto &it : a) { for (int i = 0; i < it.second; ++i) { res.emplace_back(it.first, 0); } } for (auto &it : b) { for (int i = 0; i < it.second; ++i) { res[c].second = it.first; ++c; } } sort(begin(res), end(res)); cout << "Yes\n"; for (int i = 0; i < n; ++i) { cout << res[i].second << ' '; } cout << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstring> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; map<int, int> a; for (int i = 0; i < n; ++i) { int j; cin >> j; a[j]++; } map<int, int> b; for (int i = 0; i < n; ++i) { int j; cin >> j; b[j]++; } set<pair<int, int>, greater<pair<int, int>>> s; for (auto &it : a) { if (b.count(it.first) > 0) { int cnt = it.second; s.insert({cnt + b[it.first], it.first}); } } vector<pair<int, int>> res; while (!s.empty()) { auto it = begin(s); int cnt = it->first; int num = it->second; if (cnt > n) { cout << "No\n"; return 0; } if (s.size() > 1) { auto it2 = ++begin(s); int num2 = it2->second; int cnt2 = it2->first; a[num]--; b[num2]--; res.emplace_back(num, num2); s.erase(it); s.erase(it2); if (a[num] != 0) { s.insert({cnt - 1, num}); } else { a.erase(num); } if (b[num2] != 0) { s.insert({cnt2 - 1, num2}); } else { b.erase(num2); } } else { auto it2 = begin(b); if (it2->first == num) { ++it2; } int num2 = it2->first; a[num]--; b[num2]--; res.emplace_back(num, num2); s.erase(it); if (a[num] != 0) { s.insert({cnt - 1, num}); } else { a.erase(num); } if (b[num2] == 0) { b.erase(num2); } } } int c = res.size(); for (auto &it : a) { for (int i = 0; i < it.second; ++i) { res.emplace_back(it.first, 0); } } for (auto &it : b) { for (int i = 0; i < it.second; ++i) { res[c].second = it.first; ++c; } } sort(begin(res), end(res)); cout << "Yes\n"; for (int i = 0; i < n; ++i) { cout << res[i].second << ' '; } cout << endl; return 0; }
replace
85
87
85
86
0
p02557
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #pragma GCC optimization("O3") #define endl '\n' #define pb push_back #define fr first #define sc second #define ll long long int #define ld long double #define bit(idx) idx & (-idx) #define bin(x, a) bitset<a>(x) #define all(A) A.begin(), A.end() #define de(x) cout << #x << " = " << x << endl; #define row vector<ll> #define matrix vector<row> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; /// find_by_order(x) -> x-th element in the set /// order_of_key(x) -> how many elements are smaller than x /// insert(x) -> inserts x into the set int main() { /// ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin >> n; vector<ll> A(n), B(n), cnt(n + 2); for (int i = 0; i < n; i++) cin >> A[i]; for (int i = 0; i < n; i++) cin >> B[i]; for (int i = 0; i < n; i++) { ++cnt[A[i]]; ++cnt[B[i]]; } for (int i = 1; i <= n; i++) { if (cnt[i] > n) { cout << "No\n"; return 0; } } reverse(all(B)); int L = 0, R = n - 1; for (int i = 0; i < n; i++) { if (A[i] == B[i]) { if (B[L] != A[i] && A[L] != A[i]) { swap(B[L], B[i]); --L; } else { swap(B[R], B[i]); --R; } } } cout << "Yes\n"; for (auto x : B) cout << x << " "; cout << endl; } /** */
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #pragma GCC optimization("O3") #define endl '\n' #define pb push_back #define fr first #define sc second #define ll long long int #define ld long double #define bit(idx) idx & (-idx) #define bin(x, a) bitset<a>(x) #define all(A) A.begin(), A.end() #define de(x) cout << #x << " = " << x << endl; #define row vector<ll> #define matrix vector<row> using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; /// find_by_order(x) -> x-th element in the set /// order_of_key(x) -> how many elements are smaller than x /// insert(x) -> inserts x into the set int main() { /// ios_base::sync_with_stdio(false); cin.tie(NULL); ll n; cin >> n; vector<ll> A(n), B(n), cnt(n + 2); for (int i = 0; i < n; i++) cin >> A[i]; for (int i = 0; i < n; i++) cin >> B[i]; for (int i = 0; i < n; i++) { ++cnt[A[i]]; ++cnt[B[i]]; } for (int i = 1; i <= n; i++) { if (cnt[i] > n) { cout << "No\n"; return 0; } } reverse(all(B)); int L = 0, R = n - 1; for (int i = 0; i < n; i++) { if (A[i] == B[i]) { if (B[L] != A[i] && A[L] != A[i]) { swap(B[L], B[i]); ++L; } else { swap(B[R], B[i]); --R; } } } cout << "Yes\n"; for (auto x : B) cout << x << " "; cout << endl; } /** */
replace
53
54
53
54
0
p02557
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair using namespace std; typedef pair<int, int> pii; set<pii> s1, s2; int a[200010], b[200010], ans[200010]; int pos[200010], cnt[200010]; set<pii>::iterator get_pre(set<pii>::iterator it) { it--; return it; } int main() { int n; scanf("%d", &n); memset(pos, -1, sizeof(pos)); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); if (pos[a[i]] == -1) pos[a[i]] = i; cnt[a[i]]++; } for (int i = 1; i <= n; i++) { if (cnt[i]) s1.insert(mp(cnt[i], i)); } for (int i = 0; i < n; i++) { scanf("%d", &b[i]); cnt[b[i]]++; } for (int i = 1; i <= n; i++) { if (cnt[i] > n) { printf("No\n"); return 0; } } memset(cnt, 0, sizeof(cnt)); for (int i = 0; i < n; i++) { cnt[b[i]]++; } for (int i = 1; i <= n; i++) { if (cnt[i]) s2.insert(mp(cnt[i], i)); } for (int i = 0; i < n; i++) { int cnt = 0; for (auto x : s1) cnt += x.fi; set<pii>::iterator it = s1.end(); it--; if (it == s1.begin() || get_pre(it)->fi != it->fi) { pii tmp = *it; s1.erase(tmp); tmp.fi--; if (tmp.fi) s1.insert(tmp); it = s2.lower_bound(mp(get_pre(s2.end())->fi, -1)); if (it->se == tmp.se) { it++; if (it == s2.end()) it--, it--; } pii ttt = *it; s2.erase(ttt); ttt.fi--; if (ttt.fi) s2.insert(ttt); ans[pos[tmp.se]++] = ttt.se; } else { it = s2.end(); it--; pii tmp = *it; s2.erase(tmp); tmp.fi--; if (tmp.fi) s2.insert(tmp); it = s1.lower_bound(mp(get_pre(s1.end())->fi, -1)); if (it->se == tmp.se) { it++; if (it == s1.end()) { it--, it--; } } pii ttt = *it; s1.erase(ttt); ttt.fi--; if (ttt.fi) s1.insert(ttt); ans[pos[ttt.se]++] = tmp.se; } } printf("Yes\n"); for (int i = 0; i < n; i++) { printf("%d ", ans[i]); } printf("\n"); return 0; }
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair using namespace std; typedef pair<int, int> pii; set<pii> s1, s2; int a[200010], b[200010], ans[200010]; int pos[200010], cnt[200010]; set<pii>::iterator get_pre(set<pii>::iterator it) { it--; return it; } int main() { int n; scanf("%d", &n); memset(pos, -1, sizeof(pos)); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); if (pos[a[i]] == -1) pos[a[i]] = i; cnt[a[i]]++; } for (int i = 1; i <= n; i++) { if (cnt[i]) s1.insert(mp(cnt[i], i)); } for (int i = 0; i < n; i++) { scanf("%d", &b[i]); cnt[b[i]]++; } for (int i = 1; i <= n; i++) { if (cnt[i] > n) { printf("No\n"); return 0; } } memset(cnt, 0, sizeof(cnt)); for (int i = 0; i < n; i++) { cnt[b[i]]++; } for (int i = 1; i <= n; i++) { if (cnt[i]) s2.insert(mp(cnt[i], i)); } for (int i = 0; i < n; i++) { set<pii>::iterator it = s1.end(); it--; if (it == s1.begin() || get_pre(it)->fi != it->fi) { pii tmp = *it; s1.erase(tmp); tmp.fi--; if (tmp.fi) s1.insert(tmp); it = s2.lower_bound(mp(get_pre(s2.end())->fi, -1)); if (it->se == tmp.se) { it++; if (it == s2.end()) it--, it--; } pii ttt = *it; s2.erase(ttt); ttt.fi--; if (ttt.fi) s2.insert(ttt); ans[pos[tmp.se]++] = ttt.se; } else { it = s2.end(); it--; pii tmp = *it; s2.erase(tmp); tmp.fi--; if (tmp.fi) s2.insert(tmp); it = s1.lower_bound(mp(get_pre(s1.end())->fi, -1)); if (it->se == tmp.se) { it++; if (it == s1.end()) { it--, it--; } } pii ttt = *it; s1.erase(ttt); ttt.fi--; if (ttt.fi) s1.insert(ttt); ans[pos[ttt.se]++] = tmp.se; } } printf("Yes\n"); for (int i = 0; i < n; i++) { printf("%d ", ans[i]); } printf("\n"); return 0; }
delete
50
53
50
50
TLE
p02557
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; using ll = long long; #ifdef LOCAL_TEST #define BOOST_STACKTRACE_USE_ADDR2LINE #define BOOST_STACKTRACE_ADDR2LINE_LOCATION \ / usr / local / opt / binutils / bin / addr2line #define _GNU_SOURCE 1 #include <boost/stacktrace.hpp> 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 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() #endif #ifdef LOCAL_DEV template <typename T1, typename T2> std::ostream &operator<<(std::ostream &s, const std::pair<T1, T2> &p) { return s << "(" << p.first << ", " << p.second << ")"; } 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 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 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 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::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; } 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 << ":" << __LINE__ << " (" << #__VA_ARGS__ << ") ="; \ debug_impl(__VA_ARGS__); \ } while (false) #else #define debug(...) \ do { \ } while (false) #endif int main() { ll N; cin >> N; vector<ll> a(N), b(N); for (ll i = 0; i < N; i++) cin >> a[i]; for (ll i = 0; i < N; i++) cin >> b[i]; map<ll, ll> am, bm; for (ll i = 0; i < N; i++) { am[a[i]]++; bm[b[i]]++; } for (auto &&pr : am) { if (pr.second + bm[pr.first] > N) { cout << "No\n"; return 0; } } vector<pair<ll, ll>> ans; priority_queue<array<ll, 4>> q; //(a+bの要素数, aの要素数, bの要素数, 値) vector<ll> onlya, onlyb; for (auto &&pr : am) { ll acount = am[pr.first]; ll bcount = bm[pr.first]; if (bcount) { q.push({acount + bcount, acount, bcount, pr.first}); } else { for (ll i = 0; i < pr.second; i++) onlya.push_back(pr.first); } } for (auto &&pr : bm) { if (am[pr.first]) continue; for (ll i = 0; i < pr.first; i++) onlyb.push_back(pr.second); } while ((ll)q.size() >= 2) { array<ll, 4> x = q.top(); q.pop(); array<ll, 4> y = q.top(); q.pop(); x[0]--; y[0]--; x[1]--; y[2]--; ans.push_back({x[3], y[3]}); if (x[1] == 0 || x[2] == 0) { if (x[1] > 0) for (ll i = 0; i < x[1]; i++) onlya.push_back(x[3]); if (x[2] > 0) for (ll i = 0; i < x[2]; i++) onlyb.push_back(x[3]); } else { q.push(x); } if (y[1] == 0 || y[2] == 0) { if (y[1] > 0) for (ll i = 0; i < y[1]; i++) onlya.push_back(y[3]); if (y[2] > 0) for (ll i = 0; i < y[2]; i++) onlyb.push_back(y[3]); } else { q.push(y); } } while (!q.empty()) { array<ll, 4> x = q.top(); q.pop(); for (ll i = 0; i < x[1]; i++) { ans.push_back({x[3], onlyb.back()}); onlyb.pop_back(); } for (ll i = 0; i < x[2]; i++) { ans.push_back({onlya.back(), x[3]}); onlya.pop_back(); } } for (ll i = 0; i < (ll)onlya.size(); i++) { ans.push_back({onlya[i], onlyb[i]}); } debug(onlya); debug(onlyb); debug(ans); sort(ans.begin(), ans.end()); cout << "Yes\n"; for (ll i = 0; i < N; i++) cout << ans[i].second << " \n"[i == N - 1]; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; #ifdef LOCAL_TEST #define BOOST_STACKTRACE_USE_ADDR2LINE #define BOOST_STACKTRACE_ADDR2LINE_LOCATION \ / usr / local / opt / binutils / bin / addr2line #define _GNU_SOURCE 1 #include <boost/stacktrace.hpp> 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 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() #endif #ifdef LOCAL_DEV template <typename T1, typename T2> std::ostream &operator<<(std::ostream &s, const std::pair<T1, T2> &p) { return s << "(" << p.first << ", " << p.second << ")"; } 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 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 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 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::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; } 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 << ":" << __LINE__ << " (" << #__VA_ARGS__ << ") ="; \ debug_impl(__VA_ARGS__); \ } while (false) #else #define debug(...) \ do { \ } while (false) #endif int main() { ll N; cin >> N; vector<ll> a(N), b(N); for (ll i = 0; i < N; i++) cin >> a[i]; for (ll i = 0; i < N; i++) cin >> b[i]; map<ll, ll> am, bm; for (ll i = 0; i < N; i++) { am[a[i]]++; bm[b[i]]++; } for (auto &&pr : am) { if (pr.second + bm[pr.first] > N) { cout << "No\n"; return 0; } } vector<pair<ll, ll>> ans; priority_queue<array<ll, 4>> q; //(a+bの要素数, aの要素数, bの要素数, 値) vector<ll> onlya, onlyb; for (auto &&pr : am) { ll acount = am[pr.first]; ll bcount = bm[pr.first]; if (bcount) { q.push({acount + bcount, acount, bcount, pr.first}); } else { for (ll i = 0; i < pr.second; i++) onlya.push_back(pr.first); } } for (auto &&pr : bm) { if (am[pr.first]) continue; for (ll i = 0; i < pr.second; i++) onlyb.push_back(pr.first); } while ((ll)q.size() >= 2) { array<ll, 4> x = q.top(); q.pop(); array<ll, 4> y = q.top(); q.pop(); x[0]--; y[0]--; x[1]--; y[2]--; ans.push_back({x[3], y[3]}); if (x[1] == 0 || x[2] == 0) { if (x[1] > 0) for (ll i = 0; i < x[1]; i++) onlya.push_back(x[3]); if (x[2] > 0) for (ll i = 0; i < x[2]; i++) onlyb.push_back(x[3]); } else { q.push(x); } if (y[1] == 0 || y[2] == 0) { if (y[1] > 0) for (ll i = 0; i < y[1]; i++) onlya.push_back(y[3]); if (y[2] > 0) for (ll i = 0; i < y[2]; i++) onlyb.push_back(y[3]); } else { q.push(y); } } while (!q.empty()) { array<ll, 4> x = q.top(); q.pop(); for (ll i = 0; i < x[1]; i++) { ans.push_back({x[3], onlyb.back()}); onlyb.pop_back(); } for (ll i = 0; i < x[2]; i++) { ans.push_back({onlya.back(), x[3]}); onlya.pop_back(); } } for (ll i = 0; i < (ll)onlya.size(); i++) { ans.push_back({onlya[i], onlyb[i]}); } debug(onlya); debug(onlyb); debug(ans); sort(ans.begin(), ans.end()); cout << "Yes\n"; for (ll i = 0; i < N; i++) cout << ans[i].second << " \n"[i == N - 1]; return 0; }
replace
201
203
201
203
0
p02557
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; using i64 = long long; #define endl "\n" const i64 timeLimit = 1950; unsigned long xor128() { static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123; unsigned long t = (x ^ (x << 11)); x = y; y = z; z = w; return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8))); } int main() { i64 N; cin >> N; vector<i64> A(N), B(N); for (i64 i = 0; i < N; i++) cin >> A[i]; for (i64 i = 0; i < N; i++) cin >> B[i]; reverse(B.begin(), B.end()); i64 cnt = 0; for (i64 i = 0; i < N; i++) if (A[i] == B[i]) cnt++; chrono::system_clock::time_point start = chrono::system_clock::now(); while (chrono::duration_cast<chrono::microseconds>( chrono::system_clock::now() - start) .count() / 1000 < timeLimit) { i64 x = xor128() % N, y = xor128() % N; if (A[x] == B[y] || A[y] == B[x]) continue; if (A[x] == B[x]) cnt--; if (A[y] == B[y]) cnt--; swap(B[x], B[y]); if (cnt == 0) { cout << "Yes" << endl; for (i64 i = 0; i < N; i++) cout << B[i] << " "[i + 1 == N]; return 0; } } cout << "No" << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using i64 = long long; #define endl "\n" const i64 timeLimit = 1900; unsigned long xor128() { static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123; unsigned long t = (x ^ (x << 11)); x = y; y = z; z = w; return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8))); } int main() { i64 N; cin >> N; vector<i64> A(N), B(N); for (i64 i = 0; i < N; i++) cin >> A[i]; for (i64 i = 0; i < N; i++) cin >> B[i]; reverse(B.begin(), B.end()); i64 cnt = 0; for (i64 i = 0; i < N; i++) if (A[i] == B[i]) cnt++; chrono::system_clock::time_point start = chrono::system_clock::now(); while (chrono::duration_cast<chrono::microseconds>( chrono::system_clock::now() - start) .count() / 1000 < timeLimit) { i64 x = xor128() % N, y = xor128() % N; if (A[x] == B[y] || A[y] == B[x]) continue; if (A[x] == B[x]) cnt--; if (A[y] == B[y]) cnt--; swap(B[x], B[y]); if (cnt == 0) { cout << "Yes" << endl; for (i64 i = 0; i < N; i++) cout << B[i] << " "[i + 1 == N]; return 0; } } cout << "No" << endl; return 0; }
replace
5
6
5
6
TLE
p02557
C++
Runtime Error
/** * Dont raise your voice, improve your argument. * --Desmond Tutu */ #include <bits/stdc++.h> using namespace std; const bool ready = []() { ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(12); return true; }(); const double PI = acos(-1); using ll = long long; #define int ll #define all(v) (v).begin(), (v).end() #define fori(n) for (int i = 0; i < int(n); i++) #define cini(i) \ int i; \ cin >> i; #define cins(s) \ string s; \ cin >> s; #define cind(d) \ double d; \ cin >> d; #define cinai(a, n) \ vi a(n); \ fori(n) { cin >> a[i]; } #define cinas(s, n) \ vs s(n); \ fori(n) { cin >> s[i]; } #define cinad(a, n) \ vd a(n); \ fori(n) { cin >> a[i]; } using pii = pair<int, int>; using pdd = pair<double, double>; using vd = vector<double>; using vb = vector<bool>; using vi = vector<int>; using vvi = vector<vi>; using vs = vector<string>; #define endl "\n" const int INF = 1e9; void solve() { cini(n); vi a(n + 1); vi aa(n); for (int i = 0; i < n; i++) { cin >> aa[i]; a[aa[i]]++; } vi b(n + 1); vi bb(n); bool imp = false; for (int i = 0; i < n; i++) { cin >> bb[i]; b[bb[i]]++; if (a[bb[i]] + b[bb[i]] > n) imp = true; } if (imp) { cout << "No" << endl; return; } cout << "Yes" << endl; set<pii> q; vi cnt(n + 1); for (int i = 1; i <= n; i++) { cnt[i] = a[i] + b[i]; if (b[i] > 0) q.emplace(-cnt[i], i); } vi ans(n); for (int i = 0; i < n; i++) { assert(q.size() > 0); auto it = q.begin(); if (aa[i] == it->second) it++; ans[i] = it->second; it = q.lower_bound({-cnt[aa[i]], aa[i]}); if (it != q.end()) q.erase(it); cnt[aa[i]]--; if (b[aa[i]] > 0) q.emplace(-cnt[aa[i]], aa[i]); it = q.lower_bound({-cnt[ans[i]], ans[i]}); assert(it != q.end()); q.erase(it); cnt[ans[i]]--; b[ans[i]]--; if (b[ans[i]] > 0) q.emplace(-cnt[ans[i]], ans[i]); } for (int i = 0; i < n; i++) cout << ans[i] << " "; cout << endl; } signed main() { solve(); } // FIRST THINK, THEN CODE // DO NOT JUMP BETWEEN PROBLEMS
/** * Dont raise your voice, improve your argument. * --Desmond Tutu */ #include <bits/stdc++.h> using namespace std; const bool ready = []() { ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(12); return true; }(); const double PI = acos(-1); using ll = long long; #define int ll #define all(v) (v).begin(), (v).end() #define fori(n) for (int i = 0; i < int(n); i++) #define cini(i) \ int i; \ cin >> i; #define cins(s) \ string s; \ cin >> s; #define cind(d) \ double d; \ cin >> d; #define cinai(a, n) \ vi a(n); \ fori(n) { cin >> a[i]; } #define cinas(s, n) \ vs s(n); \ fori(n) { cin >> s[i]; } #define cinad(a, n) \ vd a(n); \ fori(n) { cin >> a[i]; } using pii = pair<int, int>; using pdd = pair<double, double>; using vd = vector<double>; using vb = vector<bool>; using vi = vector<int>; using vvi = vector<vi>; using vs = vector<string>; #define endl "\n" const int INF = 1e9; void solve() { cini(n); vi a(n + 1); vi aa(n); for (int i = 0; i < n; i++) { cin >> aa[i]; a[aa[i]]++; } vi b(n + 1); vi bb(n); bool imp = false; for (int i = 0; i < n; i++) { cin >> bb[i]; b[bb[i]]++; if (a[bb[i]] + b[bb[i]] > n) imp = true; } if (imp) { cout << "No" << endl; return; } cout << "Yes" << endl; set<pii> q; vi cnt(n + 1); for (int i = 1; i <= n; i++) { cnt[i] = a[i] + b[i]; if (b[i] > 0) q.emplace(-cnt[i], i); } vi ans(n); for (int i = 0; i < n; i++) { assert(q.size() > 0); auto it = q.begin(); if (aa[i] == it->second) it++; ans[i] = it->second; q.erase({-cnt[aa[i]], aa[i]}); cnt[aa[i]]--; if (b[aa[i]] > 0) q.emplace(-cnt[aa[i]], aa[i]); it = q.lower_bound({-cnt[ans[i]], ans[i]}); assert(it != q.end()); q.erase(it); cnt[ans[i]]--; b[ans[i]]--; if (b[ans[i]] > 0) q.emplace(-cnt[ans[i]], ans[i]); } for (int i = 0; i < n; i++) cout << ans[i] << " "; cout << endl; } signed main() { solve(); } // FIRST THINK, THEN CODE // DO NOT JUMP BETWEEN PROBLEMS
replace
96
99
96
97
0
p02557
C++
Runtime Error
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #define _USE_MATH_DEFINES #include <cassert> #include <complex> #include <functional> #include <math.h> using namespace std; #define rep(i, x) for (ll i = 0; i < x; i++) #define repn(i, x) for (ll i = 1; i <= x; i++) typedef long long ll; const ll INF = 1e17; const ll MOD = 1000000007; const ll MAX = 4000001; const long double eps = 1E-14; ll max(ll a, ll b) { if (a > b) { return a; } return b; } ll min(ll a, ll b) { if (a > b) { return b; } return a; } ll gcd(ll a, ll b) { if (b == 0) { return a; } if (a < b) { return gcd(b, a); } return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } struct edge { ll ind; ll fr; ll to; ll d; }; class mint { long long x; public: mint(long long 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 { mint res(*this); return res += a; } mint operator-(const mint &a) const { mint res(*this); return res -= a; } mint operator*(const mint &a) const { mint res(*this); return res *= 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 { mint res(*this); return res /= a; } friend ostream &operator<<(ostream &os, const mint &m) { os << m.x; return os; } }; mint pw(mint a, ll b) { if (b == 0) { return 1; } mint ret = pw(a, b >> 1); ret *= ret; if (b & 1) { ret *= a; } return ret; } typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef vector<vector<vector<ll>>> vvvll; typedef vector<mint> vmint; typedef vector<vector<mint>> vvmint; typedef vector<vector<vector<mint>>> vvvmint; ///////////////////////////////////// vmint f, finv, inv; void cominit(ll N) { f.assign(N + 1, 1); finv.assign(N + 1, 1); inv.assign(N + 1, 1); inv[1] = 1; repn(i, N) { f[i] = f[i - 1] * i; if (i > 1) inv[i] = -inv[MOD % i] * (MOD / i); finv[i] = finv[i - 1] * inv[i]; } } mint com(ll a, ll b) { if (a < 0 || b < 0 || a < b) { return 0; } return f[a] * finv[b] * finv[a - b]; } int main() { ll N; cin >> N; vll A(N + 1), B(N + 1); repn(i, N) cin >> A[i]; repn(i, N) cin >> B[i]; vll acount(N + 1, 0), bcount(N + 1, 0), count(N + 1, 0); repn(i, N) { acount[A[i]]++; bcount[B[i]]++; } repn(i, N) { count[i] = acount[i] + bcount[i]; } repn(i, N) { if (count[i] > N) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; set<pair<ll, ll>> st; repn(i, N) if (count[i] > 0) st.insert({count[i], i}); vvll mat(N + 1); repn(i, N) { // cout << i << endl; if (st.count({count[B[i]], B[i]})) st.erase({count[B[i]], B[i]}); ll x = 0; while (1) { auto itr = --st.end(); x = (*itr).second; // cout << x << " " << acount[x] << endl; st.erase(itr); if (acount[x] > 0) { break; } } // cout << x << endl; mat[x].push_back(B[i]); acount[x]--; count[x] = acount[x] + bcount[x]; st.insert({count[x], x}); st.insert({count[B[i]], B[i]}); } repn(i, N) { for (ll x : mat[i]) { cout << x << " "; } } cout << endl; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #define _USE_MATH_DEFINES #include <cassert> #include <complex> #include <functional> #include <math.h> using namespace std; #define rep(i, x) for (ll i = 0; i < x; i++) #define repn(i, x) for (ll i = 1; i <= x; i++) typedef long long ll; const ll INF = 1e17; const ll MOD = 1000000007; const ll MAX = 4000001; const long double eps = 1E-14; ll max(ll a, ll b) { if (a > b) { return a; } return b; } ll min(ll a, ll b) { if (a > b) { return b; } return a; } ll gcd(ll a, ll b) { if (b == 0) { return a; } if (a < b) { return gcd(b, a); } return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } struct edge { ll ind; ll fr; ll to; ll d; }; class mint { long long x; public: mint(long long 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 { mint res(*this); return res += a; } mint operator-(const mint &a) const { mint res(*this); return res -= a; } mint operator*(const mint &a) const { mint res(*this); return res *= 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 { mint res(*this); return res /= a; } friend ostream &operator<<(ostream &os, const mint &m) { os << m.x; return os; } }; mint pw(mint a, ll b) { if (b == 0) { return 1; } mint ret = pw(a, b >> 1); ret *= ret; if (b & 1) { ret *= a; } return ret; } typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef vector<vector<vector<ll>>> vvvll; typedef vector<mint> vmint; typedef vector<vector<mint>> vvmint; typedef vector<vector<vector<mint>>> vvvmint; ///////////////////////////////////// vmint f, finv, inv; void cominit(ll N) { f.assign(N + 1, 1); finv.assign(N + 1, 1); inv.assign(N + 1, 1); inv[1] = 1; repn(i, N) { f[i] = f[i - 1] * i; if (i > 1) inv[i] = -inv[MOD % i] * (MOD / i); finv[i] = finv[i - 1] * inv[i]; } } mint com(ll a, ll b) { if (a < 0 || b < 0 || a < b) { return 0; } return f[a] * finv[b] * finv[a - b]; } int main() { ll N; cin >> N; vll A(N + 1), B(N + 1); repn(i, N) cin >> A[i]; repn(i, N) cin >> B[i]; vll acount(N + 1, 0), bcount(N + 1, 0), count(N + 1, 0); repn(i, N) { acount[A[i]]++; bcount[B[i]]++; } repn(i, N) { count[i] = acount[i] + bcount[i]; } repn(i, N) { if (count[i] > N) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; set<pair<ll, ll>> st; repn(i, N) if (count[i] > 0) st.insert({count[i], i}); vvll mat(N + 1); repn(i, N) { // cout << i << endl; if (st.count({count[B[i]], B[i]})) st.erase({count[B[i]], B[i]}); ll x = 0; while (1) { auto itr = --st.end(); x = (*itr).second; // cout << x << " " << acount[x] << endl; st.erase(itr); if (acount[x] > 0) { break; } } // cout << x << endl; mat[x].push_back(B[i]); acount[x]--; count[x] = acount[x] + bcount[x]; bcount[B[i]]--; count[B[i]] = acount[B[i]] + bcount[B[i]]; st.insert({count[x], x}); st.insert({count[B[i]], B[i]}); } repn(i, N) { for (ll x : mat[i]) { cout << x << " "; } } cout << endl; }
insert
208
208
208
210
0
p02557
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> A(N), B(N); for (int i = 0; i < N; i++) cin >> A[i]; for (int i = 0; i < N; i++) cin >> B[i]; reverse(B.begin(), B.end()); for (int i = 0; i < N; i++) { if (A[i] == B[i]) { int now = N, now2 = N; for (int j = i + 1; j < N; j++) { if (A[i] != B[j]) now2 = min(now2, j); if (A[i] != B[j] && A[i] != A[j]) { now = j; break; } } int old = now; now = -1; for (int j = i - 1; j >= 0; j--) if (A[i] != B[j] && A[i] != A[j]) { now = j; break; } if (!(now + 1 + N - old < now2 - i)) { for (int j = i; j < now2; j++) { if (j - i < N - old) swap(B[j], B[old + j - i]); else swap(B[j], B[now - (j - i)]); } } else { cout << "No" << endl; return 0; } } } cout << "Yes" << endl; for (int i = 0; i < N; i++) { cout << B[i] << ((i + 1 == N) ? "\n" : " "); } }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> A(N), B(N); for (int i = 0; i < N; i++) cin >> A[i]; for (int i = 0; i < N; i++) cin >> B[i]; reverse(B.begin(), B.end()); for (int i = 0; i < N; i++) { if (A[i] == B[i]) { int now = N, now2 = N; for (int j = i + 1; j < N; j++) { if (A[i] != B[j]) now2 = min(now2, j); if (A[i] != B[j] && A[i] != A[j]) { now = j; break; } } int old = now; now = -1; for (int j = i - 1; j >= 0; j--) if (A[i] != B[j] && A[i] != A[j]) { now = j; break; } if (!(now + 1 + N - old < now2 - i)) { for (int j = i; j < now2; j++) { if (j - i < N - old) swap(B[j], B[old + j - i]); else swap(B[j], B[now - (j - i) + (N - old)]); } } else { cout << "No" << endl; return 0; } } } cout << "Yes" << endl; for (int i = 0; i < N; i++) { cout << B[i] << ((i + 1 == N) ? "\n" : " "); } }
replace
34
35
34
35
0
p02557
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; #define mem(a, x) memset(a, x, sizeof(a)); #define ft \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); int main() { ft int t, i, j, n, m, l, r; cin >> n; int a[n + 1], b[n + 1], c[n + 1]; mem(c, 0); for (i = 0; i < n; i++) { cin >> a[i]; c[a[i]]++; } for (i = 0; i < n; i++) { cin >> b[i]; c[b[i]]++; } for (i = 1; i <= n; i++) { if (c[i] > n) { cout << "No\n"; return 0; } } cout << "Yes\n"; for (i = 0; i < n; i++) { if (a[i] == b[i]) { for (j = 0; j < n; j++) { if (b[j] != a[i] && b[i] != a[j]) { swap(b[i], b[j]); break; } } } } for (i = 0; i < n; i++) { cout << b[i] << " "; } return 0; }
#include <bits/stdc++.h> using namespace std; #define mem(a, x) memset(a, x, sizeof(a)); #define ft \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); int main() { ft int t, i, j, n, m, l, r; cin >> n; int a[n + 1], b[n + 1], c[n + 1]; mem(c, 0); for (i = 0; i < n; i++) { cin >> a[i]; c[a[i]]++; } for (i = 0; i < n; i++) { cin >> b[i]; c[b[i]]++; } for (i = 1; i <= n; i++) { if (c[i] > n) { cout << "No\n"; return 0; } } cout << "Yes\n"; reverse(b, b + n); for (i = 0; i < n; i++) { if (a[i] == b[i]) { for (j = 0; j < n; j++) { if (b[j] != a[i] && b[i] != a[j]) { swap(b[i], b[j]); break; } } } } for (i = 0; i < n; i++) { cout << b[i] << " "; } return 0; }
insert
27
27
27
28
TLE
p02557
C++
Runtime Error
/*input 10 1 1 5 1 4 5 5 4 9 4 1 4 9 9 8 2 1 8 2 1 */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; #pragma GCC optimize("unroll-loops,no-stack-protector") // order_of_key #of elements less than x // find_by_order kth element typedef long long int ll; #define ld double #define pii pair<ll, ll> #define f first #define s second #define pb push_back #define REP(i, n) for (ll i = 0; i < n; i++) #define REP1(i, n) for (int i = 1; i <= n; i++) #define FILL(n, x) memset(n, x, sizeof(n)) #define ALL(_a) _a.begin(), _a.end() #define sz(x) (int)x.size() const ll maxn = 2e5 + 5; const ll maxlg = __lg(maxn) + 2; const ll INF64 = 4e18; const int INF = 0x3f3f3f3f; const ll MOD = 1e9 + 7; const ld PI = 3.14159265358979323846; const ld eps = 1e-9; #define lowb(x) x & (-x) #define MNTO(x, y) x = min(x, (__typeof__(x))y) #define MXTO(x, y) x = max(x, (__typeof__(x))y) #define SORT_UNIQUE(c) \ (sort(c.begin(), c.end()), \ c.resize(distance(c.begin(), unique(c.begin(), c.end())))) #define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin()) #define MP make_pair ll mult(ll a, ll b) { return (a * b) % MOD; } ll mypow(ll a, ll b) { ll res = 1LL; while (b) { if (b & 1) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } int a[maxn], b[maxn], cnt[maxn], cnt2[maxn]; int nxt[maxn]; int lst[maxn]; vector<int> v[maxn]; int main() { ios::sync_with_stdio(false), cin.tie(0); srand(time(NULL)); int n; cin >> n; REP(i, n) cin >> a[i], cnt2[a[i]]++, v[a[i]].pb(i); REP1(i, n) v[i].pb(INF); REP(i, n) { cin >> b[i], cnt[b[i]]++; // cout<<b[i]<<' '; } // cout<<'\n'; // REP(i,n) cout<<a[i]<<' '; // cout<<'\n'; set<pair<pair<pii, int>, int>> s; REP1(i, n) if (cnt[i] + cnt2[i] > n) { cout << "No\n"; return 0; } reverse(b, b + n); vector<int> v; int x = -1; REP(i, n) { if (a[i] == b[i]) v.pb(i), x = i; } if (x != -1) { REP(i, n) { if (a[i] != x and b[i] != x) { swap(b[i], b[v.back()]); v.pop_back(); } if (!sz(v)) break; } } cout << "Yes\n"; REP(i, n) { assert(a[i] != b[i]); cout << b[i] << ' '; } }
/*input 10 1 1 5 1 4 5 5 4 9 4 1 4 9 9 8 2 1 8 2 1 */ #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> indexed_set; #pragma GCC optimize("unroll-loops,no-stack-protector") // order_of_key #of elements less than x // find_by_order kth element typedef long long int ll; #define ld double #define pii pair<ll, ll> #define f first #define s second #define pb push_back #define REP(i, n) for (ll i = 0; i < n; i++) #define REP1(i, n) for (int i = 1; i <= n; i++) #define FILL(n, x) memset(n, x, sizeof(n)) #define ALL(_a) _a.begin(), _a.end() #define sz(x) (int)x.size() const ll maxn = 2e5 + 5; const ll maxlg = __lg(maxn) + 2; const ll INF64 = 4e18; const int INF = 0x3f3f3f3f; const ll MOD = 1e9 + 7; const ld PI = 3.14159265358979323846; const ld eps = 1e-9; #define lowb(x) x & (-x) #define MNTO(x, y) x = min(x, (__typeof__(x))y) #define MXTO(x, y) x = max(x, (__typeof__(x))y) #define SORT_UNIQUE(c) \ (sort(c.begin(), c.end()), \ c.resize(distance(c.begin(), unique(c.begin(), c.end())))) #define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin()) #define MP make_pair ll mult(ll a, ll b) { return (a * b) % MOD; } ll mypow(ll a, ll b) { ll res = 1LL; while (b) { if (b & 1) res = res * a % MOD; a = a * a % MOD; b >>= 1; } return res; } int a[maxn], b[maxn], cnt[maxn], cnt2[maxn]; int nxt[maxn]; int lst[maxn]; vector<int> v[maxn]; int main() { ios::sync_with_stdio(false), cin.tie(0); srand(time(NULL)); int n; cin >> n; REP(i, n) cin >> a[i], cnt2[a[i]]++, v[a[i]].pb(i); REP1(i, n) v[i].pb(INF); REP(i, n) { cin >> b[i], cnt[b[i]]++; // cout<<b[i]<<' '; } // cout<<'\n'; // REP(i,n) cout<<a[i]<<' '; // cout<<'\n'; set<pair<pair<pii, int>, int>> s; REP1(i, n) if (cnt[i] + cnt2[i] > n) { cout << "No\n"; return 0; } reverse(b, b + n); vector<int> v; int x = -1; REP(i, n) { if (a[i] == b[i]) v.pb(i), x = a[i]; } if (x != -1) { REP(i, n) { if (a[i] != x and b[i] != x) { swap(b[i], b[v.back()]); v.pop_back(); } if (!sz(v)) break; } } cout << "Yes\n"; REP(i, n) { assert(a[i] != b[i]); cout << b[i] << ' '; } }
replace
81
82
81
82
0
p02557
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; typedef long long ll; void pv(vector<int> &v) { for (int i = 0; i < v.size(); i++) cout << v[i] << " "; cout << endl; } void solve() {} int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n; cin >> n; vector<int> a(n, 0); vector<int> b(n, 0); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; reverse(b.begin(), b.end()); // pv(b); int prob = 0; for (int i = 0; i < n; i++) { if (a[i] == b[i]) prob++; } int c = -1; int l = INT_MAX; int r = INT_MIN; for (int i = 0; i < n; i++) { if (a[i] == b[i]) { c = a[i]; l = i; break; } } for (int i = n - 1; i >= 0; i--) { if (a[i] == b[i]) { r = i; break; } } int toSwap = (r - l + 1); if (toSwap == 0 || prob == 0) { cout << "Yes" << endl; pv(b); return 0; } int l0 = l; int r0 = r; int avail = 0; for (int i = 0; i < l; i++) { if (a[i] != c && b[i] != c) avail++; } for (int i = r + 1; i < n; i++) { if (a[i] != c && b[i] != c) avail++; } if (avail < toSwap) { cout << "No" << endl; return 0; } else cout << "Yes" << endl; int i = 0; int j = r0 + 1; while (l <= r) { if (i < l0 && i < n) { if (a[i] != c && b[i] != c) { swap(b[i], b[l]); l++; } } i++; // if(i == n) break; } // if(j < n) { while (l <= r) { if (j < n && a[j] != c && b[j] != c) { swap(b[j], b[l]); l++; } j++; // if(j == n) break; } // } // while(l <= r) { // if(i < l0 && a[i] != c && b[i] != c) { // swap(b[i], b[l]); // l++; // i++; // continue; // } // else if(i == l0 && a[j] != c && b[j] != c && j < n) { // swap(b[j], b[l]); // l++; // j++; // continue; // } // i++; // if(i == l0) j++; // } pv(b); return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; void pv(vector<int> &v) { for (int i = 0; i < v.size(); i++) cout << v[i] << " "; cout << endl; } void solve() {} int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n; cin >> n; vector<int> a(n, 0); vector<int> b(n, 0); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; reverse(b.begin(), b.end()); // pv(b); int prob = 0; for (int i = 0; i < n; i++) { if (a[i] == b[i]) prob++; } int c = -1; int l = INT_MAX; int r = INT_MIN; for (int i = 0; i < n; i++) { if (a[i] == b[i]) { c = a[i]; l = i; break; } } for (int i = n - 1; i >= 0; i--) { if (a[i] == b[i]) { r = i; break; } } int toSwap = (r - l + 1); if (toSwap == 0 || prob == 0) { cout << "Yes" << endl; pv(b); return 0; } int l0 = l; int r0 = r; int avail = 0; for (int i = 0; i < l; i++) { if (a[i] != c && b[i] != c) avail++; } for (int i = r + 1; i < n; i++) { if (a[i] != c && b[i] != c) avail++; } if (avail < toSwap) { cout << "No" << endl; return 0; } else cout << "Yes" << endl; int i = 0; int j = r0 + 1; while (l <= r) { if (i < l0 && i < n) { if (a[i] != c && b[i] != c) { swap(b[i], b[l]); l++; } } i++; if (i == n) break; } // if(j < n) { while (l <= r) { if (j < n && a[j] != c && b[j] != c) { swap(b[j], b[l]); l++; } j++; // if(j == n) break; } // } // while(l <= r) { // if(i < l0 && a[i] != c && b[i] != c) { // swap(b[i], b[l]); // l++; // i++; // continue; // } // else if(i == l0 && a[j] != c && b[j] != c && j < n) { // swap(b[j], b[l]); // l++; // j++; // continue; // } // i++; // if(i == l0) j++; // } pv(b); return 0; }
replace
87
88
87
89
TLE
p02557
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define fastIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define int long long int #define fi first #define se second #define pub push_back #define pi pair<int, int> #define all(v) (v).begin(), (v).end() #define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++) #define repd(i, l, r) for (int i = (int)(l); i >= (int)(r); i--) #define clrg(i, l, r) \ for (int i = (int)(l); i < (int)(r); i++) \ vis[i] = 0, v[i].clear(); int power(int x, unsigned int y) { int res = 1; while (y > 0) { if (y & 1) { res = res * x; } y = y >> 1; x = x * x; } return res; } int powermod(int x, unsigned int y, int p) { int res = 1; x = x % p; while (y > 0) { if (y & 1) { res = (res * x) % p; } y = y >> 1; x = (x * x) % p; } return res; } #define print2d(mat, n, m) \ { \ for (int i = 0; i < (int)(n); i++) { \ for (int j = 0; j < (m); j++) { \ cout << mat[i][j] << " "; \ } \ cout << endl; \ } \ } #define clr(a, x) memset(a, x, sizeof(a)) #define rr(v) for (auto &val : v) #define print(v) \ for (const auto itr : v) { \ cout << itr << ' '; \ } \ cout << "\n"; #define ln length() #define sz size() #define mod 1000000007 #define elif else if int32_t main() { int n; cin >> n; vector<int> v(n), u(n); rep(i, 0, n) cin >> v[i]; rep(i, 0, n) cin >> u[i]; reverse(all(u)); int l = 0, r = n - 1, c = -1; rep(i, 0, n) { if (u[i] == v[i]) { l = i; c = v[i]; break; } } repd(i, n - 1, 0) { if (u[i] == v[i]) { r = i; break; } } rep(i, 0, n) { if (u[i] != c and v[i] != c) { swap(u[i], u[l++]); } } if (l <= r) cout << "No\n"; else { cout << "Yes\n"; print(u); } return 0; } /* Edge cases? n=1? a[i]<=0? long vs int? 1LL? 64bits? Re-read problem. Is it as easy as it seems? KEEP CORRECTING AND SUBMITTING! */
#include <bits/stdc++.h> using namespace std; #define fastIO \ ios_base::sync_with_stdio(false); \ cin.tie(NULL); \ cout.tie(NULL); #define int long long int #define fi first #define se second #define pub push_back #define pi pair<int, int> #define all(v) (v).begin(), (v).end() #define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++) #define repd(i, l, r) for (int i = (int)(l); i >= (int)(r); i--) #define clrg(i, l, r) \ for (int i = (int)(l); i < (int)(r); i++) \ vis[i] = 0, v[i].clear(); int power(int x, unsigned int y) { int res = 1; while (y > 0) { if (y & 1) { res = res * x; } y = y >> 1; x = x * x; } return res; } int powermod(int x, unsigned int y, int p) { int res = 1; x = x % p; while (y > 0) { if (y & 1) { res = (res * x) % p; } y = y >> 1; x = (x * x) % p; } return res; } #define print2d(mat, n, m) \ { \ for (int i = 0; i < (int)(n); i++) { \ for (int j = 0; j < (m); j++) { \ cout << mat[i][j] << " "; \ } \ cout << endl; \ } \ } #define clr(a, x) memset(a, x, sizeof(a)) #define rr(v) for (auto &val : v) #define print(v) \ for (const auto itr : v) { \ cout << itr << ' '; \ } \ cout << "\n"; #define ln length() #define sz size() #define mod 1000000007 #define elif else if int32_t main() { int n; cin >> n; vector<int> v(n), u(n); rep(i, 0, n) cin >> v[i]; rep(i, 0, n) cin >> u[i]; reverse(all(u)); int l = 0, r = n - 1, c = -1; rep(i, 0, n) { if (u[i] == v[i]) { l = i; c = v[i]; break; } } repd(i, n - 1, 0) { if (u[i] == v[i]) { r = i; break; } } rep(i, 0, n) { if (u[i] != c and v[i] != c and l <= r) { swap(u[i], u[l++]); } } if (l <= r) cout << "No\n"; else { cout << "Yes\n"; print(u); } return 0; } /* Edge cases? n=1? a[i]<=0? long vs int? 1LL? 64bits? Re-read problem. Is it as easy as it seems? KEEP CORRECTING AND SUBMITTING! */
replace
82
83
82
83
0
p02557
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define x first #define y second #define pb push_back using namespace std; typedef long long LL; typedef pair<int, int> PII; const double PI = acos(-1.0); const double eps = 1e-8; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const int N = 3e5 + 10; const int M = 1e6 + 10; const int mod = 1e9 + 7; inline LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; } inline LL lcm(LL a, LL b) { return a * b / gcd(a, b); } inline LL read() { LL x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } return x * f; } inline LL qpow(LL x, LL k = mod - 2, LL m = mod) { LL res = 1; while (k) { if (k & 1) res = res * x % m; x = x * x % m; k >>= 1; } return res; } /*=================================================================================================================*/ int n, a[N], b[N]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) scanf("%d", &b[i]); reverse(b + 1, b + n + 1); for (int i = 1; i <= n; i++) { if (b[i] != a[i]) continue; for (int k = 1; k <= n; k++) if (b[i] != a[k] && b[k] != a[i]) { swap(b[i], b[k]); break; } } for (int i = 1; i <= n; i++) if (a[i] == b[i]) return printf("No\n"), 0; printf("Yes\n"); for (int i = 1; i <= n; i++) printf("%d ", b[i]); return 0; }
#include <bits/stdc++.h> #define x first #define y second #define pb push_back using namespace std; typedef long long LL; typedef pair<int, int> PII; const double PI = acos(-1.0); const double eps = 1e-8; const int inf = 0x3f3f3f3f; const LL INF = 0x3f3f3f3f3f3f3f3f; const int N = 3e5 + 10; const int M = 1e6 + 10; const int mod = 1e9 + 7; inline LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; } inline LL lcm(LL a, LL b) { return a * b / gcd(a, b); } inline LL read() { LL x = 0, f = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } return x * f; } inline LL qpow(LL x, LL k = mod - 2, LL m = mod) { LL res = 1; while (k) { if (k & 1) res = res * x % m; x = x * x % m; k >>= 1; } return res; } /*=================================================================================================================*/ int n, a[N], b[N]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) scanf("%d", &b[i]); reverse(b + 1, b + n + 1); for (int i = 1; i <= n; i++) { if (b[i] != a[i]) continue; for (int k = 1; k <= n; k++) if (b[i] != a[k] && b[k] != a[i]) { swap(b[i], b[k]); break; } if (b[i] == a[i]) break; } for (int i = 1; i <= n; i++) if (a[i] == b[i]) return printf("No\n"), 0; printf("Yes\n"); for (int i = 1; i <= n; i++) printf("%d ", b[i]); return 0; }
insert
58
58
58
60
TLE
p02557
C++
Time Limit Exceeded
#include <algorithm> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <vector> // using namespace atcoder; // #include <atcoder/convolution> // #include <atcoder/lazysegtree> // #include <atcoder/math> // #include <atcoder/maxflow> // #include <atcoder/mincostflow> // #include <atcoder/modint> // #include <atcoder/scc> // #include <atcoder/segtree> // #include <atcoder/string> // #include <atcoder/twosat> using namespace std; // マクロ&定数&関数 ================================================ typedef unsigned int uint; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pint; typedef vector<int> vint; typedef vector<ll> vll; typedef vector<double> vdouble; typedef vector<bool> vbool; typedef vector<string> vstring; typedef vector<pair<int, int>> vpint; typedef vector<pair<ll, ll>> vpll; typedef vector<pair<double, double>> vpdouble; typedef vector<vector<int>> vvint; typedef vector<vector<ll>> vvll; typedef vector<vpint> vvpint; typedef vector<vpll> vvpll; typedef vector<vector<double>> vvdouble; typedef vector<vector<string>> vvstring; typedef vector<vector<bool>> vvbool; typedef vector<vector<vector<ll>>> vvvll; typedef vector<vector<vector<bool>>> vvvbool; const int INF = 1e9 + 1; const ll LLINF = 1e17 + 1; const int DX[9] = {0, 0, 1, -1, 1, 1, -1, -1, 0}; // 4;4近傍 const int DY[9] = {1, -1, 0, 0, 1, -1, 1, -1, 0}; // 8:8近傍 9:(0,0)を含む const double PI = 3.14159265358979323846264338327950288; // VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV const ll MOD = 1000000007; // 10^9 + 7 // VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } else return false; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } else return false; } //--------------------------------------------------------------- // オーバーフローチェック //--------------------------------------------------------------- void is_overflow(ll a, ll b) { if ((a * b) / b != a) cout << "OVERFLOW!!!!!" << endl; } //--------------------------------------------------------------- // 整数の乱数生成 //--------------------------------------------------------------- ll random_int(ll start, ll last) { // srand((uint)time(NULL)); return start + rand() % (last - start + 1); } //--------------------------------------------------------------- // x∈[a, b) //--------------------------------------------------------------- bool is_in(ll x, ll a, ll b) { return (a <= x && x < b); } //--------------------------------------------------------------- // 約数列挙 //--------------------------------------------------------------- vll divisor(ll n) { vll ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } //--------------------------------------------------------------- // N以下のすべての素数を列挙する(エラトステネスの篩) //--------------------------------------------------------------- vbool searchSosuu(ll N) { vbool sosuu; for (ll i = 0; i < N; i++) { sosuu.emplace_back(true); } sosuu[0] = false; sosuu[1] = false; for (ll i = 2; i < N; i++) { if (sosuu[i]) { for (ll j = 2; i * j < N; j++) { sosuu[i * j] = false; } } } return sosuu; } //--------------------------------------------------------------- // 素因数分解 O(√N) //--------------------------------------------------------------- vpll to_prime(ll n) { vpll prime_factor; for (ll i = 2; i * i <= n; i++) { ll count = 0; while (n % i == 0) { count++; n /= i; } if (count) { pair<ll, ll> temp = {i, count}; prime_factor.emplace_back(temp); } } if (n != 1) { pair<ll, ll> temp = {n, 1}; prime_factor.emplace_back(temp); } return prime_factor; } //--------------------------------------------------------------- // 高速素因数分解(前処理O(N), 分解O(logN)) //--------------------------------------------------------------- class FastPrime { public: vll div; vbool is_sosuu; FastPrime(ll N) : div(N + 10, -1), is_sosuu(N + 10, true) { for (ll i = 2; i < N; i++) if (div[i] == -1) for (ll j = 2; i * j <= N; j++) { div[i * j] = i; is_sosuu[i * j] = false; } } vpll to_prime(ll N) { if (N == 1) return vpll({}); vll divs; while (div[N] != -1) { divs.emplace_back(div[N]); N /= div[N]; } if (N > 1) divs.emplace_back(N); sort(divs.begin(), divs.end()); vpll primes; ll count = 1; for (int i = 1; i < divs.size(); i++) { if (divs[i] > divs[i - 1]) { primes.emplace_back(pll(divs[i - 1], count)); count = 0; } count++; } primes.emplace_back(pll(divs[divs.size() - 1], count)); return primes; } }; //--------------------------------------------------------------- // 最大公約数(ユークリッドの互除法) //--------------------------------------------------------------- ll gcd(ll a, ll b) { if (a < b) { ll tmp = a; a = b; b = tmp; } ll r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; } //--------------------------------------------------------------- // 最小公倍数 //--------------------------------------------------------------- ll lcm(ll a, ll b) { ll temp = gcd(a, b); return temp * (a / temp) * (b / temp); } //--------------------------------------------------------------- // 階乗 //--------------------------------------------------------------- ll factorial(ll n) { if (n <= 1) { return 1; } return (n * (factorial(n - 1))) % MOD; } //--------------------------------------------------------------- // 高速コンビネーション計算(前処理:O(N) 計算:O(1)) //--------------------------------------------------------------- // テーブルを作る前処理 ll comb_const = 300005; vll fac(comb_const), finv(comb_const), inv(comb_const); bool COMineted = false; void COMinit(ll mod = MOD) { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < comb_const; 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; } COMineted = true; } // 二項係数計算 ll COM(ll n, ll k, ll mod = MOD) { if (COMineted == false) COMinit(mod); if (n < k) return 0; if (n < 0 || k < 0) return 0; return (fac[n] * (finv[k] * finv[n - k] % mod)) % mod; } //--------------------------------------------------------------- // 繰り返し2乗法 base^sisuu //--------------------------------------------------------------- ll RepeatSquaring(ll base, ll sisuu, ll mod = MOD) { if (sisuu < 0) { cout << "RepeatSquaring: 指数が負です!" << endl; return 0; } if (sisuu == 0) return 1; if (sisuu % 2 == 0) { ll t = RepeatSquaring(base, sisuu / 2, mod) % mod; return (t * t) % mod; } return (base * RepeatSquaring(base, sisuu - 1, mod)) % mod; } //--------------------------------------------------------------- // 高速単発コンビネーション計算(O(logN)) //--------------------------------------------------------------- ll fast_com(ll a, ll b, ll mod = MOD) { ll bunshi = 1; ll bunbo = 1; for (ll i = 1; i <= b; i++) { bunbo *= i; bunbo %= mod; bunshi *= (a - i + 1); bunshi %= mod; } ll ret = bunshi * RepeatSquaring(bunbo, mod - 2, mod); ret %= mod; while (ret < 0) { ret += mod; } return ret; } //--------------------------------------------------------------- // 整数をビットのリストに変換する ll->vbool //--------------------------------------------------------------- vbool to_bitlist(ll bit, ll fixed_size = 1) { if (bit == 0) return vbool(fixed_size, 0); vbool list; while (bit > 0) { list.emplace_back(bit & 1); bit /= 2; } while (list.size() < fixed_size) { list.emplace_back(0); } return list; } //--------------------------------------------------------------- // 座標圧縮(O(NlogN)) 0スタートになることに注意! //--------------------------------------------------------------- class PosPress { /* 配列Pを座圧→instance = PosPress(P); 座圧済み配列→instance.pressed fooの圧縮後→instance.func[foo] fooの圧縮前→instance.rev[foo] */ public: vll pressed; map<ll, ll> func; map<ll, ll> rev; PosPress(vll P) { pressed = P; sort(P.begin(), P.end()); func[P[0]] = 0; rev[0] = P[0]; ll next = 1; for (int i = 1; i < P.size(); i++) { if (P[i] != P[i - 1]) { func[P[i]] = next; rev[next] = P[i]; next++; } } for (int i = 0; i < P.size(); i++) { pressed[i] = func[pressed[i]]; } } }; //--------------------------------------------------------------- // 行列累乗(O(N^3)) //--------------------------------------------------------------- vvll mat_cross(vvll A, vvll B) { ll N = A.size(); ll K = B.size(); ll M = B[0].size(); vvll C(N, vll(M)); for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) for (int k = 0; k < K; k++) C[i][j] += A[i][k] * B[k][j]; return C; } //--------------------------------------------------------------- // 2直線の交差判定(直線(x1, y1)->(x2, y2) と 直線(X1, Y1)->(X2, Y2)) //--------------------------------------------------------------- bool is_cross(ll x1, ll y1, ll x2, ll y2, ll X1, ll Y1, ll X2, ll Y2) { ll dx_ai = X1 - x1; ll dy_ai = Y1 - y1; ll dx_bi = X1 - x2; ll dy_bi = Y1 - y2; ll dx_ai2 = X2 - x1; ll dy_ai2 = Y2 - y1; ll dx_bi2 = X2 - x2; ll dy_bi2 = Y2 - y2; ll si = dx_ai * dy_bi - dy_ai * dx_bi; ll si2 = dx_ai2 * dy_bi2 - dy_ai2 * dx_bi2; ll si3 = dx_ai * dy_ai2 - dy_ai * dx_ai2; ll si4 = dx_bi * dy_bi2 - dy_bi * dx_bi2; return (si * si2 < 0 && si3 * si4 < 0); } //--------------------------------------------------------------- // 最長増加部分列の長さ(O(NlogN)) //--------------------------------------------------------------- ll LSI(vll vec) { ll size = vec.size(); vll lsi(size + 1); // 長さjを作った時の右端の最小値 for (ll i = 0; i <= size; i++) { lsi[i] = LLINF; } lsi[0] = 0; lsi[1] = vec[0]; for (ll i = 1; i < size; i++) { // 初めてvec[i]の方が小さくなるところを探す auto Iter = lower_bound(lsi.begin(), lsi.end(), vec[i]); ll idx = Iter - lsi.begin(); if (idx > 0 && lsi[idx - 1] < vec[i]) { lsi[idx] = vec[i]; } } for (ll i = size; i >= 0; i--) { if (lsi[i] < LLINF) { return i; } } } //--------------------------------------------------------------- // LCS(最長共通部分列) O(|S||T|) //--------------------------------------------------------------- string LCS(string S, string T) { vvll dp(S.length() + 1); for (int i = 0; i < dp.size(); i++) { vll t(T.length() + 1, 0); dp[i] = t; } for (int i = 0; i < S.length(); i++) { for (int j = 0; j < T.length(); j++) { dp[i + 1][j + 1] = max({dp[i][j] + ll(S[i] == T[j]), dp[i + 1][j], dp[i][j + 1], dp[i + 1][j + 1]}); } } ll len = dp[S.length()][T.length()]; string ans = ""; ll i = dp.size() - 1; ll j = dp[0].size() - 1; while (len > 0) { if (dp[i - 1][j] == len) { i--; } else if (dp[i][j - 1] == len) { j--; } else { ans += S[i - 1]; i--; j--; len--; } } reverse(ans.begin(), ans.end()); return ans; } vll LCS(vll S, vll T) { vvll dp(S.size() + 1); for (int i = 0; i < dp.size(); i++) { vll t(T.size() + 1, 0); dp[i] = t; } for (int i = 0; i < S.size(); i++) { for (int j = 0; j < T.size(); j++) { dp[i + 1][j + 1] = max({dp[i][j] + ll(S[i] == T[j]), dp[i + 1][j], dp[i][j + 1], dp[i + 1][j + 1]}); } } ll len = dp[S.size()][T.size()]; vll ans; ll i = dp.size() - 1; ll j = dp[0].size() - 1; while (len > 0) { if (dp[i - 1][j] == len) { i--; } else if (dp[i][j - 1] == len) { j--; } else { ans.emplace_back(S[i - 1]); i--; j--; len--; } } reverse(ans.begin(), ans.end()); return ans; } //--------------------------------------------------------------- // 木の根からの深さ //--------------------------------------------------------------- vll tree_depth(vvll edge, ll start_node) { ll n_node = edge.size(); vll dist(n_node, LLINF); dist[start_node] = 0; stack<pll> S; S.push({start_node, 0}); while (!S.empty()) { ll node = S.top().first; ll d = S.top().second; dist[node] = d; S.pop(); for (int i = 0; i < edge[node].size(); i++) { if (dist[edge[node][i]] == LLINF) { S.push({edge[node][i], d + 1}); } } } return dist; } //--------------------------------------------------------------- // ワーシャルフロイド法(O(N^3)) d: 正方行列(N*N) //--------------------------------------------------------------- vvll warshall_floyd(vvll d) { ll n = d.size(); for (int k = 0; k < n; k++) { // 経由する頂点 for (int i = 0; i < n; i++) { // 始点 for (int j = 0; j < n; j++) { // 終点 d[i][j] = min(d[i][j], d[i][k] + d[k][j]); } } } return d; } //--------------------------------------------------------------- // Union Find //--------------------------------------------------------------- class UnionFind { public: /* UnionFind uf(要素の個数); for(int i = 0;i < 関係の個数; i++) { uf.merge(A[i], B[i]); } nを含む集合の大きさ = uf.size(n) nを含む集合の代表者 = uf.root(n) 集合の個数 = uf.n_group */ vector<ll> par; // 各元の親を表す配列 vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化) ll n_group; // 集合の数 // Constructor UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) { for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 n_group = sz_; } void init(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); // resize だとなぜか初期化されなかった for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } // Member Function // Find ll root(ll x) { // 根の検索 while (par[x] != x) { x = par[x] = par[par[x]]; // x の親の親を x の親とする } return x; } // Union(Unite, Merge) bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; // merge technique(データ構造をマージするテク.小を大にくっつける) if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; n_group--; return true; } bool issame(ll x, ll y) { // 連結判定 return root(x) == root(y); } ll size(ll x) { // 素集合のサイズ return siz[root(x)]; } }; //--------------------------------------------------------------- // ダイクストラ(O(ElogV)) edge: 隣接リスト from->pair{to, cost} //--------------------------------------------------------------- class Dijkstra { public: vll dist; // iまでの最短距離 vll past; // (iまで最短で行くときの一つ前) // edge[i] -> {to, cost} Dijkstra(vvpll edge, ll start) : dist(edge.size(), LLINF), past(edge.size(), -1) { using Pi = pll; priority_queue<Pi, vector<Pi>, greater<Pi>> que; dist[start] = 0; que.emplace(dist[start], start); while (!que.empty()) { ll cost; int idx; tie(cost, idx) = que.top(); que.pop(); if (dist[idx] < cost) continue; for (int i = 0; i < edge[idx].size(); i++) { ll next_cost = cost + edge[idx][i].second; if (dist[edge[idx][i].first] <= next_cost) continue; dist[edge[idx][i].first] = next_cost; past[edge[idx][i].first] = idx; que.emplace(dist[edge[idx][i].first], edge[idx][i].first); } } } // goalまでの最短経路 vll shortest(ll goal) { vll ret; while (goal != -1) { ret.emplace_back(goal); goal = past[goal]; } reverse(ret.begin(), ret.end()); return ret; } }; //--------------------------------------------------------------- // LCA: 最近共通祖先 (O()) //--------------------------------------------------------------- class Lca { public: vll depth; // 根0からiまでの最短距離 vvll doubling; ll n_bit = 30; // edge[i] -> {to, cost} Lca(vvll edge, ll root = 0) : doubling(50, vll(edge.size(), -1)) { // 深さ depth = tree_depth(edge, root); // ダブリングで親を辿れるようにする // jから2^i回親を辿ったノード doubling[0][0] = -1; for (int i = 1; i < edge.size(); i++) for (int j : edge[i]) if (depth[i] > depth[j]) { doubling[0][i] = j; break; } for (int i = 1; i < n_bit; i++) for (int j = 0; j < edge.size(); j++) { if (doubling[i - 1][j] != -1) doubling[i][j] = doubling[i - 1][doubling[i - 1][j]]; else doubling[i][j] = -1; } } // aとbの最近共通祖先 ll get_lca(ll a, ll b) { // depth[a] >= depth[b]にする if (depth[a] < depth[b]) swap(a, b); ll oa = a; ll ob = b; ll d = depth[a] - depth[b]; // aをdだけさかのぼる。 vbool bit = to_bitlist(d, n_bit); for (int i = 0; i < n_bit; i++) if (bit[i]) a = doubling[i][a]; // depth[a] == depth[b]になっている。 for (int i = n_bit - 1; i >= 0; i--) { if (doubling[i][a] == doubling[i][b]) continue; a = doubling[i][a]; b = doubling[i][b]; } return a == b ? a : doubling[0][a]; } }; //--------------------------------------------------------------- // Z-algorithm(SとS[i:]の最長接頭辞長) O(|S|) //--------------------------------------------------------------- vll Zalgorithm(string S) { ll n = S.size(); vll Z(n, 0); ll start = -1; ll last = -1; for (ll i = 1; i < n; i++) { if (start >= 0) { Z[i] = min(Z[i - start], last - i); chmax(Z[i], 0LL); } while (i + Z[i] < S.size() && S[Z[i]] == S[i + Z[i]]) Z[i]++; if (last < i + Z[i]) { last = i + Z[i]; start = i; } } Z[0] = n; return Z; } vll Zalgorithm(vll S) { ll n = S.size(); vll Z(n, 0); ll start = -1; ll last = -1; for (ll i = 1; i < n; i++) { if (start >= 0) { Z[i] = min(Z[i - start], last - i); chmax(Z[i], 0LL); } while (i + Z[i] < S.size() && S[Z[i]] == S[i + Z[i]]) Z[i]++; if (last < i + Z[i]) { last = i + Z[i]; start = i; } } Z[0] = n; return Z; } //--------------------------------------------------------------- // 二部グラフ判定(O(E)) edge -> リスト //--------------------------------------------------------------- bool is_bipartite(vvll edge) { ll N = edge.size(); vll color(N, -1); color[0] = 0; queue<ll> Q; Q.push(0); while (!Q.empty()) { ll now = Q.front(); Q.pop(); for (int i : edge[now]) { if (color[i] == -1) { color[i] = (color[now] == 0 ? 1 : 0); Q.push(i); } else if (color[i] == color[now]) { return false; } } } return true; } //--------------------------------------------------------------- // セグメント木 //--------------------------------------------------------------- class SegmentTree { public: const ll SEG_LEN = 1 << 19; vector<ll> seg; ll s; ll E; SegmentTree(ll N, ll e) : seg(SEG_LEN * 2, e) { s = N; E = e; } ll func(ll a, ll b) { return a + b; } void set(ll p, ll to) { ll pos = p + SEG_LEN; seg[pos] = to; while (true) { pos /= 2; if (pos <= 0) break; seg[pos] = func(seg[pos * 2], seg[pos * 2 + 1]); } } void add(ll p, ll d) { ll pos = p + SEG_LEN; seg[pos] += d; while (true) { pos /= 2; if (pos <= 0) break; seg[pos] = func(seg[pos * 2], seg[pos * 2 + 1]); } } ll get(ll left, ll right) { left += SEG_LEN; right += SEG_LEN + 1; ll ret = E; while (left < right) { while (left % 2 == 1) { ret = func(ret, seg[left]); left++; } while (right % 2 == 1) { ret = func(ret, seg[right - 1]); right--; } left /= 2; right /= 2; } return ret; } }; //--------------------------------------------------------------- // ダブリング //--------------------------------------------------------------- class Doubling { public: ll M = 100; vvll doubling; Doubling(vll to) : doubling(M, vll(to.size(), -1)) { ll N = to.size(); for (int i = 0; i < N; i++) doubling[0][i] = to[i]; for (int i = 1; i < M; i++) for (int j = 0; j < N; j++) doubling[i][j] = doubling[i - 1][doubling[i - 1][j]]; } ll destination(ll from, ll K) { vbool bits = to_bitlist(K); ll now = from; for (int i = 0; i < bits.size(); i++) { if (bits[i]) { now = doubling[i][now]; } } return now; } }; //======================================================================== //======================================================================== //======================================================================== //======================================================================== int main() { //////================================== cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(25); //////================================== /* ~思いついたことはとりあえず絶対メモする!!~ */ ll N; cin >> N; vll A(N), B(N); for (int i = 0; i < N; i++) cin >> A[i]; for (int i = 0; i < N; i++) cin >> B[i]; ll M = 2 * 1e5 + 5; vll Acount(M, 0), Bcount(M, 0); for (int i = 0; i < N; i++) { Acount[A[i]]++; Bcount[B[i]]++; } for (int i = 0; i < M; i++) { if (Acount[i] + Bcount[i] > N) { cout << "No"; return 0; } } for (int q = 0; q < 1; q++) { bool ok = true; for (int i = 0; i < N; i++) { if (A[i] == B[i]) { for (int j = N - 1; j > i; j--) { if (A[i] != B[j]) { swap(B[i], B[j]); break; } } for (int j = i; j >= 0; j--) { if (A[i] != B[j] && B[i] != A[j]) { swap(B[i], B[j]); break; } } } if (A[i] == B[i]) { ok = false; break; } } if (ok) { for (int i = 0; i < N; i++) { if (A[i] == B[i]) ok = false; } if (ok) { cout << "Yes" << endl; for (int i = 0; i < N; i++) { cout << B[i] << " "; } return 0; } } } cout << "No"; }
#include <algorithm> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <numeric> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <vector> // using namespace atcoder; // #include <atcoder/convolution> // #include <atcoder/lazysegtree> // #include <atcoder/math> // #include <atcoder/maxflow> // #include <atcoder/mincostflow> // #include <atcoder/modint> // #include <atcoder/scc> // #include <atcoder/segtree> // #include <atcoder/string> // #include <atcoder/twosat> using namespace std; // マクロ&定数&関数 ================================================ typedef unsigned int uint; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pint; typedef vector<int> vint; typedef vector<ll> vll; typedef vector<double> vdouble; typedef vector<bool> vbool; typedef vector<string> vstring; typedef vector<pair<int, int>> vpint; typedef vector<pair<ll, ll>> vpll; typedef vector<pair<double, double>> vpdouble; typedef vector<vector<int>> vvint; typedef vector<vector<ll>> vvll; typedef vector<vpint> vvpint; typedef vector<vpll> vvpll; typedef vector<vector<double>> vvdouble; typedef vector<vector<string>> vvstring; typedef vector<vector<bool>> vvbool; typedef vector<vector<vector<ll>>> vvvll; typedef vector<vector<vector<bool>>> vvvbool; const int INF = 1e9 + 1; const ll LLINF = 1e17 + 1; const int DX[9] = {0, 0, 1, -1, 1, 1, -1, -1, 0}; // 4;4近傍 const int DY[9] = {1, -1, 0, 0, 1, -1, 1, -1, 0}; // 8:8近傍 9:(0,0)を含む const double PI = 3.14159265358979323846264338327950288; // VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV const ll MOD = 1000000007; // 10^9 + 7 // VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } else return false; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } else return false; } //--------------------------------------------------------------- // オーバーフローチェック //--------------------------------------------------------------- void is_overflow(ll a, ll b) { if ((a * b) / b != a) cout << "OVERFLOW!!!!!" << endl; } //--------------------------------------------------------------- // 整数の乱数生成 //--------------------------------------------------------------- ll random_int(ll start, ll last) { // srand((uint)time(NULL)); return start + rand() % (last - start + 1); } //--------------------------------------------------------------- // x∈[a, b) //--------------------------------------------------------------- bool is_in(ll x, ll a, ll b) { return (a <= x && x < b); } //--------------------------------------------------------------- // 約数列挙 //--------------------------------------------------------------- vll divisor(ll n) { vll ret; for (ll i = 1; i * i <= n; i++) { if (n % i == 0) { ret.push_back(i); if (i * i != n) ret.push_back(n / i); } } sort(begin(ret), end(ret)); return (ret); } //--------------------------------------------------------------- // N以下のすべての素数を列挙する(エラトステネスの篩) //--------------------------------------------------------------- vbool searchSosuu(ll N) { vbool sosuu; for (ll i = 0; i < N; i++) { sosuu.emplace_back(true); } sosuu[0] = false; sosuu[1] = false; for (ll i = 2; i < N; i++) { if (sosuu[i]) { for (ll j = 2; i * j < N; j++) { sosuu[i * j] = false; } } } return sosuu; } //--------------------------------------------------------------- // 素因数分解 O(√N) //--------------------------------------------------------------- vpll to_prime(ll n) { vpll prime_factor; for (ll i = 2; i * i <= n; i++) { ll count = 0; while (n % i == 0) { count++; n /= i; } if (count) { pair<ll, ll> temp = {i, count}; prime_factor.emplace_back(temp); } } if (n != 1) { pair<ll, ll> temp = {n, 1}; prime_factor.emplace_back(temp); } return prime_factor; } //--------------------------------------------------------------- // 高速素因数分解(前処理O(N), 分解O(logN)) //--------------------------------------------------------------- class FastPrime { public: vll div; vbool is_sosuu; FastPrime(ll N) : div(N + 10, -1), is_sosuu(N + 10, true) { for (ll i = 2; i < N; i++) if (div[i] == -1) for (ll j = 2; i * j <= N; j++) { div[i * j] = i; is_sosuu[i * j] = false; } } vpll to_prime(ll N) { if (N == 1) return vpll({}); vll divs; while (div[N] != -1) { divs.emplace_back(div[N]); N /= div[N]; } if (N > 1) divs.emplace_back(N); sort(divs.begin(), divs.end()); vpll primes; ll count = 1; for (int i = 1; i < divs.size(); i++) { if (divs[i] > divs[i - 1]) { primes.emplace_back(pll(divs[i - 1], count)); count = 0; } count++; } primes.emplace_back(pll(divs[divs.size() - 1], count)); return primes; } }; //--------------------------------------------------------------- // 最大公約数(ユークリッドの互除法) //--------------------------------------------------------------- ll gcd(ll a, ll b) { if (a < b) { ll tmp = a; a = b; b = tmp; } ll r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; } //--------------------------------------------------------------- // 最小公倍数 //--------------------------------------------------------------- ll lcm(ll a, ll b) { ll temp = gcd(a, b); return temp * (a / temp) * (b / temp); } //--------------------------------------------------------------- // 階乗 //--------------------------------------------------------------- ll factorial(ll n) { if (n <= 1) { return 1; } return (n * (factorial(n - 1))) % MOD; } //--------------------------------------------------------------- // 高速コンビネーション計算(前処理:O(N) 計算:O(1)) //--------------------------------------------------------------- // テーブルを作る前処理 ll comb_const = 300005; vll fac(comb_const), finv(comb_const), inv(comb_const); bool COMineted = false; void COMinit(ll mod = MOD) { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < comb_const; 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; } COMineted = true; } // 二項係数計算 ll COM(ll n, ll k, ll mod = MOD) { if (COMineted == false) COMinit(mod); if (n < k) return 0; if (n < 0 || k < 0) return 0; return (fac[n] * (finv[k] * finv[n - k] % mod)) % mod; } //--------------------------------------------------------------- // 繰り返し2乗法 base^sisuu //--------------------------------------------------------------- ll RepeatSquaring(ll base, ll sisuu, ll mod = MOD) { if (sisuu < 0) { cout << "RepeatSquaring: 指数が負です!" << endl; return 0; } if (sisuu == 0) return 1; if (sisuu % 2 == 0) { ll t = RepeatSquaring(base, sisuu / 2, mod) % mod; return (t * t) % mod; } return (base * RepeatSquaring(base, sisuu - 1, mod)) % mod; } //--------------------------------------------------------------- // 高速単発コンビネーション計算(O(logN)) //--------------------------------------------------------------- ll fast_com(ll a, ll b, ll mod = MOD) { ll bunshi = 1; ll bunbo = 1; for (ll i = 1; i <= b; i++) { bunbo *= i; bunbo %= mod; bunshi *= (a - i + 1); bunshi %= mod; } ll ret = bunshi * RepeatSquaring(bunbo, mod - 2, mod); ret %= mod; while (ret < 0) { ret += mod; } return ret; } //--------------------------------------------------------------- // 整数をビットのリストに変換する ll->vbool //--------------------------------------------------------------- vbool to_bitlist(ll bit, ll fixed_size = 1) { if (bit == 0) return vbool(fixed_size, 0); vbool list; while (bit > 0) { list.emplace_back(bit & 1); bit /= 2; } while (list.size() < fixed_size) { list.emplace_back(0); } return list; } //--------------------------------------------------------------- // 座標圧縮(O(NlogN)) 0スタートになることに注意! //--------------------------------------------------------------- class PosPress { /* 配列Pを座圧→instance = PosPress(P); 座圧済み配列→instance.pressed fooの圧縮後→instance.func[foo] fooの圧縮前→instance.rev[foo] */ public: vll pressed; map<ll, ll> func; map<ll, ll> rev; PosPress(vll P) { pressed = P; sort(P.begin(), P.end()); func[P[0]] = 0; rev[0] = P[0]; ll next = 1; for (int i = 1; i < P.size(); i++) { if (P[i] != P[i - 1]) { func[P[i]] = next; rev[next] = P[i]; next++; } } for (int i = 0; i < P.size(); i++) { pressed[i] = func[pressed[i]]; } } }; //--------------------------------------------------------------- // 行列累乗(O(N^3)) //--------------------------------------------------------------- vvll mat_cross(vvll A, vvll B) { ll N = A.size(); ll K = B.size(); ll M = B[0].size(); vvll C(N, vll(M)); for (int i = 0; i < N; i++) for (int j = 0; j < M; j++) for (int k = 0; k < K; k++) C[i][j] += A[i][k] * B[k][j]; return C; } //--------------------------------------------------------------- // 2直線の交差判定(直線(x1, y1)->(x2, y2) と 直線(X1, Y1)->(X2, Y2)) //--------------------------------------------------------------- bool is_cross(ll x1, ll y1, ll x2, ll y2, ll X1, ll Y1, ll X2, ll Y2) { ll dx_ai = X1 - x1; ll dy_ai = Y1 - y1; ll dx_bi = X1 - x2; ll dy_bi = Y1 - y2; ll dx_ai2 = X2 - x1; ll dy_ai2 = Y2 - y1; ll dx_bi2 = X2 - x2; ll dy_bi2 = Y2 - y2; ll si = dx_ai * dy_bi - dy_ai * dx_bi; ll si2 = dx_ai2 * dy_bi2 - dy_ai2 * dx_bi2; ll si3 = dx_ai * dy_ai2 - dy_ai * dx_ai2; ll si4 = dx_bi * dy_bi2 - dy_bi * dx_bi2; return (si * si2 < 0 && si3 * si4 < 0); } //--------------------------------------------------------------- // 最長増加部分列の長さ(O(NlogN)) //--------------------------------------------------------------- ll LSI(vll vec) { ll size = vec.size(); vll lsi(size + 1); // 長さjを作った時の右端の最小値 for (ll i = 0; i <= size; i++) { lsi[i] = LLINF; } lsi[0] = 0; lsi[1] = vec[0]; for (ll i = 1; i < size; i++) { // 初めてvec[i]の方が小さくなるところを探す auto Iter = lower_bound(lsi.begin(), lsi.end(), vec[i]); ll idx = Iter - lsi.begin(); if (idx > 0 && lsi[idx - 1] < vec[i]) { lsi[idx] = vec[i]; } } for (ll i = size; i >= 0; i--) { if (lsi[i] < LLINF) { return i; } } } //--------------------------------------------------------------- // LCS(最長共通部分列) O(|S||T|) //--------------------------------------------------------------- string LCS(string S, string T) { vvll dp(S.length() + 1); for (int i = 0; i < dp.size(); i++) { vll t(T.length() + 1, 0); dp[i] = t; } for (int i = 0; i < S.length(); i++) { for (int j = 0; j < T.length(); j++) { dp[i + 1][j + 1] = max({dp[i][j] + ll(S[i] == T[j]), dp[i + 1][j], dp[i][j + 1], dp[i + 1][j + 1]}); } } ll len = dp[S.length()][T.length()]; string ans = ""; ll i = dp.size() - 1; ll j = dp[0].size() - 1; while (len > 0) { if (dp[i - 1][j] == len) { i--; } else if (dp[i][j - 1] == len) { j--; } else { ans += S[i - 1]; i--; j--; len--; } } reverse(ans.begin(), ans.end()); return ans; } vll LCS(vll S, vll T) { vvll dp(S.size() + 1); for (int i = 0; i < dp.size(); i++) { vll t(T.size() + 1, 0); dp[i] = t; } for (int i = 0; i < S.size(); i++) { for (int j = 0; j < T.size(); j++) { dp[i + 1][j + 1] = max({dp[i][j] + ll(S[i] == T[j]), dp[i + 1][j], dp[i][j + 1], dp[i + 1][j + 1]}); } } ll len = dp[S.size()][T.size()]; vll ans; ll i = dp.size() - 1; ll j = dp[0].size() - 1; while (len > 0) { if (dp[i - 1][j] == len) { i--; } else if (dp[i][j - 1] == len) { j--; } else { ans.emplace_back(S[i - 1]); i--; j--; len--; } } reverse(ans.begin(), ans.end()); return ans; } //--------------------------------------------------------------- // 木の根からの深さ //--------------------------------------------------------------- vll tree_depth(vvll edge, ll start_node) { ll n_node = edge.size(); vll dist(n_node, LLINF); dist[start_node] = 0; stack<pll> S; S.push({start_node, 0}); while (!S.empty()) { ll node = S.top().first; ll d = S.top().second; dist[node] = d; S.pop(); for (int i = 0; i < edge[node].size(); i++) { if (dist[edge[node][i]] == LLINF) { S.push({edge[node][i], d + 1}); } } } return dist; } //--------------------------------------------------------------- // ワーシャルフロイド法(O(N^3)) d: 正方行列(N*N) //--------------------------------------------------------------- vvll warshall_floyd(vvll d) { ll n = d.size(); for (int k = 0; k < n; k++) { // 経由する頂点 for (int i = 0; i < n; i++) { // 始点 for (int j = 0; j < n; j++) { // 終点 d[i][j] = min(d[i][j], d[i][k] + d[k][j]); } } } return d; } //--------------------------------------------------------------- // Union Find //--------------------------------------------------------------- class UnionFind { public: /* UnionFind uf(要素の個数); for(int i = 0;i < 関係の個数; i++) { uf.merge(A[i], B[i]); } nを含む集合の大きさ = uf.size(n) nを含む集合の代表者 = uf.root(n) 集合の個数 = uf.n_group */ vector<ll> par; // 各元の親を表す配列 vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化) ll n_group; // 集合の数 // Constructor UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) { for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 n_group = sz_; } void init(ll sz_) { par.resize(sz_); siz.assign(sz_, 1LL); // resize だとなぜか初期化されなかった for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } // Member Function // Find ll root(ll x) { // 根の検索 while (par[x] != x) { x = par[x] = par[par[x]]; // x の親の親を x の親とする } return x; } // Union(Unite, Merge) bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; // merge technique(データ構造をマージするテク.小を大にくっつける) if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; n_group--; return true; } bool issame(ll x, ll y) { // 連結判定 return root(x) == root(y); } ll size(ll x) { // 素集合のサイズ return siz[root(x)]; } }; //--------------------------------------------------------------- // ダイクストラ(O(ElogV)) edge: 隣接リスト from->pair{to, cost} //--------------------------------------------------------------- class Dijkstra { public: vll dist; // iまでの最短距離 vll past; // (iまで最短で行くときの一つ前) // edge[i] -> {to, cost} Dijkstra(vvpll edge, ll start) : dist(edge.size(), LLINF), past(edge.size(), -1) { using Pi = pll; priority_queue<Pi, vector<Pi>, greater<Pi>> que; dist[start] = 0; que.emplace(dist[start], start); while (!que.empty()) { ll cost; int idx; tie(cost, idx) = que.top(); que.pop(); if (dist[idx] < cost) continue; for (int i = 0; i < edge[idx].size(); i++) { ll next_cost = cost + edge[idx][i].second; if (dist[edge[idx][i].first] <= next_cost) continue; dist[edge[idx][i].first] = next_cost; past[edge[idx][i].first] = idx; que.emplace(dist[edge[idx][i].first], edge[idx][i].first); } } } // goalまでの最短経路 vll shortest(ll goal) { vll ret; while (goal != -1) { ret.emplace_back(goal); goal = past[goal]; } reverse(ret.begin(), ret.end()); return ret; } }; //--------------------------------------------------------------- // LCA: 最近共通祖先 (O()) //--------------------------------------------------------------- class Lca { public: vll depth; // 根0からiまでの最短距離 vvll doubling; ll n_bit = 30; // edge[i] -> {to, cost} Lca(vvll edge, ll root = 0) : doubling(50, vll(edge.size(), -1)) { // 深さ depth = tree_depth(edge, root); // ダブリングで親を辿れるようにする // jから2^i回親を辿ったノード doubling[0][0] = -1; for (int i = 1; i < edge.size(); i++) for (int j : edge[i]) if (depth[i] > depth[j]) { doubling[0][i] = j; break; } for (int i = 1; i < n_bit; i++) for (int j = 0; j < edge.size(); j++) { if (doubling[i - 1][j] != -1) doubling[i][j] = doubling[i - 1][doubling[i - 1][j]]; else doubling[i][j] = -1; } } // aとbの最近共通祖先 ll get_lca(ll a, ll b) { // depth[a] >= depth[b]にする if (depth[a] < depth[b]) swap(a, b); ll oa = a; ll ob = b; ll d = depth[a] - depth[b]; // aをdだけさかのぼる。 vbool bit = to_bitlist(d, n_bit); for (int i = 0; i < n_bit; i++) if (bit[i]) a = doubling[i][a]; // depth[a] == depth[b]になっている。 for (int i = n_bit - 1; i >= 0; i--) { if (doubling[i][a] == doubling[i][b]) continue; a = doubling[i][a]; b = doubling[i][b]; } return a == b ? a : doubling[0][a]; } }; //--------------------------------------------------------------- // Z-algorithm(SとS[i:]の最長接頭辞長) O(|S|) //--------------------------------------------------------------- vll Zalgorithm(string S) { ll n = S.size(); vll Z(n, 0); ll start = -1; ll last = -1; for (ll i = 1; i < n; i++) { if (start >= 0) { Z[i] = min(Z[i - start], last - i); chmax(Z[i], 0LL); } while (i + Z[i] < S.size() && S[Z[i]] == S[i + Z[i]]) Z[i]++; if (last < i + Z[i]) { last = i + Z[i]; start = i; } } Z[0] = n; return Z; } vll Zalgorithm(vll S) { ll n = S.size(); vll Z(n, 0); ll start = -1; ll last = -1; for (ll i = 1; i < n; i++) { if (start >= 0) { Z[i] = min(Z[i - start], last - i); chmax(Z[i], 0LL); } while (i + Z[i] < S.size() && S[Z[i]] == S[i + Z[i]]) Z[i]++; if (last < i + Z[i]) { last = i + Z[i]; start = i; } } Z[0] = n; return Z; } //--------------------------------------------------------------- // 二部グラフ判定(O(E)) edge -> リスト //--------------------------------------------------------------- bool is_bipartite(vvll edge) { ll N = edge.size(); vll color(N, -1); color[0] = 0; queue<ll> Q; Q.push(0); while (!Q.empty()) { ll now = Q.front(); Q.pop(); for (int i : edge[now]) { if (color[i] == -1) { color[i] = (color[now] == 0 ? 1 : 0); Q.push(i); } else if (color[i] == color[now]) { return false; } } } return true; } //--------------------------------------------------------------- // セグメント木 //--------------------------------------------------------------- class SegmentTree { public: const ll SEG_LEN = 1 << 19; vector<ll> seg; ll s; ll E; SegmentTree(ll N, ll e) : seg(SEG_LEN * 2, e) { s = N; E = e; } ll func(ll a, ll b) { return a + b; } void set(ll p, ll to) { ll pos = p + SEG_LEN; seg[pos] = to; while (true) { pos /= 2; if (pos <= 0) break; seg[pos] = func(seg[pos * 2], seg[pos * 2 + 1]); } } void add(ll p, ll d) { ll pos = p + SEG_LEN; seg[pos] += d; while (true) { pos /= 2; if (pos <= 0) break; seg[pos] = func(seg[pos * 2], seg[pos * 2 + 1]); } } ll get(ll left, ll right) { left += SEG_LEN; right += SEG_LEN + 1; ll ret = E; while (left < right) { while (left % 2 == 1) { ret = func(ret, seg[left]); left++; } while (right % 2 == 1) { ret = func(ret, seg[right - 1]); right--; } left /= 2; right /= 2; } return ret; } }; //--------------------------------------------------------------- // ダブリング //--------------------------------------------------------------- class Doubling { public: ll M = 100; vvll doubling; Doubling(vll to) : doubling(M, vll(to.size(), -1)) { ll N = to.size(); for (int i = 0; i < N; i++) doubling[0][i] = to[i]; for (int i = 1; i < M; i++) for (int j = 0; j < N; j++) doubling[i][j] = doubling[i - 1][doubling[i - 1][j]]; } ll destination(ll from, ll K) { vbool bits = to_bitlist(K); ll now = from; for (int i = 0; i < bits.size(); i++) { if (bits[i]) { now = doubling[i][now]; } } return now; } }; //======================================================================== //======================================================================== //======================================================================== //======================================================================== int main() { //////================================== cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(25); //////================================== /* ~思いついたことはとりあえず絶対メモする!!~ */ ll N; cin >> N; vll A(N), B(N); for (int i = 0; i < N; i++) cin >> A[i]; for (int i = 0; i < N; i++) cin >> B[i]; ll M = 2 * 1e5 + 5; vll Acount(M, 0), Bcount(M, 0); for (int i = 0; i < N; i++) { Acount[A[i]]++; Bcount[B[i]]++; } for (int i = 0; i < M; i++) { if (Acount[i] + Bcount[i] > N) { cout << "No"; return 0; } } for (int q = 0; q < 1; q++) { std::random_device seed_gen; std::mt19937 engine(seed_gen()); shuffle(B.begin(), B.end(), engine); bool ok = true; for (int i = 0; i < N; i++) { if (A[i] == B[i]) { for (int j = N - 1; j > i; j--) { if (A[i] != B[j]) { swap(B[i], B[j]); break; } } for (int j = i; j >= 0; j--) { if (A[i] != B[j] && B[i] != A[j]) { swap(B[i], B[j]); break; } } } if (A[i] == B[i]) { ok = false; break; } } if (ok) { for (int i = 0; i < N; i++) { if (A[i] == B[i]) ok = false; } if (ok) { cout << "Yes" << endl; for (int i = 0; i < N; i++) { cout << B[i] << " "; } return 0; } } } cout << "No"; }
insert
914
914
914
918
TLE
p02557
C++
Time Limit Exceeded
#include <bits/stdc++.h> using namespace std; void Main() { int n; cin >> n; vector<int> a(n), b(n); map<int, int> m; for (int i = 0; i < n; i++) { cin >> a[i]; m[a[i]]++; } for (int i = 0; i < n; i++) { cin >> b[n - 1 - i]; m[b[i]]++; } for (auto i : m) { if (i.second > n) { cout << "No" << endl; return; } } cout << "Yes" << endl; for (int i = 0; i < n; i++) { while (a[i] == b[i]) { int r = rand() % n; if (a[r] != b[i] && b[r] != b[i]) { swap(b[i], b[r]); } } } for (int i = 0; i < n; i++) { if (i != 0) cout << " "; cout << b[i]; } cout << endl; } int main(int argc, char **argv) { ios::sync_with_stdio(false); std::cin.tie(nullptr); Main(); return 0; }
#include <bits/stdc++.h> using namespace std; void Main() { int n; cin >> n; vector<int> a(n), b(n); map<int, int> m; for (int i = 0; i < n; i++) { cin >> a[i]; m[a[i]]++; } for (int i = 0; i < n; i++) { cin >> b[n - 1 - i]; m[b[n - 1 - i]]++; } for (auto i : m) { if (i.second > n) { cout << "No" << endl; return; } } cout << "Yes" << endl; for (int i = 0; i < n; i++) { while (a[i] == b[i]) { int r = rand() % n; if (a[r] != b[i] && b[r] != b[i]) { swap(b[i], b[r]); } } } for (int i = 0; i < n; i++) { if (i != 0) cout << " "; cout << b[i]; } cout << endl; } int main(int argc, char **argv) { ios::sync_with_stdio(false); std::cin.tie(nullptr); Main(); return 0; }
replace
14
15
14
15
TLE
p02557
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define fo(i, a, b) for (int i = (a); i < (b); i++) #define qi queue<int> #define vi vector<int> #define ll long long #define pb push_back #define lb lower_bound #define ub upper_bound #define pii pair<int, int> #define mp make_pair #define all(a) (a).begin(), (a).end() #define fi first #define se second #define prq priority_queue #define foreach(it, c) \ for (__typeof((c).begin()) it = c.begin(); it != c.end(); it++) // #define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0) using namespace std; inline ll read() { ll x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + (c - '0'); return x * f; } inline void out(int x) { if (x >= 10) out(x / 10); putchar(x % 10 + '0'); } int n, a[202020], b[202020]; int main() { // freopen("a.in","r",stdin); // freopen("a.out","w",stdout); cin >> n; fo(i, 0, n) cin >> a[i]; fo(i, 0, n) cin >> b[i]; if (n <= 200000) { fo(i, 0, n) { bool q = 1; fo(j, i, i + n) if (a[j - i] == b[j % n]) { q = 0; break; } if (q) { cout << "Yes\n"; fo(j, i, i + n - 1) cout << b[j % n] << ' '; cout << b[(i + n - 1) % n] << endl; return 0; } } cout << "No\n"; return 0; } fo(i, 0, n) if (a[0] != b[i]) { fo(j, i, i + n) { while (a[j - i] == b[j % n]) { i++; j++; } if (i >= n) { cout << "No\n"; return 0; } } fo(j, i, i + n) if (a[j - i] == b[j % n]) { cout << "No\n"; return 0; } cout << "Yes\n"; fo(j, i, i + n - 1) cout << b[j % n] << ' '; cout << b[(i + n - 1) % n] << endl; return 0; } cout << "No\n"; return 0; }
#include <bits/stdc++.h> #define fo(i, a, b) for (int i = (a); i < (b); i++) #define qi queue<int> #define vi vector<int> #define ll long long #define pb push_back #define lb lower_bound #define ub upper_bound #define pii pair<int, int> #define mp make_pair #define all(a) (a).begin(), (a).end() #define fi first #define se second #define prq priority_queue #define foreach(it, c) \ for (__typeof((c).begin()) it = c.begin(); it != c.end(); it++) // #define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0) using namespace std; inline ll read() { ll x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + (c - '0'); return x * f; } inline void out(int x) { if (x >= 10) out(x / 10); putchar(x % 10 + '0'); } int n, a[202020], b[202020]; int main() { // freopen("a.in","r",stdin); // freopen("a.out","w",stdout); cin >> n; fo(i, 0, n) cin >> a[i]; fo(i, 0, n) cin >> b[i]; if (n <= 190000) { fo(i, 0, n) { bool q = 1; fo(j, i, i + n) if (a[j - i] == b[j % n]) { q = 0; break; } if (q) { cout << "Yes\n"; fo(j, i, i + n - 1) cout << b[j % n] << ' '; cout << b[(i + n - 1) % n] << endl; return 0; } } cout << "No\n"; return 0; } fo(i, 0, n) if (a[0] != b[i]) { fo(j, i, i + n) { while (a[j - i] == b[j % n]) { i++; j++; } if (i >= n) { cout << "No\n"; return 0; } } fo(j, i, i + n) if (a[j - i] == b[j % n]) { cout << "No\n"; return 0; } cout << "Yes\n"; fo(j, i, i + n - 1) cout << b[j % n] << ' '; cout << b[(i + n - 1) % n] << endl; return 0; } cout << "No\n"; return 0; }
replace
41
42
41
42
TLE
p02557
C++
Runtime Error
#include <bits/stdc++.h> /* #include <atcoder/all> using namespace atcoder; */ #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") // #include <boost/multiprecision/cpp_int.hpp> using namespace std; using dou = long double; string yes = "yes"; string Yes = "Yes"; string YES = "YES"; string no = "no"; string No = "No"; string NO = "NO"; 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; } typedef long long ll; typedef pair<int, int> P; typedef pair<ll, ll> PL; const ll mod = 1000000007ll; // const ll mod = 10000000000ll; // const ll mod = 10000; 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; } #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define brep(n) for (int bit = 0; bit < (1 << n); bit++) #define bbrep(n) for (int bbit = 0; bbit < (1 << n); bbit++) #define erep(i, container) for (auto &i : container) #define itrep(i, container) for (auto i : container) #define irep(i, n) for (ll i = n - 1; i >= (ll)0ll; i--) #define rrep(i, m, n) for (ll i = m; i < (ll)(n); i++) #define reprep(i, j, h, w) rep(i, h) rep(j, w) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define VEC(type, name, n) \ std::vector<type> name(n); \ rep(i, n) std::cin >> name[i]; #define pb push_back #define pf push_front #define query \ int qq; \ std::cin >> qq; \ rep(qqq, qq) #define lb lower_bound #define ub upper_bound #define fi first #define se second #define itn int #define mp make_pair // #define sum(a) accumulate(all(a),0ll) #define keta fixed << setprecision #define vout(a) \ erep(qxqxqx, a) std::cout << qxqxqx << ' '; \ std::cout << std::endl; #define vvector(name, typ, m, n, a) \ vector<vector<typ>> name(m, vector<typ>(n, a)) // #define vvector(name,typ,m,n)vector<vector<typ> > name(m,vector<typ> (n)) #define vvvector(name, t, l, m, n, a) \ vector<vector<vector<t>>> name(l, vector<vector<t>>(m, vector<t>(n, a))); #define vvvvector(name, t, k, l, m, n, a) \ vector<vector<vector<vector<t>>>> name( \ k, vector<vector<vector<t>>>(l, vector<vector<t>>(m, vector<t>(n, a)))); #define case std::cout << "Case #" << qqq + 1 << ":" #define RES(a, i, j) \ a.resize(i); \ rep(ii, i) a[ii].resize(j); #define RESRES(a, i, j, k) \ a.resize(i); \ rep(ii, i) a[ii].resize(j); \ reprep(ii, jj, i, j){dp[ii][jj].resize(k)}; #define res resize #define as assign #define ffor for (;;) #define ppri(a, b) std::cout << a << " " << b << std::endl #define pppri(a, b, c) std::cout << a << " " << b << " " << c << std::endl #define ppppri(a, b, c, d) \ std::cout << a << " " << b << " " << c << ' ' << d << std::endl #define aall(x, n) (x).begin(), (x).begin() + (n) #define SUM(a) accumulate(all(a), 0ll) #define stirng string #define gin(a, b) \ int a, b; \ std::cin >> a >> b; \ a--; \ b--; #define popcount __builtin_popcount #define permu(a) next_permutation(all(a)) // #define grid_input(a,type) int h,w;std::cin >> // h>>w;vvector(a,type,h,w,0);reprep(i,j,h,w)std::cin >> a[i][j]; // typedef long long T; ll ceil(ll a, ll b) { return ((a + b - 1) / b); } const int INF = 2000000000; // const ll INF64 =3223372036854775807ll; // const ll INF64 = 9223372036854775807ll; const ll INF64 = 243000000000001ll; ; ; const ll MOD = 1000000007ll; // const ll MOD = 1000003ll; const ll OD = 1000000000000007ll; const dou pi = 3.141592653589793; long long modpow(long long a, long long n) { // 累乗の余剰 long long res = 1; while (n > 0) { if (n & 1) res = res * a % MOD; a = a * a % MOD; n >>= 1; } return res; } // メモ // ゲーム(Grundy数とか)の復習をする // 群論の勉強をする? // ドツボにハマったら頑張って今までの思考をリセットする // 学会のスライドを作る(水曜日まで) // 周期性の実験をする // リスニング力をどうにかする // GT学会の会費を払う /* #include <atcoder/all> using namespace atcoder; */ /* #include <atcoder/all> using namespace atcoder; */ int main() { int n; std::cin >> n; VEC(int, a, n); VEC(int, b, n); std::vector<int> c(n + 1), cc(n + 1); rep(i, n) { c[a[i]]++; cc[b[i]]++; } rep(i, n + 1) { if (c[i] > n / 2 && cc[i] > n / 2) { std::cout << No << std::endl; exit(0); } } sort(rall(b)); std::priority_queue<int, // 要素の型はint std::vector<int>, // 内部コンテナはstd::vector // (デフォルトのまま) std::greater<int> // 昇順 (デフォルトはstd::less<T>) > ichi, le; priority_queue<int> ri; bool owa = 0; rep(i, n) { if (a[i] == b[i]) { ichi.push(i); owa = 1; } else { if (owa) ri.push(i); else le.push(i); } } // pppri(ichi.size(),le.size(),ri.size()); // vout(a); // vout(b); while (!ichi.empty()) { // pppri(ichi.size(),le.size(),ri.size()); if (ri.size() != 0) { int p = ichi.top(); int pp = ri.top(); // ppri(p,pp); if (b[p] == a[pp] || b[p] == b[pp]) { while (ri.size() != 0) { ri.pop(); } goto to; } swap(b[p], b[pp]); ichi.pop(); ri.pop(); } else { to: int p = ichi.top(); int pp = le.top(); swap(b[p], b[pp]); ichi.pop(); le.pop(); } } std::cout << Yes << std::endl; vout(b); }
#include <bits/stdc++.h> /* #include <atcoder/all> using namespace atcoder; */ #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") // #include <boost/multiprecision/cpp_int.hpp> using namespace std; using dou = long double; string yes = "yes"; string Yes = "Yes"; string YES = "YES"; string no = "no"; string No = "No"; string NO = "NO"; 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; } typedef long long ll; typedef pair<int, int> P; typedef pair<ll, ll> PL; const ll mod = 1000000007ll; // const ll mod = 10000000000ll; // const ll mod = 10000; 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; } #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define brep(n) for (int bit = 0; bit < (1 << n); bit++) #define bbrep(n) for (int bbit = 0; bbit < (1 << n); bbit++) #define erep(i, container) for (auto &i : container) #define itrep(i, container) for (auto i : container) #define irep(i, n) for (ll i = n - 1; i >= (ll)0ll; i--) #define rrep(i, m, n) for (ll i = m; i < (ll)(n); i++) #define reprep(i, j, h, w) rep(i, h) rep(j, w) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define VEC(type, name, n) \ std::vector<type> name(n); \ rep(i, n) std::cin >> name[i]; #define pb push_back #define pf push_front #define query \ int qq; \ std::cin >> qq; \ rep(qqq, qq) #define lb lower_bound #define ub upper_bound #define fi first #define se second #define itn int #define mp make_pair // #define sum(a) accumulate(all(a),0ll) #define keta fixed << setprecision #define vout(a) \ erep(qxqxqx, a) std::cout << qxqxqx << ' '; \ std::cout << std::endl; #define vvector(name, typ, m, n, a) \ vector<vector<typ>> name(m, vector<typ>(n, a)) // #define vvector(name,typ,m,n)vector<vector<typ> > name(m,vector<typ> (n)) #define vvvector(name, t, l, m, n, a) \ vector<vector<vector<t>>> name(l, vector<vector<t>>(m, vector<t>(n, a))); #define vvvvector(name, t, k, l, m, n, a) \ vector<vector<vector<vector<t>>>> name( \ k, vector<vector<vector<t>>>(l, vector<vector<t>>(m, vector<t>(n, a)))); #define case std::cout << "Case #" << qqq + 1 << ":" #define RES(a, i, j) \ a.resize(i); \ rep(ii, i) a[ii].resize(j); #define RESRES(a, i, j, k) \ a.resize(i); \ rep(ii, i) a[ii].resize(j); \ reprep(ii, jj, i, j){dp[ii][jj].resize(k)}; #define res resize #define as assign #define ffor for (;;) #define ppri(a, b) std::cout << a << " " << b << std::endl #define pppri(a, b, c) std::cout << a << " " << b << " " << c << std::endl #define ppppri(a, b, c, d) \ std::cout << a << " " << b << " " << c << ' ' << d << std::endl #define aall(x, n) (x).begin(), (x).begin() + (n) #define SUM(a) accumulate(all(a), 0ll) #define stirng string #define gin(a, b) \ int a, b; \ std::cin >> a >> b; \ a--; \ b--; #define popcount __builtin_popcount #define permu(a) next_permutation(all(a)) // #define grid_input(a,type) int h,w;std::cin >> // h>>w;vvector(a,type,h,w,0);reprep(i,j,h,w)std::cin >> a[i][j]; // typedef long long T; ll ceil(ll a, ll b) { return ((a + b - 1) / b); } const int INF = 2000000000; // const ll INF64 =3223372036854775807ll; // const ll INF64 = 9223372036854775807ll; const ll INF64 = 243000000000001ll; ; ; const ll MOD = 1000000007ll; // const ll MOD = 1000003ll; const ll OD = 1000000000000007ll; const dou pi = 3.141592653589793; long long modpow(long long a, long long n) { // 累乗の余剰 long long res = 1; while (n > 0) { if (n & 1) res = res * a % MOD; a = a * a % MOD; n >>= 1; } return res; } // メモ // ゲーム(Grundy数とか)の復習をする // 群論の勉強をする? // ドツボにハマったら頑張って今までの思考をリセットする // 学会のスライドを作る(水曜日まで) // 周期性の実験をする // リスニング力をどうにかする // GT学会の会費を払う /* #include <atcoder/all> using namespace atcoder; */ /* #include <atcoder/all> using namespace atcoder; */ int main() { int n; std::cin >> n; VEC(int, a, n); VEC(int, b, n); std::vector<int> c(n + 1), cc(n + 1); rep(i, n) { c[a[i]]++; cc[b[i]]++; } rep(i, n + 1) { if (c[i] > n - cc[i] || cc[i] > n - c[i]) { std::cout << No << std::endl; exit(0); } } sort(rall(b)); std::priority_queue<int, // 要素の型はint std::vector<int>, // 内部コンテナはstd::vector // (デフォルトのまま) std::greater<int> // 昇順 (デフォルトはstd::less<T>) > ichi, le; priority_queue<int> ri; bool owa = 0; rep(i, n) { if (a[i] == b[i]) { ichi.push(i); owa = 1; } else { if (owa) ri.push(i); else le.push(i); } } // pppri(ichi.size(),le.size(),ri.size()); // vout(a); // vout(b); while (!ichi.empty()) { // pppri(ichi.size(),le.size(),ri.size()); if (ri.size() != 0) { int p = ichi.top(); int pp = ri.top(); // ppri(p,pp); if (b[p] == a[pp] || b[p] == b[pp]) { while (ri.size() != 0) { ri.pop(); } goto to; } swap(b[p], b[pp]); ichi.pop(); ri.pop(); } else { to: int p = ichi.top(); int pp = le.top(); swap(b[p], b[pp]); ichi.pop(); le.pop(); } } std::cout << Yes << std::endl; vout(b); }
replace
195
196
195
196
0
p02557
C++
Runtime Error
#include <algorithm> #include <iostream> #include <queue> #include <vector> using namespace std; typedef pair<int, int> P; typedef pair<P, int> PP; int a[200005], b[200005]; vector<int> c[200005], d[200005]; PP p[200005]; int ans[200005]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; a[i]--; c[a[i]].push_back(i); } for (int i = 0; i < n; i++) { cin >> b[i]; b[i]--; d[b[i]].push_back(i); } for (int i = 0; i < n; i++) { if ((int)c[i].size() + (int)d[i].size() > n) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; for (int i = 0; i < n; i++) { p[i] = PP(P((int)c[i].size(), (int)d[i].size()), i); } sort(p, p + n, greater<PP>()); queue<P> que; int j = 0; int i; for (i = 0; i < n; i++) { if (i == j) { que.push(P(p[j].first.first, p[j].second)); j++; } int u = p[i].second; while (d[u].size() && j < n) { int v = p[j].second; while (c[v].size() == 0 && j < n) { j++; v = p[j].second; } if (j == n) break; ans[c[v].back()] = d[u].back(); d[u].pop_back(); p[i].first.second--; c[v].pop_back(); p[j].first.first--; } if (j == n) break; } for (; i < n; i++) { if (que.empty()) break; int u = p[i].second; P q = que.front(); que.pop(); int v = q.second; while ((int)d[u].size() >= q.first) { for (int t = 0; t < q.first; t++) { ans[c[v].back()] = d[u].back(); d[u].pop_back(); c[v].pop_back(); } q = que.front(); que.pop(); v = q.second; } while (d[u].size()) { ans[c[v].back()] = d[u].back(); d[u].pop_back(); c[v].pop_back(); } que.push(P((int)c[v].size(), v)); } for (int i = 0; i < n; i++) cout << b[ans[i]] + 1 << " "; cout << endl; }
#include <algorithm> #include <iostream> #include <queue> #include <vector> using namespace std; typedef pair<int, int> P; typedef pair<P, int> PP; int a[200005], b[200005]; vector<int> c[200005], d[200005]; PP p[200005]; int ans[200005]; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; a[i]--; c[a[i]].push_back(i); } for (int i = 0; i < n; i++) { cin >> b[i]; b[i]--; d[b[i]].push_back(i); } for (int i = 0; i < n; i++) { if ((int)c[i].size() + (int)d[i].size() > n) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; for (int i = 0; i < n; i++) { p[i] = PP(P((int)c[i].size(), (int)d[i].size()), i); } sort(p, p + n, greater<PP>()); queue<P> que; int j = 0; int i; for (i = 0; i < n; i++) { if (i == j) { que.push(P(p[j].first.first, p[j].second)); j++; } int u = p[i].second; while (d[u].size() && j < n) { int v = p[j].second; while (c[v].size() == 0 && j < n) { j++; v = p[j].second; } if (j == n) break; ans[c[v].back()] = d[u].back(); d[u].pop_back(); p[i].first.second--; c[v].pop_back(); p[j].first.first--; } if (j == n) break; } for (; i < n; i++) { if (que.empty()) break; int u = p[i].second; P q = que.front(); que.pop(); int v = q.second; while ((int)d[u].size() >= q.first) { for (int t = 0; t < q.first; t++) { ans[c[v].back()] = d[u].back(); d[u].pop_back(); c[v].pop_back(); } if (que.empty()) break; q = que.front(); que.pop(); v = q.second; } while (d[u].size()) { ans[c[v].back()] = d[u].back(); d[u].pop_back(); c[v].pop_back(); } que.push(P((int)c[v].size(), v)); } for (int i = 0; i < n; i++) cout << b[ans[i]] + 1 << " "; cout << endl; }
insert
76
76
76
78
-11
p02557
C++
Runtime Error
// Never stop trying #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") #include <bits/stdc++.h> using namespace std; #define boost \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) typedef string str; typedef long long ll; typedef double db; typedef long double ld; typedef pair<int, int> pi; #define fi first #define se second typedef vector<int> vi; typedef vector<pi> vpi; typedef vector<str> vs; typedef vector<ld> vd; #define pb push_back #define sz(x) (int)x.size() #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) #define endl "\n" #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define F0R(i, a) FOR(i, 0, a) #define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i) #define R0F(i, a) ROF(i, 0, a) const int MOD = 1e9 + 7; // 998244353 const ll INF = 1e18; const int MX = 2e5 + 10; const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; // right left down up template <class T> using V = vector<T>; template <class T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x)) #define dbg(x) cerr << " - " << #x << " : " << x << endl; #define dbgs(x, y) \ cerr << " - " << #x << " : " << x << " / " << #y << " : " << y << endl; #define dbgv(v) \ cerr << " - " << #v << " : " << endl << "[ "; \ for (auto it : v) \ cerr << it << ' '; \ cerr << ']' << endl; void IO() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int main() { boost; IO(); int N; cin >> N; vi a(N), b(N); FOR(i, 0, N) cin >> a[i]; multiset<int> s; FOR(i, 0, N) cin >> b[i], s.insert(b[i]); vi res(N, -1); FOR(i, 0, N) { int x = a[i]; auto it = s.begin(); if (*it != x) res[i] = (*it); else { it = s.upper_bound(x); if (it != s.end()) res[i] = (*it); } if (it != s.end()) s.erase(it); } if (!s.empty()) { // of only one integer is remaining bool y = true, p = -1; for (auto x : s) { if (p != -1 && x != p) y = false; p = x; } assert(y); vi v; int x = (*s.begin()); FOR(i, 0, N) if (res[i] != -1 && res[i] != x && a[i] != x) { v.pb(res[i]), res[i] = x; s.erase(s.begin()); if (s.empty()) break; } if (!s.empty()) { cout << "No" << endl; return 0; } FOR(i, 0, N) if (res[i] == -1) { if (v.empty()) { cout << "No" << endl; return 0; } if (a[i] != v.back()) { res[i] = v.back(); v.pop_back(); } } if (!v.empty()) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; FOR(i, 0, N) cout << res[i] << ' '; cout << endl; return 0; } /* Careful!!! .Array bounds .Infinite loops .Uninitialized variables / empty containers .Order of input Some insights: .Binary search .Graph representation .Write brute force code .Change your approach */
// Never stop trying #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") #include <bits/stdc++.h> using namespace std; #define boost \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) typedef string str; typedef long long ll; typedef double db; typedef long double ld; typedef pair<int, int> pi; #define fi first #define se second typedef vector<int> vi; typedef vector<pi> vpi; typedef vector<str> vs; typedef vector<ld> vd; #define pb push_back #define sz(x) (int)x.size() #define all(x) begin(x), end(x) #define rall(x) rbegin(x), rend(x) #define endl "\n" #define FOR(i, a, b) for (int i = (a); i < (b); ++i) #define F0R(i, a) FOR(i, 0, a) #define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i) #define R0F(i, a) ROF(i, 0, a) const int MOD = 1e9 + 7; // 998244353 const ll INF = 1e18; const int MX = 2e5 + 10; const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; // right left down up template <class T> using V = vector<T>; template <class T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template <class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } ll cdiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up constexpr int log2(int x) { return 31 - __builtin_clz(x); } // floor(log2(x)) #define dbg(x) cerr << " - " << #x << " : " << x << endl; #define dbgs(x, y) \ cerr << " - " << #x << " : " << x << " / " << #y << " : " << y << endl; #define dbgv(v) \ cerr << " - " << #v << " : " << endl << "[ "; \ for (auto it : v) \ cerr << it << ' '; \ cerr << ']' << endl; void IO() { #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } int main() { boost; IO(); int N; cin >> N; vi a(N), b(N); FOR(i, 0, N) cin >> a[i]; multiset<int> s; FOR(i, 0, N) cin >> b[i], s.insert(b[i]); vi res(N, -1); FOR(i, 0, N) { int x = a[i]; auto it = s.begin(); if (*it != x) res[i] = (*it); else { it = s.upper_bound(x); if (it != s.end()) res[i] = (*it); } if (it != s.end()) s.erase(it); } if (!s.empty()) { // of only one integer is remaining bool y = true, p = -1; for (auto x : s) { if (p != -1 && x != p) y = false; p = x; } // assert(y); vi v; int x = (*s.begin()); FOR(i, 0, N) if (res[i] != -1 && res[i] != x && a[i] != x) { v.pb(res[i]), res[i] = x; s.erase(s.begin()); if (s.empty()) break; } if (!s.empty()) { cout << "No" << endl; return 0; } FOR(i, 0, N) if (res[i] == -1) { if (v.empty()) { cout << "No" << endl; return 0; } if (a[i] != v.back()) { res[i] = v.back(); v.pop_back(); } } if (!v.empty()) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; FOR(i, 0, N) cout << res[i] << ' '; cout << endl; return 0; } /* Careful!!! .Array bounds .Infinite loops .Uninitialized variables / empty containers .Order of input Some insights: .Binary search .Graph representation .Write brute force code .Change your approach */
replace
99
100
99
100
-6
terminate called after throwing an instance of 'std::length_error' what(): cannot create std::vector larger than max_size()
p02557
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define PI 3.141592653589793238462 using namespace std; typedef long long ll; typedef long double db; ll a[200005], b[200005], p[200005]; int main() { ll n; cin >> n; for (ll i = 1; i <= n; i++) { cin >> a[i]; p[a[i]]++; } for (ll i = 1; i <= n; i++) { cin >> b[i]; p[b[i]]++; } for (int i = 1; i <= n; i++) { if (p[i] > n) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; for (int i = 1; i <= n; i++) { if (a[i] == b[i]) { for (int j = 1; j <= n; j++) { if (b[j] != a[i] && b[i] != a[j]) { swap(b[i], b[j]); break; } } } } for (int i = 1; i <= n; i++) { cout << b[i] << " "; } cout << endl; }
#include <bits/stdc++.h> #define PI 3.141592653589793238462 using namespace std; typedef long long ll; typedef long double db; ll a[200005], b[200005], p[200005]; int main() { ll n; cin >> n; for (ll i = 1; i <= n; i++) { cin >> a[i]; p[a[i]]++; } for (ll i = 1; i <= n; i++) { cin >> b[i]; p[b[i]]++; } for (int i = 1; i <= n; i++) { if (p[i] > n) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; reverse(b + 1, b + 1 + n); for (int i = 1; i <= n; i++) { if (a[i] == b[i]) { for (int j = 1; j <= n; j++) { if (b[j] != a[i] && b[i] != a[j]) { swap(b[i], b[j]); break; } } } } for (int i = 1; i <= n; i++) { cout << b[i] << " "; } cout << endl; }
insert
24
24
24
25
TLE
p02557
C++
Runtime Error
#include <stdbool.h> #include <stdio.h> #include <stdlib.h> int32_t n, *a, *b; void swap(int32_t *x, int32_t *y) { int32_t t = *x; *x = *y; *y = t; } int32_t main() { scanf("%d", &n); a = (int32_t *)malloc(n * sizeof(int32_t)); b = (int32_t *)malloc(n * sizeof(int32_t)); for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int i = 0; i < n; i++) scanf("%d", &b[n - i]); bool bad = false; for (int i = 0; i < n; i++) { if (a[i] == b[i]) { bool ok = false; for (int j = 0; j < n; j++) { if (a[i] != b[j] && a[j] != b[i]) { swap(&b[i], &b[j]); ok = true; break; } } if (!ok) { bad = true; break; } } } if (bad) { puts("No"); exit(0); } puts("Yes"); for (int i = 0; i < n; i++) printf("%d ", b[i]); puts(""); return 0; }
#include <stdbool.h> #include <stdio.h> #include <stdlib.h> int32_t n, *a, *b; void swap(int32_t *x, int32_t *y) { int32_t t = *x; *x = *y; *y = t; } int32_t main() { scanf("%d", &n); a = (int32_t *)malloc(n * sizeof(int32_t)); b = (int32_t *)malloc(n * sizeof(int32_t)); for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int i = 0; i < n; i++) scanf("%d", &b[n - i - 1]); bool bad = false; for (int i = 0; i < n; i++) { if (a[i] == b[i]) { bool ok = false; for (int j = 0; j < n; j++) { if (a[i] != b[j] && a[j] != b[i]) { swap(&b[i], &b[j]); ok = true; break; } } if (!ok) { bad = true; break; } } } if (bad) { puts("No"); exit(0); } puts("Yes"); for (int i = 0; i < n; i++) printf("%d ", b[i]); puts(""); return 0; }
replace
20
21
20
21
-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)
p02557
C++
Time Limit Exceeded
#include <bits/stdc++.h> #include <iostream> using namespace std; #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define deb(x) cout << #x << " " << x << endl; typedef long long int ll; int main() { IOS int n; cin >> n; int a[n], b[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; bool swapped = true; for (int i = 0; i < n; i++) { if (a[i] == b[i]) { swapped = false; for (int j = 0; j < n; j++) { if (b[i] == b[j]) continue; if (a[j] == b[i]) continue; if (a[i] == b[j]) continue; swap(b[i], b[j]); swapped = true; break; } if (!swapped) break; } } if (swapped) { cout << "Yes" << endl; for (int i = 0; i < n; i++) cout << b[i] << " "; } else cout << "No"; return 0; }
#include <bits/stdc++.h> #include <iostream> using namespace std; #define IOS \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define deb(x) cout << #x << " " << x << endl; typedef long long int ll; int main() { IOS int n; cin >> n; int a[n], b[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = n - 1; i >= 0; i--) cin >> b[i]; bool swapped = true; for (int i = 0; i < n; i++) { if (a[i] == b[i]) { swapped = false; for (int j = 0; j < n; j++) { if (b[i] == b[j]) continue; if (a[j] == b[i]) continue; if (a[i] == b[j]) continue; swap(b[i], b[j]); swapped = true; break; } if (!swapped) break; } } if (swapped) { cout << "Yes" << endl; for (int i = 0; i < n; i++) cout << b[i] << " "; } else cout << "No"; return 0; }
replace
24
25
24
25
TLE
p02557
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int n, k, a[N], f[N], b[N], F, le, ri, l, r; int main() { cin >> n; for (k = 1; k <= n; k++) { cin >> a[k]; f[a[k]]++; } for (k = 1; k <= n; k++) { cin >> b[k]; f[b[k]]++; if (f[b[k]] > n) { F = 1; } } if (F) cout << "No" << endl; else { reverse(b + 1, b + n + 1); for (k = 1; k <= n; k++) { if (a[k] == b[k]) F = a[k]; } if (F) { l = n; for (k = 1; k <= n; k++) { if (a[k] == F) l = min(l, k); if (b[k] == F) l = min(l, k); } le = 1; ri = n; for (k = 1; k <= n; k++) { if (b[k] == F && a[k] == F) { if (le < l) { swap(b[k], b[le]); le++; } else { swap(b[k], b[ri]); ri--; } } } } cout << "Yes" << endl; for (k = 1; k <= n; k++) { cout << b[k] << " "; } } }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, k, a[N], f[N], b[N], F, le, ri, l, r; int main() { cin >> n; for (k = 1; k <= n; k++) { cin >> a[k]; f[a[k]]++; } for (k = 1; k <= n; k++) { cin >> b[k]; f[b[k]]++; if (f[b[k]] > n) { F = 1; } } if (F) cout << "No" << endl; else { reverse(b + 1, b + n + 1); for (k = 1; k <= n; k++) { if (a[k] == b[k]) F = a[k]; } if (F) { l = n; for (k = 1; k <= n; k++) { if (a[k] == F) l = min(l, k); if (b[k] == F) l = min(l, k); } le = 1; ri = n; for (k = 1; k <= n; k++) { if (b[k] == F && a[k] == F) { if (le < l) { swap(b[k], b[le]); le++; } else { swap(b[k], b[ri]); ri--; } } } } cout << "Yes" << endl; for (k = 1; k <= n; k++) { cout << b[k] << " "; } } }
replace
2
3
2
3
0
p02557
C++
Runtime Error
#include <bits/stdc++.h> // #include <boost/multiprecision/cpp_int.hpp> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("O3") #define REP(i, n) for (int i = 0; i < n; i++) #define REPP(i, n) for (int i = 1; i <= n; i++) #define ALL(obj) (obj).begin(), (obj).end() #define EPS (1e-9) #define INF (1e17) #define PI (acos(-1)) // const double PI = acos(-1); // const double EPS = 1e-15; // long long INF=(long long)1E17; #define i_7 (long long)(1e9 + 7) // #define i_7 998'244'353 long mod(long a) { long long c = a % i_7; if (c >= 0) return c; return c + i_7; } long long po(long a, long b) { if (b == 0) { return 1; } long long z = po(a, b / 2); z = mod(z * z); if (b % 2 != 0) { z = mod(a * z); } return z; } bool prime_(int n) { if (n == 1) { return false; } else if (n == 2) { return true; } else { for (int i = 2; i <= std::sqrt(n); i++) { if (n % i == 0) { return false; } } return true; } } long long gcd_(long long a, long long b) { if (a < b) { std::swap(a, b); } if (a % b == 0) { return b; } else { return gcd_(b, a % b); } } long long lcm_(long long x, long long y) { return (x / gcd_(x, y)) * y; } // using namespace std; // using namespace boost::multiprecision; // using namespace __gnu_pbds; int main() { using namespace std; int n; cin >> n; int a[n], b[n]; REP(i, n) cin >> a[i]; REP(i, n) cin >> b[i]; vector<int> cnt1(n + 1, 0), cnt2(n + 1, 0); REP(i, n) { cnt1[a[i]]++; cnt2[b[i]]++; } bool possible = true; REP(i, n + 1) if (cnt1[i] > n / 2 && cnt2[i] > n / 2) possible = false; if (!possible) { cout << "No" << endl; return 0; } // cout << "PASSED!!" << endl; multiset<int> st1, st2; vector<int> ans; REP(i, n) { st1.insert(b[i]); st2.insert(-b[i]); } REP(i, n) { auto it1 = st1.upper_bound(a[i]); auto it2 = st2.upper_bound(-a[i]); if (it1 == st1.end() && it2 == st2.end()) { possible = false; break; } else if (it1 == st1.end()) { int tb = 0 - *it2; auto it = st1.find(tb); st1.erase(it); st2.erase(it2); ans.push_back(tb); // cout << "From 2: " << tb << endl; } else { int tb = *it1; auto it = st2.find(0 - tb); st1.erase(it1); st2.erase(it); ans.push_back(tb); // cout << "From 1: " << tb << endl; } /* for(int x: st1) cout << x << ' '; cout << endl; for(int y: st2) cout << y << ' '; cout << endl; */ } if (possible) { cout << "Yes" << endl; REP(i, n) cout << ans[i] << ' '; cout << endl; return 0; } st1 = multiset<int>(); st2 = multiset<int>(); ans = vector<int>(); possible = true; REP(i, n) { st1.insert(b[i]); st2.insert(-b[i]); } REP(i, n) { auto it1 = st1.upper_bound(a[i]); auto it2 = st2.upper_bound(-a[i]); if (it1 == st1.end() && it2 == st2.end()) { possible = false; break; } else if (it2 == st2.end()) { int tb = *it1; auto it = st2.find(0 - tb); st1.erase(it1); st2.erase(it); ans.push_back(tb); // cout << "From 2: " << tb << endl; } else { int tb = 0 - *it2; auto it = st1.find(tb); st1.erase(it); st2.erase(it2); ans.push_back(tb); // cout << "From 1: " << tb << endl; } /* for(int x: st1) cout << x << ' '; cout << endl; for(int y: st2) cout << y << ' '; cout << endl; */ } if (possible) { cout << "Yes" << endl; REP(i, n) cout << ans[i] << ' '; cout << endl; return 0; } st1 = multiset<int>(); st2 = multiset<int>(); ans = vector<int>(); possible = true; REP(i, n) { st1.insert(b[i]); st2.insert(-b[i]); } REP(i, n) { if (a[i] != b[n - 1 - i]) { st1.erase(st1.find(b[n - 1 - i])); st2.erase(st2.find(-b[n - 1 - i])); ans.push_back(b[n - 1 - i]); continue; } auto it1 = st1.upper_bound(a[i]); auto it2 = st2.upper_bound(-a[i]); if (it1 == st1.end() && it2 == st2.end()) { possible = false; break; } else if (it2 == st2.end()) { int tb = *it1; auto it = st2.find(0 - tb); st1.erase(it1); st2.erase(it); ans.push_back(tb); // cout << "From 2: " << tb << endl; } else { int tb = 0 - *it2; auto it = st1.find(tb); st1.erase(it); st2.erase(it2); ans.push_back(tb); // cout << "From 1: " << tb << endl; } } if (possible) { cout << "Yes" << endl; REP(i, n) cout << ans[i] << ' '; cout << endl; } else { cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> // #include <boost/multiprecision/cpp_int.hpp> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> #pragma GCC optimize("O3") #define REP(i, n) for (int i = 0; i < n; i++) #define REPP(i, n) for (int i = 1; i <= n; i++) #define ALL(obj) (obj).begin(), (obj).end() #define EPS (1e-9) #define INF (1e17) #define PI (acos(-1)) // const double PI = acos(-1); // const double EPS = 1e-15; // long long INF=(long long)1E17; #define i_7 (long long)(1e9 + 7) // #define i_7 998'244'353 long mod(long a) { long long c = a % i_7; if (c >= 0) return c; return c + i_7; } long long po(long a, long b) { if (b == 0) { return 1; } long long z = po(a, b / 2); z = mod(z * z); if (b % 2 != 0) { z = mod(a * z); } return z; } bool prime_(int n) { if (n == 1) { return false; } else if (n == 2) { return true; } else { for (int i = 2; i <= std::sqrt(n); i++) { if (n % i == 0) { return false; } } return true; } } long long gcd_(long long a, long long b) { if (a < b) { std::swap(a, b); } if (a % b == 0) { return b; } else { return gcd_(b, a % b); } } long long lcm_(long long x, long long y) { return (x / gcd_(x, y)) * y; } // using namespace std; // using namespace boost::multiprecision; // using namespace __gnu_pbds; int main() { using namespace std; int n; cin >> n; int a[n], b[n]; REP(i, n) cin >> a[i]; REP(i, n) cin >> b[i]; vector<int> cnt1(n + 1, 0), cnt2(n + 1, 0); REP(i, n) { cnt1[a[i]]++; cnt2[b[i]]++; } bool possible = true; REP(i, n + 1) if (cnt1[i] > n / 2 && cnt2[i] > n / 2) possible = false; if (!possible) { cout << "No" << endl; return 0; } // cout << "PASSED!!" << endl; multiset<int> st1, st2; vector<int> ans; REP(i, n) { st1.insert(b[i]); st2.insert(-b[i]); } REP(i, n) { auto it1 = st1.upper_bound(a[i]); auto it2 = st2.upper_bound(-a[i]); if (it1 == st1.end() && it2 == st2.end()) { possible = false; break; } else if (it1 == st1.end()) { int tb = 0 - *it2; auto it = st1.find(tb); st1.erase(it); st2.erase(it2); ans.push_back(tb); // cout << "From 2: " << tb << endl; } else { int tb = *it1; auto it = st2.find(0 - tb); st1.erase(it1); st2.erase(it); ans.push_back(tb); // cout << "From 1: " << tb << endl; } /* for(int x: st1) cout << x << ' '; cout << endl; for(int y: st2) cout << y << ' '; cout << endl; */ } if (possible) { cout << "Yes" << endl; REP(i, n) cout << ans[i] << ' '; cout << endl; return 0; } st1 = multiset<int>(); st2 = multiset<int>(); ans = vector<int>(); possible = true; REP(i, n) { st1.insert(b[i]); st2.insert(-b[i]); } REP(i, n) { auto it1 = st1.upper_bound(a[i]); auto it2 = st2.upper_bound(-a[i]); if (it1 == st1.end() && it2 == st2.end()) { possible = false; break; } else if (it2 == st2.end()) { int tb = *it1; auto it = st2.find(0 - tb); st1.erase(it1); st2.erase(it); ans.push_back(tb); // cout << "From 2: " << tb << endl; } else { int tb = 0 - *it2; auto it = st1.find(tb); st1.erase(it); st2.erase(it2); ans.push_back(tb); // cout << "From 1: " << tb << endl; } /* for(int x: st1) cout << x << ' '; cout << endl; for(int y: st2) cout << y << ' '; cout << endl; */ } if (possible) { cout << "Yes" << endl; REP(i, n) cout << ans[i] << ' '; cout << endl; return 0; } st1 = multiset<int>(); st2 = multiset<int>(); ans = vector<int>(); possible = true; REP(i, n) { st1.insert(b[i]); st2.insert(-b[i]); } REP(i, n) { if (a[i] != b[n - 1 - i] && st1.find(b[n - 1 - i]) != st1.end()) { st1.erase(st1.find(b[n - 1 - i])); st2.erase(st2.find(-b[n - 1 - i])); ans.push_back(b[n - 1 - i]); continue; } auto it1 = st1.upper_bound(a[i]); auto it2 = st2.upper_bound(-a[i]); if (it1 == st1.end() && it2 == st2.end()) { possible = false; break; } else if (it2 == st2.end()) { int tb = *it1; auto it = st2.find(0 - tb); st1.erase(it1); st2.erase(it); ans.push_back(tb); // cout << "From 2: " << tb << endl; } else { int tb = 0 - *it2; auto it = st1.find(tb); st1.erase(it); st2.erase(it2); ans.push_back(tb); // cout << "From 1: " << tb << endl; } } if (possible) { cout << "Yes" << endl; REP(i, n) cout << ans[i] << ' '; cout << endl; } else { cout << "No" << endl; } return 0; }
replace
182
183
182
183
0
p02557
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define SZ(a) ((int)(a).size()) typedef long long int64; int main() { #ifdef LOCAL freopen(".a.in", "r", stdin); #endif ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0); int n; cin >> n; vector<int> A(n), B(n), C(3 * n); for (auto &i : A) cin >> i; for (auto &i : B) cin >> i; for (int i = 0; i < n; ++i) { int l = lower_bound(B.begin(), B.end(), A[i]) - B.begin(); if (l == n || B[l] != A[i]) continue; int r = upper_bound(B.begin(), B.end(), A[i]) - B.begin() - 1; if (i <= l) { C[i - l]++; C[r - i + 1]--; } else if (i > r) { C[n - i + l]++; C[n - i + r + 1]--; } else { C[0]++; C[r - i + 1]--; C[n - i + l]++; } } for (int i = 1; i < n; ++i) C[i] += C[i - 1]; for (int i = 0; i < n; ++i) if (C[i] == 0) { cout << "Yes\n"; for (int j = 0; j < n; ++j) cout << B[(i + j) % n] << " "; cout << "\n"; return 0; } cout << "No"; return 0; } // 2020.09.13 21:03:42
#include <bits/stdc++.h> using namespace std; #define SZ(a) ((int)(a).size()) typedef long long int64; int main() { #ifdef LOCAL freopen(".a.in", "r", stdin); #endif ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0); int n; cin >> n; vector<int> A(n), B(n), C(3 * n); for (auto &i : A) cin >> i; for (auto &i : B) cin >> i; for (int i = 0; i < n; ++i) { int l = lower_bound(B.begin(), B.end(), A[i]) - B.begin(); if (l == n || B[l] != A[i]) continue; int r = upper_bound(B.begin(), B.end(), A[i]) - B.begin() - 1; if (i <= l) { C[l - i]++; C[r - i + 1]--; } else if (i > r) { C[n - i + l]++; C[n - i + r + 1]--; } else { C[0]++; C[r - i + 1]--; C[n - i + l]++; } } for (int i = 1; i < n; ++i) C[i] += C[i - 1]; for (int i = 0; i < n; ++i) if (C[i] == 0) { cout << "Yes\n"; for (int j = 0; j < n; ++j) cout << B[(i + j) % n] << " "; cout << "\n"; return 0; } cout << "No"; return 0; } // 2020.09.13 21:03:42
replace
22
23
22
23
0
p02557
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; const string YES = "Yes"; const string NO = "No"; void solve(int N, vector<int> A, vector<int> B) { vector<int> cnt_A(N + 1), cnt_B(N + 1); for (int i = 0; i < N; i++) { cnt_A.at(A.at(i))++; cnt_B.at(B.at(i))++; } for (int i = 1; i <= N; i++) { if (cnt_A.at(i) + cnt_B.at(i) > N) { cout << NO << endl; return; } } cout << YES << endl; vector<int> C(N + 1), D(N + 1); for (int i = 1; i <= N; i++) { C.at(i) = C.at(i - 1) + cnt_A.at(i); D.at(i) = D.at(i - 1) + cnt_B.at(i); } int x = 0; for (int i = 1; i <= N; i++) { x = max(x, C.at(i) - D.at(i - 1)); } for (int i = 0; i < N - 1; i++) { cout << B.at((i - x + N) % N) << " "; } cout << B.at((N - 1 - x) % N) << endl; } int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A.at(i); } vector<int> B(N); for (int i = 0; i < N; i++) { cin >> B.at(i); } solve(N, move(A), move(B)); return 0; }
#include <bits/stdc++.h> using namespace std; const string YES = "Yes"; const string NO = "No"; void solve(int N, vector<int> A, vector<int> B) { vector<int> cnt_A(N + 1), cnt_B(N + 1); for (int i = 0; i < N; i++) { cnt_A.at(A.at(i))++; cnt_B.at(B.at(i))++; } for (int i = 1; i <= N; i++) { if (cnt_A.at(i) + cnt_B.at(i) > N) { cout << NO << endl; return; } } cout << YES << endl; vector<int> C(N + 1), D(N + 1); for (int i = 1; i <= N; i++) { C.at(i) = C.at(i - 1) + cnt_A.at(i); D.at(i) = D.at(i - 1) + cnt_B.at(i); } int x = 0; for (int i = 1; i <= N; i++) { x = max(x, C.at(i) - D.at(i - 1)); } for (int i = 0; i < N - 1; i++) { cout << B.at((i - x + N) % N) << " "; } cout << B.at((N - 1 - x + N) % N) << endl; } int main() { int N; cin >> N; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A.at(i); } vector<int> B(N); for (int i = 0; i < N; i++) { cin >> B.at(i); } solve(N, move(A), move(B)); return 0; }
replace
33
34
33
34
0
p02557
C++
Runtime Error
/* これを入れて実行 g++ code.cpp ./a.out */ #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; typedef long double ld; int dy4[4] = {-1, 0, +1, 0}; int dx4[4] = {0, +1, 0, -1}; int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const long long INF = 1LL << 60; const ll MOD = 1e9 + 7; bool greaterSecond(const pair<int, int> &f, const pair<int, int> &s) { return f.second > s.second; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll conbinationMemo[100][100]; void cmemoInit() { rep(i, 100) { rep(j, 100) { conbinationMemo[i][j] = -1; } } } ll nCr(ll n, ll r) { if (conbinationMemo[n][r] != -1) return conbinationMemo[n][r]; if (r == 0 || r == n) { return 1; } else if (r == 1) { return n; } return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1)); } ll nPr(ll n, ll r) { r = n - r; ll ret = 1; for (ll i = n; i >= r + 1; i--) ret *= i; return ret; } //-----------------------ここから----------- int main(void) { ll n; cin >> n; vector<ll> a(n), b(n); rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; ; vector<ll> rb = b; reverse(all(rb)); vector<ll> same; rep(i, n) { if (a[i] == rb[i]) { same.push_back(i); } } set<ll> st; rep(i, same.size()) { st.insert(same[i]); } if (st.size() > 1) { assert(false); } vector<ll> ans = rb; ll bidx = n - 1; rep(i, same.size() / 2) { swap(ans[same[i]], ans[bidx]); bidx--; } ll fidx = 0; for (ll i = (ll)same.size() - 1; i >= (ll)same.size() / 2; i--) { swap(ans[same[i]], ans[fidx]); fidx++; } bool ok = true; rep(i, n) { if (ans[i] == a[i]) ok = false; } if (ok) { cout << "Yes" << endl; rep(i, n) cout << ans[i] << " "; cout << endl; } else { cout << "No" << endl; } }
/* これを入れて実行 g++ code.cpp ./a.out */ #include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <cstring> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <random> #include <set> #include <stack> #include <stdio.h> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; typedef long double ld; int dy4[4] = {-1, 0, +1, 0}; int dx4[4] = {0, +1, 0, -1}; int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1}; int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1}; const long long INF = 1LL << 60; const ll MOD = 1e9 + 7; bool greaterSecond(const pair<int, int> &f, const pair<int, int> &s) { return f.second > s.second; } ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); } ll lcm(ll a, ll b) { return a / gcd(a, b) * b; } ll conbinationMemo[100][100]; void cmemoInit() { rep(i, 100) { rep(j, 100) { conbinationMemo[i][j] = -1; } } } ll nCr(ll n, ll r) { if (conbinationMemo[n][r] != -1) return conbinationMemo[n][r]; if (r == 0 || r == n) { return 1; } else if (r == 1) { return n; } return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1)); } ll nPr(ll n, ll r) { r = n - r; ll ret = 1; for (ll i = n; i >= r + 1; i--) ret *= i; return ret; } //-----------------------ここから----------- int main(void) { ll n; cin >> n; vector<ll> a(n), b(n); rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; ; vector<ll> rb = b; reverse(all(rb)); vector<ll> same; rep(i, n) { if (a[i] == rb[i]) { same.push_back(i); } } set<ll> st; rep(i, same.size()) { st.insert(a[same[i]]); } if (st.size() > 1) { assert(false); } vector<ll> ans = rb; ll bidx = n - 1; rep(i, same.size() / 2) { swap(ans[same[i]], ans[bidx]); bidx--; } ll fidx = 0; for (ll i = (ll)same.size() - 1; i >= (ll)same.size() / 2; i--) { swap(ans[same[i]], ans[fidx]); fidx++; } bool ok = true; rep(i, n) { if (ans[i] == a[i]) ok = false; } if (ok) { cout << "Yes" << endl; rep(i, n) cout << ans[i] << " "; cout << endl; } else { cout << "No" << endl; } }
replace
104
105
104
105
0
p02557
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; #define rep(i, n) REP(i, 0, n) #define REP(i, s, e) for (int i = (s); i < (int)(e); i++) #define repr(i, n) REPR(i, n, 0) #define REPR(i, s, e) for (int i = (int)(s - 1); i >= (int)(e); i--) #define all(r) r.begin(), r.end() #define rall(r) r.rbegin(), r.rend() typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; const ll INF = 1e18; const ll MOD = 1e9 + 7; template <typename T> T chmax(T &a, const T &b) { return a = (a > b ? a : b); } template <typename T> T chmin(T &a, const T &b) { return a = (a < b ? a : b); } #define DEBUG_MODE #ifdef DEBUG_MODE #define dump(x) cout << #x << " : " << x << " " #define dumpL(x) cout << #x << " : " << x << '\n' #define LINE cout << "line : " << __LINE__ << " " #define LINEL cout << "line : " << __LINE__ << '\n' #define dumpV(v) \ cout << #v << " : ["; \ for (auto &t : v) \ cout << t << ", "; \ cout << "]" \ << " " #define dumpVL(v) \ cout << #v << " : ["; \ for (auto &t : v) \ cout << t << ", "; \ cout << "]" << endl #define STOP assert(false) #else #define dump(x) #define dumpL(x) #define LINE #define LINEL #define dumpV(v) #define dumpVL(v) #define STOP assert(false) #endif #define mp make_pair namespace std { template <class S, class T> ostream &operator<<(ostream &out, const pair<S, T> &a) { out << '(' << a.first << ", " << a.second << ')'; return out; } } // namespace std int main() { int n; cin >> n; vi a(n), b(n); rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; map<int, int> ma, mb; rep(i, n) { ma[a[i]]++; mb[b[i]]++; } for (auto &&p : mb) { if (ma.count(p.first) == 0) continue; if (p.second + ma[p.first] > n) { cout << "No" << '\n'; return 0; } } using P = pair<int, int>; priority_queue<P> pa, pb; for (auto &&p : ma) pa.emplace(p.second, p.first); for (auto &&p : mb) pb.emplace(p.second, p.first); vector<vector<int>> ind(n + 1); rep(i, n) ind[a[i]].emplace_back(i); vi ans(n, -1); while (pa.size()) { auto p = pa.top(); pa.pop(); auto q = pb.top(); pb.pop(); P x = q; if (p.second == q.second) { x = pb.top(); pb.pop(); pb.emplace(q); } int a = p.second; ans[ind[a].back()] = x.second; ind[a].pop_back(); x.first--; p.first--; if (x.first > 0) pb.emplace(x); if (p.first > 0) pa.emplace(p); } // dumpVL(a); // dumpVL(ans); rep(i, n) if (a[i] == ans[i]) { rep(j, n) { if (a[i] != ans[j] && a[j] != ans[i]) { swap(ans[i], ans[j]); break; } } } cout << "Yes" << '\n'; rep(i, n) { cout << ans[i] << (i + 1 == n ? '\n' : ' '); } return 0; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) REP(i, 0, n) #define REP(i, s, e) for (int i = (s); i < (int)(e); i++) #define repr(i, n) REPR(i, n, 0) #define REPR(i, s, e) for (int i = (int)(s - 1); i >= (int)(e); i--) #define all(r) r.begin(), r.end() #define rall(r) r.rbegin(), r.rend() typedef long long ll; typedef vector<int> vi; typedef vector<ll> vl; const ll INF = 1e18; const ll MOD = 1e9 + 7; template <typename T> T chmax(T &a, const T &b) { return a = (a > b ? a : b); } template <typename T> T chmin(T &a, const T &b) { return a = (a < b ? a : b); } #define DEBUG_MODE #ifdef DEBUG_MODE #define dump(x) cout << #x << " : " << x << " " #define dumpL(x) cout << #x << " : " << x << '\n' #define LINE cout << "line : " << __LINE__ << " " #define LINEL cout << "line : " << __LINE__ << '\n' #define dumpV(v) \ cout << #v << " : ["; \ for (auto &t : v) \ cout << t << ", "; \ cout << "]" \ << " " #define dumpVL(v) \ cout << #v << " : ["; \ for (auto &t : v) \ cout << t << ", "; \ cout << "]" << endl #define STOP assert(false) #else #define dump(x) #define dumpL(x) #define LINE #define LINEL #define dumpV(v) #define dumpVL(v) #define STOP assert(false) #endif #define mp make_pair namespace std { template <class S, class T> ostream &operator<<(ostream &out, const pair<S, T> &a) { out << '(' << a.first << ", " << a.second << ')'; return out; } } // namespace std int main() { int n; cin >> n; vi a(n), b(n); rep(i, n) cin >> a[i]; rep(i, n) cin >> b[i]; map<int, int> ma, mb; rep(i, n) { ma[a[i]]++; mb[b[i]]++; } for (auto &&p : mb) { if (ma.count(p.first) == 0) continue; if (p.second + ma[p.first] > n) { cout << "No" << '\n'; return 0; } } using P = pair<int, int>; priority_queue<P> pa, pb; for (auto &&p : ma) pa.emplace(p.second, p.first); for (auto &&p : mb) pb.emplace(p.second, p.first); vector<vector<int>> ind(n + 1); rep(i, n) ind[a[i]].emplace_back(i); vi ans(n, -1); while (pa.size()) { auto p = pa.top(); pa.pop(); auto q = pb.top(); pb.pop(); P x = q; if (p.second == q.second && pb.size() > 0) { x = pb.top(); pb.pop(); pb.emplace(q); } int a = p.second; ans[ind[a].back()] = x.second; ind[a].pop_back(); x.first--; p.first--; if (x.first > 0) pb.emplace(x); if (p.first > 0) pa.emplace(p); } // dumpVL(a); // dumpVL(ans); rep(i, n) if (a[i] == ans[i]) { rep(j, n) { if (a[i] != ans[j] && a[j] != ans[i]) { swap(ans[i], ans[j]); break; } } } cout << "Yes" << '\n'; rep(i, n) { cout << ans[i] << (i + 1 == n ? '\n' : ' '); } return 0; }
replace
94
95
94
95
0
p02557
C++
Time Limit Exceeded
#define _USE_MATH_DEFINES #include <bits/stdc++.h> #define REP(i, start, end) for (ll i = start, i##Len = (end); i < i##Len; ++i) #define REPR(i, start, end) for (ll i = start, i##Len = (end); i > i##Len; --i) using ll = long long; using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); ll n; cin >> n; vector<ll> a(n), b(n), a_cnt(n + 1), b_cnt(n + 1); REP(i, 0, n) { cin >> a[i]; a_cnt[a[i]]++; } REP(i, 0, n) { cin >> b[i]; b_cnt[b[i]]++; } vector<int> idx(n + 1); iota(idx.begin(), idx.end(), 0); sort(idx.begin(), idx.end(), [&](int i, int j) { return a_cnt[i] > a_cnt[j]; }); deque<pair<int, int>> dq; REP(i, 0, n + 1) { if (b_cnt[idx[i]] > 0) dq.emplace_back(idx[i], b_cnt[idx[i]]); } map<int, vector<int>> mp; REP(i, 0, n + 1) { if (a_cnt[idx[i]] == 0) break; int x = idx[i]; while (!dq.empty() && dq.front().first == x) { dq.push_back(dq.front()); dq.pop_front(); } REP(_, 0, a_cnt[x]) { if (dq.front().first == x) { cout << "No" << endl; return 0; } mp[x].emplace_back(dq.front().first); dq.front().second--; if (dq.front().second == 0) dq.pop_front(); } } cout << "Yes\n"; REP(i, 0, n) { cout << mp[a[i]].back() << " "; mp[a[i]].pop_back(); } cout << endl; }
#define _USE_MATH_DEFINES #include <bits/stdc++.h> #define REP(i, start, end) for (ll i = start, i##Len = (end); i < i##Len; ++i) #define REPR(i, start, end) for (ll i = start, i##Len = (end); i > i##Len; --i) using ll = long long; using namespace std; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); ll n; cin >> n; vector<ll> a(n), b(n), a_cnt(n + 1), b_cnt(n + 1); REP(i, 0, n) { cin >> a[i]; a_cnt[a[i]]++; } REP(i, 0, n) { cin >> b[i]; b_cnt[b[i]]++; } vector<int> idx(n + 1); iota(idx.begin(), idx.end(), 0); sort(idx.begin(), idx.end(), [&](int i, int j) { return a_cnt[i] > a_cnt[j]; }); deque<pair<int, int>> dq; REP(i, 0, n + 1) { if (b_cnt[idx[i]] > 0) dq.emplace_back(idx[i], b_cnt[idx[i]]); } map<int, vector<int>> mp; REP(i, 0, n + 1) { if (a_cnt[idx[i]] == 0) break; int x = idx[i]; if (!dq.empty() && dq.front().first == x) { dq.push_back(dq.front()); dq.pop_front(); } REP(_, 0, a_cnt[x]) { if (dq.front().first == x) { cout << "No" << endl; return 0; } mp[x].emplace_back(dq.front().first); dq.front().second--; if (dq.front().second == 0) dq.pop_front(); } } cout << "Yes\n"; REP(i, 0, n) { cout << mp[a[i]].back() << " "; mp[a[i]].pop_back(); } cout << endl; }
replace
40
41
40
41
TLE
p02557
C++
Time Limit Exceeded
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<ll>; #define MOD 1000000007 int main() { int n; cin >> n; map<int, int> ma, mb; vi aa(n), bb(n); rep(i, n) { int a; cin >> a; ma[a]++; aa[i] = a; } queue<int> que; rep(i, n) { int b; cin >> b; mb[b]++; bb[i] = b; } for (auto x : ma) { if (x.second + mb[x.first] > n) { cout << "No" << endl; return 0; } } vi ans; cout << "Yes" << endl; int i = 0; reverse(bb.begin(), bb.end()); rep(i, n) { que.push(bb[i]); } while (!que.empty()) { if (que.front() != aa[i]) { ans.push_back(que.front()); que.pop(); i++; } else { que.push(que.front()); que.pop(); } } for (int x : ans) cout << x << " "; cout << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<ll>; #define MOD 1000000007 int main() { int n; cin >> n; map<int, int> ma, mb; vi aa(n), bb(n); rep(i, n) { int a; cin >> a; ma[a]++; aa[i] = a; } queue<int> que; rep(i, n) { int b; cin >> b; mb[b]++; bb[i] = b; } for (auto x : ma) { if (x.second + mb[x.first] > n) { cout << "No" << endl; return 0; } } vi ans; cout << "Yes" << endl; int i = 0; reverse(bb.begin(), bb.end()); rep(i, n) { if (i % 3 == 0) que.push(bb[i]); } rep(i, n) { if (i % 3 == 1) que.push(bb[i]); } rep(i, n) { if (i % 3 == 2) que.push(bb[i]); } while (!que.empty()) { if (que.front() != aa[i]) { ans.push_back(que.front()); que.pop(); i++; } else { que.push(que.front()); que.pop(); } } for (int x : ans) cout << x << " "; cout << endl; }
replace
36
37
36
48
TLE
p02557
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define fi first #define se second typedef pair<ll, ll> P; using VP = vector<P>; using VVP = vector<VP>; using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>; const int inf = 1e9 + 7; const ll INF = 1LL << 61; const ll mod = 1e9 + 7; 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 i, j; ll n; cin >> n; ll a[n], b[n]; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n; i++) cin >> b[i]; map<ll, ll> ma, mb; for (i = 0; i < n; i++) { ma[a[i]]++; mb[b[i]]++; } for (auto it = ma.begin(); it != ma.end(); ++it) { if (it->second + mb[it->first] > n) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; ll poa = 0; ll pob = 0; ll p = 0; for (auto it = ma.begin(); it != ma.end(); ++it) { poa += it->second; chmax(p, poa - pob); pob += mb[it->first]; } VI v(n, -1); ll r = p; for (auto it = ma.begin(); it != ma.end(); ++it) { for (j = 0; j < mb[it->first]; j++) { v[r] = it->first; r++; r %= n; } } r = 0; for (auto it = mb.begin(); it != mb.end(); ++it) { if (ma[it->first] > 0) continue; for (j = 0; j < it->second; j++) { while (v[r] > 0) r++; v[r] = it->first; } } for (i = 0; i < n; i++) { cout << v[i]; if (i != n - 1) cout << " "; else cout << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define fi first #define se second typedef pair<ll, ll> P; using VP = vector<P>; using VVP = vector<VP>; using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>; const int inf = 1e9 + 7; const ll INF = 1LL << 61; const ll mod = 1e9 + 7; 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 i, j; ll n; cin >> n; ll a[n], b[n]; for (i = 0; i < n; i++) cin >> a[i]; for (i = 0; i < n; i++) cin >> b[i]; map<ll, ll> ma, mb; for (i = 0; i < n; i++) { ma[a[i]]++; mb[b[i]]++; } for (auto it = ma.begin(); it != ma.end(); ++it) { if (it->second + mb[it->first] > n) { cout << "No" << endl; return 0; } } cout << "Yes" << endl; ll poa = 0; ll pob = 0; ll p = 0; for (auto it = ma.begin(); it != ma.end(); ++it) { poa += it->second; chmax(p, poa - pob); pob += mb[it->first]; } VI v(n, -1); ll r = p % n; for (auto it = ma.begin(); it != ma.end(); ++it) { for (j = 0; j < mb[it->first]; j++) { v[r] = it->first; r++; r %= n; } } r = 0; for (auto it = mb.begin(); it != mb.end(); ++it) { if (ma[it->first] > 0) continue; for (j = 0; j < it->second; j++) { while (v[r] > 0) r++; v[r] = it->first; } } for (i = 0; i < n; i++) { cout << v[i]; if (i != n - 1) cout << " "; else cout << endl; } }
replace
64
65
64
65
0
p02557
C++
Runtime Error
#include <bits/stdc++.h> using namespace std; int n, a[200001], b[200001], ta[200001], tb[200001], l = 1, r = 1; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]), ta[a[i]]++; for (int i = 1; i <= n; i++) scanf("%d", &b[i]), tb[b[i]]++; for (int i = 1; i <= n; i++) if (ta[i] + tb[i] > n) puts("No"), exit(0); memset(b, 0, sizeof(b)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= tb[i]; j++) { while (b[l]) ++l; while (a[r] <= a[l] && r <= n) ++r; while (b[r]) ++r; if (a[l] != i) b[l++] = i; else b[r++] = i; } } l = 1; for (int i = n + 1; b[i]; i++) { while (b[l]) ++l; if (a[l] != b[i]) a[l] = b[i]; else { while (a[r = (rand() % n + 1)] == b[i] || b[r] == a[l]) ; b[l] = b[r], b[r] = b[i]; } } puts("Yes"); for (int i = 1; i <= n; i++) printf("%d ", b[i]); return 0; }
#include <bits/stdc++.h> using namespace std; int n, a[400001], b[400001], ta[400001], tb[400001], l = 1, r = 1; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]), ta[a[i]]++; for (int i = 1; i <= n; i++) scanf("%d", &b[i]), tb[b[i]]++; for (int i = 1; i <= n; i++) if (ta[i] + tb[i] > n) puts("No"), exit(0); memset(b, 0, sizeof(b)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= tb[i]; j++) { while (b[l]) ++l; while (a[r] <= a[l] && r <= n) ++r; while (b[r]) ++r; if (a[l] != i) b[l++] = i; else b[r++] = i; } } l = 1; for (int i = n + 1; b[i]; i++) { while (b[l]) ++l; if (a[l] != b[i]) a[l] = b[i]; else { while (a[r = (rand() % n + 1)] == b[i] || b[r] == a[l]) ; b[l] = b[r], b[r] = b[i]; } } puts("Yes"); for (int i = 1; i <= n; i++) printf("%d ", b[i]); return 0; }
replace
2
3
2
3
0
p02558
Python
Time Limit Exceeded
from typing import List class DSU: def __init__(self, n: int) -> None: self._n = n self.parent_or_size = [-1] * n def merge(self, a: int, b: int) -> int: assert 0 <= a <= self._n assert 0 <= b <= self._n x, y = self.leader(a), self.leader(b) if x == y: return x if -self.parent_or_size[x] < -self.parent_or_size[y]: x, y = y, x self.parent_or_size[x] += self.parent_or_size[y] self.parent_or_size[y] = x return x def same(self, a: int, b: int) -> bool: assert 0 <= a <= self._n assert 0 <= b <= self._n return self.leader(a) == self.leader(b) def leader(self, a: int) -> int: assert 0 <= a < self._n stack = [] while self.parent_or_size[a] >= 0: stack.append(a) for i in stack: self.parent_or_size[i] = a return a def size(self, a: int) -> int: assert 0 <= a <= self._n return -self.parent_or_size[self.leader(a)] def groups(self) -> List[List[int]]: leader_buf = [self.leader(i) for i in range(self._n)] group_size = [0] * self._n for i in leader_buf: group_size[i] += 1 result = [[] for _ in range(self._n)] for i in range(self._n): result[leader_buf[i]].append(i) result = [i for i in result if i] return result n, q = map(int, input().split()) dsu = DSU(n) for _ in range(q): t, u, v = map(int, input().split()) if t == 0: dsu.merge(u, v) else: print(1 if dsu.same(u, v) else 0)
from typing import List class DSU: def __init__(self, n: int) -> None: self._n = n self.parent_or_size = [-1] * n def merge(self, a: int, b: int) -> int: assert 0 <= a <= self._n assert 0 <= b <= self._n x, y = self.leader(a), self.leader(b) if x == y: return x if -self.parent_or_size[x] < -self.parent_or_size[y]: x, y = y, x self.parent_or_size[x] += self.parent_or_size[y] self.parent_or_size[y] = x return x def same(self, a: int, b: int) -> bool: assert 0 <= a <= self._n assert 0 <= b <= self._n return self.leader(a) == self.leader(b) def leader(self, a: int) -> int: assert 0 <= a < self._n stack = [] while self.parent_or_size[a] >= 0: stack.append(a) a = self.parent_or_size[a] for i in stack: self.parent_or_size[i] = a return a def size(self, a: int) -> int: assert 0 <= a <= self._n return -self.parent_or_size[self.leader(a)] def groups(self) -> List[List[int]]: leader_buf = [self.leader(i) for i in range(self._n)] group_size = [0] * self._n for i in leader_buf: group_size[i] += 1 result = [[] for _ in range(self._n)] for i in range(self._n): result[leader_buf[i]].append(i) result = [i for i in result if i] return result n, q = map(int, input().split()) dsu = DSU(n) for _ in range(q): t, u, v = map(int, input().split()) if t == 0: dsu.merge(u, v) else: print(1 if dsu.same(u, v) else 0)
insert
30
30
30
31
TLE
p02558
C++
Runtime Error
// #Sazaの1日1AC #include <bits/stdc++.h> using namespace std; const long long mod = 1000000000 + 7; const long long INF = 9e18; const double PI = 3.14159265358979323846; // マクロ // 型エイリアス using ll = long long; using P = pair<long long, long long>; using vl = vector<long long>; using vvl = vector<vector<long long>>; using vP = vector<pair<long long, long long>>; // ショートカット #define rep(i, n) for (long long i = 0; i < n; i++) #define rep2(i, k, n) for (long long i = k; i < n; i++) // 半開区間 #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define pb push_back #define mkp make_pair // 入力 #define vin(v, N) \ for (long long i = 0; i < N; i++) \ cin >> v.at(i) #define lin(n) \ long long n; \ cin >> n #define chin(x) \ char x; \ cin >> x; #define sin(s) \ string s; \ cin >> s; #define vlin(v, N) \ vector<long long> v(N); \ for (long long i = 0; i < N; i++) \ cin >> v.at(i) #define max(a, b) max((ll)a, (ll)b) #define min(a, b) min((ll)a, (ll)b) // 関数 // 最大公約数 long long gcd(long long m, long long n) { long long a = max(m, n); long long b = min(m, n); long long r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; } // 最小公倍数 long long lcd(long long m, long long n) { return m * n / gcd(m, n); } // xのn乗 long long power(long long x, long long N) { long long ret = 1; for (long long i = 0; i < N; i++) ret *= x; return ret; } // 繰り返し二乗法 long long repeat_squaring(long long x, long long n) { if (n == 0) return 1; else if (n % 2 == 0) { long long t = repeat_squaring(x, n / 2); return t * t % mod; } else return x * repeat_squaring(x, n - 1) % mod; } // 素因数分解(mapで返す) map<long long, long long> factor(long long p) { ll p1 = p; map<long long, long long> ret; for (long long i = 2; i * i <= p1; i++) { while (p % i == 0) { ret[i]++; p /= i; } } if (p != 1) ret[p]++; return ret; } // 素数判定 bool is_prime(long long N) { for (long long i = 2; i * i <= N; i++) { if (N % i == 0) return false; } return true; } // 最大値更新 void chmax(long long &a, long long b) { a = max(a, b); } // 最小値更新 void chmin(long long &a, long long b) { a = min(a, b); } // 構造体 // Union-Find木 struct UnionFind { // メンバ変数 vector<long long> par; // par[i]:=頂点iの親 vector<long long> s; // s[i]:=頂点iが属する集合の個数(iが根のとき) // コンストラクタ UnionFind(long long N) : par(N), s(N) { for (long long i = 0; i < N; i++) { par[i] = i; // 最初はすべてが根として初期化 s[i] = 1; } } // メンバ関数 // root(i):=頂点iの根 long long root(long long i) { if (par[i] == i) return i; par[i] = root(par[i]); // 経路圧縮 return root(par[i]); // 再帰 } // size[i]:=iが属する集合の個数 long long size(long long i) { return s[root(i)]; } // same(x,y) xとyが同じ根を持つか(同じ集合に含まれるか) bool same(long long x, long long y) { return root(x) == root(y); } // unite(x,y) xの根をyの根に繋げる(集合を合併) void unite(long long x, long long y) { if (!same(x, y)) { long long rx = root(x); long long ry = root(y); par[rx] = par[ry]; s[ry] = s[rx] + s[ry]; } } }; /////////////////⊂('ω'⊂ )))Σ≡GO!///////////////// // メイン関数 int main() { // doubleの桁数 lin(N); lin(Q); UnionFind T(N); rep(i, Q) { lin(t); lin(u); lin(v); u--; v--; if (t == 0) T.unite(u, v); else { if (T.same(u, v)) cout << 1 << endl; else cout << 0 << endl; } } }
// #Sazaの1日1AC #include <bits/stdc++.h> using namespace std; const long long mod = 1000000000 + 7; const long long INF = 9e18; const double PI = 3.14159265358979323846; // マクロ // 型エイリアス using ll = long long; using P = pair<long long, long long>; using vl = vector<long long>; using vvl = vector<vector<long long>>; using vP = vector<pair<long long, long long>>; // ショートカット #define rep(i, n) for (long long i = 0; i < n; i++) #define rep2(i, k, n) for (long long i = k; i < n; i++) // 半開区間 #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define pb push_back #define mkp make_pair // 入力 #define vin(v, N) \ for (long long i = 0; i < N; i++) \ cin >> v.at(i) #define lin(n) \ long long n; \ cin >> n #define chin(x) \ char x; \ cin >> x; #define sin(s) \ string s; \ cin >> s; #define vlin(v, N) \ vector<long long> v(N); \ for (long long i = 0; i < N; i++) \ cin >> v.at(i) #define max(a, b) max((ll)a, (ll)b) #define min(a, b) min((ll)a, (ll)b) // 関数 // 最大公約数 long long gcd(long long m, long long n) { long long a = max(m, n); long long b = min(m, n); long long r = a % b; while (r != 0) { a = b; b = r; r = a % b; } return b; } // 最小公倍数 long long lcd(long long m, long long n) { return m * n / gcd(m, n); } // xのn乗 long long power(long long x, long long N) { long long ret = 1; for (long long i = 0; i < N; i++) ret *= x; return ret; } // 繰り返し二乗法 long long repeat_squaring(long long x, long long n) { if (n == 0) return 1; else if (n % 2 == 0) { long long t = repeat_squaring(x, n / 2); return t * t % mod; } else return x * repeat_squaring(x, n - 1) % mod; } // 素因数分解(mapで返す) map<long long, long long> factor(long long p) { ll p1 = p; map<long long, long long> ret; for (long long i = 2; i * i <= p1; i++) { while (p % i == 0) { ret[i]++; p /= i; } } if (p != 1) ret[p]++; return ret; } // 素数判定 bool is_prime(long long N) { for (long long i = 2; i * i <= N; i++) { if (N % i == 0) return false; } return true; } // 最大値更新 void chmax(long long &a, long long b) { a = max(a, b); } // 最小値更新 void chmin(long long &a, long long b) { a = min(a, b); } // 構造体 // Union-Find木 struct UnionFind { // メンバ変数 vector<long long> par; // par[i]:=頂点iの親 vector<long long> s; // s[i]:=頂点iが属する集合の個数(iが根のとき) // コンストラクタ UnionFind(long long N) : par(N), s(N) { for (long long i = 0; i < N; i++) { par[i] = i; // 最初はすべてが根として初期化 s[i] = 1; } } // メンバ関数 // root(i):=頂点iの根 long long root(long long i) { if (par[i] == i) return i; par[i] = root(par[i]); // 経路圧縮 return root(par[i]); // 再帰 } // size[i]:=iが属する集合の個数 long long size(long long i) { return s[root(i)]; } // same(x,y) xとyが同じ根を持つか(同じ集合に含まれるか) bool same(long long x, long long y) { return root(x) == root(y); } // unite(x,y) xの根をyの根に繋げる(集合を合併) void unite(long long x, long long y) { if (!same(x, y)) { long long rx = root(x); long long ry = root(y); par[rx] = par[ry]; s[ry] = s[rx] + s[ry]; } } }; /////////////////⊂('ω'⊂ )))Σ≡GO!///////////////// // メイン関数 int main() { // doubleの桁数 lin(N); lin(Q); UnionFind T(N); rep(i, Q) { lin(t); lin(u); lin(v); if (t == 0) T.unite(u, v); else { if (T.same(u, v)) cout << 1 << endl; else cout << 0 << endl; } } }
delete
152
154
152
152
-6
free(): invalid pointer
p02558
C++
Runtime Error
#include <iostream> #include <vector> using namespace std; struct Unionfind { vector<int> par; vector<int> rank; void init(int n) { par.resize(n); rank.resize(n); for (int i = 0; i < n; i++) par[i] = i; } int root(int x) { if (par[x] == x) return x; else return par[x] = root(par[x]); } void unite(int x, int y) { x = root(x), y = root(y); if (x == y) return; else { if (rank[x] < rank[y]) par[x] = y; else { par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } } bool issame(int x, int y) { return root(x) == root(y); } }; int main() { int n, q; cin >> n >> q; Unionfind uf; uf.init(n); for (int i = 0; i < q; i++) { int query, a, b; cin >> query >> a >> b, a--, b--; if (query == 0) uf.unite(a, b); else cout << (uf.issame(a, b) ? 1 : 0) << endl; } }
#include <iostream> #include <vector> using namespace std; struct Unionfind { vector<int> par; vector<int> rank; void init(int n) { par.resize(n); rank.resize(n); for (int i = 0; i < n; i++) par[i] = i; } int root(int x) { if (par[x] == x) return x; else return par[x] = root(par[x]); } void unite(int x, int y) { x = root(x), y = root(y); if (x == y) return; else { if (rank[x] < rank[y]) par[x] = y; else { par[y] = x; if (rank[x] == rank[y]) rank[x]++; } } } bool issame(int x, int y) { return root(x) == root(y); } }; int main() { int n, q; cin >> n >> q; Unionfind uf; uf.init(n); for (int i = 0; i < q; i++) { int query, a, b; cin >> query >> a >> b; if (query == 0) uf.unite(a, b); else cout << (uf.issame(a, b) ? 1 : 0) << endl; } }
replace
48
49
48
49
0
p02558
C++
Runtime Error
#include "algorithm" #include "bitset" #include "cassert" #include "climits" #include "cmath" #include "cstdio" #include "ctime" #include "functional" #include "iomanip" #include "iostream" #include "list" #include "map" #include "numeric" #include "queue" #include "random" #include "set" #include "stack" #include "string" #include "unordered_map" #include "unordered_set" using namespace std; constexpr long long int MOD = 1000000007; // constexpr int MOD = 1000000007; // constexpr int MOD = 998244353; // constexpr long long int MOD = 998244353; constexpr double EPS = 1e-12; // int N, M, K, T, H, W, L, R; long long int N, M, K, T, H, W, L, R; class UnionFind { vector<int> parent; vector<int> rank; public: UnionFind(int num) { num++; parent.resize(num); rank.resize(num); for (int i = 0; i < num; i++) { parent[i] = i; rank[i] = 0; } } int Find(int node) { if (parent[node] == node) return node; else return parent[node] = Find(parent[node]); } void Unite(int u, int v) { u = Find(u); v = Find(v); if (u == v) return; if (rank[u] < rank[v]) parent[u] = v; else { parent[v] = u; if (rank[u] == rank[v]) rank[u]++; } } bool Check_Same(int u, int v) { return Find(u) == Find(v); } }; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> K; UnionFind uf(N); while (K--) { int a, b, c; cin >> a >> b >> c; b--, c--; if (a) { cout << uf.Check_Same(b, c) << endl; } else { uf.Unite(b, c); } } }
#include "algorithm" #include "bitset" #include "cassert" #include "climits" #include "cmath" #include "cstdio" #include "ctime" #include "functional" #include "iomanip" #include "iostream" #include "list" #include "map" #include "numeric" #include "queue" #include "random" #include "set" #include "stack" #include "string" #include "unordered_map" #include "unordered_set" using namespace std; constexpr long long int MOD = 1000000007; // constexpr int MOD = 1000000007; // constexpr int MOD = 998244353; // constexpr long long int MOD = 998244353; constexpr double EPS = 1e-12; // int N, M, K, T, H, W, L, R; long long int N, M, K, T, H, W, L, R; class UnionFind { vector<int> parent; vector<int> rank; public: UnionFind(int num) { num++; parent.resize(num); rank.resize(num); for (int i = 0; i < num; i++) { parent[i] = i; rank[i] = 0; } } int Find(int node) { if (parent[node] == node) return node; else return parent[node] = Find(parent[node]); } void Unite(int u, int v) { u = Find(u); v = Find(v); if (u == v) return; if (rank[u] < rank[v]) parent[u] = v; else { parent[v] = u; if (rank[u] == rank[v]) rank[u]++; } } bool Check_Same(int u, int v) { return Find(u) == Find(v); } }; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N >> K; UnionFind uf(N); while (K--) { int a, b, c; cin >> a >> b >> c; if (a) { cout << uf.Check_Same(b, c) << endl; } else { uf.Unite(b, c); } } }
delete
77
78
77
77
0
p02558
C++
Runtime Error
#include <bits/stdc++.h> #define fast \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define int long long using namespace std; const int N = 1e5 + 5; const int mod = 1e9 + 7; int parent[N], siz[N]; void make_set(int v) { parent[v] = v; } int find_set(int v) { while (v != parent[v]) v = parent[v]; return v; } void union_sets(int a, int b) { a = find_set(a); b = find_set(b); if (a != b) { if (siz[a] < siz[b]) swap(a, b); parent[b] = a; siz[a] += siz[b]; } } int32_t main() { fast; memset(siz, 0, sizeof siz); int n, q; cin >> n >> q; for (int i = 0; i < n; i++) make_set(i); while (q--) { int t, u, v; cin >> t >> u >> v; if (t == 0) union_sets(u, v); else { if (find_set(u) == find_set(v)) cout << 1 << endl; else cout << 0 << endl; } } }
#include <bits/stdc++.h> #define fast \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0) #define int long long using namespace std; const int N = 2e5 + 5; const int mod = 1e9 + 7; int parent[N], siz[N]; void make_set(int v) { parent[v] = v; } int find_set(int v) { while (v != parent[v]) v = parent[v]; return v; } void union_sets(int a, int b) { a = find_set(a); b = find_set(b); if (a != b) { if (siz[a] < siz[b]) swap(a, b); parent[b] = a; siz[a] += siz[b]; } } int32_t main() { fast; memset(siz, 0, sizeof siz); int n, q; cin >> n >> q; for (int i = 0; i < n; i++) make_set(i); while (q--) { int t, u, v; cin >> t >> u >> v; if (t == 0) union_sets(u, v); else { if (find_set(u) == find_set(v)) cout << 1 << endl; else cout << 0 << endl; } } }
replace
8
9
8
9
0
p02558
C++
Runtime Error
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define ll long long #define FASTIO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define inf 1e9 #define ff first #define ss second #define lb lower_bound #define ub upper_bound #define bs binary_search #define mod 1000000007 #define pb push_back #define all(s) s.begin(), s.end() #define pie 3.14159265358979323846 #define fr(i, a, b) for (ll i = a; i < b; i++) #define frr(i, a, b) for (ll i = b - 1; i >= a; i--) #define gcd __gcd #define con continue #define pii pair<ll, ll> const ll N = 1e5 + 6; ll n, a, b, x; ll par[N]; void make_par() { for (ll i = 0; i < N; i++) par[i] = i; } ll find_par(ll u) { if (par[u] == u) return u; return par[u] = find_par(par[u]); } void union_par(ll a, ll b) { a = find_par(a); b = find_par(b); par[a] = b; return; } signed main() { FASTIO; ll tt = 1; // cin>>tt; while (tt--) { make_par(); ll n, m; cin >> m >> n; for (ll i = 0; i < n; i++) { cin >> x; if (x == 1) { cin >> a >> b; a = find_par(a); b = find_par(b); if (a == b) cout << "1\n"; else cout << "0\n"; con; } cin >> a >> b; union_par(a, b); } } }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define ll long long #define FASTIO \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define inf 1e9 #define ff first #define ss second #define lb lower_bound #define ub upper_bound #define bs binary_search #define mod 1000000007 #define pb push_back #define all(s) s.begin(), s.end() #define pie 3.14159265358979323846 #define fr(i, a, b) for (ll i = a; i < b; i++) #define frr(i, a, b) for (ll i = b - 1; i >= a; i--) #define gcd __gcd #define con continue #define pii pair<ll, ll> const ll N = 4e5 + 6; ll n, a, b, x; ll par[N]; void make_par() { for (ll i = 0; i < N; i++) par[i] = i; } ll find_par(ll u) { if (par[u] == u) return u; return par[u] = find_par(par[u]); } void union_par(ll a, ll b) { a = find_par(a); b = find_par(b); par[a] = b; return; } signed main() { FASTIO; ll tt = 1; // cin>>tt; while (tt--) { make_par(); ll n, m; cin >> m >> n; for (ll i = 0; i < n; i++) { cin >> x; if (x == 1) { cin >> a >> b; a = find_par(a); b = find_par(b); if (a == b) cout << "1\n"; else cout << "0\n"; con; } cin >> a >> b; union_par(a, b); } } }
replace
28
29
28
29
0