/* code by PixelCat */
/* meow owo */
#include <bits/stdc++.h>
#define int LL //__int128
#define double long double
using namespace std;
using LL = long long;
// using i128 = __int128_t;
using ull = unsigned long long;
using pii = pair<int, int>;
#define For(i, a, b) for (int i = a; i <= b; i++)
#define Fors(i, a, b, s) for (int i = a; i <= b; i += s)
#define Forr(i, a, b) for (int i = a; i >= b; i--)
#define F first
#define S second
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define mkp make_pair
#define MOD (int)(998244353)
// #define MOD (int)((LL)1'000'000'007)
#define EPS (1e-6)
namespace {
#ifdef NYAOWO
#include "./library/debug.hpp"
inline void USACO(const string &s) {
cerr << "USACO: " << s << "\n";
}
#else
#define debug(...)
inline void timer() {}
inline void USACO(const string &s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
#endif
inline void NYA() {
ios::sync_with_stdio(false);
cin.tie(0);
}
inline int gcd(int a, int b) {
return __gcd(a, b);
}
inline int lcm(int a, int b) {
return a / gcd(a, b) * b;
}
inline int fpow(int b, int p, const int &mod = MOD) {
if(p < 0) return fpow(fpow(b, -p, mod), mod - 2, mod);
b %= mod;
int ans = 1;
for (; p; p >>= 1, b = b * b % mod)
if (p & 1) ans = ans * b % mod;
return ans;
}
template <typename T>
inline void chmin(T &_a, const T &_b) {
if (_b < _a) _a = _b;
}
template <typename T>
inline void chmax(T &_a, const T &_b) {
if (_a < _b) _a = _b;
}
mt19937_64 rng(
chrono::steady_clock::now().time_since_epoch().count());
} // namespace
const int MAXN = 100'000;
int cnt[MAXN + 10][3];
int32_t main() {
NYA();
// nyaacho >/////<
int n; cin >> n;
int ans = 0;
For(i, 1, n * 2) {
int x, y; cin >> x >> y;
if(x < 1) { ans += 1 - x; x = 1; }
if(x > n) { ans += x - n; x = n; }
if(y < 1) { ans += 1 - y; y = 1; }
if(y > 2) { ans += y - 2; y = 2; }
cnt[x][y]++;
}
queue<int> c1, c2;
int r = 0;
For(l, 1, n) {
while(sz(c1) + sz(c2) < 2) {
r++;
while(cnt[r][1]--) c1.emplace(r);
while(cnt[r][2]--) c2.emplace(r);
}
if(sz(c1)) {
ans += abs(c1.front() - l);
c1.pop();
} else {
ans += 1 + abs(c2.front() - l);
c2.pop();
}
if(sz(c2)) {
ans += abs(c2.front() - l);
c2.pop();
} else {
ans += 1 + abs(c1.front() - l);
c1.pop();
}
}
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |