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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02680 | C++ | Runtime Error | #include <bits/stdc++.h>
#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if (!(p))
#define until(p) while (!(p))
using ll = std::int64_t;
using P = std::tuple<int, int>;
constexpr int INF = 1000000000;
int N, M;
int A[1100], B[1100], C[1100];
int D[1100], E[1100], F[1100];
std::vector<int> xs, ys;
bool filled[5100][5100], visited[5100][5100];
std::stack<P> st;
int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
ll area() {
ll res = 0;
for (int i = 0; i + 1 < xs.size(); ++i) {
for (int j = 0; j + 1 < ys.size(); ++j) {
unless(visited[i * 2 + 1][j * 2 + 1]) { continue; }
if (i == 0 || i + 1 == xs.size() - 1 || j == 0 ||
j + 1 == ys.size() - 1) {
return -1;
}
int x1 = xs[i], x2 = xs[i + 1], y1 = ys[j], y2 = ys[j + 1];
res += 1ll * (x2 - x1) * (y2 - y1);
}
}
return res;
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
xs.emplace_back(0);
xs.emplace_back(-INF - 1);
xs.emplace_back(-INF);
xs.emplace_back(INF);
xs.emplace_back(INF + 1);
ys.emplace_back(0);
ys.emplace_back(-INF - 1);
ys.emplace_back(-INF);
ys.emplace_back(INF);
ys.emplace_back(INF + 1);
std::cin >> N >> M;
for (int i = 0; i < N; ++i) {
std::cin >> A[i] >> B[i] >> C[i];
xs.emplace_back(A[i]);
xs.emplace_back(B[i]);
ys.emplace_back(C[i]);
}
for (int i = 0; i < M; ++i) {
std::cin >> D[i] >> E[i] >> F[i];
xs.emplace_back(D[i]);
ys.emplace_back(E[i]);
ys.emplace_back(F[i]);
}
std::sort(xs.begin(), xs.end());
xs.erase(std::unique(xs.begin(), xs.end()), xs.end());
std::sort(ys.begin(), ys.end());
ys.erase(std::unique(ys.begin(), ys.end()), ys.end());
for (int i = 0; i < N; ++i) {
A[i] = std::lower_bound(xs.begin(), xs.end(), A[i]) - xs.begin();
B[i] = std::lower_bound(xs.begin(), xs.end(), B[i]) - xs.begin();
C[i] = std::lower_bound(ys.begin(), ys.end(), C[i]) - ys.begin();
for (int j = A[i] * 2; j <= B[i] * 2; ++j) {
filled[j][C[i] * 2] = true;
}
}
for (int i = 0; i < M; ++i) {
D[i] = std::lower_bound(xs.begin(), xs.end(), D[i]) - xs.begin();
E[i] = std::lower_bound(ys.begin(), ys.end(), E[i]) - ys.begin();
F[i] = std::lower_bound(ys.begin(), ys.end(), F[i]) - ys.begin();
for (int j = E[i] * 2; j <= F[i] * 2; ++j) {
filled[D[i] * 2][j] = true;
}
}
int sx = (std::lower_bound(xs.begin(), xs.end(), 0) - xs.begin()) * 2,
sy = (std::lower_bound(ys.begin(), ys.end(), 0) - ys.begin()) * 2;
visited[sx][sy] = true;
st.emplace(sx, sy);
int mx_x = xs.size() * 2, mx_y = ys.size() * 2;
// for(int j=0;j<mx_y;++j){
// for(int i=0;i<mx_x;++i){
// std::cout << filled[i][j];
// }
// std::cout << std::endl;
// }
// std::cout << "----------" << std::endl;
until(st.empty()) {
int x, y;
std::tie(x, y) = st.top();
st.pop();
for (int i = 0; i < 4; ++i) {
int nx = x + dx[i], ny = y + dy[i];
if (nx < 0 || nx >= mx_x || ny < 0 || ny >= mx_y) {
continue;
}
if (filled[nx][ny] || visited[nx][ny]) {
continue;
}
visited[nx][ny] = true;
st.emplace(nx, ny);
}
}
// for(int j=0;j<mx_y;++j){
// for(int i=0;i<mx_x;++i){
// std::cout << visited[i][j];
// }
// std::cout << std::endl;
// }
// std::cout << "----------" << std::endl;
ll res = area();
if (res >= 0) {
std::cout << res << std::endl;
} else {
std::cout << "INF" << std::endl;
}
}
| #include <bits/stdc++.h>
#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if (!(p))
#define until(p) while (!(p))
using ll = std::int64_t;
using P = std::tuple<int, int>;
constexpr int INF = 1000000000;
int N, M;
int A[1100], B[1100], C[1100];
int D[1100], E[1100], F[1100];
std::vector<int> xs, ys;
bool filled[7100][7100], visited[7100][7100];
std::stack<P> st;
int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
ll area() {
ll res = 0;
for (int i = 0; i + 1 < xs.size(); ++i) {
for (int j = 0; j + 1 < ys.size(); ++j) {
unless(visited[i * 2 + 1][j * 2 + 1]) { continue; }
if (i == 0 || i + 1 == xs.size() - 1 || j == 0 ||
j + 1 == ys.size() - 1) {
return -1;
}
int x1 = xs[i], x2 = xs[i + 1], y1 = ys[j], y2 = ys[j + 1];
res += 1ll * (x2 - x1) * (y2 - y1);
}
}
return res;
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
xs.emplace_back(0);
xs.emplace_back(-INF - 1);
xs.emplace_back(-INF);
xs.emplace_back(INF);
xs.emplace_back(INF + 1);
ys.emplace_back(0);
ys.emplace_back(-INF - 1);
ys.emplace_back(-INF);
ys.emplace_back(INF);
ys.emplace_back(INF + 1);
std::cin >> N >> M;
for (int i = 0; i < N; ++i) {
std::cin >> A[i] >> B[i] >> C[i];
xs.emplace_back(A[i]);
xs.emplace_back(B[i]);
ys.emplace_back(C[i]);
}
for (int i = 0; i < M; ++i) {
std::cin >> D[i] >> E[i] >> F[i];
xs.emplace_back(D[i]);
ys.emplace_back(E[i]);
ys.emplace_back(F[i]);
}
std::sort(xs.begin(), xs.end());
xs.erase(std::unique(xs.begin(), xs.end()), xs.end());
std::sort(ys.begin(), ys.end());
ys.erase(std::unique(ys.begin(), ys.end()), ys.end());
for (int i = 0; i < N; ++i) {
A[i] = std::lower_bound(xs.begin(), xs.end(), A[i]) - xs.begin();
B[i] = std::lower_bound(xs.begin(), xs.end(), B[i]) - xs.begin();
C[i] = std::lower_bound(ys.begin(), ys.end(), C[i]) - ys.begin();
for (int j = A[i] * 2; j <= B[i] * 2; ++j) {
filled[j][C[i] * 2] = true;
}
}
for (int i = 0; i < M; ++i) {
D[i] = std::lower_bound(xs.begin(), xs.end(), D[i]) - xs.begin();
E[i] = std::lower_bound(ys.begin(), ys.end(), E[i]) - ys.begin();
F[i] = std::lower_bound(ys.begin(), ys.end(), F[i]) - ys.begin();
for (int j = E[i] * 2; j <= F[i] * 2; ++j) {
filled[D[i] * 2][j] = true;
}
}
int sx = (std::lower_bound(xs.begin(), xs.end(), 0) - xs.begin()) * 2,
sy = (std::lower_bound(ys.begin(), ys.end(), 0) - ys.begin()) * 2;
visited[sx][sy] = true;
st.emplace(sx, sy);
int mx_x = xs.size() * 2, mx_y = ys.size() * 2;
// for(int j=0;j<mx_y;++j){
// for(int i=0;i<mx_x;++i){
// std::cout << filled[i][j];
// }
// std::cout << std::endl;
// }
// std::cout << "----------" << std::endl;
until(st.empty()) {
int x, y;
std::tie(x, y) = st.top();
st.pop();
for (int i = 0; i < 4; ++i) {
int nx = x + dx[i], ny = y + dy[i];
if (nx < 0 || nx >= mx_x || ny < 0 || ny >= mx_y) {
continue;
}
if (filled[nx][ny] || visited[nx][ny]) {
continue;
}
visited[nx][ny] = true;
st.emplace(nx, ny);
}
}
// for(int j=0;j<mx_y;++j){
// for(int i=0;i<mx_x;++i){
// std::cout << visited[i][j];
// }
// std::cout << std::endl;
// }
// std::cout << "----------" << std::endl;
ll res = area();
if (res >= 0) {
std::cout << res << std::endl;
} else {
std::cout << "INF" << std::endl;
}
}
| replace | 16 | 17 | 16 | 17 | 0 | |
p02680 | C++ | Runtime Error | #include <bits/stdc++.h>
#define DEBUG if (0)
#define lli long long int
#define ull unsigned long long int
#define ldouble long double
using namespace std;
/*
compress the coordinates
floodfill
*/
const int maxN = 1e3 + 10;
int n, m, limitx, limity;
lli horizontal[3][maxN], vertical[3][maxN];
map<int, lli> revx, revy;
int mat[6 * maxN][6 * maxN];
int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
lli ans = 0;
bool bfs(int sx, int sy) {
queue<pair<int, int>> q;
q.push({sx, sy});
while (!q.empty()) {
int x = q.front().first, y = q.front().second;
q.pop();
if (x < 0 || x >= limitx || y < 0 || y >= limity)
return true;
if (mat[x][y] != 0)
continue;
mat[x][y] = 2;
if (x & y & 1LL) {
ans += (revx[x + 1] - revx[x - 1]) * (revy[y + 1] - revy[y - 1]);
assert(revx[x + 1] - revx[x - 1] >= 0);
assert(revy[y + 1] - revy[y - 1] >= 0);
}
for (int k = 0; k < 4; k++) {
int nx = x + dx[k], ny = y + dy[k];
if (nx < 0 || nx >= limitx || ny < 0 || ny >= limity)
return true;
if (mat[nx][ny] == 0)
q.push({x + dx[k], y + dy[k]});
}
}
return false;
}
void removeRepeated(vector<lli> &arr) {
sort(arr.begin(), arr.end());
arr.resize(distance(arr.begin(), unique(arr.begin(), arr.end())));
}
int main() {
int t = 0;
while (scanf("%d %d", &n, &m) != EOF) {
if (t++)
memset(mat, 0, sizeof(mat));
vector<lli> xs, ys;
xs.push_back(0), ys.push_back(0);
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++)
scanf("%lld", &horizontal[j][i]);
xs.push_back(horizontal[0][i]), xs.push_back(horizontal[1][i]);
ys.push_back(horizontal[2][i]);
assert(horizontal[2][i] >= -1e9 && horizontal[2][i] <= 1e9);
assert(horizontal[0][i] >= -1e9 && horizontal[0][i] < horizontal[1][i]);
assert(horizontal[1][i] <= 1e9);
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < 3; j++)
scanf("%lld", &vertical[j][i]);
xs.push_back(vertical[0][i]);
ys.push_back(vertical[1][i]), ys.push_back(vertical[2][i]);
assert(vertical[0][i] >= -1e9 && vertical[0][i] <= 1e9);
assert(vertical[1][i] >= -1e9 && vertical[1][i] < vertical[2][i]);
assert(vertical[2][i] <= 1e9);
}
removeRepeated(xs), removeRepeated(ys);
map<lli, int> compx, compy;
revx.clear(), revy.clear();
for (int i = 0; i < xs.size(); i++)
compx[xs[i]] = 2 * i, revx[2 * i] = xs[i];
for (int i = 0; i < ys.size(); i++)
compy[ys[i]] = 2 * i, revy[2 * i] = ys[i];
for (int i = 0; i < n; i++) {
horizontal[0][i] = compx[horizontal[0][i]],
horizontal[1][i] = compx[horizontal[1][i]];
horizontal[2][i] = compy[horizontal[2][i]];
}
for (int i = 0; i < m; i++) {
vertical[0][i] = compx[vertical[0][i]];
vertical[1][i] = compy[vertical[1][i]],
vertical[2][i] = compy[vertical[2][i]];
}
limitx = 2 * xs.size() + 1, limity = 2 * ys.size() + 1;
assert(limitx <= 6 * maxN);
assert(limity <= 6 * maxN);
for (int i = 0; i < n; i++)
for (int j = horizontal[0][i]; j <= horizontal[1][i]; j++)
mat[j][horizontal[2][i]] = 1;
for (int i = 0; i < m; i++)
for (int j = vertical[1][i]; j <= vertical[2][i]; j++)
mat[vertical[0][i]][j] = 1;
int zerox = compx[0], zeroy = compy[0];
ans = 0;
bool beyond = bfs(zerox, zeroy);
DEBUG
for (int y = 0; y < limity; y++) {
for (int x = 0; x < limitx; x++)
if (x == zerox && y == zeroy)
printf("x");
else
printf("%c", mat[x][y] == 1 ? '@'
: mat[x][y] == 2 ? ((x & 1LL & y) ? '~' : '.')
: ' ');
printf("\n");
}
if (beyond)
printf("INF\n");
else {
assert(ans >= 0);
printf("%lld\n", ans);
}
}
return 0;
} | #include <bits/stdc++.h>
#define DEBUG if (0)
#define lli long long int
#define ull unsigned long long int
#define ldouble long double
using namespace std;
/*
compress the coordinates
floodfill
*/
const int maxN = 1e3 + 10;
int n, m, limitx, limity;
lli horizontal[3][maxN], vertical[3][maxN];
map<int, lli> revx, revy;
int mat[6 * maxN][6 * maxN];
int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
lli ans = 0;
bool bfs(int sx, int sy) {
queue<pair<int, int>> q;
q.push({sx, sy});
while (!q.empty()) {
int x = q.front().first, y = q.front().second;
q.pop();
if (x < 0 || x >= limitx || y < 0 || y >= limity)
return true;
if (mat[x][y] != 0)
continue;
mat[x][y] = 2;
if (x & y & 1LL) {
ans += (revx[x + 1] - revx[x - 1]) * (revy[y + 1] - revy[y - 1]);
// assert(revx[x + 1] - revx[x - 1] >= 0);
// assert(revy[y + 1] - revy[y - 1] >= 0);
}
for (int k = 0; k < 4; k++) {
int nx = x + dx[k], ny = y + dy[k];
if (nx < 0 || nx >= limitx || ny < 0 || ny >= limity)
return true;
if (mat[nx][ny] == 0)
q.push({x + dx[k], y + dy[k]});
}
}
return false;
}
void removeRepeated(vector<lli> &arr) {
sort(arr.begin(), arr.end());
arr.resize(distance(arr.begin(), unique(arr.begin(), arr.end())));
}
int main() {
int t = 0;
while (scanf("%d %d", &n, &m) != EOF) {
if (t++)
memset(mat, 0, sizeof(mat));
vector<lli> xs, ys;
xs.push_back(0), ys.push_back(0);
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++)
scanf("%lld", &horizontal[j][i]);
xs.push_back(horizontal[0][i]), xs.push_back(horizontal[1][i]);
ys.push_back(horizontal[2][i]);
assert(horizontal[2][i] >= -1e9 && horizontal[2][i] <= 1e9);
assert(horizontal[0][i] >= -1e9 && horizontal[0][i] < horizontal[1][i]);
assert(horizontal[1][i] <= 1e9);
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < 3; j++)
scanf("%lld", &vertical[j][i]);
xs.push_back(vertical[0][i]);
ys.push_back(vertical[1][i]), ys.push_back(vertical[2][i]);
assert(vertical[0][i] >= -1e9 && vertical[0][i] <= 1e9);
assert(vertical[1][i] >= -1e9 && vertical[1][i] < vertical[2][i]);
assert(vertical[2][i] <= 1e9);
}
removeRepeated(xs), removeRepeated(ys);
map<lli, int> compx, compy;
revx.clear(), revy.clear();
for (int i = 0; i < xs.size(); i++)
compx[xs[i]] = 2 * i, revx[2 * i] = xs[i];
for (int i = 0; i < ys.size(); i++)
compy[ys[i]] = 2 * i, revy[2 * i] = ys[i];
for (int i = 0; i < n; i++) {
horizontal[0][i] = compx[horizontal[0][i]],
horizontal[1][i] = compx[horizontal[1][i]];
horizontal[2][i] = compy[horizontal[2][i]];
}
for (int i = 0; i < m; i++) {
vertical[0][i] = compx[vertical[0][i]];
vertical[1][i] = compy[vertical[1][i]],
vertical[2][i] = compy[vertical[2][i]];
}
limitx = 2 * xs.size() + 1, limity = 2 * ys.size() + 1;
assert(limitx <= 6 * maxN);
assert(limity <= 6 * maxN);
for (int i = 0; i < n; i++)
for (int j = horizontal[0][i]; j <= horizontal[1][i]; j++)
mat[j][horizontal[2][i]] = 1;
for (int i = 0; i < m; i++)
for (int j = vertical[1][i]; j <= vertical[2][i]; j++)
mat[vertical[0][i]][j] = 1;
int zerox = compx[0], zeroy = compy[0];
ans = 0;
bool beyond = bfs(zerox, zeroy);
DEBUG
for (int y = 0; y < limity; y++) {
for (int x = 0; x < limitx; x++)
if (x == zerox && y == zeroy)
printf("x");
else
printf("%c", mat[x][y] == 1 ? '@'
: mat[x][y] == 2 ? ((x & 1LL & y) ? '~' : '.')
: ' ');
printf("\n");
}
if (beyond)
printf("INF\n");
else {
assert(ans >= 0);
printf("%lld\n", ans);
}
}
return 0;
} | replace | 35 | 37 | 35 | 37 | -11 | |
p02680 | C++ | Runtime Error | // #include "bits/stdc++.h"
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
// typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
bool G[1010][1010][2];
bool checked[1010][1010];
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vector<pair<pii, pii>> XE(M), YE(N);
rep(i, 0, N) {
cin >> YE[i].first.second >> YE[i].second.second >> YE[i].first.first;
YE[i].second.first = YE[i].first.first;
}
rep(i, 0, M) {
cin >> XE[i].first.second >> XE[i].first.first >> XE[i].second.first;
XE[i].second.second = XE[i].first.second;
}
vector<int> XV, YV;
XV.push_back(0), YV.push_back(0);
rep(i, 0, M) {
XV.push_back(XE[i].first.first);
XV.push_back(XE[i].second.first);
YV.push_back(XE[i].first.second);
YV.push_back(XE[i].second.second);
}
rep(i, 0, N) {
XV.push_back(YE[i].first.first);
XV.push_back(YE[i].second.first);
YV.push_back(YE[i].first.second);
YV.push_back(YE[i].second.second);
}
sort(all(XV));
sort(all(YV));
XV.erase(unique(all(XV)), XV.end());
YV.erase(unique(all(YV)), YV.end());
int H = SZ(YV) - 1, W = SZ(XV) - 1;
rep(i, 0, M) {
int lx = lower_bound(all(XV), XE[i].first.first) - XV.begin();
int rx = lower_bound(all(XV), XE[i].second.first) - XV.begin();
int y = lower_bound(all(YV), XE[i].first.second) - YV.begin();
rep(j, lx, rx) { G[y][j][0] = true; }
}
rep(i, 0, N) {
int x = lower_bound(all(XV), YE[i].first.first) - XV.begin();
int uy = lower_bound(all(YV), YE[i].first.second) - YV.begin();
int dy = lower_bound(all(YV), YE[i].second.second) - YV.begin();
rep(j, uy, dy) { G[j][x][1] = true; }
}
queue<pii> q;
pii sp;
sp.first = lower_bound(all(XV), 0) - XV.begin();
sp.second = lower_bound(all(YV), 0) - YV.begin();
q.push(sp);
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
checked[sp.second][sp.first] = true;
bool inf = false;
while (!q.empty()) {
auto p = q.front();
q.pop();
if (!G[p.second][p.first][1]) {
if (p.first == 0) {
inf = true;
break;
} else {
if (!checked[p.second][p.first - 1]) {
checked[p.second][p.first - 1] = true;
q.push(mp(p.first - 1, p.second));
}
}
}
if (!G[p.second][p.first + 1][1]) {
if (p.first == W - 1) {
inf = true;
break;
} else {
if (!checked[p.second][p.first + 1]) {
checked[p.second][p.first + 1] = true;
q.push(mp(p.first + 1, p.second));
}
}
}
if (!G[p.second][p.first][0]) {
if (p.second == 0) {
inf = true;
break;
} else {
if (!checked[p.second - 1][p.first]) {
checked[p.second - 1][p.first] = true;
q.push(mp(p.first, p.second - 1));
}
}
}
if (!G[p.second + 1][p.first][0]) {
if (p.second == H - 1) {
inf = true;
break;
} else {
if (!checked[p.second + 1][p.first]) {
checked[p.second + 1][p.first] = true;
q.push(mp(p.first, p.second + 1));
}
}
}
}
if (inf) {
cout << "INF" << endl;
} else {
int ans = 0;
rep(i, 0, H) rep(j, 0, W) {
if (checked[i][j]) {
ans += (XV[j + 1] - XV[j]) * (YV[i + 1] - YV[i]);
}
}
cout << ans << endl;
}
return 0;
} | // #include "bits/stdc++.h"
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define rep(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(c) begin(c), end(c)
#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
// typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
const int INF =
sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
bool G[3010][3010][2];
bool checked[3010][3010];
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vector<pair<pii, pii>> XE(M), YE(N);
rep(i, 0, N) {
cin >> YE[i].first.second >> YE[i].second.second >> YE[i].first.first;
YE[i].second.first = YE[i].first.first;
}
rep(i, 0, M) {
cin >> XE[i].first.second >> XE[i].first.first >> XE[i].second.first;
XE[i].second.second = XE[i].first.second;
}
vector<int> XV, YV;
XV.push_back(0), YV.push_back(0);
rep(i, 0, M) {
XV.push_back(XE[i].first.first);
XV.push_back(XE[i].second.first);
YV.push_back(XE[i].first.second);
YV.push_back(XE[i].second.second);
}
rep(i, 0, N) {
XV.push_back(YE[i].first.first);
XV.push_back(YE[i].second.first);
YV.push_back(YE[i].first.second);
YV.push_back(YE[i].second.second);
}
sort(all(XV));
sort(all(YV));
XV.erase(unique(all(XV)), XV.end());
YV.erase(unique(all(YV)), YV.end());
int H = SZ(YV) - 1, W = SZ(XV) - 1;
rep(i, 0, M) {
int lx = lower_bound(all(XV), XE[i].first.first) - XV.begin();
int rx = lower_bound(all(XV), XE[i].second.first) - XV.begin();
int y = lower_bound(all(YV), XE[i].first.second) - YV.begin();
rep(j, lx, rx) { G[y][j][0] = true; }
}
rep(i, 0, N) {
int x = lower_bound(all(XV), YE[i].first.first) - XV.begin();
int uy = lower_bound(all(YV), YE[i].first.second) - YV.begin();
int dy = lower_bound(all(YV), YE[i].second.second) - YV.begin();
rep(j, uy, dy) { G[j][x][1] = true; }
}
queue<pii> q;
pii sp;
sp.first = lower_bound(all(XV), 0) - XV.begin();
sp.second = lower_bound(all(YV), 0) - YV.begin();
q.push(sp);
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
checked[sp.second][sp.first] = true;
bool inf = false;
while (!q.empty()) {
auto p = q.front();
q.pop();
if (!G[p.second][p.first][1]) {
if (p.first == 0) {
inf = true;
break;
} else {
if (!checked[p.second][p.first - 1]) {
checked[p.second][p.first - 1] = true;
q.push(mp(p.first - 1, p.second));
}
}
}
if (!G[p.second][p.first + 1][1]) {
if (p.first == W - 1) {
inf = true;
break;
} else {
if (!checked[p.second][p.first + 1]) {
checked[p.second][p.first + 1] = true;
q.push(mp(p.first + 1, p.second));
}
}
}
if (!G[p.second][p.first][0]) {
if (p.second == 0) {
inf = true;
break;
} else {
if (!checked[p.second - 1][p.first]) {
checked[p.second - 1][p.first] = true;
q.push(mp(p.first, p.second - 1));
}
}
}
if (!G[p.second + 1][p.first][0]) {
if (p.second == H - 1) {
inf = true;
break;
} else {
if (!checked[p.second + 1][p.first]) {
checked[p.second + 1][p.first] = true;
q.push(mp(p.first, p.second + 1));
}
}
}
}
if (inf) {
cout << "INF" << endl;
} else {
int ans = 0;
rep(i, 0, H) rep(j, 0, W) {
if (checked[i][j]) {
ans += (XV[j + 1] - XV[j]) * (YV[i + 1] - YV[i]);
}
}
cout << ans << endl;
}
return 0;
} | replace | 66 | 68 | 66 | 68 | 0 | |
p02680 | C++ | Runtime Error | // #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define lfs cout << fixed << setprecision(10)
#define ALL(a) (a).begin(), (a).end()
#define ALLR(a) (a).rbegin(), (a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i, n, m) for (ll i = (n); i < (ll)(m); i++)
#define rrep(i, n, m) for (ll i = (ll)(m)-1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9 + 7;
const ll MOD9 = 998244353;
const int INF = 1e9;
using P = pair<ll, ll>;
template <typename T1, typename T2> bool chmin(T1 &a, T2 b) {
if (a > b) {
a = b;
return true;
} else
return false;
}
template <typename T1, typename T2> bool chmax(T1 &a, T2 b) {
if (a < b) {
a = b;
return true;
} else
return false;
}
ll median(ll a, ll b, ll c) {
return a + b + c - max({a, b, c}) - min({a, b, c});
}
void ans1(bool x) {
if (x)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
void ans2(bool x) {
if (x)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
void ans3(bool x) {
if (x)
cout << "Yay!" << endl;
else
cout << ":(" << endl;
}
template <typename T1, typename T2> void ans(bool x, T1 y, T2 z) {
if (x)
cout << y << endl;
else
cout << z << endl;
}
template <typename T> void debug(vector<vector<T>> &v, ll h, ll w) {
for (ll i = 0; i < h; i++) {
cout << v[i][0];
for (ll j = 1; j < w; j++)
cout spa v[i][j];
cout << endl;
}
};
void debug(vector<string> &v, ll h, ll w) {
for (ll i = 0; i < h; i++) {
for (ll j = 0; j < w; j++)
cout << v[i][j];
cout << endl;
}
};
template <typename T> void debug(vector<T> &v, ll n) {
if (n != 0)
cout << v[0];
for (ll i = 1; i < n; i++)
cout spa v[i];
cout << endl;
};
template <typename T> vector<vector<T>> vec(ll x, ll y, T w) {
vector<vector<T>> v(x, vector<T>(y, w));
return v;
}
ll gcd(ll x, ll y) {
ll r;
while (y != 0 && (r = x % y) != 0) {
x = y;
y = r;
}
return y == 0 ? x : y;
}
vector<ll> dx = {1, 0, -1, 0, 1, 1, -1, -1};
vector<ll> dy = {0, 1, 0, -1, 1, -1, 1, -1};
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...));
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
return os << p.first << " " << p.second;
}
// mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
struct z {
ll x, y, d;
z(ll a, ll b, ll c) : x(a), y(b), d(c){};
};
vector<vector<int>> dist(4005, vector<int>(4005, INF));
void bfs(ll h, ll w, ll sx, ll sy, vector<vector<vector<bool>>> &t) {
rep(i, 0, h) rep(j, 0, w) dist[i][j] = INF;
queue<struct z> que;
que.emplace(sx, sy, 0);
while (!que.empty()) {
auto pos = que.front();
que.pop();
if (dist[pos.x][pos.y] != INF)
continue;
dist[pos.x][pos.y] = pos.d;
for (ll i = 0; i < 4; i++) {
if (!t[pos.x][pos.y][i])
continue;
ll x = pos.x + dx[i], y = pos.y + dy[i], d = pos.d + 1;
if (x < 0 || x >= h || y < 0 || y >= w)
continue;
que.emplace(x, y, d);
}
}
}
template <typename T> map<T, ll> compress(vector<T> &v) {
sort(ALL(v));
v.erase(unique(ALL(v)), v.end());
map<T, ll> ret;
for (ll i = 0; i < (ll)v.size(); i++)
ret[v[i]] = i;
return ret;
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
ll res = 0, buf = 0;
bool judge = true;
ll n, m;
cin >> n >> m;
vector<ll> a(n), b(n), c(n);
rep(i, 0, n) cin >> a[i] >> b[i] >> c[i];
vector<ll> d(m), e(m), f(m);
rep(i, 0, m) cin >> d[i] >> e[i] >> f[i];
vector<ll> valx, valy;
rep(i, 0, n) {
valx.PB(a[i]);
valx.PB(b[i]);
valy.PB(c[i]);
}
rep(i, 0, m) {
valx.PB(d[i]);
valy.PB(e[i]);
valy.PB(f[i]);
}
valx.PB(0);
valy.PB(0);
valx.PB(2e9);
valy.PB(2e9);
valx.PB(-2e9);
valy.PB(-2e9);
auto mpx = compress(valx);
auto mpy = compress(valy);
ll h = (ll)mpx.size() - 1;
ll w = (ll)mpy.size() - 1;
// vector<ll>dx={1,0,-1,0,1,1,-1,-1};
// vector<ll>dy={0,1,0,-1,1,-1,1,-1};
auto t = make_v(h, w, 4, true);
rep(i, 0, n) {
ll ux = mpx[a[i]], vx = mpx[b[i]], y = mpy[c[i]];
rep(j, ux, vx) {
t[j][y][3] = false;
t[j][y - 1][1] = false;
}
}
rep(i, 0, n) {
ll x = mpx[d[i]], uy = mpy[e[i]], vy = mpy[f[i]];
rep(j, uy, vy) {
t[x][j][2] = false;
t[x - 1][j][0] = false;
}
}
bfs(h, w, mpx[0], mpy[0], t);
rep(i, 0, h) rep(j, 0, w) {
if (dist[i][j] != INF) {
if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
judge = false;
res += (valx[i + 1] - valx[i]) * (valy[j + 1] - valy[j]);
}
}
ans(!judge, "INF", res);
return 0;
} | // #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define lfs cout << fixed << setprecision(10)
#define ALL(a) (a).begin(), (a).end()
#define ALLR(a) (a).rbegin(), (a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i, n, m) for (ll i = (n); i < (ll)(m); i++)
#define rrep(i, n, m) for (ll i = (ll)(m)-1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9 + 7;
const ll MOD9 = 998244353;
const int INF = 1e9;
using P = pair<ll, ll>;
template <typename T1, typename T2> bool chmin(T1 &a, T2 b) {
if (a > b) {
a = b;
return true;
} else
return false;
}
template <typename T1, typename T2> bool chmax(T1 &a, T2 b) {
if (a < b) {
a = b;
return true;
} else
return false;
}
ll median(ll a, ll b, ll c) {
return a + b + c - max({a, b, c}) - min({a, b, c});
}
void ans1(bool x) {
if (x)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
void ans2(bool x) {
if (x)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
void ans3(bool x) {
if (x)
cout << "Yay!" << endl;
else
cout << ":(" << endl;
}
template <typename T1, typename T2> void ans(bool x, T1 y, T2 z) {
if (x)
cout << y << endl;
else
cout << z << endl;
}
template <typename T> void debug(vector<vector<T>> &v, ll h, ll w) {
for (ll i = 0; i < h; i++) {
cout << v[i][0];
for (ll j = 1; j < w; j++)
cout spa v[i][j];
cout << endl;
}
};
void debug(vector<string> &v, ll h, ll w) {
for (ll i = 0; i < h; i++) {
for (ll j = 0; j < w; j++)
cout << v[i][j];
cout << endl;
}
};
template <typename T> void debug(vector<T> &v, ll n) {
if (n != 0)
cout << v[0];
for (ll i = 1; i < n; i++)
cout spa v[i];
cout << endl;
};
template <typename T> vector<vector<T>> vec(ll x, ll y, T w) {
vector<vector<T>> v(x, vector<T>(y, w));
return v;
}
ll gcd(ll x, ll y) {
ll r;
while (y != 0 && (r = x % y) != 0) {
x = y;
y = r;
}
return y == 0 ? x : y;
}
vector<ll> dx = {1, 0, -1, 0, 1, 1, -1, -1};
vector<ll> dy = {0, 1, 0, -1, 1, -1, 1, -1};
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...));
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
return os << p.first << " " << p.second;
}
// mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
struct z {
ll x, y, d;
z(ll a, ll b, ll c) : x(a), y(b), d(c){};
};
vector<vector<int>> dist(4005, vector<int>(4005, INF));
void bfs(ll h, ll w, ll sx, ll sy, vector<vector<vector<bool>>> &t) {
rep(i, 0, h) rep(j, 0, w) dist[i][j] = INF;
queue<struct z> que;
que.emplace(sx, sy, 0);
while (!que.empty()) {
auto pos = que.front();
que.pop();
if (dist[pos.x][pos.y] != INF)
continue;
dist[pos.x][pos.y] = pos.d;
for (ll i = 0; i < 4; i++) {
if (!t[pos.x][pos.y][i])
continue;
ll x = pos.x + dx[i], y = pos.y + dy[i], d = pos.d + 1;
if (x < 0 || x >= h || y < 0 || y >= w)
continue;
que.emplace(x, y, d);
}
}
}
template <typename T> map<T, ll> compress(vector<T> &v) {
sort(ALL(v));
v.erase(unique(ALL(v)), v.end());
map<T, ll> ret;
for (ll i = 0; i < (ll)v.size(); i++)
ret[v[i]] = i;
return ret;
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
ll res = 0, buf = 0;
bool judge = true;
ll n, m;
cin >> n >> m;
vector<ll> a(n), b(n), c(n);
rep(i, 0, n) cin >> a[i] >> b[i] >> c[i];
vector<ll> d(m), e(m), f(m);
rep(i, 0, m) cin >> d[i] >> e[i] >> f[i];
vector<ll> valx, valy;
rep(i, 0, n) {
valx.PB(a[i]);
valx.PB(b[i]);
valy.PB(c[i]);
}
rep(i, 0, m) {
valx.PB(d[i]);
valy.PB(e[i]);
valy.PB(f[i]);
}
valx.PB(0);
valy.PB(0);
valx.PB(2e9);
valy.PB(2e9);
valx.PB(-2e9);
valy.PB(-2e9);
auto mpx = compress(valx);
auto mpy = compress(valy);
ll h = (ll)mpx.size() - 1;
ll w = (ll)mpy.size() - 1;
// vector<ll>dx={1,0,-1,0,1,1,-1,-1};
// vector<ll>dy={0,1,0,-1,1,-1,1,-1};
auto t = make_v(h, w, 4, true);
rep(i, 0, n) {
ll ux = mpx[a[i]], vx = mpx[b[i]], y = mpy[c[i]];
rep(j, ux, vx) {
t[j][y][3] = false;
t[j][y - 1][1] = false;
}
}
rep(i, 0, m) {
ll x = mpx[d[i]], uy = mpy[e[i]], vy = mpy[f[i]];
rep(j, uy, vy) {
t[x][j][2] = false;
t[x - 1][j][0] = false;
}
}
bfs(h, w, mpx[0], mpy[0], t);
rep(i, 0, h) rep(j, 0, w) {
if (dist[i][j] != INF) {
if (i == 0 || i == h - 1 || j == 0 || j == w - 1)
judge = false;
res += (valx[i + 1] - valx[i]) * (valy[j + 1] - valy[j]);
}
}
ans(!judge, "INF", res);
return 0;
} | replace | 187 | 188 | 187 | 188 | 0 | |
p02680 | C++ | Time Limit Exceeded | #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 pb push_back
#define all(r) r.begin(), r.end()
#define rall(r) r.rbegin(), r.rend()
#define fi first
#define se second
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;
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.fi << ", " << a.se << ')';
return out;
}
} // namespace std
struct UF { // O(loga(n))
int n;
int m;
vi d, r;
UF(int n) : n(n), m(n), d(n, -1), r(n, 0){};
int root(int i) {
if (d[i] < 0)
return i;
return d[i] = root(d[i]);
}
bool same(int x, int y) { return root(x) == root(y); }
bool unite(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (r[x] < r[y])
swap(x, y);
else if (r[x] == r[y])
r[x]++;
d[x] += d[y];
d[y] = x;
--m;
return true;
}
int size(int i) { return -d[root(i)]; }
int size() { return m; }
};
int main() {
int n, m;
cin >> n >> m;
vi a(n), b(n), c(n), d(m), e(m), f(m);
rep(i, n) cin >> a[i] >> b[i] >> c[i];
rep(i, m) cin >> d[i] >> e[i] >> f[i];
const int INF = 1e9 + 10;
map<int, int> mx, my;
mx[0] = 1;
my[0] = 1;
mx[-INF] = 1;
mx[INF] = 1;
mx[-INF - 1] = 1;
mx[INF + 1] = 1;
my[-INF] = 1;
my[INF] = 1;
my[-INF - 1] = 1;
my[INF + 1] = 1;
rep(i, n) {
mx[a[i]] = 1;
mx[b[i]] = 1;
my[c[i]] = 1;
}
rep(i, m) {
mx[d[i]] = 1;
my[e[i]] = 1;
my[f[i]] = 1;
}
{
int cnt = 0;
for (auto &p : mx)
p.se = cnt++;
}
{
int cnt = 0;
for (auto &p : my)
p.se = cnt++;
}
using B = bitset<4>;
vector<vector<B>> nxt(my.size() - 1, vector<B>(mx.size() - 1));
rep(i, nxt.size()) rep(j, nxt[i].size()) nxt[i][j].set();
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
rep(i, n) {
auto y = my[c[i]];
for (auto it = mx.lower_bound(a[i]); it->fi != b[i]; ++it) {
auto x = it->se;
nxt[y - 1][x].reset(3);
nxt[y][x].reset(1);
}
}
rep(i, m) {
auto x = mx[d[i]];
for (auto it = my.lower_bound(e[i]); it->fi != f[i]; ++it) {
auto y = it->se;
nxt[y][x - 1].reset(2);
nxt[y][x].reset(0);
}
}
const int sx = mx[-INF], tx = mx[INF];
const int sy = my[-INF], ty = my[INF];
vl rx(mx.size()), ry(my.size());
for (auto &&p : mx)
rx[p.se] = p.fi;
for (auto &&p : my)
ry[p.se] = p.fi;
vector<vl> area(my.size() - 1, vl(mx.size() - 1));
queue<pii> q;
q.push({my[0], mx[0]});
while (!q.empty()) {
auto p = q.front();
q.pop();
int y = p.fi, x = p.se;
if (y == sy || y == ty || x == sx || x == tx) {
cout << "INF" << '\n';
return 0;
}
{ area[y][x] = (ry[y + 1] - ry[y]) * (rx[x + 1] - rx[x]); }
rep(k, 4) if (nxt[y][x][k]) {
int ny = y + dy[k], nx = x + dx[k];
if (area[ny][nx] == 0)
q.push({ny, nx});
}
}
ll ans = 0LL;
for (auto &&low : area)
ans += accumulate(all(low), 0LL);
cout << ans << '\n';
// for(auto&& v: area) {dumpVL(v);};
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 pb push_back
#define all(r) r.begin(), r.end()
#define rall(r) r.rbegin(), r.rend()
#define fi first
#define se second
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;
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.fi << ", " << a.se << ')';
return out;
}
} // namespace std
struct UF { // O(loga(n))
int n;
int m;
vi d, r;
UF(int n) : n(n), m(n), d(n, -1), r(n, 0){};
int root(int i) {
if (d[i] < 0)
return i;
return d[i] = root(d[i]);
}
bool same(int x, int y) { return root(x) == root(y); }
bool unite(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (r[x] < r[y])
swap(x, y);
else if (r[x] == r[y])
r[x]++;
d[x] += d[y];
d[y] = x;
--m;
return true;
}
int size(int i) { return -d[root(i)]; }
int size() { return m; }
};
int main() {
int n, m;
cin >> n >> m;
vi a(n), b(n), c(n), d(m), e(m), f(m);
rep(i, n) cin >> a[i] >> b[i] >> c[i];
rep(i, m) cin >> d[i] >> e[i] >> f[i];
const int INF = 1e9 + 10;
map<int, int> mx, my;
mx[0] = 1;
my[0] = 1;
mx[-INF] = 1;
mx[INF] = 1;
mx[-INF - 1] = 1;
mx[INF + 1] = 1;
my[-INF] = 1;
my[INF] = 1;
my[-INF - 1] = 1;
my[INF + 1] = 1;
rep(i, n) {
mx[a[i]] = 1;
mx[b[i]] = 1;
my[c[i]] = 1;
}
rep(i, m) {
mx[d[i]] = 1;
my[e[i]] = 1;
my[f[i]] = 1;
}
{
int cnt = 0;
for (auto &p : mx)
p.se = cnt++;
}
{
int cnt = 0;
for (auto &p : my)
p.se = cnt++;
}
using B = bitset<4>;
vector<vector<B>> nxt(my.size() - 1, vector<B>(mx.size() - 1));
rep(i, nxt.size()) rep(j, nxt[i].size()) nxt[i][j].set();
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
rep(i, n) {
auto y = my[c[i]];
for (auto it = mx.lower_bound(a[i]); it->fi != b[i]; ++it) {
auto x = it->se;
nxt[y - 1][x].reset(3);
nxt[y][x].reset(1);
}
}
rep(i, m) {
auto x = mx[d[i]];
for (auto it = my.lower_bound(e[i]); it->fi != f[i]; ++it) {
auto y = it->se;
nxt[y][x - 1].reset(2);
nxt[y][x].reset(0);
}
}
const int sx = mx[-INF], tx = mx[INF];
const int sy = my[-INF], ty = my[INF];
vl rx(mx.size()), ry(my.size());
for (auto &&p : mx)
rx[p.se] = p.fi;
for (auto &&p : my)
ry[p.se] = p.fi;
vector<vl> area(my.size() - 1, vl(mx.size() - 1));
queue<pii> q;
q.push({my[0], mx[0]});
while (!q.empty()) {
auto p = q.front();
q.pop();
int y = p.fi, x = p.se;
if (area[y][x] != 0)
continue;
if (y == sy || y == ty || x == sx || x == tx) {
cout << "INF" << '\n';
return 0;
}
{ area[y][x] = (ry[y + 1] - ry[y]) * (rx[x + 1] - rx[x]); }
rep(k, 4) if (nxt[y][x][k]) {
int ny = y + dy[k], nx = x + dx[k];
if (area[ny][nx] == 0)
q.push({ny, nx});
}
}
ll ans = 0LL;
for (auto &&low : area)
ans += accumulate(all(low), 0LL);
cout << ans << '\n';
// for(auto&& v: area) {dumpVL(v);};
return 0;
} | insert | 170 | 170 | 170 | 172 | TLE | |
p02680 | Python | Runtime Error | def main():
import sys
readline = sys.stdin.readline
# readlines = sys.stdin.readlines
from collections import deque
from bisect import bisect_left
N, M = map(int, input().split())
tate = []
yoko = []
X = set()
Y = set()
for _ in range(N):
A, B, C = map(int, readline().split())
X.add(A)
X.add(B)
Y.add(C)
tate.append((C, A, B))
for _ in range(M):
D, E, F = map(int, readline().split())
X.add(D)
Y.add(E)
Y.add(F)
yoko.append((D, E, F))
X = sorted(list(X))
Y = sorted(list(Y))
H = len(X)
W = len(Y)
ix = {}
for i, x in enumerate(X):
ix[x] = i
jy = {}
for j, y in enumerate(Y):
jy[y] = j
wall = [[15] * W for _ in range(H)]
for c, a, b in tate:
ia = ix[a]
ib = ix[b]
jc = jy[c]
for i in range(ia, ib):
wall[i][jc - 1] &= 15 - (1 << 1)
wall[i][jc] &= 15 - (1 << 3)
for d, e, f in yoko:
i_d = ix[d]
je = jy[e]
jf = jy[f]
for j in range(je, jf):
wall[i_d - 1][j] &= 15 - (1 << 2)
wall[i_d][j] &= 15 - (1 << 0)
q = deque()
x0 = max(0, bisect_left(X, 0) - (0 not in ix))
y0 = max(0, bisect_left(Y, 0) - (0 not in jy))
path = [True] * (W * H)
path[x0 * W + y0] = False
q.append((x0, y0))
direction = ((-1, 0), (0, 1), (1, 0), (0, -1))
cnt = 0
while q:
x, y = q.popleft()
cnt += (X[x + 1] - X[x]) * (Y[y + 1] - Y[y])
for i, (dx, dy) in enumerate(direction):
if wall[x][y] & (1 << i):
nx = x + dx
ny = y + dy
if 0 <= nx < H - 1 and 0 <= ny < W - 1:
if path[nx * W + ny]:
path[nx * W + ny] = False
q.append((nx, ny))
else:
print("INF")
exit()
print(cnt)
if __name__ == "__main__":
main()
| def main():
import sys
readline = sys.stdin.readline
# readlines = sys.stdin.readlines
from collections import deque
from bisect import bisect_left
N, M = map(int, input().split())
tate = []
yoko = []
X = set()
Y = set()
for _ in range(N):
A, B, C = map(int, readline().split())
X.add(A)
X.add(B)
Y.add(C)
tate.append((C, A, B))
for _ in range(M):
D, E, F = map(int, readline().split())
X.add(D)
Y.add(E)
Y.add(F)
yoko.append((D, E, F))
X = sorted(list(X))
Y = sorted(list(Y))
H = len(X)
W = len(Y)
ix = {}
for i, x in enumerate(X):
ix[x] = i
jy = {}
for j, y in enumerate(Y):
jy[y] = j
wall = [[15] * W for _ in range(H)]
for c, a, b in tate:
ia = ix[a]
ib = ix[b]
jc = jy[c]
for i in range(ia, ib):
wall[i][jc - 1] &= 15 - (1 << 1)
wall[i][jc] &= 15 - (1 << 3)
for d, e, f in yoko:
i_d = ix[d]
je = jy[e]
jf = jy[f]
for j in range(je, jf):
wall[i_d - 1][j] &= 15 - (1 << 2)
wall[i_d][j] &= 15 - (1 << 0)
q = deque()
x0 = bisect_left(X, 0) - (0 not in ix)
y0 = bisect_left(Y, 0) - (0 not in jy)
if x0 == H - 1 or y0 == W - 1:
print("INF")
exit()
path = [True] * (W * H)
path[x0 * W + y0] = False
q.append((x0, y0))
direction = ((-1, 0), (0, 1), (1, 0), (0, -1))
cnt = 0
while q:
x, y = q.popleft()
cnt += (X[x + 1] - X[x]) * (Y[y + 1] - Y[y])
for i, (dx, dy) in enumerate(direction):
if wall[x][y] & (1 << i):
nx = x + dx
ny = y + dy
if 0 <= nx < H - 1 and 0 <= ny < W - 1:
if path[nx * W + ny]:
path[nx * W + ny] = False
q.append((nx, ny))
else:
print("INF")
exit()
print(cnt)
if __name__ == "__main__":
main()
| replace | 56 | 58 | 56 | 62 | 0 | |
p02680 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0, _n = (int)(n); i < _n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define CLR(t, v) memset(t, (v), sizeof(t))
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &a) {
return os << "(" << a.first << "," << a.second << ")";
}
template <class T> void pv(T a, T b) {
for (T i = a; i != b; ++i)
cout << (*i) << " ";
cout << endl;
}
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;
}
ll nextLong() {
ll x;
scanf("%lld", &x);
return x;
}
// 座標圧縮
// vector<ll> rev; // 圧縮後の値から元の値への写像
vector<int> normalize(const vector<ll> v) {
const int N = v.size();
vector<int> res(N);
vector<pair<ll, int>> t(N);
// rev = vector<ll>(N);
REP(i, N) t[i] = {v[i], i};
sort(ALL(t));
int r = 0;
REP(i, N) {
r += (i > 0 && t[i - 1].first != t[i].first);
res[t[i].second] = r;
// rev[r] = t[i].first;
}
return res;
}
vector<ll> bai(const vector<ll> &a) {
vector<ll> res;
REP(i, a.size()) {
res.push_back(a[i]);
res.push_back(a[i]);
}
return res;
}
bool wall[3010][3010];
bool vis[3010][3010];
int main2() {
CLR(wall, 0);
CLR(vis, 0);
int N = nextLong();
int M = nextLong();
const ll B = 1e9 + 10;
vector<ll> xs({-B, 0, B}), ys({-B, 0, B});
vector<int> tate, yoko;
REP(i, N) {
int A = nextLong();
int B = nextLong();
int C = nextLong();
tate.push_back(A);
tate.push_back(B);
tate.push_back(C);
xs.push_back(A);
xs.push_back(B);
ys.push_back(C);
}
REP(i, M) {
int D = nextLong();
int E = nextLong();
int F = nextLong();
yoko.push_back(D);
yoko.push_back(E);
yoko.push_back(F);
xs.push_back(D);
ys.push_back(E);
ys.push_back(F);
}
sort(ALL(xs));
xs.erase(unique(ALL(xs)), xs.end());
sort(ALL(ys));
ys.erase(unique(ALL(ys)), ys.end());
xs = bai(xs);
ys = bai(ys);
const int X = xs.size();
const int Y = ys.size();
REP(i, N) {
int a = next(lower_bound(ALL(xs), tate[i * 3])) - xs.begin();
int b = next(lower_bound(ALL(xs), tate[i * 3 + 1])) - xs.begin();
int c = next(lower_bound(ALL(ys), tate[i * 3 + 2])) - ys.begin();
for (int x = a; x <= b; x++)
wall[x][c] = true;
}
REP(i, M) {
int d = next(lower_bound(ALL(xs), yoko[i * 3])) - xs.begin();
int e = next(lower_bound(ALL(ys), yoko[i * 3 + 1])) - ys.begin();
int f = next(lower_bound(ALL(ys), yoko[i * 3 + 2])) - ys.begin();
for (int y = e; y <= f; y++)
wall[d][y] = true;
}
queue<pair<int, int>> q;
{
int x = next(lower_bound(ALL(xs), 0)) - xs.begin();
int y = next(lower_bound(ALL(ys), 0)) - ys.begin();
q.push({x, y});
vis[x][y] = true;
}
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
bool inf = false;
ll ans = 0;
while (!q.empty()) {
int x = q.front().first;
int y = q.front().second;
q.pop();
{
if (x == 0 || y == 0) {
inf = true;
break;
}
ans += (xs[x] - xs[x - 1]) * (ys[y] - ys[y - 1]);
}
REP(i, 4) {
int nx = x + dx[i];
int ny = y + dy[i];
if (0 <= nx && nx < X && 0 <= ny && ny < Y && !wall[nx][ny] &&
!vis[nx][ny]) {
vis[nx][ny] = true;
q.push({nx, ny});
}
}
}
// REP(i, X) {
// REP(j, Y) {
// cout << (wall[i][j] ? 1 : 0);
// }
// cout << endl;
// }
// REP(i, X) {
// printf("%20d : ", xs[i]);
// REP(j, Y) {
// cout << (vis[i][j] ? 1 : 0);
// }
// cout << endl;
// }
if (inf) {
cout << "INF" << endl;
} else {
cout << ans << endl;
}
return 0;
}
int main() {
#ifdef LOCAL
for (; !cin.eof(); cin >> ws)
#endif
main2();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0, _n = (int)(n); i < _n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define CLR(t, v) memset(t, (v), sizeof(t))
template <class T1, class T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &a) {
return os << "(" << a.first << "," << a.second << ")";
}
template <class T> void pv(T a, T b) {
for (T i = a; i != b; ++i)
cout << (*i) << " ";
cout << endl;
}
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;
}
ll nextLong() {
ll x;
scanf("%lld", &x);
return x;
}
// 座標圧縮
// vector<ll> rev; // 圧縮後の値から元の値への写像
vector<int> normalize(const vector<ll> v) {
const int N = v.size();
vector<int> res(N);
vector<pair<ll, int>> t(N);
// rev = vector<ll>(N);
REP(i, N) t[i] = {v[i], i};
sort(ALL(t));
int r = 0;
REP(i, N) {
r += (i > 0 && t[i - 1].first != t[i].first);
res[t[i].second] = r;
// rev[r] = t[i].first;
}
return res;
}
vector<ll> bai(const vector<ll> &a) {
vector<ll> res;
REP(i, a.size()) {
res.push_back(a[i]);
res.push_back(a[i]);
}
return res;
}
const int SZ = 6010;
bool wall[SZ][SZ];
bool vis[SZ][SZ];
int main2() {
CLR(wall, 0);
CLR(vis, 0);
int N = nextLong();
int M = nextLong();
const ll B = 1e9 + 10;
vector<ll> xs({-B, 0, B}), ys({-B, 0, B});
vector<int> tate, yoko;
REP(i, N) {
int A = nextLong();
int B = nextLong();
int C = nextLong();
tate.push_back(A);
tate.push_back(B);
tate.push_back(C);
xs.push_back(A);
xs.push_back(B);
ys.push_back(C);
}
REP(i, M) {
int D = nextLong();
int E = nextLong();
int F = nextLong();
yoko.push_back(D);
yoko.push_back(E);
yoko.push_back(F);
xs.push_back(D);
ys.push_back(E);
ys.push_back(F);
}
sort(ALL(xs));
xs.erase(unique(ALL(xs)), xs.end());
sort(ALL(ys));
ys.erase(unique(ALL(ys)), ys.end());
xs = bai(xs);
ys = bai(ys);
const int X = xs.size();
const int Y = ys.size();
REP(i, N) {
int a = next(lower_bound(ALL(xs), tate[i * 3])) - xs.begin();
int b = next(lower_bound(ALL(xs), tate[i * 3 + 1])) - xs.begin();
int c = next(lower_bound(ALL(ys), tate[i * 3 + 2])) - ys.begin();
for (int x = a; x <= b; x++)
wall[x][c] = true;
}
REP(i, M) {
int d = next(lower_bound(ALL(xs), yoko[i * 3])) - xs.begin();
int e = next(lower_bound(ALL(ys), yoko[i * 3 + 1])) - ys.begin();
int f = next(lower_bound(ALL(ys), yoko[i * 3 + 2])) - ys.begin();
for (int y = e; y <= f; y++)
wall[d][y] = true;
}
queue<pair<int, int>> q;
{
int x = next(lower_bound(ALL(xs), 0)) - xs.begin();
int y = next(lower_bound(ALL(ys), 0)) - ys.begin();
q.push({x, y});
vis[x][y] = true;
}
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
bool inf = false;
ll ans = 0;
while (!q.empty()) {
int x = q.front().first;
int y = q.front().second;
q.pop();
{
if (x == 0 || y == 0) {
inf = true;
break;
}
ans += (xs[x] - xs[x - 1]) * (ys[y] - ys[y - 1]);
}
REP(i, 4) {
int nx = x + dx[i];
int ny = y + dy[i];
if (0 <= nx && nx < X && 0 <= ny && ny < Y && !wall[nx][ny] &&
!vis[nx][ny]) {
vis[nx][ny] = true;
q.push({nx, ny});
}
}
}
// REP(i, X) {
// REP(j, Y) {
// cout << (wall[i][j] ? 1 : 0);
// }
// cout << endl;
// }
// REP(i, X) {
// printf("%20d : ", xs[i]);
// REP(j, Y) {
// cout << (vis[i][j] ? 1 : 0);
// }
// cout << endl;
// }
if (inf) {
cout << "INF" << endl;
} else {
cout << ans << endl;
}
return 0;
}
int main() {
#ifdef LOCAL
for (; !cin.eof(); cin >> ws)
#endif
main2();
return 0;
} | replace | 58 | 60 | 58 | 61 | 0 | |
p02680 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
#define REP(i, n, m) for (ll i = n; i < (ll)m; ++i)
#define IREP(i, n, m) for (ll i = n - 1; i >= m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) \
for (auto e : v) { \
cout << e << " "; \
}; \
cout << endl;
#define vvprint(vv) \
for (auto v : vv) { \
vprint(v) \
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(20);
ll N, M;
cin >> N >> M;
vll A(N), B(N), C(N);
vll D(M), E(M), F(M);
rep(i, N) cin >> A[i] >> B[i] >> C[i];
rep(i, M) cin >> D[i] >> E[i] >> F[i];
set<ll> xs = {0}, ys = {0};
rep(i, N) {
xs.insert(A[i]);
xs.insert(B[i]);
ys.insert(C[i]);
}
rep(i, M) {
ys.insert(E[i]);
ys.insert(F[i]);
xs.insert(D[i]);
}
unordered_map<ll, ll> xm, ym;
vll xv(xs.size()), yv(ys.size());
ll idx = 0;
for (ll x : xs) {
xm[x] = idx;
xv[idx++] = x;
}
idx = 0;
for (ll y : ys) {
ym[y] = idx;
yv[idx++] = y;
}
vvll m(ys.size() * 2, vll(xs.size() * 2, 0));
rep(i, N) REP(j, xm[A[i]] * 2, xm[B[i]] * 2 + 1) m[ym[C[i]] * 2][j] = 1;
rep(i, M) REP(j, ym[E[i]] * 2, ym[F[i]] * 2 + 1) m[j][xm[D[i]] * 2] = 1;
ll cx = xm[0] * 2, cy = ym[0] * 2, a = 0;
ll xmax = xs.size() * 2 - 2, ymax = ys.size() * 2 - 2;
vvll dirs = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
vll ws(xs.size()), hs(ys.size());
rep(i, xs.size() - 1) ws[i] = xv[i + 1] - xv[i];
rep(i, ys.size() - 1) hs[i] = yv[i + 1] - yv[i];
queue<pair<ll, ll>> q;
q.push({cx, cy});
m[cy][cx] = 1;
while (!q.empty()) {
auto p = q.front();
q.pop();
if (p.first == 0 || p.first == xmax || p.second == 0 || p.second == ymax) {
cout << "INF" << endl;
return 0;
}
if (p.first % 2 == 1 && p.second % 2 == 1)
a += ws[p.first / 2] * hs[p.second / 2];
for (auto d : dirs) {
ll nx = p.first + d[0], ny = p.second + d[1];
if (!m[ny][nx])
q.push({nx, ny}), m[ny][nx] = 1;
}
}
cout << a << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
#define REP(i, n, m) for (ll i = n; i < (ll)m; ++i)
#define IREP(i, n, m) for (ll i = n - 1; i >= m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) \
for (auto e : v) { \
cout << e << " "; \
}; \
cout << endl;
#define vvprint(vv) \
for (auto v : vv) { \
vprint(v) \
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(20);
ll N, M;
cin >> N >> M;
vll A(N), B(N), C(N);
vll D(M), E(M), F(M);
rep(i, N) cin >> A[i] >> B[i] >> C[i];
rep(i, M) cin >> D[i] >> E[i] >> F[i];
set<ll> xs = {0}, ys = {0};
rep(i, N) {
xs.insert(A[i]);
xs.insert(B[i]);
ys.insert(C[i]);
}
rep(i, M) {
ys.insert(E[i]);
ys.insert(F[i]);
xs.insert(D[i]);
}
unordered_map<ll, ll> xm, ym;
vll xv(xs.size()), yv(ys.size());
ll idx = 0;
for (ll x : xs) {
xm[x] = idx;
xv[idx++] = x;
}
idx = 0;
for (ll y : ys) {
ym[y] = idx;
yv[idx++] = y;
}
vector<vector<bool>> m(ys.size() * 2, vector<bool>(xs.size() * 2, 0));
rep(i, N) REP(j, xm[A[i]] * 2, xm[B[i]] * 2 + 1) m[ym[C[i]] * 2][j] = 1;
rep(i, M) REP(j, ym[E[i]] * 2, ym[F[i]] * 2 + 1) m[j][xm[D[i]] * 2] = 1;
ll cx = xm[0] * 2, cy = ym[0] * 2, a = 0;
ll xmax = xs.size() * 2 - 2, ymax = ys.size() * 2 - 2;
vvll dirs = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
vll ws(xs.size()), hs(ys.size());
rep(i, xs.size() - 1) ws[i] = xv[i + 1] - xv[i];
rep(i, ys.size() - 1) hs[i] = yv[i + 1] - yv[i];
queue<pair<ll, ll>> q;
q.push({cx, cy});
m[cy][cx] = 1;
while (!q.empty()) {
auto p = q.front();
q.pop();
if (p.first == 0 || p.first == xmax || p.second == 0 || p.second == ymax) {
cout << "INF" << endl;
return 0;
}
if (p.first % 2 == 1 && p.second % 2 == 1)
a += ws[p.first / 2] * hs[p.second / 2];
for (auto d : dirs) {
ll nx = p.first + d[0], ny = p.second + d[1];
if (!m[ny][nx])
q.push({nx, ny}), m[ny][nx] = 1;
}
}
cout << a << endl;
}
| replace | 59 | 60 | 59 | 60 | TLE | |
p02680 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
const int INF = 0x3f3f3f3f;
const int N = 2e3 + 10;
int n, m;
int A[N], B[N], C[N], D[N], E[N], F[N];
ll ans;
vector<int> xx, yy;
int id(vector<int> &vc, int x) {
return lower_bound(vc.begin(), vc.end(), x) - vc.begin();
}
int dx[]{0, 0, -1, 1};
int dy[]{-1, 1, 0, 0};
int die[N][N][4];
typedef pair<int, int> pii;
queue<pii> q;
int vis[N][N];
int main() {
scanf("%d%d", &n, &m);
xx.push_back(0);
yy.push_back(0);
xx.push_back(-INF);
xx.push_back(INF);
yy.push_back(-INF);
yy.push_back(INF);
for (int i = 1; i <= n; i++) {
scanf("%d%d%d", &A[i], &B[i], &C[i]);
xx.push_back(A[i]);
xx.push_back(B[i]);
yy.push_back(C[i]);
}
for (int i = 1; i <= m; i++) {
scanf("%d%d%d", &D[i], &E[i], &F[i]);
yy.push_back(E[i]);
yy.push_back(F[i]);
xx.push_back(D[i]);
}
sort(xx.begin(), xx.end());
xx.erase(unique(xx.begin(), xx.end()), xx.end());
sort(yy.begin(), yy.end());
yy.erase(unique(yy.begin(), yy.end()), yy.end());
for (int i = 1; i <= n; i++) {
A[i] = id(xx, A[i]);
B[i] = id(xx, B[i]);
C[i] = id(yy, C[i]);
for (int j = A[i]; j < B[i]; j++) {
die[j][C[i]][0] = 1;
die[j][C[i] - 1][1] = 1;
}
}
for (int i = 1; i <= m; i++) {
D[i] = id(xx, D[i]);
E[i] = id(yy, E[i]);
F[i] = id(yy, F[i]);
for (int j = E[i]; j < F[i]; j++) {
die[D[i]][j][2] = 1;
die[D[i] - 1][j][3] = 1;
}
}
q.push(pii(id(xx, 0), id(yy, 0)));
while (!q.empty()) {
int x = q.front().first, y = q.front().second;
q.pop();
for (int i = 0; i < 4; i++) {
if (die[x][y][i])
continue;
int nx = x + dx[i], ny = y + dy[i];
if (nx == 0 || nx == (int)xx.size() - 1 || ny == 0 ||
ny == (int)yy.size() - 1) {
puts("INF");
return 0;
}
if (vis[nx][ny])
continue;
vis[nx][ny] = 1;
ans += 1ll * (xx[nx + 1] - xx[nx]) * (yy[ny + 1] - yy[ny]);
q.push(pii(nx, ny));
}
}
printf("%lld\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
const int INF = 0x3f3f3f3f;
const int N = 3e3 + 10;
int n, m;
int A[N], B[N], C[N], D[N], E[N], F[N];
ll ans;
vector<int> xx, yy;
int id(vector<int> &vc, int x) {
return lower_bound(vc.begin(), vc.end(), x) - vc.begin();
}
int dx[]{0, 0, -1, 1};
int dy[]{-1, 1, 0, 0};
int die[N][N][4];
typedef pair<int, int> pii;
queue<pii> q;
int vis[N][N];
int main() {
scanf("%d%d", &n, &m);
xx.push_back(0);
yy.push_back(0);
xx.push_back(-INF);
xx.push_back(INF);
yy.push_back(-INF);
yy.push_back(INF);
for (int i = 1; i <= n; i++) {
scanf("%d%d%d", &A[i], &B[i], &C[i]);
xx.push_back(A[i]);
xx.push_back(B[i]);
yy.push_back(C[i]);
}
for (int i = 1; i <= m; i++) {
scanf("%d%d%d", &D[i], &E[i], &F[i]);
yy.push_back(E[i]);
yy.push_back(F[i]);
xx.push_back(D[i]);
}
sort(xx.begin(), xx.end());
xx.erase(unique(xx.begin(), xx.end()), xx.end());
sort(yy.begin(), yy.end());
yy.erase(unique(yy.begin(), yy.end()), yy.end());
for (int i = 1; i <= n; i++) {
A[i] = id(xx, A[i]);
B[i] = id(xx, B[i]);
C[i] = id(yy, C[i]);
for (int j = A[i]; j < B[i]; j++) {
die[j][C[i]][0] = 1;
die[j][C[i] - 1][1] = 1;
}
}
for (int i = 1; i <= m; i++) {
D[i] = id(xx, D[i]);
E[i] = id(yy, E[i]);
F[i] = id(yy, F[i]);
for (int j = E[i]; j < F[i]; j++) {
die[D[i]][j][2] = 1;
die[D[i] - 1][j][3] = 1;
}
}
q.push(pii(id(xx, 0), id(yy, 0)));
while (!q.empty()) {
int x = q.front().first, y = q.front().second;
q.pop();
for (int i = 0; i < 4; i++) {
if (die[x][y][i])
continue;
int nx = x + dx[i], ny = y + dy[i];
if (nx == 0 || nx == (int)xx.size() - 1 || ny == 0 ||
ny == (int)yy.size() - 1) {
puts("INF");
return 0;
}
if (vis[nx][ny])
continue;
vis[nx][ny] = 1;
ans += 1ll * (xx[nx + 1] - xx[nx]) * (yy[ny + 1] - yy[ny]);
q.push(pii(nx, ny));
}
}
printf("%lld\n", ans);
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02680 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) \
({ \
if (1) \
cerr << "TR: " << (#X) << " = " << (X) << endl; \
})
void compress(vl &i2x, map<ll, ll> &x2i) {
sort(all(i2x));
i2x.erase(unique(all(i2x)), end(i2x));
FOR(i, 0, sz(i2x)) x2i[i2x[i]] = i;
}
const ll N = 1010;
bool wallns[N][N], wallew[N][N], reach[N][N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll m, n;
cin >> m >> n;
vl i2x = {-oo, oo}, j2y = {-oo, oo};
vector<tuple<ll, ll, ll>> ns, ew;
while (m--) {
ll a, b, c;
cin >> a >> b >> c;
i2x.pb(a), i2x.pb(b), j2y.pb(c);
ns.pb(make_tuple(a, b, c));
}
while (n--) {
ll d, e, f;
cin >> d >> e >> f;
i2x.pb(d), j2y.pb(e), j2y.pb(f);
ew.pb(make_tuple(d, e, f));
}
map<ll, ll> x2i, y2j;
compress(i2x, x2i), compress(j2y, y2j);
for (auto tpl : ns) {
ll a, b, c;
tie(a, b, c) = tpl;
a = x2i[a], b = x2i[b], c = y2j[c];
FOR(i, a, b)
wallns[i][c - 1] = 1; //, cerr << "NS " << i << " " << c-1 << endl;
}
for (auto tpl : ew) {
ll d, e, f;
tie(d, e, f) = tpl;
d = x2i[d], e = y2j[e], f = y2j[f];
FOR(j, e, f)
wallew[d - 1][j] = 1; //, cerr << "EW " << d-1 << " " << j << endl;
}
queue<pll> q;
FOR(i, 0, sz(i2x) - 1) if (i2x[i] <= 0 && i2x[i + 1] >= 0) {
FOR(j, 0, sz(j2y) - 1) if (j2y[j] <= 0 && j2y[j + 1] >= 0) {
q.emplace(i, j), reach[i][j] = 1;
}
}
while (sz(q)) {
ll i, j;
tie(i, j) = q.front();
q.pop();
// cerr << i << " " << j << endl;
if (i > 0 && !wallew[i - 1][j] && !reach[i - 1][j]) {
q.emplace(i - 1, j), reach[i - 1][j] = 1;
}
if (j > 0 && !wallns[i][j - 1] && !reach[i][j - 1]) {
q.emplace(i, j - 1), reach[i][j - 1] = 1;
}
if (i + 2 < sz(i2x) && !wallew[i][j] && !reach[i + 1][j]) {
q.emplace(i + 1, j), reach[i + 1][j] = 1;
}
if (j + 2 < sz(j2y) && !wallns[i][j] && !reach[i][j + 1]) {
q.emplace(i, j + 1), reach[i][j + 1] = 1;
}
}
ll res = 0;
FOR(i, 0, sz(i2x) - 1) FOR(j, 0, sz(j2y) - 1) if (reach[i][j]) {
if (i == 0 || j == 0 || i == sz(i2x) - 2 || j == sz(j2y) - 2) {
cout << "INF" << endl;
return 0;
}
res += (i2x[i + 1] - i2x[i]) * (j2y[j + 1] - j2y[j]);
}
cout << res << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) \
({ \
if (1) \
cerr << "TR: " << (#X) << " = " << (X) << endl; \
})
void compress(vl &i2x, map<ll, ll> &x2i) {
sort(all(i2x));
i2x.erase(unique(all(i2x)), end(i2x));
FOR(i, 0, sz(i2x)) x2i[i2x[i]] = i;
}
const ll N = 3010;
bool wallns[N][N], wallew[N][N], reach[N][N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll m, n;
cin >> m >> n;
vl i2x = {-oo, oo}, j2y = {-oo, oo};
vector<tuple<ll, ll, ll>> ns, ew;
while (m--) {
ll a, b, c;
cin >> a >> b >> c;
i2x.pb(a), i2x.pb(b), j2y.pb(c);
ns.pb(make_tuple(a, b, c));
}
while (n--) {
ll d, e, f;
cin >> d >> e >> f;
i2x.pb(d), j2y.pb(e), j2y.pb(f);
ew.pb(make_tuple(d, e, f));
}
map<ll, ll> x2i, y2j;
compress(i2x, x2i), compress(j2y, y2j);
for (auto tpl : ns) {
ll a, b, c;
tie(a, b, c) = tpl;
a = x2i[a], b = x2i[b], c = y2j[c];
FOR(i, a, b)
wallns[i][c - 1] = 1; //, cerr << "NS " << i << " " << c-1 << endl;
}
for (auto tpl : ew) {
ll d, e, f;
tie(d, e, f) = tpl;
d = x2i[d], e = y2j[e], f = y2j[f];
FOR(j, e, f)
wallew[d - 1][j] = 1; //, cerr << "EW " << d-1 << " " << j << endl;
}
queue<pll> q;
FOR(i, 0, sz(i2x) - 1) if (i2x[i] <= 0 && i2x[i + 1] >= 0) {
FOR(j, 0, sz(j2y) - 1) if (j2y[j] <= 0 && j2y[j + 1] >= 0) {
q.emplace(i, j), reach[i][j] = 1;
}
}
while (sz(q)) {
ll i, j;
tie(i, j) = q.front();
q.pop();
// cerr << i << " " << j << endl;
if (i > 0 && !wallew[i - 1][j] && !reach[i - 1][j]) {
q.emplace(i - 1, j), reach[i - 1][j] = 1;
}
if (j > 0 && !wallns[i][j - 1] && !reach[i][j - 1]) {
q.emplace(i, j - 1), reach[i][j - 1] = 1;
}
if (i + 2 < sz(i2x) && !wallew[i][j] && !reach[i + 1][j]) {
q.emplace(i + 1, j), reach[i + 1][j] = 1;
}
if (j + 2 < sz(j2y) && !wallns[i][j] && !reach[i][j + 1]) {
q.emplace(i, j + 1), reach[i][j + 1] = 1;
}
}
ll res = 0;
FOR(i, 0, sz(i2x) - 1) FOR(j, 0, sz(j2y) - 1) if (reach[i][j]) {
if (i == 0 || j == 0 || i == sz(i2x) - 2 || j == sz(j2y) - 2) {
cout << "INF" << endl;
return 0;
}
res += (i2x[i + 1] - i2x[i]) * (j2y[j + 1] - j2y[j]);
}
cout << res << endl;
}
| replace | 31 | 32 | 31 | 32 | 0 | |
p02680 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
// #define MOD 998244353
#define INF 1145141919810893364
// #define INF 810114514
#define PI 3.141592653589
typedef long long ll;
typedef pair<ll, ll> PP;
#define int ll
#define setdouble setprecision
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define OREP(i, n) for (int i = 1; i <= (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define GOODBYE \
do { \
cout << "0" << endl; \
return 0; \
} while (false)
#define MM << " " <<
#define Endl endl
#define debug false
#define debug2 false
class compress {
private:
std::vector<int> E;
std::map<int, int> G;
public:
void init(std::vector<long long> A) {
E.clear();
sort(A.begin(), A.end());
for (int i = 0; i < A.size(); i++) {
if (i == 0 || A[i] != A[i - 1]) {
E.push_back(A[i]);
G[A[i]] = (int)E.size();
}
}
}
int size() { return (int)E.size(); }
int value(int x) {
if (0 <= x && x < (int)E.size()) {
return E[x];
} else {
return 0;
}
}
int index(int X) {
return (upper_bound(E.begin(), E.end(), X)) - E.begin() - 1;
}
};
signed main(void) {
int N, M;
vector<int> A, B, C, D, E, F;
vector<int> x, y;
cin >> N >> M;
REP(i, N) {
int a;
cin >> a;
A.push_back(a);
x.push_back(a);
cin >> a;
B.push_back(a);
x.push_back(a);
cin >> a;
C.push_back(a);
y.push_back(a);
}
REP(i, M) {
int a;
cin >> a;
D.push_back(a);
x.push_back(a);
cin >> a;
E.push_back(a);
y.push_back(a);
cin >> a;
F.push_back(a);
y.push_back(a);
}
x.push_back(-INF);
x.push_back(INF);
y.push_back(-INF);
y.push_back(INF);
compress X, Y;
X.init(x);
Y.init(y);
const int MEM = 320;
bool wallx[MEM][MEM] = {}, wally[MEM][MEM] = {};
REP(i, N) {
int a = X.index(A[i]);
int b = X.index(B[i]);
int c = Y.index(C[i]);
// cout << "x! " << a << " " << b << " " << c << endl;
for (int i = a; i < b; i++) {
wally[c][i] = true;
}
}
REP(i, M) {
int d = X.index(D[i]);
int e = Y.index(E[i]);
int f = Y.index(F[i]);
for (int i = e; i < f; i++) {
wallx[i][d] = true;
}
}
int Ans = 0;
queue<pair<int, int>> que;
bool Map[MEM][MEM];
int xs = X.index(0), ys = Y.index(0);
que.push({xs, ys});
Map[xs][ys] = true;
bool infinity = false;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
while (!que.empty()) {
int s = que.front().first;
int t = que.front().second;
que.pop();
// cout << X.value(s) << " " << Y.value(t) << endl;
int Xe = (X.value(s + 1) - X.value(s));
int Ye = (Y.value(t + 1) - Y.value(t));
if (X.value(s + 1) == INF || X.value(s) == -INF) {
infinity = true;
}
if (Y.value(t + 1) == INF || Y.value(t) == -INF) {
infinity = true;
}
Ans += Xe * Ye;
REP(k, 4) {
if (s + dx[k] < 0 || X.size() <= s + dx[k]) {
continue;
}
if (t + dy[k] < 0 || Y.size() <= t + dy[k]) {
continue;
}
if (k == 0 && wallx[t][s + 1]) {
continue;
}
if (k == 1 && wally[t + 1][s]) {
continue;
}
if (k == 2 && wallx[t][s]) {
continue;
}
if (k == 3 && wally[t][s]) {
continue;
}
if (!Map[s + dx[k]][t + dy[k]]) {
Map[s + dx[k]][t + dy[k]] = true;
que.push({s + dx[k], t + dy[k]});
}
}
}
if (infinity) {
cout << "INF" << endl;
} else {
cout << Ans << endl;
}
#if debug
cout << " ";
REP(j, 10) {
if (X.value(j) >= 0)
cout << "+";
if (X.value(j) == -INF) {
cout << "-I ";
} else {
cout << X.value(j) << " ";
}
}
cout << endl;
REP(i, 10) {
if (Y.value(i) >= 0)
cout << "+";
if (Y.value(i) == -INF) {
cout << "-I ";
} else {
cout << Y.value(i) << " ";
}
REP(j, 10) { cout << wallx[i][j] << " "; }
cout << endl;
}
cout << endl;
#endif
#if debug
cout << " ";
REP(j, 10) {
if (X.value(j) >= 0)
cout << "+";
if (X.value(j) == -INF) {
cout << "-I ";
} else {
cout << X.value(j) << " ";
}
}
cout << endl;
REP(i, 10) {
if (Y.value(i) >= 0)
cout << "+";
if (Y.value(i) == -INF) {
cout << "-I ";
} else {
cout << Y.value(i) << " ";
}
REP(j, 10) { cout << wally[i][j] << " "; }
cout << endl;
}
cout << endl;
#endif
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
// #define MOD 998244353
#define INF 1145141919810893364
// #define INF 810114514
#define PI 3.141592653589
typedef long long ll;
typedef pair<ll, ll> PP;
#define int ll
#define setdouble setprecision
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define OREP(i, n) for (int i = 1; i <= (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define GOODBYE \
do { \
cout << "0" << endl; \
return 0; \
} while (false)
#define MM << " " <<
#define Endl endl
#define debug false
#define debug2 false
class compress {
private:
std::vector<int> E;
std::map<int, int> G;
public:
void init(std::vector<long long> A) {
E.clear();
sort(A.begin(), A.end());
for (int i = 0; i < A.size(); i++) {
if (i == 0 || A[i] != A[i - 1]) {
E.push_back(A[i]);
G[A[i]] = (int)E.size();
}
}
}
int size() { return (int)E.size(); }
int value(int x) {
if (0 <= x && x < (int)E.size()) {
return E[x];
} else {
return 0;
}
}
int index(int X) {
return (upper_bound(E.begin(), E.end(), X)) - E.begin() - 1;
}
};
signed main(void) {
int N, M;
vector<int> A, B, C, D, E, F;
vector<int> x, y;
cin >> N >> M;
REP(i, N) {
int a;
cin >> a;
A.push_back(a);
x.push_back(a);
cin >> a;
B.push_back(a);
x.push_back(a);
cin >> a;
C.push_back(a);
y.push_back(a);
}
REP(i, M) {
int a;
cin >> a;
D.push_back(a);
x.push_back(a);
cin >> a;
E.push_back(a);
y.push_back(a);
cin >> a;
F.push_back(a);
y.push_back(a);
}
x.push_back(-INF);
x.push_back(INF);
y.push_back(-INF);
y.push_back(INF);
compress X, Y;
X.init(x);
Y.init(y);
const int MEM = 3020;
bool wallx[MEM][MEM] = {}, wally[MEM][MEM] = {};
REP(i, N) {
int a = X.index(A[i]);
int b = X.index(B[i]);
int c = Y.index(C[i]);
// cout << "x! " << a << " " << b << " " << c << endl;
for (int i = a; i < b; i++) {
wally[c][i] = true;
}
}
REP(i, M) {
int d = X.index(D[i]);
int e = Y.index(E[i]);
int f = Y.index(F[i]);
for (int i = e; i < f; i++) {
wallx[i][d] = true;
}
}
int Ans = 0;
queue<pair<int, int>> que;
bool Map[MEM][MEM];
int xs = X.index(0), ys = Y.index(0);
que.push({xs, ys});
Map[xs][ys] = true;
bool infinity = false;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
while (!que.empty()) {
int s = que.front().first;
int t = que.front().second;
que.pop();
// cout << X.value(s) << " " << Y.value(t) << endl;
int Xe = (X.value(s + 1) - X.value(s));
int Ye = (Y.value(t + 1) - Y.value(t));
if (X.value(s + 1) == INF || X.value(s) == -INF) {
infinity = true;
}
if (Y.value(t + 1) == INF || Y.value(t) == -INF) {
infinity = true;
}
Ans += Xe * Ye;
REP(k, 4) {
if (s + dx[k] < 0 || X.size() <= s + dx[k]) {
continue;
}
if (t + dy[k] < 0 || Y.size() <= t + dy[k]) {
continue;
}
if (k == 0 && wallx[t][s + 1]) {
continue;
}
if (k == 1 && wally[t + 1][s]) {
continue;
}
if (k == 2 && wallx[t][s]) {
continue;
}
if (k == 3 && wally[t][s]) {
continue;
}
if (!Map[s + dx[k]][t + dy[k]]) {
Map[s + dx[k]][t + dy[k]] = true;
que.push({s + dx[k], t + dy[k]});
}
}
}
if (infinity) {
cout << "INF" << endl;
} else {
cout << Ans << endl;
}
#if debug
cout << " ";
REP(j, 10) {
if (X.value(j) >= 0)
cout << "+";
if (X.value(j) == -INF) {
cout << "-I ";
} else {
cout << X.value(j) << " ";
}
}
cout << endl;
REP(i, 10) {
if (Y.value(i) >= 0)
cout << "+";
if (Y.value(i) == -INF) {
cout << "-I ";
} else {
cout << Y.value(i) << " ";
}
REP(j, 10) { cout << wallx[i][j] << " "; }
cout << endl;
}
cout << endl;
#endif
#if debug
cout << " ";
REP(j, 10) {
if (X.value(j) >= 0)
cout << "+";
if (X.value(j) == -INF) {
cout << "-I ";
} else {
cout << X.value(j) << " ";
}
}
cout << endl;
REP(i, 10) {
if (Y.value(i) >= 0)
cout << "+";
if (Y.value(i) == -INF) {
cout << "-I ";
} else {
cout << Y.value(i) << " ";
}
REP(j, 10) { cout << wally[i][j] << " "; }
cout << endl;
}
cout << endl;
#endif
return 0;
}
| replace | 95 | 96 | 95 | 96 | 0 | |
p02680 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <stdio.h>
#include <vector>
using ll = long long int;
using P = std::pair<int, int>;
const int INF = (1 << 30);
const ll INFLL = (1ll << 60);
const ll MOD = (ll)(1e9 + 7);
#define l_ength size
void mul_mod(ll &a, ll b) {
a *= b;
a %= MOD;
}
void add_mod(ll &a, ll b) {
a = (a < MOD) ? a : (a - MOD);
b = (b < MOD) ? b : (b - MOD);
a += b;
a = (a < MOD) ? a : (a - MOD);
}
bool visited[4444][4444], obs[4444][4444];
int obsn[4444][4444];
std::set<ll> x, y;
std::vector<ll> u, v;
ll a[1111], b[1111], c[1111], d[1111], e[1111], f[1111];
std::queue<P> que;
int main(void) {
int n, m, i, j, k, s = -1, t = -1, p, q, dx[4] = {-1, 0, 0, 1},
dy[4] = {0, -1, 1, 0};
ll ans = 0ll;
u.push_back(INF);
u.push_back(-INF);
u.push_back(INF);
u.push_back(-INF);
v.push_back(INF);
v.push_back(-INF);
v.push_back(INF);
v.push_back(-INF);
std::cin >> n >> m;
for (i = 0; i < n; ++i) {
std::cin >> a[i] >> b[i] >> c[i];
if (!x.count(a[i])) {
x.insert(a[i]);
u.push_back(a[i]);
u.push_back(a[i]);
}
if (!x.count(b[i])) {
x.insert(b[i]);
u.push_back(b[i]);
u.push_back(b[i]);
}
if (!y.count(c[i])) {
y.insert(c[i]);
v.push_back(c[i]);
v.push_back(c[i]);
}
}
for (j = 0; j < m; ++j) {
std::cin >> d[j] >> e[j] >> f[j];
if (!x.count(d[j])) {
x.insert(d[j]);
u.push_back(d[j]);
u.push_back(d[j]);
}
if (!y.count(e[j])) {
y.insert(e[j]);
v.push_back(e[j]);
v.push_back(e[j]);
}
if (!y.count(f[j])) {
y.insert(f[j]);
v.push_back(f[j]);
v.push_back(f[j]);
}
}
std::sort(u.begin(), u.end());
std::sort(v.begin(), v.end());
s += u.l_ength();
t += v.l_ength();
for (k = 0; k < n; ++k) {
p = (int)(std::lower_bound(u.begin(), u.end(), b[k]) - u.begin());
q = (int)(std::lower_bound(v.begin(), v.end(), c[k]) - v.begin());
for (i = (int)(std::lower_bound(u.begin(), u.end(), a[k]) - u.begin());
i <= p; ++i) {
obs[i][q] = true;
obsn[i][q] = k;
}
}
for (k = 0; k < m; ++k) {
p = (int)(std::lower_bound(u.begin(), u.end(), d[k]) - u.begin());
q = (int)(std::lower_bound(v.begin(), v.end(), f[k]) - v.begin());
for (j = (int)(std::lower_bound(v.begin(), v.end(), e[k]) - v.begin());
j <= q; ++j) {
obs[p][j] = true;
obsn[p][j] = k;
}
}
for (i = 0; i < s; ++i) {
if (!(u[i] <= 0 && 0 <= u[i + 1])) {
continue;
}
for (j = 0; j < t; ++j) {
if (v[j] <= 0 && 0 <= v[j + 1]) {
que.push(P(i, j));
while (!que.empty()) {
p = que.front().first;
q = que.front().second;
que.pop();
if (visited[p][q]) {
continue;
}
visited[p][q] = true;
for (k = 0; k < 4; ++k) {
if (!(0 <= p + dx[k] && p + dx[k] < s)) {
continue;
}
if (!(0 <= q + dy[k] && q + dy[k] < t)) {
continue;
}
if (obs[p + dx[k]][q + dy[k]]) {
continue;
}
if (visited[p + dx[k]][q + dy[k]]) {
continue;
}
que.push(P(p + dx[k], q + dy[k]));
}
}
break;
}
}
}
/*
for(i=0; i<s; ++i){
for(j=0; j<t; ++j){
if(obs[i][j]){
std::cout << obsn[i][j];
}else if(visited[i][j]){
std::cout << "#";
}else{
std::cout << " ";
}
}
std::cout << std::endl;
}
*/
for (i = 0; i < t; ++i) {
if (visited[0][i] || visited[s - 1][i]) {
std::cout << "INF" << std::endl;
return 0;
}
}
for (i = 0; i < s; ++i) {
if (visited[i][0] || visited[i][t - 1]) {
std::cout << "INF" << std::endl;
return 0;
}
}
for (i = 0; i < s; ++i) {
for (j = 0; j < t; ++j) {
if (visited[i][j]) {
ans += (u[i + 1] - u[i]) * (v[j + 1] - v[j]);
}
}
}
std::cout << ans << std::endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <stdio.h>
#include <vector>
using ll = long long int;
using P = std::pair<int, int>;
const int INF = (1 << 30);
const ll INFLL = (1ll << 60);
const ll MOD = (ll)(1e9 + 7);
#define l_ength size
void mul_mod(ll &a, ll b) {
a *= b;
a %= MOD;
}
void add_mod(ll &a, ll b) {
a = (a < MOD) ? a : (a - MOD);
b = (b < MOD) ? b : (b - MOD);
a += b;
a = (a < MOD) ? a : (a - MOD);
}
bool visited[8888][8888], obs[8888][8888];
int obsn[8888][8888];
std::set<ll> x, y;
std::vector<ll> u, v;
ll a[1111], b[1111], c[1111], d[1111], e[1111], f[1111];
std::queue<P> que;
int main(void) {
int n, m, i, j, k, s = -1, t = -1, p, q, dx[4] = {-1, 0, 0, 1},
dy[4] = {0, -1, 1, 0};
ll ans = 0ll;
u.push_back(INF);
u.push_back(-INF);
u.push_back(INF);
u.push_back(-INF);
v.push_back(INF);
v.push_back(-INF);
v.push_back(INF);
v.push_back(-INF);
std::cin >> n >> m;
for (i = 0; i < n; ++i) {
std::cin >> a[i] >> b[i] >> c[i];
if (!x.count(a[i])) {
x.insert(a[i]);
u.push_back(a[i]);
u.push_back(a[i]);
}
if (!x.count(b[i])) {
x.insert(b[i]);
u.push_back(b[i]);
u.push_back(b[i]);
}
if (!y.count(c[i])) {
y.insert(c[i]);
v.push_back(c[i]);
v.push_back(c[i]);
}
}
for (j = 0; j < m; ++j) {
std::cin >> d[j] >> e[j] >> f[j];
if (!x.count(d[j])) {
x.insert(d[j]);
u.push_back(d[j]);
u.push_back(d[j]);
}
if (!y.count(e[j])) {
y.insert(e[j]);
v.push_back(e[j]);
v.push_back(e[j]);
}
if (!y.count(f[j])) {
y.insert(f[j]);
v.push_back(f[j]);
v.push_back(f[j]);
}
}
std::sort(u.begin(), u.end());
std::sort(v.begin(), v.end());
s += u.l_ength();
t += v.l_ength();
for (k = 0; k < n; ++k) {
p = (int)(std::lower_bound(u.begin(), u.end(), b[k]) - u.begin());
q = (int)(std::lower_bound(v.begin(), v.end(), c[k]) - v.begin());
for (i = (int)(std::lower_bound(u.begin(), u.end(), a[k]) - u.begin());
i <= p; ++i) {
obs[i][q] = true;
obsn[i][q] = k;
}
}
for (k = 0; k < m; ++k) {
p = (int)(std::lower_bound(u.begin(), u.end(), d[k]) - u.begin());
q = (int)(std::lower_bound(v.begin(), v.end(), f[k]) - v.begin());
for (j = (int)(std::lower_bound(v.begin(), v.end(), e[k]) - v.begin());
j <= q; ++j) {
obs[p][j] = true;
obsn[p][j] = k;
}
}
for (i = 0; i < s; ++i) {
if (!(u[i] <= 0 && 0 <= u[i + 1])) {
continue;
}
for (j = 0; j < t; ++j) {
if (v[j] <= 0 && 0 <= v[j + 1]) {
que.push(P(i, j));
while (!que.empty()) {
p = que.front().first;
q = que.front().second;
que.pop();
if (visited[p][q]) {
continue;
}
visited[p][q] = true;
for (k = 0; k < 4; ++k) {
if (!(0 <= p + dx[k] && p + dx[k] < s)) {
continue;
}
if (!(0 <= q + dy[k] && q + dy[k] < t)) {
continue;
}
if (obs[p + dx[k]][q + dy[k]]) {
continue;
}
if (visited[p + dx[k]][q + dy[k]]) {
continue;
}
que.push(P(p + dx[k], q + dy[k]));
}
}
break;
}
}
}
/*
for(i=0; i<s; ++i){
for(j=0; j<t; ++j){
if(obs[i][j]){
std::cout << obsn[i][j];
}else if(visited[i][j]){
std::cout << "#";
}else{
std::cout << " ";
}
}
std::cout << std::endl;
}
*/
for (i = 0; i < t; ++i) {
if (visited[0][i] || visited[s - 1][i]) {
std::cout << "INF" << std::endl;
return 0;
}
}
for (i = 0; i < s; ++i) {
if (visited[i][0] || visited[i][t - 1]) {
std::cout << "INF" << std::endl;
return 0;
}
}
for (i = 0; i < s; ++i) {
for (j = 0; j < t; ++j) {
if (visited[i][j]) {
ans += (u[i + 1] - u[i]) * (v[j + 1] - v[j]);
}
}
}
std::cout << ans << std::endl;
return 0;
}
| replace | 27 | 29 | 27 | 29 | -11 | |
p02680 | C++ | Runtime Error | #include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
map<int, int> mpx, mpy;
int invx[14000], invy[14000], bias = 7000;
int a[1111], b[1111], c[1111], d[1111], e[1111], f[1111];
bool vis[14000][14000], l[14000][14000];
ll ans = 0;
int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
bool is_inf;
int mnx, mxx, mxy, mny;
void dfs(int x, int y) {
if (is_inf)
return;
if (x > mxx || x < mnx || y > mxy || y < mny) {
is_inf = 1;
return;
}
if (vis[x + bias][y + bias]) {
return;
}
vis[x + bias][y + bias] = 1;
ll tmpx, tmpy;
if (x % 2) {
tmpx = 0;
} else {
tmpx = invx[x + 1 + bias] - invx[x - 1 + bias];
}
if (y % 2) {
tmpy = 0;
} else {
tmpy = invy[y + 1 + bias] - invy[y - 1 + bias];
}
ans += tmpx * tmpy;
if (l[x + bias][y + bias]) {
return;
}
for (int i = 0; i < 4; ++i) {
int xx = x + dx[i];
int yy = y + dy[i];
dfs(xx, yy);
}
}
set<int> xx[2], yy[2];
int main() {
int n, m;
while (cin >> n >> m) {
for (int i = 0; i < n; ++i) {
scanf("%d%d%d", a + i, b + i, c + i);
xx[a[i] > 0].insert(a[i]);
xx[b[i] > 0].insert(b[i]);
yy[c[i] > 0].insert(c[i]);
}
for (int i = 0; i < m; ++i) {
scanf("%d%d%d", d + i, e + i, f + i);
xx[d[i] > 0].insert(d[i]);
yy[e[i] > 0].insert(e[i]);
yy[f[i] > 0].insert(f[i]);
}
int cnt = -1;
for (set<int>::reverse_iterator it = xx[0].rbegin(); it != xx[0].rend();
++it) {
mpx[*it] = cnt;
invx[cnt + bias] = *it;
cnt -= 2;
}
mnx = cnt;
cnt = 1;
for (auto it : xx[1]) {
mpx[it] = cnt;
invx[cnt + bias] = it;
cnt += 2;
}
mxx = cnt;
cnt = -1;
for (set<int>::reverse_iterator it = yy[0].rbegin(); it != yy[0].rend();
++it) {
mpy[*it] = cnt;
// cout<<*it<<" "<<cnt<<endl;
invy[cnt + bias] = *it;
cnt -= 2;
}
mny = cnt;
cnt = 1;
for (auto it : yy[1]) {
mpy[it] = cnt;
// cout<<it<< " "<<cnt<<endl;
invy[cnt + bias] = it;
cnt += 2;
}
mxy = cnt;
for (int i = 0; i < n; ++i) {
int tmp = mpy[c[i]];
for (int j = mpx[a[i]]; j <= mpx[b[i]]; ++j) {
// l[j][tmp]=1;
l[j + bias][tmp + bias] = 1;
// cout<<j<<" "<<tmp<<endl;
}
}
for (int i = 0; i < m; ++i) {
int tmp = mpx[d[i]];
for (int j = mpy[e[i]]; j <= mpy[f[i]]; ++j) {
// l[tmp][j]=1;
l[tmp + bias][j + bias] = 1;
// cout<<tmp<<" "<<j<<endl;
}
}
// for(int i=-10; i<=10; ++i){
// for(int j=-10; j<=10; ++j){
// if(i==0 && j==0){
// cout<<'*';
// continue;
// }
// if(l.count(mk(i, j))){
// cout<<'#';
// }
// else{
// cout<<".";
// }
// }
// cout<<endl;
// }
ans = 0;
is_inf = 0;
dfs(0, 0);
if (is_inf) {
printf("INF\n");
} else
printf("%lld\n", ans);
}
return 0;
}
| #include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
map<int, int> mpx, mpy;
int invx[14000], invy[14000], bias = 7000;
int a[1111], b[1111], c[1111], d[1111], e[1111], f[1111];
bool vis[14000][14000], l[14000][14000];
ll ans = 0;
int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
bool is_inf;
int mnx, mxx, mxy, mny;
void dfs(int x, int y) {
stack<pair<int, int>> st;
st.push(mk(x, y));
while (!st.empty()) {
x = st.top().fs;
y = st.top().sc;
st.pop();
if (x > mxx || x < mnx || y > mxy || y < mny) {
is_inf = 1;
return;
}
if (vis[x + bias][y + bias]) {
continue;
}
vis[x + bias][y + bias] = 1;
ll tmpx, tmpy;
if (x % 2) {
tmpx = 0;
} else {
tmpx = invx[x + 1 + bias] - invx[x - 1 + bias];
}
if (y % 2) {
tmpy = 0;
} else {
tmpy = invy[y + 1 + bias] - invy[y - 1 + bias];
}
ans += tmpx * tmpy;
if (l[x + bias][y + bias]) {
continue;
}
for (int i = 0; i < 4; ++i) {
int xx = x + dx[i];
int yy = y + dy[i];
st.push(mk(xx, yy));
}
}
}
set<int> xx[2], yy[2];
int main() {
int n, m;
while (cin >> n >> m) {
for (int i = 0; i < n; ++i) {
scanf("%d%d%d", a + i, b + i, c + i);
xx[a[i] > 0].insert(a[i]);
xx[b[i] > 0].insert(b[i]);
yy[c[i] > 0].insert(c[i]);
}
for (int i = 0; i < m; ++i) {
scanf("%d%d%d", d + i, e + i, f + i);
xx[d[i] > 0].insert(d[i]);
yy[e[i] > 0].insert(e[i]);
yy[f[i] > 0].insert(f[i]);
}
int cnt = -1;
for (set<int>::reverse_iterator it = xx[0].rbegin(); it != xx[0].rend();
++it) {
mpx[*it] = cnt;
invx[cnt + bias] = *it;
cnt -= 2;
}
mnx = cnt;
cnt = 1;
for (auto it : xx[1]) {
mpx[it] = cnt;
invx[cnt + bias] = it;
cnt += 2;
}
mxx = cnt;
cnt = -1;
for (set<int>::reverse_iterator it = yy[0].rbegin(); it != yy[0].rend();
++it) {
mpy[*it] = cnt;
// cout<<*it<<" "<<cnt<<endl;
invy[cnt + bias] = *it;
cnt -= 2;
}
mny = cnt;
cnt = 1;
for (auto it : yy[1]) {
mpy[it] = cnt;
// cout<<it<< " "<<cnt<<endl;
invy[cnt + bias] = it;
cnt += 2;
}
mxy = cnt;
for (int i = 0; i < n; ++i) {
int tmp = mpy[c[i]];
for (int j = mpx[a[i]]; j <= mpx[b[i]]; ++j) {
// l[j][tmp]=1;
l[j + bias][tmp + bias] = 1;
// cout<<j<<" "<<tmp<<endl;
}
}
for (int i = 0; i < m; ++i) {
int tmp = mpx[d[i]];
for (int j = mpy[e[i]]; j <= mpy[f[i]]; ++j) {
// l[tmp][j]=1;
l[tmp + bias][j + bias] = 1;
// cout<<tmp<<" "<<j<<endl;
}
}
// for(int i=-10; i<=10; ++i){
// for(int j=-10; j<=10; ++j){
// if(i==0 && j==0){
// cout<<'*';
// continue;
// }
// if(l.count(mk(i, j))){
// cout<<'#';
// }
// else{
// cout<<".";
// }
// }
// cout<<endl;
// }
ans = 0;
is_inf = 0;
dfs(0, 0);
if (is_inf) {
printf("INF\n");
} else
printf("%lld\n", ans);
}
return 0;
}
| replace | 16 | 45 | 16 | 50 | -11 | |
p02680 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// one-based numbering
struct UnionFind {
vector<int> data;
// i: (data[i] < 0) -> group size, (data[i] > 0) -> parent;
UnionFind(int n) { data.resize(n + 1, -1); }
int find(int x) {
if (data[x] < 0)
return x;
else
return data[x] = find(data[x]);
}
int size(int x) { return -data[find(x)]; }
bool unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)
return false;
if (data[x] > data[y])
swap(x, y);
data[x] += data[y];
data[y] = x;
return true;
}
bool same(int x, int y) {
x = find(x);
y = find(y);
return x == y;
}
};
bool V[9100000][2];
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vector<long long> A(N), B(N), C(N), D(M), E(M), F(M);
vector<long long> X, Y;
for (int i = 0; i < N; i++) {
cin >> A[i] >> B[i] >> C[i];
X.emplace_back(A[i]);
X.emplace_back(B[i]);
Y.emplace_back(C[i]);
}
for (int i = 0; i < M; i++) {
cin >> D[i] >> E[i] >> F[i];
X.emplace_back(D[i]);
Y.emplace_back(E[i]);
Y.emplace_back(F[i]);
}
sort(X.begin(), X.end());
X.erase(unique(X.begin(), X.end()), X.end());
sort(Y.begin(), Y.end());
Y.erase(unique(Y.begin(), Y.end()), Y.end());
int Xs = X.size(), Ys = Y.size();
auto encode = [&](int i, int j) { return i * (Ys + 1) + j + 1; };
for (int i = 0; i < N; i++) {
int a = A[i], b = B[i], c = C[i];
int xl = lower_bound(X.begin(), X.end(), a) - X.begin();
int xr = lower_bound(X.begin(), X.end(), b) - X.begin();
int y = lower_bound(Y.begin(), Y.end(), c) - Y.begin();
for (int x = xl + 1; x <= xr; x++) {
V[encode(x, y)][0] = true;
}
}
for (int i = 0; i < M; i++) {
int d = D[i], e = E[i], f = F[i];
int x = lower_bound(X.begin(), X.end(), d) - X.begin();
int yl = lower_bound(Y.begin(), Y.end(), e) - Y.begin();
int yr = lower_bound(Y.begin(), Y.end(), f) - Y.begin();
for (int y = yl + 1; y <= yr; y++) {
V[encode(x, y)][1] = true;
}
}
UnionFind uf((Xs + 1) * (Ys + 1));
for (int i = 0; i <= Xs; i++) {
for (int j = 0; j <= Ys; j++) {
int cur = encode(i, j);
int s = encode(i + 1, j);
int t = encode(i, j + 1);
if (!V[cur][0])
uf.unite(cur, t);
if (!V[cur][1])
uf.unite(cur, s);
}
}
int xz = lower_bound(X.begin(), X.end(), 0LL) - X.begin();
int yz = lower_bound(Y.begin(), Y.end(), 0LL) - Y.begin();
int Z = encode(xz, yz);
long long ans = 0;
for (int i = 0; i <= Xs; i++) {
for (int j = 0; j <= Ys; j++) {
int cur = encode(i, j);
if (!uf.same(cur, Z))
continue;
if (i == 0 || j == 0 || i == Xs || j == Ys) {
cout << "INF\n";
return 0;
}
ans += (X[i] - X[i - 1]) * (Y[j] - Y[j - 1]);
}
}
cout << ans << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
// one-based numbering
struct UnionFind {
vector<int> data;
// i: (data[i] < 0) -> group size, (data[i] > 0) -> parent;
UnionFind(int n) { data.resize(n + 1, -1); }
int find(int x) {
if (data[x] < 0)
return x;
else
return data[x] = find(data[x]);
}
int size(int x) { return -data[find(x)]; }
bool unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)
return false;
if (data[x] > data[y])
swap(x, y);
data[x] += data[y];
data[y] = x;
return true;
}
bool same(int x, int y) {
x = find(x);
y = find(y);
return x == y;
}
};
bool V[9100000][2];
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vector<long long> A(N), B(N), C(N), D(M), E(M), F(M);
vector<long long> X, Y;
for (int i = 0; i < N; i++) {
cin >> A[i] >> B[i] >> C[i];
X.emplace_back(A[i]);
X.emplace_back(B[i]);
Y.emplace_back(C[i]);
}
for (int i = 0; i < M; i++) {
cin >> D[i] >> E[i] >> F[i];
X.emplace_back(D[i]);
Y.emplace_back(E[i]);
Y.emplace_back(F[i]);
}
sort(X.begin(), X.end());
X.erase(unique(X.begin(), X.end()), X.end());
sort(Y.begin(), Y.end());
Y.erase(unique(Y.begin(), Y.end()), Y.end());
int Xs = X.size(), Ys = Y.size();
auto encode = [&](int i, int j) { return i * (Ys + 1) + j + 1; };
for (int i = 0; i < N; i++) {
int a = A[i], b = B[i], c = C[i];
int xl = lower_bound(X.begin(), X.end(), a) - X.begin();
int xr = lower_bound(X.begin(), X.end(), b) - X.begin();
int y = lower_bound(Y.begin(), Y.end(), c) - Y.begin();
for (int x = xl + 1; x <= xr; x++) {
V[encode(x, y)][0] = true;
}
}
for (int i = 0; i < M; i++) {
int d = D[i], e = E[i], f = F[i];
int x = lower_bound(X.begin(), X.end(), d) - X.begin();
int yl = lower_bound(Y.begin(), Y.end(), e) - Y.begin();
int yr = lower_bound(Y.begin(), Y.end(), f) - Y.begin();
for (int y = yl + 1; y <= yr; y++) {
V[encode(x, y)][1] = true;
}
}
UnionFind uf((Xs + 1) * (Ys + 1));
for (int i = 0; i < Xs; i++) {
for (int j = 0; j < Ys; j++) {
int cur = encode(i, j);
int s = encode(i + 1, j);
int t = encode(i, j + 1);
if (!V[cur][0])
uf.unite(cur, t);
if (!V[cur][1])
uf.unite(cur, s);
}
}
int xz = lower_bound(X.begin(), X.end(), 0LL) - X.begin();
int yz = lower_bound(Y.begin(), Y.end(), 0LL) - Y.begin();
int Z = encode(xz, yz);
long long ans = 0;
for (int i = 0; i <= Xs; i++) {
for (int j = 0; j <= Ys; j++) {
int cur = encode(i, j);
if (!uf.same(cur, Z))
continue;
if (i == 0 || j == 0 || i == Xs || j == Ys) {
cout << "INF\n";
return 0;
}
ans += (X[i] - X[i - 1]) * (Y[j] - Y[j - 1]);
}
}
cout << ans << "\n";
return 0;
} | replace | 86 | 88 | 86 | 88 | -11 | |
p02680 | 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 uint = unsigned int;
struct L {
int a, b, c;
L(int a = 0, int b = 0, int c = 0) : a(a), b(b), c(c) {}
};
int main() {
int n, m;
cin >> n >> m;
vector<L> lh(n), lv(m);
map<int, int> mpx, mpy; // その座標が何番目か
mpx[0] = 0, mpy[0] = 0;
rep(i, n) {
int a, b, c;
cin >> a >> b >> c;
lh[i] = L(a, b, c);
mpx[a] = 0, mpx[b] = 0, mpy[c] = 0;
}
rep(i, m) {
int a, b, c;
cin >> c >> a >> b;
L l(a, b, c);
lv[i] = L(a, b, c);
mpy[a] = 0, mpy[b] = 0, mpx[c] = 0;
}
vector<int> xs, ys; // i番目の座標
for (auto &it : mpx) {
it.second = xs.size();
xs.push_back(it.first);
}
for (auto &it : mpy) {
it.second = ys.size();
ys.push_back(it.first);
}
int w = xs.size() * 2, h = ys.size() * 2;
vector<vector<int>> board(h, vector<int>(w));
for (auto l : lh) {
for (int i = mpx[l.a] * 2; i <= mpx[l.b] * 2; i++)
board[mpy[l.c] * 2][i] = -1;
}
for (auto l : lv) {
for (int i = mpy[l.a] * 2; i <= mpy[l.b] * 2; i++)
board[i][mpy[l.c] * 2] = -1;
}
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int x = mpx[0] * 2, y = mpy[0] * 2;
board[y][x] = 1;
queue<pair<int, int>> visit;
visit.push(make_pair(x, y));
bool inf = false;
while (!visit.empty()) {
x = visit.front().first, y = visit.front().second;
visit.pop();
if (x <= 0 || w - 1 <= x || y <= 0 || h - 1 <= y) {
inf = true;
break;
}
rep(i, 4) {
int xx = x + dx[i], yy = y + dy[i];
if (board[yy][xx] == 1 || board[yy][xx] == -1)
continue;
board[yy][xx] = 1;
visit.push(make_pair(xx, yy));
}
}
if (inf) {
cout << "INF" << endl;
return 0;
}
ll sum = 0;
for (int j = 1; j < h; j += 2) {
for (int i = 1; i < w; i += 2) {
if (board[j][i] == 1) {
sum += (ll)(xs[(i + 1) / 2] - xs[(i - 1) / 2]) *
(ll)(ys[(j + 1) / 2] - ys[(j - 1) / 2]);
}
}
}
cout << sum << endl;
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 uint = unsigned int;
struct L {
int a, b, c;
L(int a = 0, int b = 0, int c = 0) : a(a), b(b), c(c) {}
};
int main() {
int n, m;
cin >> n >> m;
vector<L> lh(n), lv(m);
map<int, int> mpx, mpy; // その座標が何番目か
mpx[0] = 0, mpy[0] = 0;
rep(i, n) {
int a, b, c;
cin >> a >> b >> c;
lh[i] = L(a, b, c);
mpx[a] = 0, mpx[b] = 0, mpy[c] = 0;
}
rep(i, m) {
int a, b, c;
cin >> c >> a >> b;
L l(a, b, c);
lv[i] = L(a, b, c);
mpy[a] = 0, mpy[b] = 0, mpx[c] = 0;
}
vector<int> xs, ys; // i番目の座標
for (auto &it : mpx) {
it.second = xs.size();
xs.push_back(it.first);
}
for (auto &it : mpy) {
it.second = ys.size();
ys.push_back(it.first);
}
int w = xs.size() * 2, h = ys.size() * 2;
vector<vector<int>> board(h, vector<int>(w));
for (auto l : lh) {
for (int i = mpx[l.a] * 2; i <= mpx[l.b] * 2; i++)
board[mpy[l.c] * 2][i] = -1;
}
for (auto l : lv) {
for (int i = mpy[l.a] * 2; i <= mpy[l.b] * 2; i++)
board[i][mpx[l.c] * 2] = -1;
}
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int x = mpx[0] * 2, y = mpy[0] * 2;
board[y][x] = 1;
queue<pair<int, int>> visit;
visit.push(make_pair(x, y));
bool inf = false;
while (!visit.empty()) {
x = visit.front().first, y = visit.front().second;
visit.pop();
if (x <= 0 || w - 1 <= x || y <= 0 || h - 1 <= y) {
inf = true;
break;
}
rep(i, 4) {
int xx = x + dx[i], yy = y + dy[i];
if (board[yy][xx] == 1 || board[yy][xx] == -1)
continue;
board[yy][xx] = 1;
visit.push(make_pair(xx, yy));
}
}
if (inf) {
cout << "INF" << endl;
return 0;
}
ll sum = 0;
for (int j = 1; j < h; j += 2) {
for (int i = 1; i < w; i += 2) {
if (board[j][i] == 1) {
sum += (ll)(xs[(i + 1) / 2] - xs[(i - 1) / 2]) *
(ll)(ys[(j + 1) / 2] - ys[(j - 1) / 2]);
}
}
}
cout << sum << endl;
return 0;
}
| replace | 47 | 48 | 47 | 48 | 0 | |
p02680 | C++ | Runtime Error | // includes
#include <bits/stdc++.h>
using namespace std;
// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define whole(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define bit(n) (1LL << (n))
#define F first
#define S second
// functions
template <typename T> void unique(T &c) {
c.erase(std::unique(c.begin(), c.end()), c.end());
}
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 (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (auto &v : vec)
is >> v;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
for (int i = 0; i < vec.size(); i++) {
os << vec[i];
if (i + 1 != vec.size())
os << " ";
}
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &st) {
for (auto itr = st.begin(); itr != st.end(); ++itr) {
os << *itr;
auto titr = itr;
if (++titr != st.end())
os << " ";
}
return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &st) {
for (auto itr = st.begin(); itr != st.end(); ++itr) {
os << *itr;
auto titr = itr;
if (++titr != st.end())
os << " ";
}
return os;
}
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &st) {
for (auto itr = st.begin(); itr != st.end(); ++itr) {
os << *itr;
auto titr = itr;
if (++titr != st.end())
os << " ";
}
return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_multiset<T> &st) {
for (auto itr = st.begin(); itr != st.end(); ++itr) {
os << *itr;
auto titr = itr;
if (++titr != st.end())
os << " ";
}
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
os << "(" << itr->first << ", " << itr->second << ")";
auto titr = itr;
if (++titr != mp.end())
os << " ";
}
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp) {
for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
os << "(" << itr->first << ", " << itr->second << ")";
auto titr = itr;
if (++titr != mp.end())
os << " ";
}
return os;
}
// types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 60;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io {
fast_io() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(20);
}
} fast_io_;
bool v[6010][6010];
int col[6010][6010];
int X = 0, Y = 0;
void dfs(int i, int j, int c) {
queue<P> q;
q.push(mk(i, j));
col[i][j] = c;
while (!q.empty()) {
auto p = q.front();
q.pop();
rep(k, 4) {
int nx = p.F + dx[k], ny = p.S + dy[k];
if (nx >= 0 && nx < X && ny >= 0 && ny < Y) {
if (v[nx][ny])
continue;
if (col[nx][ny])
continue;
col[nx][ny] = c;
q.push(mk(nx, ny));
}
}
}
}
int main(int argc, char const *argv[]) {
int n, m;
cin >> n >> m;
vector<ll> a(n), b(n), c(n), d(m), e(m), f(m);
rep(i, n) cin >> a[i] >> b[i] >> c[i];
rep(i, m) cin >> d[i] >> e[i] >> f[i];
rep(i, n) {
a[i] *= 2;
b[i] *= 2;
c[i] *= 2;
}
rep(i, m) {
d[i] *= 2;
e[i] *= 2;
f[i] *= 2;
}
vector<ll> x, y;
x.pb(0);
y.pb(0);
rep(i, n) {
x.pb(a[i] - 1);
x.pb(a[i]);
x.pb(a[i] + 1);
x.pb(b[i] - 1);
x.pb(b[i]);
x.pb(b[i] + 1);
y.pb(c[i] - 1);
y.pb(c[i]);
y.pb(c[i] + 1);
}
rep(i, m) {
x.pb(d[i] - 1);
x.pb(d[i]);
x.pb(d[i] + 1);
y.pb(e[i] - 1);
y.pb(e[i]);
y.pb(e[i] + 1);
y.pb(f[i] - 1);
y.pb(f[i]);
y.pb(f[i] + 1);
}
sort(whole(x));
unique(x);
map<ll, int> mpx;
rep(i, sz(x)) mpx[x[i]] = i;
sort(whole(y));
unique(y);
map<ll, int> mpy;
rep(i, sz(y)) mpy[y[i]] = i;
rep(i, n) {
int yc = mpy[c[i]];
int xs = mpx[a[i]], xt = mpx[b[i]];
for (int j = xs; j <= xt; j++)
v[j][yc] = true;
}
rep(i, m) {
int xc = mpx[d[i]];
int ys = mpy[e[i]], yt = mpy[f[i]];
for (int j = ys; j <= yt; j++)
v[xc][j] = true;
}
X = sz(x), Y = sz(y);
int nex = 1;
rep(i, sz(x)) {
rep(j, sz(y)) {
if (v[i][j])
continue;
if (col[i][j])
continue;
dfs(i, j, nex);
nex++;
}
}
int xz = mpx[0], yz = mpy[0];
if (col[xz][yz] == 1)
cout << "INF" << endl;
else {
ll res = 0;
rep(i, sz(x)) {
rep(j, sz(y)) {
if (col[i][j] == col[xz][yz]) {
ll xl = 0, yl = 0;
if (x[i] & 1)
xl = (x[i + 1] - x[i] + 1) / 2;
else
xl = (x[i + 1] - x[i]) / 2;
if (y[j] & 1)
yl = (y[j + 1] - y[j] + 1) / 2;
else
yl = (y[j + 1] - y[j]) / 2;
res += xl * yl;
}
}
}
cout << res << endl;
}
/*
cerr << x << endl;
cerr << y << endl;
rep(i, sz(x)){
rep(j, sz(y)){
cerr << col[i][j];
}
cerr << endl;
}
*/
return 0;
}
| // includes
#include <bits/stdc++.h>
using namespace std;
// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define whole(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define bit(n) (1LL << (n))
#define F first
#define S second
// functions
template <typename T> void unique(T &c) {
c.erase(std::unique(c.begin(), c.end()), c.end());
}
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 (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (auto &v : vec)
is >> v;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
for (int i = 0; i < vec.size(); i++) {
os << vec[i];
if (i + 1 != vec.size())
os << " ";
}
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &st) {
for (auto itr = st.begin(); itr != st.end(); ++itr) {
os << *itr;
auto titr = itr;
if (++titr != st.end())
os << " ";
}
return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &st) {
for (auto itr = st.begin(); itr != st.end(); ++itr) {
os << *itr;
auto titr = itr;
if (++titr != st.end())
os << " ";
}
return os;
}
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &st) {
for (auto itr = st.begin(); itr != st.end(); ++itr) {
os << *itr;
auto titr = itr;
if (++titr != st.end())
os << " ";
}
return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_multiset<T> &st) {
for (auto itr = st.begin(); itr != st.end(); ++itr) {
os << *itr;
auto titr = itr;
if (++titr != st.end())
os << " ";
}
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
os << "(" << itr->first << ", " << itr->second << ")";
auto titr = itr;
if (++titr != mp.end())
os << " ";
}
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp) {
for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
os << "(" << itr->first << ", " << itr->second << ")";
auto titr = itr;
if (++titr != mp.end())
os << " ";
}
return os;
}
// types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 60;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io {
fast_io() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(20);
}
} fast_io_;
bool v[9010][9010];
int col[9010][9010];
int X = 0, Y = 0;
void dfs(int i, int j, int c) {
queue<P> q;
q.push(mk(i, j));
col[i][j] = c;
while (!q.empty()) {
auto p = q.front();
q.pop();
rep(k, 4) {
int nx = p.F + dx[k], ny = p.S + dy[k];
if (nx >= 0 && nx < X && ny >= 0 && ny < Y) {
if (v[nx][ny])
continue;
if (col[nx][ny])
continue;
col[nx][ny] = c;
q.push(mk(nx, ny));
}
}
}
}
int main(int argc, char const *argv[]) {
int n, m;
cin >> n >> m;
vector<ll> a(n), b(n), c(n), d(m), e(m), f(m);
rep(i, n) cin >> a[i] >> b[i] >> c[i];
rep(i, m) cin >> d[i] >> e[i] >> f[i];
rep(i, n) {
a[i] *= 2;
b[i] *= 2;
c[i] *= 2;
}
rep(i, m) {
d[i] *= 2;
e[i] *= 2;
f[i] *= 2;
}
vector<ll> x, y;
x.pb(0);
y.pb(0);
rep(i, n) {
x.pb(a[i] - 1);
x.pb(a[i]);
x.pb(a[i] + 1);
x.pb(b[i] - 1);
x.pb(b[i]);
x.pb(b[i] + 1);
y.pb(c[i] - 1);
y.pb(c[i]);
y.pb(c[i] + 1);
}
rep(i, m) {
x.pb(d[i] - 1);
x.pb(d[i]);
x.pb(d[i] + 1);
y.pb(e[i] - 1);
y.pb(e[i]);
y.pb(e[i] + 1);
y.pb(f[i] - 1);
y.pb(f[i]);
y.pb(f[i] + 1);
}
sort(whole(x));
unique(x);
map<ll, int> mpx;
rep(i, sz(x)) mpx[x[i]] = i;
sort(whole(y));
unique(y);
map<ll, int> mpy;
rep(i, sz(y)) mpy[y[i]] = i;
rep(i, n) {
int yc = mpy[c[i]];
int xs = mpx[a[i]], xt = mpx[b[i]];
for (int j = xs; j <= xt; j++)
v[j][yc] = true;
}
rep(i, m) {
int xc = mpx[d[i]];
int ys = mpy[e[i]], yt = mpy[f[i]];
for (int j = ys; j <= yt; j++)
v[xc][j] = true;
}
X = sz(x), Y = sz(y);
int nex = 1;
rep(i, sz(x)) {
rep(j, sz(y)) {
if (v[i][j])
continue;
if (col[i][j])
continue;
dfs(i, j, nex);
nex++;
}
}
int xz = mpx[0], yz = mpy[0];
if (col[xz][yz] == 1)
cout << "INF" << endl;
else {
ll res = 0;
rep(i, sz(x)) {
rep(j, sz(y)) {
if (col[i][j] == col[xz][yz]) {
ll xl = 0, yl = 0;
if (x[i] & 1)
xl = (x[i + 1] - x[i] + 1) / 2;
else
xl = (x[i + 1] - x[i]) / 2;
if (y[j] & 1)
yl = (y[j + 1] - y[j] + 1) / 2;
else
yl = (y[j + 1] - y[j]) / 2;
res += xl * yl;
}
}
}
cout << res << endl;
}
/*
cerr << x << endl;
cerr << y << endl;
rep(i, sz(x)){
rep(j, sz(y)){
cerr << col[i][j];
}
cerr << endl;
}
*/
return 0;
}
| replace | 130 | 132 | 130 | 132 | -11 | |
p02680 | C++ | Runtime Error | #define _CRT_SECURE_NO_WARNINGS
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (lint)(n); i++)
#define REP(i, n) for (int i = 1; i <= (lint)(n); i++)
#define all(V) V.begin(), V.end()
#define StackReplaceBegin(size) \
void *p = malloc(size); \
esp_new = (lint)p + size - 1; \
void *stack_extend_memory_ = malloc(size); \
void *stack_extend_origin_memory_; \
char *stack_extend_dummy_memory_ = (char *)alloca( \
(1 + (int)(((long long)stack_extend_memory_) & 127)) * 16); \
*stack_extend_dummy_memory_ = 0; \
asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp" \
: "=b"(stack_extend_origin_memory_) \
: "a"((char *)stack_extend_memory_ + (size)-1024))
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<lint, lint> P;
constexpr int INF = INT_MAX / 2;
constexpr lint LINF = LLONG_MAX / 2;
constexpr double eps = DBL_EPSILON;
constexpr double PI = 3.141592653589793238462643383279;
template <class T>
class prique : public std::priority_queue<T, std::vector<T>, std::greater<T>> {
};
template <class T, class U> inline bool chmax(T &lhs, const U &rhs) {
if (lhs < rhs) {
lhs = rhs;
return 1;
}
return 0;
}
template <class T, class U> inline bool chmin(T &lhs, const U &rhs) {
if (lhs > rhs) {
lhs = rhs;
return 1;
}
return 0;
}
inline lint gcd(lint a, lint b) {
while (b) {
lint c = a;
a = b;
b = c % b;
}
return a;
}
inline lint lcm(lint a, lint b) { return a / gcd(a, b) * b; }
bool isprime(lint n) {
if (n == 1)
return false;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0)
return false;
}
return true;
}
template <typename T> T mypow(T a, unsigned int b) {
if (!b)
return T(1);
if (b & 1)
return mypow(a, b - 1) * a;
T memo = mypow(a, b >> 1);
return memo * memo;
}
lint modpow(lint a, lint b, lint m) {
if (!b)
return 1;
if (b & 1)
return modpow(a, b - 1, m) * a % m;
lint memo = modpow(a, b >> 1, m);
return memo * memo % m;
}
template <typename T> void printArray(std::vector<T> &vec) {
rep(i, vec.size() - 1) std::cout << vec[i] << " ";
std::cout << vec.back() << std::endl;
}
template <typename T> void printArray(T l, T r) {
T rprev = r;
rprev--;
for (T i = l; i != rprev; i++) {
std::cout << *i << " ";
}
std::cout << *rprev << std::endl;
}
template <typename T> class Compression {
std::vector<T> vec;
bool built = false;
public:
Compression() {}
Compression(const std::vector<T> &initvec) : vec(initvec) {}
void push(const T &val) { vec.emplace_back(val); }
void build() {
std::sort(all(vec));
vec.erase(std::unique(all(vec)), vec.end());
built = true;
}
int operator[](const T &val) {
assert(built);
return std::lower_bound(all(vec), val) - vec.begin();
}
T at(int p) {
assert(built);
return vec[p];
}
unsigned int size() { return vec.size(); }
};
lint n, m, a[1010], b[1010], c[1010], d[1010], e[1010], f[1010];
int grid[4010][4010];
bool used[4010][4010];
std::vector<int> xvec, yvec;
Compression<lint> xcomp, ycomp;
lint ans;
int g[] = {0, 1, 0, -1};
int h[] = {1, 0, -1, 0};
void dfs(int x, int y) {
used[x][y] = true;
if (x == 0 || y == 0 || x == (int)xcomp.size() - 1 ||
y == (int)ycomp.size() - 1) {
puts("INF");
exit(0);
}
lint hl = xcomp.at(x + 1) - xcomp.at(x), wl = ycomp.at(y + 1) - ycomp.at(y);
if (xcomp.at(x) % 2)
hl++;
if (ycomp.at(y) % 2)
wl++;
hl /= 2;
wl /= 2;
ans += hl * wl;
rep(i, 4) {
int nx = x + g[i], ny = y + h[i];
if (nx < 0 || xcomp.size() <= nx || ny < 0 || ycomp.size() <= ny)
continue;
if (!grid[nx][ny] && !used[nx][ny])
dfs(nx, ny);
}
}
lint esp_org, esp_new;
int main() {
std::cin >> n >> m;
xcomp.push(-LINF);
xcomp.push(1);
xcomp.push(LINF);
ycomp.push(-LINF);
ycomp.push(1);
ycomp.push(LINF);
StackReplaceBegin(128 * 1024 * 1024);
rep(i, n) {
std::cin >> a[i] >> b[i] >> c[i];
a[i] *= 2;
b[i] *= 2;
c[i] *= 2;
xcomp.push(a[i]);
xcomp.push(b[i] + 1);
ycomp.push(c[i]);
ycomp.push(c[i] + 1);
}
rep(i, m) {
std::cin >> d[i] >> e[i] >> f[i];
d[i] *= 2;
e[i] *= 2;
f[i] *= 2;
ycomp.push(e[i]);
ycomp.push(f[i] + 1);
xcomp.push(d[i]);
xcomp.push(d[i] + 1);
}
xcomp.build();
ycomp.build();
rep(i, n) {
grid[xcomp[a[i]]][ycomp[c[i]]]++;
grid[xcomp[b[i] + 1]][ycomp[c[i]]]--;
grid[xcomp[a[i]]][ycomp[c[i] + 1]]--;
grid[xcomp[b[i] + 1]][ycomp[c[i] + 1]]++;
}
rep(i, m) {
grid[xcomp[d[i]]][ycomp[e[i]]]++;
grid[xcomp[d[i]]][ycomp[f[i] + 1]]--;
grid[xcomp[d[i] + 1]][ycomp[e[i]]]--;
grid[xcomp[d[i] + 1]][ycomp[f[i] + 1]]++;
}
rep(i, xcomp.size() - 1) {
rep(j, (int)ycomp.size()) grid[i + 1][j] += grid[i][j];
}
rep(i, xcomp.size()) {
rep(j, (int)ycomp.size() - 1) grid[i][j + 1] += grid[i][j];
}
dfs(xcomp[1], ycomp[1]);
std::cout << ans << std::endl;
return 0;
}
| #define _CRT_SECURE_NO_WARNINGS
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (lint)(n); i++)
#define REP(i, n) for (int i = 1; i <= (lint)(n); i++)
#define all(V) V.begin(), V.end()
#define StackReplaceBegin(size) \
void *p = malloc(size); \
esp_new = (lint)p + size - 1; \
void *stack_extend_memory_ = malloc(size); \
void *stack_extend_origin_memory_; \
char *stack_extend_dummy_memory_ = (char *)alloca( \
(1 + (int)(((long long)stack_extend_memory_) & 127)) * 16); \
*stack_extend_dummy_memory_ = 0; \
asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp" \
: "=b"(stack_extend_origin_memory_) \
: "a"((char *)stack_extend_memory_ + (size)-1024))
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<lint, lint> P;
constexpr int INF = INT_MAX / 2;
constexpr lint LINF = LLONG_MAX / 2;
constexpr double eps = DBL_EPSILON;
constexpr double PI = 3.141592653589793238462643383279;
template <class T>
class prique : public std::priority_queue<T, std::vector<T>, std::greater<T>> {
};
template <class T, class U> inline bool chmax(T &lhs, const U &rhs) {
if (lhs < rhs) {
lhs = rhs;
return 1;
}
return 0;
}
template <class T, class U> inline bool chmin(T &lhs, const U &rhs) {
if (lhs > rhs) {
lhs = rhs;
return 1;
}
return 0;
}
inline lint gcd(lint a, lint b) {
while (b) {
lint c = a;
a = b;
b = c % b;
}
return a;
}
inline lint lcm(lint a, lint b) { return a / gcd(a, b) * b; }
bool isprime(lint n) {
if (n == 1)
return false;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0)
return false;
}
return true;
}
template <typename T> T mypow(T a, unsigned int b) {
if (!b)
return T(1);
if (b & 1)
return mypow(a, b - 1) * a;
T memo = mypow(a, b >> 1);
return memo * memo;
}
lint modpow(lint a, lint b, lint m) {
if (!b)
return 1;
if (b & 1)
return modpow(a, b - 1, m) * a % m;
lint memo = modpow(a, b >> 1, m);
return memo * memo % m;
}
template <typename T> void printArray(std::vector<T> &vec) {
rep(i, vec.size() - 1) std::cout << vec[i] << " ";
std::cout << vec.back() << std::endl;
}
template <typename T> void printArray(T l, T r) {
T rprev = r;
rprev--;
for (T i = l; i != rprev; i++) {
std::cout << *i << " ";
}
std::cout << *rprev << std::endl;
}
template <typename T> class Compression {
std::vector<T> vec;
bool built = false;
public:
Compression() {}
Compression(const std::vector<T> &initvec) : vec(initvec) {}
void push(const T &val) { vec.emplace_back(val); }
void build() {
std::sort(all(vec));
vec.erase(std::unique(all(vec)), vec.end());
built = true;
}
int operator[](const T &val) {
assert(built);
return std::lower_bound(all(vec), val) - vec.begin();
}
T at(int p) {
assert(built);
return vec[p];
}
unsigned int size() { return vec.size(); }
};
lint n, m, a[1010], b[1010], c[1010], d[1010], e[1010], f[1010];
int grid[4010][4010];
bool used[4010][4010];
std::vector<int> xvec, yvec;
Compression<lint> xcomp, ycomp;
lint ans;
int g[] = {0, 1, 0, -1};
int h[] = {1, 0, -1, 0};
void dfs(int x, int y) {
used[x][y] = true;
if (x == 0 || y == 0 || x == (int)xcomp.size() - 1 ||
y == (int)ycomp.size() - 1) {
puts("INF");
exit(0);
}
lint hl = xcomp.at(x + 1) - xcomp.at(x), wl = ycomp.at(y + 1) - ycomp.at(y);
if (xcomp.at(x) % 2)
hl++;
if (ycomp.at(y) % 2)
wl++;
hl /= 2;
wl /= 2;
ans += hl * wl;
rep(i, 4) {
int nx = x + g[i], ny = y + h[i];
if (nx < 0 || xcomp.size() <= nx || ny < 0 || ycomp.size() <= ny)
continue;
if (!grid[nx][ny] && !used[nx][ny])
dfs(nx, ny);
}
}
lint esp_org, esp_new;
int main() {
std::cin >> n >> m;
xcomp.push(-LINF);
xcomp.push(1);
xcomp.push(LINF);
ycomp.push(-LINF);
ycomp.push(1);
ycomp.push(LINF);
StackReplaceBegin(1024 * 1024 * 1024);
rep(i, n) {
std::cin >> a[i] >> b[i] >> c[i];
a[i] *= 2;
b[i] *= 2;
c[i] *= 2;
xcomp.push(a[i]);
xcomp.push(b[i] + 1);
ycomp.push(c[i]);
ycomp.push(c[i] + 1);
}
rep(i, m) {
std::cin >> d[i] >> e[i] >> f[i];
d[i] *= 2;
e[i] *= 2;
f[i] *= 2;
ycomp.push(e[i]);
ycomp.push(f[i] + 1);
xcomp.push(d[i]);
xcomp.push(d[i] + 1);
}
xcomp.build();
ycomp.build();
rep(i, n) {
grid[xcomp[a[i]]][ycomp[c[i]]]++;
grid[xcomp[b[i] + 1]][ycomp[c[i]]]--;
grid[xcomp[a[i]]][ycomp[c[i] + 1]]--;
grid[xcomp[b[i] + 1]][ycomp[c[i] + 1]]++;
}
rep(i, m) {
grid[xcomp[d[i]]][ycomp[e[i]]]++;
grid[xcomp[d[i]]][ycomp[f[i] + 1]]--;
grid[xcomp[d[i] + 1]][ycomp[e[i]]]--;
grid[xcomp[d[i] + 1]][ycomp[f[i] + 1]]++;
}
rep(i, xcomp.size() - 1) {
rep(j, (int)ycomp.size()) grid[i + 1][j] += grid[i][j];
}
rep(i, xcomp.size()) {
rep(j, (int)ycomp.size() - 1) grid[i][j + 1] += grid[i][j];
}
dfs(xcomp[1], ycomp[1]);
std::cout << ans << std::endl;
return 0;
}
| replace | 177 | 178 | 177 | 178 | -11 | |
p02680 | C++ | Runtime Error | #define _CRT_SECURE_NO_WARNINGS
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (lint)(n); i++)
#define REP(i, n) for (int i = 1; i <= (lint)(n); i++)
#define all(V) V.begin(), V.end()
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<lint, lint> P;
constexpr int INF = INT_MAX / 2;
constexpr lint LINF = LLONG_MAX / 2;
constexpr double eps = DBL_EPSILON;
constexpr double PI = 3.141592653589793238462643383279;
template <class T>
class prique : public std::priority_queue<T, std::vector<T>, std::greater<T>> {
};
template <class T, class U> inline bool chmax(T &lhs, const U &rhs) {
if (lhs < rhs) {
lhs = rhs;
return 1;
}
return 0;
}
template <class T, class U> inline bool chmin(T &lhs, const U &rhs) {
if (lhs > rhs) {
lhs = rhs;
return 1;
}
return 0;
}
inline lint gcd(lint a, lint b) {
while (b) {
lint c = a;
a = b;
b = c % b;
}
return a;
}
inline lint lcm(lint a, lint b) { return a / gcd(a, b) * b; }
bool isprime(lint n) {
if (n == 1)
return false;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0)
return false;
}
return true;
}
template <typename T> T mypow(T a, unsigned int b) {
if (!b)
return T(1);
if (b & 1)
return mypow(a, b - 1) * a;
T memo = mypow(a, b >> 1);
return memo * memo;
}
lint modpow(lint a, lint b, lint m) {
if (!b)
return 1;
if (b & 1)
return modpow(a, b - 1, m) * a % m;
lint memo = modpow(a, b >> 1, m);
return memo * memo % m;
}
template <typename T> void printArray(std::vector<T> &vec) {
rep(i, vec.size() - 1) std::cout << vec[i] << " ";
std::cout << vec.back() << std::endl;
}
template <typename T> void printArray(T l, T r) {
T rprev = r;
rprev--;
for (T i = l; i != rprev; i++) {
std::cout << *i << " ";
}
std::cout << *rprev << std::endl;
}
template <typename T> class Compression {
std::vector<T> vec;
bool built = false;
public:
Compression() {}
Compression(const std::vector<T> &initvec) : vec(initvec) {}
void push(const T &val) { vec.emplace_back(val); }
void build() {
std::sort(all(vec));
vec.erase(std::unique(all(vec)), vec.end());
built = true;
}
int operator[](const T &val) {
assert(built);
return std::lower_bound(all(vec), val) - vec.begin();
}
T at(int p) {
assert(built);
return vec[p];
}
unsigned int size() { return vec.size(); }
};
lint n, m, a[1010], b[1010], c[1010], d[1010], e[1010], f[1010];
int grid[4010][4010];
bool used[4010][4010];
std::vector<int> xvec, yvec;
Compression<lint> xcomp, ycomp;
lint ans;
int g[] = {0, 1, 0, -1};
int h[] = {1, 0, -1, 0};
void dfs(int x, int y) {
used[x][y] = true;
if (x == 0 || y == 0 || x == (int)xcomp.size() - 1 ||
y == (int)ycomp.size() - 1) {
puts("INF");
exit(0);
}
lint hl = xcomp.at(x + 1) - xcomp.at(x), wl = ycomp.at(y + 1) - ycomp.at(y);
if (xcomp.at(x) % 2)
hl++;
if (ycomp.at(y) % 2)
wl++;
hl /= 2;
wl /= 2;
ans += hl * wl;
rep(i, 4) {
int nx = x + g[i], ny = y + h[i];
if (nx < 0 || xcomp.size() <= nx || ny < 0 || ycomp.size() <= ny)
continue;
if (!grid[nx][ny] && !used[nx][ny])
dfs(nx, ny);
}
}
lint esp_org, esp_new;
int main() {
lint size = 48 * 1024 * 1024;
void *stack_extend_memory_ = malloc(size);
void *stack_extend_origin_memory_;
char *stack_extend_dummy_memory_ =
(char *)alloca((1 + (int)(((long long)stack_extend_memory_) & 127)) * 16);
*stack_extend_dummy_memory_ = 0;
asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp"
: "=b"(stack_extend_origin_memory_)
: "a"((char *)stack_extend_memory_ + (size)-1024));
std::cin >> n >> m;
xcomp.push(-LINF);
xcomp.push(1);
xcomp.push(LINF);
ycomp.push(-LINF);
ycomp.push(1);
ycomp.push(LINF);
rep(i, n) {
std::cin >> a[i] >> b[i] >> c[i];
a[i] *= 2;
b[i] *= 2;
c[i] *= 2;
xcomp.push(a[i]);
xcomp.push(b[i] + 1);
ycomp.push(c[i]);
ycomp.push(c[i] + 1);
}
rep(i, m) {
std::cin >> d[i] >> e[i] >> f[i];
d[i] *= 2;
e[i] *= 2;
f[i] *= 2;
ycomp.push(e[i]);
ycomp.push(f[i] + 1);
xcomp.push(d[i]);
xcomp.push(d[i] + 1);
}
xcomp.build();
ycomp.build();
rep(i, n) {
grid[xcomp[a[i]]][ycomp[c[i]]]++;
grid[xcomp[b[i] + 1]][ycomp[c[i]]]--;
grid[xcomp[a[i]]][ycomp[c[i] + 1]]--;
grid[xcomp[b[i] + 1]][ycomp[c[i] + 1]]++;
}
rep(i, m) {
grid[xcomp[d[i]]][ycomp[e[i]]]++;
grid[xcomp[d[i]]][ycomp[f[i] + 1]]--;
grid[xcomp[d[i] + 1]][ycomp[e[i]]]--;
grid[xcomp[d[i] + 1]][ycomp[f[i] + 1]]++;
}
rep(i, xcomp.size() - 1) {
rep(j, (int)ycomp.size()) grid[i + 1][j] += grid[i][j];
}
rep(i, xcomp.size()) {
rep(j, (int)ycomp.size() - 1) grid[i][j + 1] += grid[i][j];
}
dfs(xcomp[1], ycomp[1]);
std::cout << ans << std::endl;
asm volatile("mov %%rax, %%rsp" ::"a"(stack_extend_origin_memory_));
free(stack_extend_memory_);
return 0;
}
| #define _CRT_SECURE_NO_WARNINGS
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (lint)(n); i++)
#define REP(i, n) for (int i = 1; i <= (lint)(n); i++)
#define all(V) V.begin(), V.end()
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<lint, lint> P;
constexpr int INF = INT_MAX / 2;
constexpr lint LINF = LLONG_MAX / 2;
constexpr double eps = DBL_EPSILON;
constexpr double PI = 3.141592653589793238462643383279;
template <class T>
class prique : public std::priority_queue<T, std::vector<T>, std::greater<T>> {
};
template <class T, class U> inline bool chmax(T &lhs, const U &rhs) {
if (lhs < rhs) {
lhs = rhs;
return 1;
}
return 0;
}
template <class T, class U> inline bool chmin(T &lhs, const U &rhs) {
if (lhs > rhs) {
lhs = rhs;
return 1;
}
return 0;
}
inline lint gcd(lint a, lint b) {
while (b) {
lint c = a;
a = b;
b = c % b;
}
return a;
}
inline lint lcm(lint a, lint b) { return a / gcd(a, b) * b; }
bool isprime(lint n) {
if (n == 1)
return false;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0)
return false;
}
return true;
}
template <typename T> T mypow(T a, unsigned int b) {
if (!b)
return T(1);
if (b & 1)
return mypow(a, b - 1) * a;
T memo = mypow(a, b >> 1);
return memo * memo;
}
lint modpow(lint a, lint b, lint m) {
if (!b)
return 1;
if (b & 1)
return modpow(a, b - 1, m) * a % m;
lint memo = modpow(a, b >> 1, m);
return memo * memo % m;
}
template <typename T> void printArray(std::vector<T> &vec) {
rep(i, vec.size() - 1) std::cout << vec[i] << " ";
std::cout << vec.back() << std::endl;
}
template <typename T> void printArray(T l, T r) {
T rprev = r;
rprev--;
for (T i = l; i != rprev; i++) {
std::cout << *i << " ";
}
std::cout << *rprev << std::endl;
}
template <typename T> class Compression {
std::vector<T> vec;
bool built = false;
public:
Compression() {}
Compression(const std::vector<T> &initvec) : vec(initvec) {}
void push(const T &val) { vec.emplace_back(val); }
void build() {
std::sort(all(vec));
vec.erase(std::unique(all(vec)), vec.end());
built = true;
}
int operator[](const T &val) {
assert(built);
return std::lower_bound(all(vec), val) - vec.begin();
}
T at(int p) {
assert(built);
return vec[p];
}
unsigned int size() { return vec.size(); }
};
lint n, m, a[1010], b[1010], c[1010], d[1010], e[1010], f[1010];
int grid[4010][4010];
bool used[4010][4010];
std::vector<int> xvec, yvec;
Compression<lint> xcomp, ycomp;
lint ans;
int g[] = {0, 1, 0, -1};
int h[] = {1, 0, -1, 0};
void dfs(int x, int y) {
used[x][y] = true;
if (x == 0 || y == 0 || x == (int)xcomp.size() - 1 ||
y == (int)ycomp.size() - 1) {
puts("INF");
exit(0);
}
lint hl = xcomp.at(x + 1) - xcomp.at(x), wl = ycomp.at(y + 1) - ycomp.at(y);
if (xcomp.at(x) % 2)
hl++;
if (ycomp.at(y) % 2)
wl++;
hl /= 2;
wl /= 2;
ans += hl * wl;
rep(i, 4) {
int nx = x + g[i], ny = y + h[i];
if (nx < 0 || xcomp.size() <= nx || ny < 0 || ycomp.size() <= ny)
continue;
if (!grid[nx][ny] && !used[nx][ny])
dfs(nx, ny);
}
}
lint esp_org, esp_new;
int main() {
lint size = 512 * 1024 * 1024;
void *stack_extend_memory_ = malloc(size);
void *stack_extend_origin_memory_;
char *stack_extend_dummy_memory_ =
(char *)alloca((1 + (int)(((long long)stack_extend_memory_) & 127)) * 16);
*stack_extend_dummy_memory_ = 0;
asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp"
: "=b"(stack_extend_origin_memory_)
: "a"((char *)stack_extend_memory_ + (size)-1024));
std::cin >> n >> m;
xcomp.push(-LINF);
xcomp.push(1);
xcomp.push(LINF);
ycomp.push(-LINF);
ycomp.push(1);
ycomp.push(LINF);
rep(i, n) {
std::cin >> a[i] >> b[i] >> c[i];
a[i] *= 2;
b[i] *= 2;
c[i] *= 2;
xcomp.push(a[i]);
xcomp.push(b[i] + 1);
ycomp.push(c[i]);
ycomp.push(c[i] + 1);
}
rep(i, m) {
std::cin >> d[i] >> e[i] >> f[i];
d[i] *= 2;
e[i] *= 2;
f[i] *= 2;
ycomp.push(e[i]);
ycomp.push(f[i] + 1);
xcomp.push(d[i]);
xcomp.push(d[i] + 1);
}
xcomp.build();
ycomp.build();
rep(i, n) {
grid[xcomp[a[i]]][ycomp[c[i]]]++;
grid[xcomp[b[i] + 1]][ycomp[c[i]]]--;
grid[xcomp[a[i]]][ycomp[c[i] + 1]]--;
grid[xcomp[b[i] + 1]][ycomp[c[i] + 1]]++;
}
rep(i, m) {
grid[xcomp[d[i]]][ycomp[e[i]]]++;
grid[xcomp[d[i]]][ycomp[f[i] + 1]]--;
grid[xcomp[d[i] + 1]][ycomp[e[i]]]--;
grid[xcomp[d[i] + 1]][ycomp[f[i] + 1]]++;
}
rep(i, xcomp.size() - 1) {
rep(j, (int)ycomp.size()) grid[i + 1][j] += grid[i][j];
}
rep(i, xcomp.size()) {
rep(j, (int)ycomp.size() - 1) grid[i][j + 1] += grid[i][j];
}
dfs(xcomp[1], ycomp[1]);
std::cout << ans << std::endl;
asm volatile("mov %%rax, %%rsp" ::"a"(stack_extend_origin_memory_));
free(stack_extend_memory_);
return 0;
}
| replace | 159 | 160 | 159 | 160 | -11 | |
p02680 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 5000;
struct NS {
int a, b, c;
} ns[N + 5];
struct EW {
int d, e, f;
} ew[N + 5];
int t_ns[N + 5], t_ew[N + 5], r_ns[N + 5], r_ew[N + 5];
template <int N> struct Disjoint_Set_Union {
int p[N + 5], sz[N + 5];
void init(int n) {
for (int i = 0; i <= n; ++i) {
p[i] = i;
sz[i] = 1;
}
}
int find(int x) { return p[x] == x ? p[x] : p[x] = find(p[x]); }
bool funion(int x, int y) {
int fx = find(x), fy = find(y);
if (fx == fy)
return false;
if (sz[fx] < sz[fy])
swap(fx, fy);
p[fy] = fx;
sz[fx] += sz[fy];
return true;
}
};
Disjoint_Set_Union<N> dsu;
bool no_ns[N + 5][N + 5], no_ew[N + 5][N + 5];
int main() {
int n, m, a, b, c, d, e, f;
scanf("%d %d", &n, &m);
int cnt_ns = 0, cnt_ew = 0;
t_ns[++cnt_ns] = 0;
t_ew[++cnt_ew] = 0;
for (int i = 1; i <= n; ++i) {
scanf("%d %d %d", &a, &b, &c);
t_ns[++cnt_ns] = a;
t_ns[++cnt_ns] = b;
t_ew[++cnt_ew] = c;
ns[i] = {a, b, c};
}
for (int i = 1; i <= m; ++i) {
scanf("%d %d %d", &d, &e, &f);
t_ns[++cnt_ns] = d;
t_ew[++cnt_ew] = e;
t_ew[++cnt_ew] = f;
ew[i] = {d, e, f};
}
sort(t_ns + 1, t_ns + cnt_ns + 1);
auto ed_ns = unique(t_ns + 1, t_ns + cnt_ns + 1);
sort(t_ew + 1, t_ew + cnt_ew + 1);
auto ed_ew = unique(t_ew + 1, t_ew + cnt_ew + 1);
for (int i = 1; i <= n; ++i) {
int tmp = lower_bound(t_ns + 1, ed_ns, ns[i].a) - t_ns;
r_ns[tmp] = ns[i].a;
ns[i].a = tmp;
tmp = lower_bound(t_ns + 1, ed_ns, ns[i].b) - t_ns;
r_ns[tmp] = ns[i].b;
ns[i].b = tmp;
tmp = lower_bound(t_ew + 1, ed_ew, ns[i].c) - t_ew;
r_ew[tmp] = ns[i].c;
ns[i].c = tmp;
for (int j = ns[i].a + 1; j <= ns[i].b; ++j) {
no_ns[j][ns[i].c] = true;
}
}
for (int i = 1; i <= m; ++i) {
int tmp = lower_bound(t_ns + 1, ed_ns, ew[i].d) - t_ns;
r_ns[tmp] = ew[i].d;
ew[i].d = tmp;
tmp = lower_bound(t_ew + 1, ed_ew, ew[i].e) - t_ew;
r_ew[tmp] = ew[i].e;
ew[i].e = tmp;
tmp = lower_bound(t_ew + 1, ed_ew, ew[i].f) - t_ew;
r_ew[tmp] = ew[i].f;
ew[i].f = tmp;
for (int j = ew[i].e + 1; j <= ew[i].f; ++j) {
no_ew[ew[i].d][j] = true;
}
}
int ns_0 = lower_bound(t_ns + 1, ed_ns, 0) - t_ns;
int ew_0 = lower_bound(t_ew + 1, ed_ew, 0) - t_ew;
int ns_max = ed_ns - t_ns;
int ew_max = ed_ew - t_ew;
dsu.init(ns_max * ew_max);
for (int i = 1; i < ns_max; ++i) {
for (int j = 1; j < ew_max; ++j) {
int id = (i - 1) * ew_max + j;
if (!no_ns[i][j])
dsu.funion(id, id + 1);
if (!no_ew[i][j])
dsu.funion(id, id + ew_max);
}
}
int parent = dsu.find((ns_0 - 1) * ew_max + ew_0);
long long ans = 0;
for (int i = 1; i <= ns_max; ++i) {
for (int j = 1, l = 0; j <= ew_max; ++j) {
int id = (i - 1) * ew_max + j;
if (dsu.find(id) == parent) {
if (i == 1 || i == ns_max || j == 1 || j == ew_max) {
ans = LLONG_MAX;
goto end;
}
if (dsu.find(id + 1) != parent) {
ans += (long long)(r_ns[i] - r_ns[i - 1]) *
(long long)(r_ew[j] - r_ew[l]);
}
} else
l = j;
}
}
end:
if (ans != LLONG_MAX)
printf("%lld\n", ans);
else
printf("INF\n");
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 5000;
struct NS {
int a, b, c;
} ns[N + 5];
struct EW {
int d, e, f;
} ew[N + 5];
int t_ns[N + 5], t_ew[N + 5], r_ns[N + 5], r_ew[N + 5];
template <int N> struct Disjoint_Set_Union {
int p[N + 5], sz[N + 5];
void init(int n) {
for (int i = 0; i <= n; ++i) {
p[i] = i;
sz[i] = 1;
}
}
int find(int x) { return p[x] == x ? p[x] : p[x] = find(p[x]); }
bool funion(int x, int y) {
int fx = find(x), fy = find(y);
if (fx == fy)
return false;
if (sz[fx] < sz[fy])
swap(fx, fy);
p[fy] = fx;
sz[fx] += sz[fy];
return true;
}
};
Disjoint_Set_Union<N * N> dsu;
bool no_ns[N + 5][N + 5], no_ew[N + 5][N + 5];
int main() {
int n, m, a, b, c, d, e, f;
scanf("%d %d", &n, &m);
int cnt_ns = 0, cnt_ew = 0;
t_ns[++cnt_ns] = 0;
t_ew[++cnt_ew] = 0;
for (int i = 1; i <= n; ++i) {
scanf("%d %d %d", &a, &b, &c);
t_ns[++cnt_ns] = a;
t_ns[++cnt_ns] = b;
t_ew[++cnt_ew] = c;
ns[i] = {a, b, c};
}
for (int i = 1; i <= m; ++i) {
scanf("%d %d %d", &d, &e, &f);
t_ns[++cnt_ns] = d;
t_ew[++cnt_ew] = e;
t_ew[++cnt_ew] = f;
ew[i] = {d, e, f};
}
sort(t_ns + 1, t_ns + cnt_ns + 1);
auto ed_ns = unique(t_ns + 1, t_ns + cnt_ns + 1);
sort(t_ew + 1, t_ew + cnt_ew + 1);
auto ed_ew = unique(t_ew + 1, t_ew + cnt_ew + 1);
for (int i = 1; i <= n; ++i) {
int tmp = lower_bound(t_ns + 1, ed_ns, ns[i].a) - t_ns;
r_ns[tmp] = ns[i].a;
ns[i].a = tmp;
tmp = lower_bound(t_ns + 1, ed_ns, ns[i].b) - t_ns;
r_ns[tmp] = ns[i].b;
ns[i].b = tmp;
tmp = lower_bound(t_ew + 1, ed_ew, ns[i].c) - t_ew;
r_ew[tmp] = ns[i].c;
ns[i].c = tmp;
for (int j = ns[i].a + 1; j <= ns[i].b; ++j) {
no_ns[j][ns[i].c] = true;
}
}
for (int i = 1; i <= m; ++i) {
int tmp = lower_bound(t_ns + 1, ed_ns, ew[i].d) - t_ns;
r_ns[tmp] = ew[i].d;
ew[i].d = tmp;
tmp = lower_bound(t_ew + 1, ed_ew, ew[i].e) - t_ew;
r_ew[tmp] = ew[i].e;
ew[i].e = tmp;
tmp = lower_bound(t_ew + 1, ed_ew, ew[i].f) - t_ew;
r_ew[tmp] = ew[i].f;
ew[i].f = tmp;
for (int j = ew[i].e + 1; j <= ew[i].f; ++j) {
no_ew[ew[i].d][j] = true;
}
}
int ns_0 = lower_bound(t_ns + 1, ed_ns, 0) - t_ns;
int ew_0 = lower_bound(t_ew + 1, ed_ew, 0) - t_ew;
int ns_max = ed_ns - t_ns;
int ew_max = ed_ew - t_ew;
dsu.init(ns_max * ew_max);
for (int i = 1; i < ns_max; ++i) {
for (int j = 1; j < ew_max; ++j) {
int id = (i - 1) * ew_max + j;
if (!no_ns[i][j])
dsu.funion(id, id + 1);
if (!no_ew[i][j])
dsu.funion(id, id + ew_max);
}
}
int parent = dsu.find((ns_0 - 1) * ew_max + ew_0);
long long ans = 0;
for (int i = 1; i <= ns_max; ++i) {
for (int j = 1, l = 0; j <= ew_max; ++j) {
int id = (i - 1) * ew_max + j;
if (dsu.find(id) == parent) {
if (i == 1 || i == ns_max || j == 1 || j == ew_max) {
ans = LLONG_MAX;
goto end;
}
if (dsu.find(id + 1) != parent) {
ans += (long long)(r_ns[i] - r_ns[i - 1]) *
(long long)(r_ew[j] - r_ew[l]);
}
} else
l = j;
}
}
end:
if (ans != LLONG_MAX)
printf("%lld\n", ans);
else
printf("INF\n");
return 0;
}
| replace | 34 | 35 | 34 | 35 | 0 | |
p02680 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
template <typename T> vector<T> compress(vector<T> A) {
sort(A.begin(), A.end());
A.erase(unique(A.begin(), A.end()), A.end());
return A;
}
struct UnionFind {
vector<int> par;
vector<int> sz;
UnionFind(int n = 0) {
if (n > 0)
initialize(n);
}
void initialize(int n) {
par.resize(n);
sz.assign(n, 1);
for (int i = 0; i < n; i++) {
par[i] = i;
}
}
int find(int x) {
if (par[x] == x) {
return x;
} else {
return par[x] = find(par[x]);
}
}
bool unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return false;
if (sz[x] > sz[y])
swap(x, y);
par[x] = y;
sz[y] += sz[x];
return true;
}
bool same(int x, int y) { return find(x) == find(y); }
int size(int x) { return sz[find(x)]; }
};
int main() {
int N, M;
cin >> N >> M;
int64_t INF = 2e9;
vector<int64_t> xs = {-INF, INF}, ys = {-INF, INF};
auto add = [&](int64_t x, int64_t y) {
xs.push_back(x);
xs.push_back(x + 1);
ys.push_back(y);
ys.push_back(y + 1);
};
vector<int64_t> A(N), B(N), C(N), D(M), E(M), F(M);
for (int i = 0; i < N; i++) {
cin >> A[i] >> B[i] >> C[i];
add(A[i], C[i]);
add(B[i], C[i]);
}
for (int i = 0; i < M; i++) {
cin >> D[i] >> E[i] >> F[i];
add(D[i], E[i]);
add(D[i], F[i]);
}
xs = compress(xs);
ys = compress(ys);
auto find_x = [&](int a) -> int {
return upper_bound(xs.begin(), xs.end(), a) - xs.begin() - 1;
};
auto find_y = [&](int a) -> int {
return upper_bound(ys.begin(), ys.end(), a) - ys.begin() - 1;
};
int xsz = xs.size(), ysz = ys.size();
bitset<4001> under[4000], right[4000];
for (int i = 0; i < N; i++) {
A[i] = find_x(A[i]);
B[i] = find_x(B[i]);
C[i] = find_y(C[i]);
for (int x = A[i] + 1; x <= B[i]; x++)
right[x][C[i]] = 1;
}
for (int i = 0; i < M; i++) {
D[i] = find_x(D[i]);
E[i] = find_y(E[i]);
F[i] = find_y(F[i]);
for (int y = E[i] + 1; y <= F[i]; y++)
under[D[i]][y] = 1;
}
auto encode = [&](int i, int j) { return i * ysz + j; };
UnionFind uf(xsz * ysz);
for (int i = 0; i < xsz - 1; i++)
for (int j = 0; j < ysz - 1; j++) {
if (!under[i][j])
uf.unite(encode(i, j), encode(i + 1, j));
if (!right[i][j])
uf.unite(encode(i, j), encode(i, j + 1));
}
auto fail = []() {
cout << "INF" << endl;
exit(0);
};
int cow = encode(find_x(0), find_y(0));
int64_t ans = 0;
for (int i = 0; i < xsz; i++)
for (int j = 0; j < ysz; j++)
if (uf.same(cow, encode(i, j))) {
if (i == 0 || i == xsz - 1 || j == 0 || j == ysz - 1)
fail();
int64_t dx = xs[i + 1] - xs[i], dy = ys[j + 1] - ys[j];
ans += dx * dy;
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
template <typename T> vector<T> compress(vector<T> A) {
sort(A.begin(), A.end());
A.erase(unique(A.begin(), A.end()), A.end());
return A;
}
struct UnionFind {
vector<int> par;
vector<int> sz;
UnionFind(int n = 0) {
if (n > 0)
initialize(n);
}
void initialize(int n) {
par.resize(n);
sz.assign(n, 1);
for (int i = 0; i < n; i++) {
par[i] = i;
}
}
int find(int x) {
if (par[x] == x) {
return x;
} else {
return par[x] = find(par[x]);
}
}
bool unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return false;
if (sz[x] > sz[y])
swap(x, y);
par[x] = y;
sz[y] += sz[x];
return true;
}
bool same(int x, int y) { return find(x) == find(y); }
int size(int x) { return sz[find(x)]; }
};
int main() {
int N, M;
cin >> N >> M;
int64_t INF = 2e9;
vector<int64_t> xs = {-INF, INF}, ys = {-INF, INF};
auto add = [&](int64_t x, int64_t y) {
xs.push_back(x);
xs.push_back(x + 1);
ys.push_back(y);
ys.push_back(y + 1);
};
vector<int64_t> A(N), B(N), C(N), D(M), E(M), F(M);
for (int i = 0; i < N; i++) {
cin >> A[i] >> B[i] >> C[i];
add(A[i], C[i]);
add(B[i], C[i]);
}
for (int i = 0; i < M; i++) {
cin >> D[i] >> E[i] >> F[i];
add(D[i], E[i]);
add(D[i], F[i]);
}
xs = compress(xs);
ys = compress(ys);
auto find_x = [&](int a) -> int {
return upper_bound(xs.begin(), xs.end(), a) - xs.begin() - 1;
};
auto find_y = [&](int a) -> int {
return upper_bound(ys.begin(), ys.end(), a) - ys.begin() - 1;
};
int xsz = xs.size(), ysz = ys.size();
bitset<6100> under[6100], right[6100];
for (int i = 0; i < N; i++) {
A[i] = find_x(A[i]);
B[i] = find_x(B[i]);
C[i] = find_y(C[i]);
for (int x = A[i] + 1; x <= B[i]; x++)
right[x][C[i]] = 1;
}
for (int i = 0; i < M; i++) {
D[i] = find_x(D[i]);
E[i] = find_y(E[i]);
F[i] = find_y(F[i]);
for (int y = E[i] + 1; y <= F[i]; y++)
under[D[i]][y] = 1;
}
auto encode = [&](int i, int j) { return i * ysz + j; };
UnionFind uf(xsz * ysz);
for (int i = 0; i < xsz - 1; i++)
for (int j = 0; j < ysz - 1; j++) {
if (!under[i][j])
uf.unite(encode(i, j), encode(i + 1, j));
if (!right[i][j])
uf.unite(encode(i, j), encode(i, j + 1));
}
auto fail = []() {
cout << "INF" << endl;
exit(0);
};
int cow = encode(find_x(0), find_y(0));
int64_t ans = 0;
for (int i = 0; i < xsz; i++)
for (int j = 0; j < ysz; j++)
if (uf.same(cow, encode(i, j))) {
if (i == 0 || i == xsz - 1 || j == 0 || j == ysz - 1)
fail();
int64_t dx = xs[i + 1] - xs[i], dy = ys[j + 1] - ys[j];
ans += dx * dy;
}
cout << ans << endl;
return 0;
}
| replace | 81 | 82 | 81 | 82 | 0 | |
p02680 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <cstdint>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
template <typename T> void fin(T const &t) {
std::cout << t << std::endl;
exit(0);
}
struct line {
int64_t p, q, r;
line() {}
};
void su(std::vector<int> &v) {
std::sort(v.begin(), v.end());
v.erase(std::unique(v.begin(), v.end()), v.end());
}
int main() {
int N, M;
std::cin >> N >> M;
std::vector<int> xs(M), ys(N);
std::vector<line> hL(N), vL(M);
// (p...q, r) / (p, q...r)
for (int i = 0; i < N; ++i) {
std::cin >> hL[i].p >> hL[i].q >> hL[i].r;
ys[i] = hL[i].r;
}
for (int i = 0; i < M; ++i) {
std::cin >> vL[i].p >> vL[i].q >> vL[i].r;
xs[i] = vL[i].p;
}
su(xs);
su(ys);
if (xs[0] >= 0 || xs.back() <= 0 || ys[0] >= 0 || ys.back() <= 0)
fin("INF");
// walls
int XS = xs.size(), YS = ys.size();
std::vector<std::vector<int>> hW(YS, std::vector<int>(XS, 0)),
vW(YS, std::vector<int>(YS, 0));
for (auto const &w : hL) { // w.p < w.q : given
int x1 = std::max(
0, (int)(std::lower_bound(xs.begin(), xs.end(), w.p) - xs.begin()));
int x2 = std::min(XS, (int)(std::upper_bound(xs.begin(), xs.end(), w.q) -
xs.begin())) -
1;
if (x2 <= 0 || x1 >= XS - 1)
continue;
int y = std::lower_bound(ys.begin(), ys.end(), w.r) - ys.begin();
assert(0 <= y && y <= YS - 1);
assert(0 <= x1 && x1 <= XS - 2);
assert(1 <= x2 && x2 <= XS - 1);
++hW[y][x1];
--hW[y][x2];
}
for (auto const &w : vL) { // w.q < w.r : given
int x = std::lower_bound(xs.begin(), xs.end(), w.p) - xs.begin();
int y1 = std::max(
0, (int)(std::lower_bound(ys.begin(), ys.end(), w.q) - ys.begin()));
int y2 = std::min(YS, (int)(std::upper_bound(ys.begin(), ys.end(), w.r) -
ys.begin())) -
1;
if (y2 <= 0 || y1 >= YS - 1)
continue;
assert(0 <= x && x <= XS - 1);
assert(0 <= y1 && y1 <= YS - 2);
assert(1 <= y2 && y2 <= YS - 1);
++vW[y1][x];
--vW[y2][x];
}
for (int y = 0; y < YS; ++y)
for (int x = 1; x < XS; ++x)
hW[y][x] += hW[y][x - 1];
for (int x = 0; x < XS; ++x)
for (int y = 1; y < YS; ++y)
vW[y][x] += vW[y - 1][x];
// bfs
std::vector<std::vector<bool>> visited(YS - 1,
std::vector<bool>(XS - 1, false));
std::queue<std::pair<int, int>> q;
int x = std::lower_bound(xs.begin(), xs.end(), 0) - xs.begin() - 1;
int y = std::lower_bound(ys.begin(), ys.end(), 0) - ys.begin() - 1;
q.push(std::make_pair(x, y));
while (!q.empty()) {
auto const &p = q.front();
x = p.first;
y = p.second;
q.pop();
if (visited[y][x])
continue;
visited[y][x] = true;
// ydec
if (hW[y][x] < 1) {
if (y <= 0)
fin("INF");
if (!visited[y - 1][x])
q.push(std::make_pair(x, y - 1));
}
// yinc
if (hW[y + 1][x] < 1) {
if (y >= YS - 2)
fin("INF");
if (!visited[y + 1][x])
q.push(std::make_pair(x, y + 1));
}
// xdec
if (vW[y][x] < 1) {
if (x <= 0)
fin("INF");
if (!visited[y][x - 1])
q.push(std::make_pair(x - 1, y));
}
// xinc
if (vW[y][x + 1] < 1) {
if (x >= XS - 2)
fin("INF");
if (!visited[y][x + 1])
q.push(std::make_pair(x + 1, y));
}
}
// calc area
int64_t ans = 0;
for (int y = 0; y < YS - 1; ++y)
for (int x = 0; x < XS - 1; ++x)
if (visited[y][x]) {
ans += (int64_t)(xs[x + 1] - xs[x]) * (ys[y + 1] - ys[y]);
}
fin(ans);
return 0;
}
| #include <algorithm>
#include <cassert>
#include <cstdint>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
template <typename T> void fin(T const &t) {
std::cout << t << std::endl;
exit(0);
}
struct line {
int64_t p, q, r;
line() {}
};
void su(std::vector<int> &v) {
std::sort(v.begin(), v.end());
v.erase(std::unique(v.begin(), v.end()), v.end());
}
int main() {
int N, M;
std::cin >> N >> M;
std::vector<int> xs(M), ys(N);
std::vector<line> hL(N), vL(M);
// (p...q, r) / (p, q...r)
for (int i = 0; i < N; ++i) {
std::cin >> hL[i].p >> hL[i].q >> hL[i].r;
ys[i] = hL[i].r;
}
for (int i = 0; i < M; ++i) {
std::cin >> vL[i].p >> vL[i].q >> vL[i].r;
xs[i] = vL[i].p;
}
su(xs);
su(ys);
if (xs[0] >= 0 || xs.back() <= 0 || ys[0] >= 0 || ys.back() <= 0)
fin("INF");
// walls
int XS = xs.size(), YS = ys.size();
std::vector<std::vector<int>> hW(YS, std::vector<int>(XS, 0)),
vW(YS, std::vector<int>(XS, 0));
for (auto const &w : hL) { // w.p < w.q : given
int x1 = std::max(
0, (int)(std::lower_bound(xs.begin(), xs.end(), w.p) - xs.begin()));
int x2 = std::min(XS, (int)(std::upper_bound(xs.begin(), xs.end(), w.q) -
xs.begin())) -
1;
if (x2 <= 0 || x1 >= XS - 1)
continue;
int y = std::lower_bound(ys.begin(), ys.end(), w.r) - ys.begin();
assert(0 <= y && y <= YS - 1);
assert(0 <= x1 && x1 <= XS - 2);
assert(1 <= x2 && x2 <= XS - 1);
++hW[y][x1];
--hW[y][x2];
}
for (auto const &w : vL) { // w.q < w.r : given
int x = std::lower_bound(xs.begin(), xs.end(), w.p) - xs.begin();
int y1 = std::max(
0, (int)(std::lower_bound(ys.begin(), ys.end(), w.q) - ys.begin()));
int y2 = std::min(YS, (int)(std::upper_bound(ys.begin(), ys.end(), w.r) -
ys.begin())) -
1;
if (y2 <= 0 || y1 >= YS - 1)
continue;
assert(0 <= x && x <= XS - 1);
assert(0 <= y1 && y1 <= YS - 2);
assert(1 <= y2 && y2 <= YS - 1);
++vW[y1][x];
--vW[y2][x];
}
for (int y = 0; y < YS; ++y)
for (int x = 1; x < XS; ++x)
hW[y][x] += hW[y][x - 1];
for (int x = 0; x < XS; ++x)
for (int y = 1; y < YS; ++y)
vW[y][x] += vW[y - 1][x];
// bfs
std::vector<std::vector<bool>> visited(YS - 1,
std::vector<bool>(XS - 1, false));
std::queue<std::pair<int, int>> q;
int x = std::lower_bound(xs.begin(), xs.end(), 0) - xs.begin() - 1;
int y = std::lower_bound(ys.begin(), ys.end(), 0) - ys.begin() - 1;
q.push(std::make_pair(x, y));
while (!q.empty()) {
auto const &p = q.front();
x = p.first;
y = p.second;
q.pop();
if (visited[y][x])
continue;
visited[y][x] = true;
// ydec
if (hW[y][x] < 1) {
if (y <= 0)
fin("INF");
if (!visited[y - 1][x])
q.push(std::make_pair(x, y - 1));
}
// yinc
if (hW[y + 1][x] < 1) {
if (y >= YS - 2)
fin("INF");
if (!visited[y + 1][x])
q.push(std::make_pair(x, y + 1));
}
// xdec
if (vW[y][x] < 1) {
if (x <= 0)
fin("INF");
if (!visited[y][x - 1])
q.push(std::make_pair(x - 1, y));
}
// xinc
if (vW[y][x + 1] < 1) {
if (x >= XS - 2)
fin("INF");
if (!visited[y][x + 1])
q.push(std::make_pair(x + 1, y));
}
}
// calc area
int64_t ans = 0;
for (int y = 0; y < YS - 1; ++y)
for (int x = 0; x < XS - 1; ++x)
if (visited[y][x]) {
ans += (int64_t)(xs[x + 1] - xs[x]) * (ys[y + 1] - ys[y]);
}
fin(ans);
return 0;
}
| replace | 43 | 44 | 43 | 44 | 0 | |
p02680 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define forall(it, c) \
for (__typeof(c.begin()) it = c.begin(); it != c.end(); ++it)
template <typename T> inline void read(T &x) {
x = 0;
bool f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-')
f = 0;
for (; isdigit(c); c = getchar())
x = x * 10 + (c & 15);
if (!f)
x = -x;
}
const int maxn = 2e3 + 5;
const int inf = 0x3f3f3f3f;
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
int n, m;
int a[maxn], b[maxn], c[maxn];
int d[maxn], e[maxn], f[maxn];
int scol[maxn][maxn], srow[maxn][maxn];
bool vis[maxn][maxn];
int que[maxn * maxn * 2 + 5], ql, qr;
vector<int> vx, vy;
bool ok[maxn][maxn][4];
int main() {
read(n);
read(m);
rep(i, n) read(a[i]), read(b[i]), read(c[i]);
rep(i, m) read(d[i]), read(e[i]), read(f[i]);
rep(i, n) vx.pb(a[i]), vx.pb(b[i]), vy.pb(c[i]);
rep(i, m) vx.pb(d[i]), vy.pb(e[i]), vy.pb(f[i]);
vx.pb(0);
vy.pb(0);
vx.pb(inf);
vy.pb(inf);
sort(vx.begin(), vx.end());
vx.erase(unique(vx.begin(), vx.end()), vx.end());
sort(vy.begin(), vy.end());
vy.erase(unique(vy.begin(), vy.end()), vy.end());
#define f(v, x) (lower_bound((v).begin(), (v).end(), (x)) - (v).begin())
rep(i, n) a[i] = f(vx, a[i]), b[i] = f(vx, b[i]), c[i] = f(vy, c[i]);
rep(i, m) d[i] = f(vx, d[i]), e[i] = f(vy, e[i]), f[i] = f(vy, f[i]);
int sx = f(vx, 0), sy = f(vy, 0);
rep(i, n) scol[a[i]][c[i]]++, scol[b[i]][c[i]]--;
rep(i, m) srow[d[i]][e[i]]++, srow[d[i]][f[i]]--;
rep(i, vx.size()) rep(j, vy.size()) if (i) scol[i][j] += scol[i - 1][j];
rep(i, vx.size()) rep(j, vy.size()) if (j) srow[i][j] += srow[i][j - 1];
rep(i, vx.size() - 1) rep(j, vy.size() - 1) {
// up
if (srow[i][j])
ok[i][j][0] = 0;
else
ok[i][j][0] = 1;
// dn
if (srow[i + 1][j])
ok[i][j][1] = 0;
else
ok[i][j][1] = 1;
// lft
if (scol[i][j])
ok[i][j][2] = 0;
else
ok[i][j][2] = 1;
// rgt
if (scol[i][j + 1])
ok[i][j][3] = 0;
else
ok[i][j][3] = 1;
}
// rep(i, vx.size()) printf("%d ", vx[i]); puts("");
// rep(i, vy.size()) printf("%d ", vy[i]); puts("");
vis[sx][sy] = 1;
que[qr++] = sx;
que[qr++] = sy;
ll ans = 0;
while (ql < qr) {
int x = que[ql++], y = que[ql++];
// eprintf("[%d, %d) [%d, %d) rec\n", vx[x], vx[x + 1], vy[y], vy[y +
//1]);
ans += 1LL * (vx[x + 1] - vx[x]) * (vy[y + 1] - vy[y]);
rep(d, 4) {
if (!ok[x][y][d])
continue;
int nx = x + dx[d], ny = y + dy[d];
// eprintf(" -> %d %d\n", nx, ny);
if (nx < 0 || ny < 0 || nx >= vx.size() - 1 || ny >= vy.size() - 1) {
puts("INF");
return 0;
}
if (!vis[nx][ny]) {
vis[nx][ny] = 1;
que[qr++] = nx;
que[qr++] = ny;
}
}
}
printf("%lld\n", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define forall(it, c) \
for (__typeof(c.begin()) it = c.begin(); it != c.end(); ++it)
template <typename T> inline void read(T &x) {
x = 0;
bool f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-')
f = 0;
for (; isdigit(c); c = getchar())
x = x * 10 + (c & 15);
if (!f)
x = -x;
}
const int maxn = 3e3 + 5;
const int inf = 0x3f3f3f3f;
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
int n, m;
int a[maxn], b[maxn], c[maxn];
int d[maxn], e[maxn], f[maxn];
int scol[maxn][maxn], srow[maxn][maxn];
bool vis[maxn][maxn];
int que[maxn * maxn * 2 + 5], ql, qr;
vector<int> vx, vy;
bool ok[maxn][maxn][4];
int main() {
read(n);
read(m);
rep(i, n) read(a[i]), read(b[i]), read(c[i]);
rep(i, m) read(d[i]), read(e[i]), read(f[i]);
rep(i, n) vx.pb(a[i]), vx.pb(b[i]), vy.pb(c[i]);
rep(i, m) vx.pb(d[i]), vy.pb(e[i]), vy.pb(f[i]);
vx.pb(0);
vy.pb(0);
vx.pb(inf);
vy.pb(inf);
sort(vx.begin(), vx.end());
vx.erase(unique(vx.begin(), vx.end()), vx.end());
sort(vy.begin(), vy.end());
vy.erase(unique(vy.begin(), vy.end()), vy.end());
#define f(v, x) (lower_bound((v).begin(), (v).end(), (x)) - (v).begin())
rep(i, n) a[i] = f(vx, a[i]), b[i] = f(vx, b[i]), c[i] = f(vy, c[i]);
rep(i, m) d[i] = f(vx, d[i]), e[i] = f(vy, e[i]), f[i] = f(vy, f[i]);
int sx = f(vx, 0), sy = f(vy, 0);
rep(i, n) scol[a[i]][c[i]]++, scol[b[i]][c[i]]--;
rep(i, m) srow[d[i]][e[i]]++, srow[d[i]][f[i]]--;
rep(i, vx.size()) rep(j, vy.size()) if (i) scol[i][j] += scol[i - 1][j];
rep(i, vx.size()) rep(j, vy.size()) if (j) srow[i][j] += srow[i][j - 1];
rep(i, vx.size() - 1) rep(j, vy.size() - 1) {
// up
if (srow[i][j])
ok[i][j][0] = 0;
else
ok[i][j][0] = 1;
// dn
if (srow[i + 1][j])
ok[i][j][1] = 0;
else
ok[i][j][1] = 1;
// lft
if (scol[i][j])
ok[i][j][2] = 0;
else
ok[i][j][2] = 1;
// rgt
if (scol[i][j + 1])
ok[i][j][3] = 0;
else
ok[i][j][3] = 1;
}
// rep(i, vx.size()) printf("%d ", vx[i]); puts("");
// rep(i, vy.size()) printf("%d ", vy[i]); puts("");
vis[sx][sy] = 1;
que[qr++] = sx;
que[qr++] = sy;
ll ans = 0;
while (ql < qr) {
int x = que[ql++], y = que[ql++];
// eprintf("[%d, %d) [%d, %d) rec\n", vx[x], vx[x + 1], vy[y], vy[y +
//1]);
ans += 1LL * (vx[x + 1] - vx[x]) * (vy[y + 1] - vy[y]);
rep(d, 4) {
if (!ok[x][y][d])
continue;
int nx = x + dx[d], ny = y + dy[d];
// eprintf(" -> %d %d\n", nx, ny);
if (nx < 0 || ny < 0 || nx >= vx.size() - 1 || ny >= vy.size() - 1) {
puts("INF");
return 0;
}
if (!vis[nx][ny]) {
vis[nx][ny] = 1;
que[qr++] = nx;
que[qr++] = ny;
}
}
}
printf("%lld\n", ans);
return 0;
}
| replace | 25 | 26 | 25 | 26 | 0 | |
p02680 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for (llint(x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for (llint(x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007
using namespace std;
typedef pair<llint, llint> P;
llint n, m;
llint u[1005], d[1005], x[1005];
llint l[1005], r[1005], y[1005];
llint h, w;
bool wall[6005][6005], used[6005][6005];
vector<llint> compX, compY;
llint dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
void comp(vector<llint> &vec) {
sort(vec.begin(), vec.end());
vec.erase(unique(vec.begin(), vec.end()), vec.end());
}
llint get(vector<llint> &vec, llint x) {
return lower_bound(vec.begin(), vec.end(), x) - vec.begin();
}
void dfs(int x, int y) {
used[x][y] = true;
for (int i = 0; i < 4; i++) {
int nx = x + dx[i], ny = y + dy[i];
if (nx < 0 || nx >= w || ny < 0 || ny >= h)
continue;
if (used[nx][ny] || wall[nx][ny])
continue;
dfs(nx, ny);
}
}
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> u[i] >> d[i] >> x[i];
for (int i = 1; i <= m; i++)
cin >> y[i] >> l[i] >> r[i];
compX.push_back(-2e9);
compX.push_back(2e9);
compY.push_back(-2e9);
compY.push_back(2e9);
for (int i = 1; i <= n; i++) {
compX.push_back(x[i]);
compY.push_back(u[i]);
compY.push_back(d[i]);
}
for (int i = 1; i <= m; i++) {
compY.push_back(y[i]);
compX.push_back(l[i]);
compX.push_back(r[i]);
}
comp(compX), comp(compY);
w = compX.size() * 2, h = compY.size() * 2;
for (int i = 1; i <= n; i++) {
llint U = get(compY, u[i]) * 2, D = get(compY, d[i]) * 2,
X = get(compX, x[i]) * 2;
for (int j = U; j <= D; j++)
wall[X][j] = true;
}
for (int i = 1; i <= m; i++) {
llint L = get(compX, l[i]) * 2, R = get(compX, r[i]) * 2,
Y = get(compY, y[i]) * 2;
for (int j = L; j <= R; j++)
wall[j][Y] = true;
}
/*for(int y = 0; y < h; y++){
for(int x = 0; x < w; x++){
cout << wall[x][y];
}
cout << endl;
}*/
llint sx = get(compX, 0) * 2 - 1, sy = get(compY, 0) * 2 - 1;
dfs(sx, sy);
llint ans = 0;
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
if (!used[x][y])
continue;
if (x == 0 || x >= w - 2 || y == 0 || y >= h - 2) {
cout << "INF" << endl;
return 0;
}
if (x % 2 == 0 || y % 2 == 0)
continue;
llint X = x / 2, Y = y / 2;
if (X + 1 >= compX.size() || Y + 1 >= compY.size()) {
cout << "INF" << endl;
return 0;
}
ans += (compX[X + 1] - compX[X]) * (compY[Y + 1] - compY[Y]);
}
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for (llint(x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for (llint(x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007
using namespace std;
typedef pair<llint, llint> P;
llint n, m;
llint u[1005], d[1005], x[1005];
llint l[1005], r[1005], y[1005];
llint h, w;
bool wall[6005][6005], used[6005][6005];
vector<llint> compX, compY;
llint dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
void comp(vector<llint> &vec) {
sort(vec.begin(), vec.end());
vec.erase(unique(vec.begin(), vec.end()), vec.end());
}
llint get(vector<llint> &vec, llint x) {
return lower_bound(vec.begin(), vec.end(), x) - vec.begin();
}
void dfs(int x, int y) {
used[x][y] = true;
queue<P> Q;
Q.push(P(x, y));
while (Q.size()) {
x = Q.front().first, y = Q.front().second;
Q.pop();
for (int i = 0; i < 4; i++) {
int nx = x + dx[i], ny = y + dy[i];
if (nx < 0 || nx >= w || ny < 0 || ny >= h)
continue;
if (used[nx][ny] || wall[nx][ny])
continue;
used[nx][ny] = true;
Q.push(P(nx, ny));
}
}
}
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++)
cin >> u[i] >> d[i] >> x[i];
for (int i = 1; i <= m; i++)
cin >> y[i] >> l[i] >> r[i];
compX.push_back(-2e9);
compX.push_back(2e9);
compY.push_back(-2e9);
compY.push_back(2e9);
for (int i = 1; i <= n; i++) {
compX.push_back(x[i]);
compY.push_back(u[i]);
compY.push_back(d[i]);
}
for (int i = 1; i <= m; i++) {
compY.push_back(y[i]);
compX.push_back(l[i]);
compX.push_back(r[i]);
}
comp(compX), comp(compY);
w = compX.size() * 2, h = compY.size() * 2;
for (int i = 1; i <= n; i++) {
llint U = get(compY, u[i]) * 2, D = get(compY, d[i]) * 2,
X = get(compX, x[i]) * 2;
for (int j = U; j <= D; j++)
wall[X][j] = true;
}
for (int i = 1; i <= m; i++) {
llint L = get(compX, l[i]) * 2, R = get(compX, r[i]) * 2,
Y = get(compY, y[i]) * 2;
for (int j = L; j <= R; j++)
wall[j][Y] = true;
}
/*for(int y = 0; y < h; y++){
for(int x = 0; x < w; x++){
cout << wall[x][y];
}
cout << endl;
}*/
llint sx = get(compX, 0) * 2 - 1, sy = get(compY, 0) * 2 - 1;
dfs(sx, sy);
llint ans = 0;
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
if (!used[x][y])
continue;
if (x == 0 || x >= w - 2 || y == 0 || y >= h - 2) {
cout << "INF" << endl;
return 0;
}
if (x % 2 == 0 || y % 2 == 0)
continue;
llint X = x / 2, Y = y / 2;
if (X + 1 >= compX.size() || Y + 1 >= compY.size()) {
cout << "INF" << endl;
return 0;
}
ans += (compX[X + 1] - compX[X]) * (compY[Y + 1] - compY[Y]);
}
}
cout << ans << endl;
return 0;
} | replace | 47 | 54 | 47 | 62 | 0 | |
p02680 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define all(v) v.begin(), v.end()
using namespace std;
ll a[2000], b[2000], c[2000];
ll d[2000], e[2000], f[2000];
int ngx[2000][2000];
int ngy[2000][2000];
bool visit[2000][2000];
ll ind(int key, const vector<int> &v) {
return lower_bound(all(v), key) - v.begin();
}
int main() {
int n, m;
cin >> n >> m;
vector<int> x, y;
rep(i, n) {
cin >> a[i] >> b[i] >> c[i];
x.push_back(a[i]);
x.pb(b[i]);
y.push_back(c[i]);
}
rep(i, m) {
cin >> d[i] >> e[i] >> f[i];
x.push_back(d[i]);
y.pb(e[i]);
y.push_back(f[i]);
}
sort(all(x));
sort(all(y));
x.erase(unique(all(x)), x.end());
y.erase(unique(all(y)), y.end());
rep(i, n) {
int from = ind(a[i], x);
int to = ind(b[i], x);
int ycor = ind(c[i], y);
FOR(j, from, to) { ngx[j][ycor] = true; }
}
rep(i, m) {
int from = ind(e[i], y);
int to = ind(f[i], y);
int xcor = ind(d[i], x);
FOR(j, from, to) { ngy[xcor][j] = true; }
}
int xs = ind(0, x) - 1;
int ys = ind(0, y) - 1;
queue<pair<int, int>> q;
q.emplace(xs, ys);
ll res = 0;
int w = x.size();
int h = y.size();
while (!q.empty()) {
int xx = q.front().first;
int yy = q.front().second;
q.pop();
if (xx < 0 || yy < 0 || xx >= w - 1 || yy >= h - 1) {
cout << "INF" << endl;
return 0;
}
if (visit[xx][yy])
continue;
res += ((ll)x[xx + 1] - x[xx]) * ((ll)y[yy + 1] - y[yy]);
if (!ngx[xx][yy])
q.emplace(xx, yy - 1);
if (!ngx[xx][yy + 1])
q.emplace(xx, yy + 1);
if (!ngy[xx][yy])
q.emplace(xx - 1, yy);
if (!ngy[xx + 1][yy])
q.emplace(xx + 1, yy);
visit[xx][yy] = 1;
}
cout << res << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define all(v) v.begin(), v.end()
using namespace std;
ll a[3007], b[3007], c[3007];
ll d[3007], e[3007], f[3007];
int ngx[3007][3007];
int ngy[3007][3007];
bool visit[3007][3007];
ll ind(int key, const vector<int> &v) {
return lower_bound(all(v), key) - v.begin();
}
int main() {
int n, m;
cin >> n >> m;
vector<int> x, y;
rep(i, n) {
cin >> a[i] >> b[i] >> c[i];
x.push_back(a[i]);
x.pb(b[i]);
y.push_back(c[i]);
}
rep(i, m) {
cin >> d[i] >> e[i] >> f[i];
x.push_back(d[i]);
y.pb(e[i]);
y.push_back(f[i]);
}
sort(all(x));
sort(all(y));
x.erase(unique(all(x)), x.end());
y.erase(unique(all(y)), y.end());
rep(i, n) {
int from = ind(a[i], x);
int to = ind(b[i], x);
int ycor = ind(c[i], y);
FOR(j, from, to) { ngx[j][ycor] = true; }
}
rep(i, m) {
int from = ind(e[i], y);
int to = ind(f[i], y);
int xcor = ind(d[i], x);
FOR(j, from, to) { ngy[xcor][j] = true; }
}
int xs = ind(0, x) - 1;
int ys = ind(0, y) - 1;
queue<pair<int, int>> q;
q.emplace(xs, ys);
ll res = 0;
int w = x.size();
int h = y.size();
while (!q.empty()) {
int xx = q.front().first;
int yy = q.front().second;
q.pop();
if (xx < 0 || yy < 0 || xx >= w - 1 || yy >= h - 1) {
cout << "INF" << endl;
return 0;
}
if (visit[xx][yy])
continue;
res += ((ll)x[xx + 1] - x[xx]) * ((ll)y[yy + 1] - y[yy]);
if (!ngx[xx][yy])
q.emplace(xx, yy - 1);
if (!ngx[xx][yy + 1])
q.emplace(xx, yy + 1);
if (!ngy[xx][yy])
q.emplace(xx - 1, yy);
if (!ngy[xx + 1][yy])
q.emplace(xx + 1, yy);
visit[xx][yy] = 1;
}
cout << res << endl;
return 0;
}
| replace | 22 | 27 | 22 | 27 | 0 | |
p02680 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) begin(v), end(v)
#define fi first
#define se second
template <typename A, typename B> inline bool chmax(A &a, B b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename A, typename B> inline bool chmin(A &a, B b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll << 30;
constexpr ll longINF = 1ll << 60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//
int main() {
int N, M;
cin >> N >> M;
vector<int> A(N), B(N), C(N);
REP(i, N) scanf("%d %d %d", &A[i], &B[i], &C[i]);
vector<int> D(N), E(N), F(N);
REP(i, M) scanf("%d %d %d", &D[i], &E[i], &F[i]);
vector<int> cx, cy;
cx.emplace_back(-INF);
cx.emplace_back(INF);
cy.emplace_back(-INF);
cy.emplace_back(INF);
REP(i, N) {
cx.emplace_back(A[i]);
cx.emplace_back(B[i]);
cy.emplace_back(C[i]);
}
REP(i, M) {
cx.emplace_back(D[i]);
cy.emplace_back(E[i]);
cy.emplace_back(F[i]);
}
sort(ALL(cx));
cx.erase(unique(ALL(cx)), cx.end());
sort(ALL(cy));
cy.erase(unique(ALL(cy)), cy.end());
auto compress = [](auto &x, const auto &cx) {
for (auto &c : x)
c = lower_bound(ALL(cx), c) - cx.begin();
};
compress(A, cx);
compress(B, cx);
compress(C, cy);
compress(D, cx);
compress(E, cy);
compress(F, cy);
vector<vector<bool>> isok[4], maps(cy.size(), vector<bool>(cx.size())),
done = maps;
// isok[urdl]
REP(i, 4) isok[i] = vector<vector<bool>>(cy.size(), vector<bool>(cx.size()));
int dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0};
REP(dir, 4) REP(i, cy.size()) REP(j, cx.size()) {
int ny = i + dy[dir], nx = j + dx[dir];
isok[dir][i][j] = nx >= 0 && nx < cx.size() && ny >= 0 && ny < cy.size();
}
REP(i, N) {
int y = C[i];
FOR(x, A[i] + 1, B[i] + 1) { isok[2][y][x] = isok[0][y + 1][x] = false; }
}
REP(i, M) {
int x = D[i];
FOR(y, E[i] + 1, F[i] + 1) { isok[1][y][x] = isok[3][y][x + 1] = false; }
}
int stx = lower_bound(ALL(cx), 0) - cx.begin(),
sty = lower_bound(ALL(cy), 0) - cy.begin();
queue<pii> que;
que.emplace(sty, stx);
done[sty][stx] = true;
ll ans = 0;
while (!que.empty()) {
int y = que.front().fi, x = que.front().se;
que.pop();
if (abs(cx[x]) == INF || abs(cy[y]) == INF) {
puts("INF");
return 0;
}
ans += (ll)(cy[y] - cy[y - 1]) * (cx[x] - cx[x - 1]);
REP(dir, 4) if (isok[dir][y][x]) {
int ny = y + dy[dir], nx = x + dx[dir];
if (!done[ny][nx]) {
done[ny][nx] = true;
que.emplace(ny, nx);
}
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) begin(v), end(v)
#define fi first
#define se second
template <typename A, typename B> inline bool chmax(A &a, B b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename A, typename B> inline bool chmin(A &a, B b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll << 30;
constexpr ll longINF = 1ll << 60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//
int main() {
int N, M;
cin >> N >> M;
vector<int> A(N), B(N), C(N);
REP(i, N) scanf("%d %d %d", &A[i], &B[i], &C[i]);
vector<int> D(M), E(M), F(M);
REP(i, M) scanf("%d %d %d", &D[i], &E[i], &F[i]);
vector<int> cx, cy;
cx.emplace_back(-INF);
cx.emplace_back(INF);
cy.emplace_back(-INF);
cy.emplace_back(INF);
REP(i, N) {
cx.emplace_back(A[i]);
cx.emplace_back(B[i]);
cy.emplace_back(C[i]);
}
REP(i, M) {
cx.emplace_back(D[i]);
cy.emplace_back(E[i]);
cy.emplace_back(F[i]);
}
sort(ALL(cx));
cx.erase(unique(ALL(cx)), cx.end());
sort(ALL(cy));
cy.erase(unique(ALL(cy)), cy.end());
auto compress = [](auto &x, const auto &cx) {
for (auto &c : x)
c = lower_bound(ALL(cx), c) - cx.begin();
};
compress(A, cx);
compress(B, cx);
compress(C, cy);
compress(D, cx);
compress(E, cy);
compress(F, cy);
vector<vector<bool>> isok[4], maps(cy.size(), vector<bool>(cx.size())),
done = maps;
// isok[urdl]
REP(i, 4) isok[i] = vector<vector<bool>>(cy.size(), vector<bool>(cx.size()));
int dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0};
REP(dir, 4) REP(i, cy.size()) REP(j, cx.size()) {
int ny = i + dy[dir], nx = j + dx[dir];
isok[dir][i][j] = nx >= 0 && nx < cx.size() && ny >= 0 && ny < cy.size();
}
REP(i, N) {
int y = C[i];
FOR(x, A[i] + 1, B[i] + 1) { isok[2][y][x] = isok[0][y + 1][x] = false; }
}
REP(i, M) {
int x = D[i];
FOR(y, E[i] + 1, F[i] + 1) { isok[1][y][x] = isok[3][y][x + 1] = false; }
}
int stx = lower_bound(ALL(cx), 0) - cx.begin(),
sty = lower_bound(ALL(cy), 0) - cy.begin();
queue<pii> que;
que.emplace(sty, stx);
done[sty][stx] = true;
ll ans = 0;
while (!que.empty()) {
int y = que.front().fi, x = que.front().se;
que.pop();
if (abs(cx[x]) == INF || abs(cy[y]) == INF) {
puts("INF");
return 0;
}
ans += (ll)(cy[y] - cy[y - 1]) * (cx[x] - cx[x - 1]);
REP(dir, 4) if (isok[dir][y][x]) {
int ny = y + dy[dir], nx = x + dx[dir];
if (!done[ny][nx]) {
done[ny][nx] = true;
que.emplace(ny, nx);
}
}
}
cout << ans << endl;
return 0;
}
| replace | 34 | 35 | 34 | 35 | 0 | |
p02680 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod = 1000000007, MAX = 10000005;
const ll INF = mod;
struct UF {
int n;
vector<int> par, size;
vector<ll> S;
void init(int n_) {
n = n_;
par.assign(n, -1);
size.assign(n, 1);
S.assign(n, 0);
for (int i = 0; i < n; i++) {
par[i] = i;
}
}
int root(int a) {
if (par[a] == a)
return a;
else
return par[a] = root(par[a]);
}
void unite(int a, int b) {
if (root(a) != root(b)) {
size[root(a)] += size[root(b)];
S[root(a)] += S[root(b)];
par[root(b)] = root(a);
}
}
bool check(int a, int b) { return root(a) == root(b); }
};
bool out[MAX][2];
int main() {
std::ifstream in("text.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
map<ll, int> MX, MY;
vector<ll> X1(N + M + 5), X2(N + M + 5), Y1(N + M + 5), Y2(N + M + 5);
UF uf;
for (int i = 0; i < N + M; i++) {
int a, b, c;
cin >> a >> b >> c;
/*a*=100000000;
b*=100000000;
c*=100000000;*/
if (i < N) {
MX[a] = 1;
MX[b] = 1;
MY[c] = 1;
X1[i] = a;
X2[i] = b;
Y1[i] = c;
Y2[i] = c;
} else {
MY[b] = 1;
MY[c] = 1;
MX[a] = 1;
X1[i] = a;
X2[i] = a;
Y1[i] = b;
Y2[i] = c;
}
}
MX[0] = 1;
MY[0] = 1;
MX[INF] = 1;
MX[-INF] = 1;
MY[INF] = 1;
MY[-INF] = 1;
X1[N + M + 1] = -INF;
X2[N + M + 1] = INF;
X1[N + M + 2] = -INF;
X2[N + M + 2] = INF;
X1[N + M + 3] = -INF;
X2[N + M + 3] = -INF;
X1[N + M + 4] = INF;
X2[N + M + 4] = INF;
Y1[N + M + 1] = -INF;
Y2[N + M + 1] = -INF;
Y1[N + M + 2] = INF;
Y2[N + M + 2] = INF;
Y1[N + M + 3] = -INF;
Y2[N + M + 3] = INF;
Y1[N + M + 4] = -INF;
Y2[N + M + 4] = INF;
int idx = 1, idy = 1;
for (auto it = MX.begin(); it != MX.end(); it++, idx++) {
MX[(*it).first] = idx;
// cout<<(*it).first<<" ";
}
// cout<<endl;
for (auto it = MY.begin(); it != MY.end(); it++, idy++) {
MY[(*it).first] = idy;
// cout<<(*it).first<<" ";
}
// cout<<endl;
for (int i = 0; i < N + M + 5; i++) {
X1[i] = MX[X1[i]];
Y1[i] = MY[Y1[i]];
X2[i] = MX[X2[i]];
Y2[i] = MY[Y2[i]];
}
vector<ll> xpos(idx - 1, INF), ypos(idy - 1, INF);
for (auto x : MX) {
xpos[x.se - 1] = x.fi;
}
for (auto y : MY) {
ypos[y.se - 1] = y.fi;
}
/*for(int i=0;i<idx-1;i++){
cout<<xpos[i]<<" ";
}
cout<<endl;
for(int i=0;i<idy-1;i++){
cout<<ypos[i]<<" ";
}
cout<<endl;*/
uf.init(idx * idy);
for (int i = 0; i < idx - 2; i++) {
for (int j = 0; j < idy - 2; j++) {
uf.S[(i + 1) + (j + 1) * idx] =
(xpos[i + 1] - xpos[i]) * (ypos[j + 1] - ypos[j]);
// cout<<i<<" "<<j<<" "<<uf.S[i+j*idx]<<endl;
}
// cout<<endl;
}
// vector<pair<int,int>> out;
for (int i = 0; i < N + M + 5; i++) {
for (int j = Y1[i]; j < Y2[i]; j++) {
out[X1[i] - 1 + j * idx][0] = 1;
out[X2[i] - i + j * idx][0] = 1;
// out.push_back({X1[i]-1+j*idx,X1[i]+j*idx});
// out.push_back({X2[i]-1+j*idx,X2[i]+j*idx});
}
for (int j = X1[i]; j < X2[i]; j++) {
out[j + (Y1[i] - 1) * idx][1] = 1;
out[j + (Y2[i] - 1) * idx][1] = 1;
// out.push_back({j+(Y1[i]-1)*idx,j+Y1[i]*idx});
// out.push_back({j+(Y2[i]-1)*idx,j+Y2[i]*idx});
}
}
for (int j = 0; j < idy; j++) {
for (int i = 0; i + 1 < idx; i++) {
if (out[i + j * idx][0] == 0) {
uf.unite(i + j * idx, i + 1 + j * idx);
// cout<<i<<" "<<j<<endl;
}
}
}
for (int i = 0; i < idx; i++) {
for (int j = 0; j + 1 < idy; j++) {
if (out[i + j * idx][1] == 0) {
uf.unite(i + j * idx, i + (j + 1) * idx);
// cout<<i<<" "<<j<<endl;
}
}
}
// cout<<idx<<" "<<idy<<endl;
// cout<<X1[N+M]<<" "<<Y1[N+M]<<endl;
if (uf.check(X1[N + M] + Y1[N + M] * idx, 1 + idx))
cout << "INF\n";
else
cout << uf.S[uf.root(X1[N + M] + Y1[N + M] * idx)] << endl;
/*for(int i=0;i<idx;i++){
for(int j=0;j<idy;j++){
if(uf.S[uf.root(i+j*idx)]>=10000) cout<<"INF ";
else cout<<uf.S[uf.root(i+j*idx)]<<" ";
}
cout<<endl;
}
for(int i=0;i<N+M+5;i++){
cout<<X1[i]<<" "<<X2[i]<<" "<<Y1[i]<<" "<<Y2[i]<<endl;
}*/
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod = 1000000007, MAX = 10000005;
const ll INF = mod;
struct UF {
int n;
vector<int> par, size;
vector<ll> S;
void init(int n_) {
n = n_;
par.assign(n, -1);
size.assign(n, 1);
S.assign(n, 0);
for (int i = 0; i < n; i++) {
par[i] = i;
}
}
int root(int a) {
if (par[a] == a)
return a;
else
return par[a] = root(par[a]);
}
void unite(int a, int b) {
if (root(a) != root(b)) {
size[root(a)] += size[root(b)];
S[root(a)] += S[root(b)];
par[root(b)] = root(a);
}
}
bool check(int a, int b) { return root(a) == root(b); }
};
bool out[MAX][2];
int main() {
std::ifstream in("text.txt");
std::cin.rdbuf(in.rdbuf());
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
map<ll, int> MX, MY;
vector<ll> X1(N + M + 5), X2(N + M + 5), Y1(N + M + 5), Y2(N + M + 5);
UF uf;
for (int i = 0; i < N + M; i++) {
int a, b, c;
cin >> a >> b >> c;
/*a*=100000000;
b*=100000000;
c*=100000000;*/
if (i < N) {
MX[a] = 1;
MX[b] = 1;
MY[c] = 1;
X1[i] = a;
X2[i] = b;
Y1[i] = c;
Y2[i] = c;
} else {
MY[b] = 1;
MY[c] = 1;
MX[a] = 1;
X1[i] = a;
X2[i] = a;
Y1[i] = b;
Y2[i] = c;
}
}
MX[0] = 1;
MY[0] = 1;
MX[INF] = 1;
MX[-INF] = 1;
MY[INF] = 1;
MY[-INF] = 1;
X1[N + M + 1] = -INF;
X2[N + M + 1] = INF;
X1[N + M + 2] = -INF;
X2[N + M + 2] = INF;
X1[N + M + 3] = -INF;
X2[N + M + 3] = -INF;
X1[N + M + 4] = INF;
X2[N + M + 4] = INF;
Y1[N + M + 1] = -INF;
Y2[N + M + 1] = -INF;
Y1[N + M + 2] = INF;
Y2[N + M + 2] = INF;
Y1[N + M + 3] = -INF;
Y2[N + M + 3] = INF;
Y1[N + M + 4] = -INF;
Y2[N + M + 4] = INF;
int idx = 1, idy = 1;
for (auto it = MX.begin(); it != MX.end(); it++, idx++) {
MX[(*it).first] = idx;
// cout<<(*it).first<<" ";
}
// cout<<endl;
for (auto it = MY.begin(); it != MY.end(); it++, idy++) {
MY[(*it).first] = idy;
// cout<<(*it).first<<" ";
}
// cout<<endl;
for (int i = 0; i < N + M + 5; i++) {
X1[i] = MX[X1[i]];
Y1[i] = MY[Y1[i]];
X2[i] = MX[X2[i]];
Y2[i] = MY[Y2[i]];
}
vector<ll> xpos(idx - 1, INF), ypos(idy - 1, INF);
for (auto x : MX) {
xpos[x.se - 1] = x.fi;
}
for (auto y : MY) {
ypos[y.se - 1] = y.fi;
}
/*for(int i=0;i<idx-1;i++){
cout<<xpos[i]<<" ";
}
cout<<endl;
for(int i=0;i<idy-1;i++){
cout<<ypos[i]<<" ";
}
cout<<endl;*/
uf.init(idx * idy);
for (int i = 0; i < idx - 2; i++) {
for (int j = 0; j < idy - 2; j++) {
uf.S[(i + 1) + (j + 1) * idx] =
(xpos[i + 1] - xpos[i]) * (ypos[j + 1] - ypos[j]);
// cout<<i<<" "<<j<<" "<<uf.S[i+j*idx]<<endl;
}
// cout<<endl;
}
// vector<pair<int,int>> out;
for (int i = 0; i < N + M + 5; i++) {
for (int j = Y1[i]; j < Y2[i]; j++) {
out[X1[i] - 1 + j * idx][0] = 1;
out[X2[i] - 1 + j * idx][0] = 1;
// out.push_back({X1[i]-1+j*idx,X1[i]+j*idx});
// out.push_back({X2[i]-1+j*idx,X2[i]+j*idx});
}
for (int j = X1[i]; j < X2[i]; j++) {
out[j + (Y1[i] - 1) * idx][1] = 1;
out[j + (Y2[i] - 1) * idx][1] = 1;
// out.push_back({j+(Y1[i]-1)*idx,j+Y1[i]*idx});
// out.push_back({j+(Y2[i]-1)*idx,j+Y2[i]*idx});
}
}
for (int j = 0; j < idy; j++) {
for (int i = 0; i + 1 < idx; i++) {
if (out[i + j * idx][0] == 0) {
uf.unite(i + j * idx, i + 1 + j * idx);
// cout<<i<<" "<<j<<endl;
}
}
}
for (int i = 0; i < idx; i++) {
for (int j = 0; j + 1 < idy; j++) {
if (out[i + j * idx][1] == 0) {
uf.unite(i + j * idx, i + (j + 1) * idx);
// cout<<i<<" "<<j<<endl;
}
}
}
// cout<<idx<<" "<<idy<<endl;
// cout<<X1[N+M]<<" "<<Y1[N+M]<<endl;
if (uf.check(X1[N + M] + Y1[N + M] * idx, 1 + idx))
cout << "INF\n";
else
cout << uf.S[uf.root(X1[N + M] + Y1[N + M] * idx)] << endl;
/*for(int i=0;i<idx;i++){
for(int j=0;j<idy;j++){
if(uf.S[uf.root(i+j*idx)]>=10000) cout<<"INF ";
else cout<<uf.S[uf.root(i+j*idx)]<<" ";
}
cout<<endl;
}
for(int i=0;i<N+M+5;i++){
cout<<X1[i]<<" "<<X2[i]<<" "<<Y1[i]<<" "<<Y2[i]<<endl;
}*/
}
| replace | 183 | 184 | 183 | 184 | 0 | |
p02680 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <ciso646>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop \
char nyaa; \
cin >> nyaa;
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define Per(i, sta, n) for (int i = n - 1; i >= sta; i--)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define per1(i, n) for (int i = n; i >= 1; i--)
#define Rep1(i, sta, n) for (int i = sta; i <= n; i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<LP, ll> edge;
typedef pair<P, P> PP;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int n, m;
set<ll> xs = {}, ys = {};
vector<ll> vx, vy;
edge hol[1010], ver[1010];
map<ll, int> ma_x, ma_y;
bool blocked[10010][10010][4];
bool visited[10010][10010];
bool isINF;
ll ans = 0;
int MAX_X, MAX_Y;
queue<P> que;
void bfs(int x, int y) {
que.push(P(x, y));
// cout << x << " " << y << endl;
if (isINF)
return;
visited[x][y] = true;
while (!que.empty()) {
int x = que.front().first, y = que.front().second;
visited[x][y] = true;
rep(k, 4) {
int nx = x + dx[k], ny = y + dy[k];
if (blocked[x][y][k])
continue;
if (nx >= 0 && ny >= 0)
if (visited[nx][ny])
continue;
if (nx < 0 || nx >= MAX_X || ny < 0 || ny >= MAX_Y) {
isINF = true;
return;
}
que.push(P(nx, ny));
}
que.pop();
}
}
void solve() {
cin >> n >> m;
rep(i, n) {
ll a, b, c;
cin >> a >> b >> c;
hol[i] = edge(LP(a, b), c);
xs.insert(c);
ys.insert(a);
ys.insert(b);
}
rep(i, m) {
ll a, b, c;
cin >> c >> a >> b;
ver[i] = edge(LP(a, b), c);
ys.insert(c);
xs.insert(a);
xs.insert(b);
}
MAX_X = xs.size() - 1;
MAX_Y = ys.size() - 1;
int id = 0;
for (ll x : xs) {
vx.push_back(x);
ma_x[x] = id;
id++;
}
id = 0;
for (ll y : ys) {
vy.push_back(y);
ma_y[y] = id;
id++;
}
rep(i, n) {
int a = ma_y[hol[i].first.first], b = ma_y[hol[i].first.second],
c = ma_x[hol[i].second];
// cout << a << " " << b << " " << c << endl;
Rep(y, a, b) {
if (c - 1 >= 0)
blocked[c - 1][y][0] = true;
blocked[c][y][1] = true;
}
}
rep(i, m) {
int a = ma_x[ver[i].first.first], b = ma_x[ver[i].first.second],
c = ma_y[ver[i].second];
Rep(x, a, b) {
if (c - 1 >= 0)
blocked[x][c - 1][2] = true;
blocked[x][c][3] = true;
}
}
// Rep(i,-1,MAX_X){
// Rep(j,-1,MAX_Y){
// cout << "(" << i << "," << j << ") (" << i+1 << "," << j << ")" <<
// " " << blocked[PP(P(i,j),P(i+1,j))] << endl; cout << "(" << i <<
// "," << j << ") (" << i << "," << j+1 << ")" << " " <<
// blocked[PP(P(i,j),P(i,j+1))] << endl;
// }
// }
// for(auto s:blocked){
// cout << "(" << s.first.first.first << "," << s.first.first.second << ")
// (" << s.first.second.first << "," << s.first.second.second << ")" <<
// endl;
// }
// cout << MAX_X << " " << MAX_Y << endl;
if (*xs.begin() >= 0 || *ys.begin() >= 0) {
cout << "INF" << endl;
return;
}
auto it_end_x = xs.end(), it_end_y = ys.end();
it_end_x--;
it_end_y--;
if (*it_end_x <= 0 || *it_end_y <= 0) {
cout << "INF" << endl;
return;
}
int sx = lower_bound(vx.begin(), vx.end(), 0) - vx.begin() - 1;
int sy = lower_bound(vy.begin(), vy.end(), 0) - vy.begin() - 1;
bfs(sx, sy);
if (isINF) {
cout << "INF" << endl;
return;
}
rep(i, MAX_X) {
rep(j, MAX_Y) {
if (visited[i][j]) {
// cout << i << " " << j << endl;
ans += (vx[i + 1] - vx[i]) * (vy[j + 1] - vy[j]);
}
}
}
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(50);
solve();
} | #include <algorithm>
#include <bitset>
#include <ciso646>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop \
char nyaa; \
cin >> nyaa;
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define Per(i, sta, n) for (int i = n - 1; i >= sta; i--)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define per1(i, n) for (int i = n; i >= 1; i--)
#define Rep1(i, sta, n) for (int i = sta; i <= n; i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<LP, ll> edge;
typedef pair<P, P> PP;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int n, m;
set<ll> xs = {}, ys = {};
vector<ll> vx, vy;
edge hol[1010], ver[1010];
map<ll, int> ma_x, ma_y;
bool blocked[10010][10010][4];
bool visited[10010][10010];
bool isINF;
ll ans = 0;
int MAX_X, MAX_Y;
queue<P> que;
void bfs(int x, int y) {
que.push(P(x, y));
// cout << x << " " << y << endl;
if (isINF)
return;
visited[x][y] = true;
while (!que.empty()) {
int x = que.front().first, y = que.front().second;
visited[x][y] = true;
rep(k, 4) {
int nx = x + dx[k], ny = y + dy[k];
if (blocked[x][y][k])
continue;
if (nx >= 0 && ny >= 0)
if (visited[nx][ny])
continue;
if (nx < 0 || nx >= MAX_X || ny < 0 || ny >= MAX_Y) {
isINF = true;
return;
}
visited[nx][ny] = true;
que.push(P(nx, ny));
}
que.pop();
}
}
void solve() {
cin >> n >> m;
rep(i, n) {
ll a, b, c;
cin >> a >> b >> c;
hol[i] = edge(LP(a, b), c);
xs.insert(c);
ys.insert(a);
ys.insert(b);
}
rep(i, m) {
ll a, b, c;
cin >> c >> a >> b;
ver[i] = edge(LP(a, b), c);
ys.insert(c);
xs.insert(a);
xs.insert(b);
}
MAX_X = xs.size() - 1;
MAX_Y = ys.size() - 1;
int id = 0;
for (ll x : xs) {
vx.push_back(x);
ma_x[x] = id;
id++;
}
id = 0;
for (ll y : ys) {
vy.push_back(y);
ma_y[y] = id;
id++;
}
rep(i, n) {
int a = ma_y[hol[i].first.first], b = ma_y[hol[i].first.second],
c = ma_x[hol[i].second];
// cout << a << " " << b << " " << c << endl;
Rep(y, a, b) {
if (c - 1 >= 0)
blocked[c - 1][y][0] = true;
blocked[c][y][1] = true;
}
}
rep(i, m) {
int a = ma_x[ver[i].first.first], b = ma_x[ver[i].first.second],
c = ma_y[ver[i].second];
Rep(x, a, b) {
if (c - 1 >= 0)
blocked[x][c - 1][2] = true;
blocked[x][c][3] = true;
}
}
// Rep(i,-1,MAX_X){
// Rep(j,-1,MAX_Y){
// cout << "(" << i << "," << j << ") (" << i+1 << "," << j << ")" <<
// " " << blocked[PP(P(i,j),P(i+1,j))] << endl; cout << "(" << i <<
// "," << j << ") (" << i << "," << j+1 << ")" << " " <<
// blocked[PP(P(i,j),P(i,j+1))] << endl;
// }
// }
// for(auto s:blocked){
// cout << "(" << s.first.first.first << "," << s.first.first.second << ")
// (" << s.first.second.first << "," << s.first.second.second << ")" <<
// endl;
// }
// cout << MAX_X << " " << MAX_Y << endl;
if (*xs.begin() >= 0 || *ys.begin() >= 0) {
cout << "INF" << endl;
return;
}
auto it_end_x = xs.end(), it_end_y = ys.end();
it_end_x--;
it_end_y--;
if (*it_end_x <= 0 || *it_end_y <= 0) {
cout << "INF" << endl;
return;
}
int sx = lower_bound(vx.begin(), vx.end(), 0) - vx.begin() - 1;
int sy = lower_bound(vy.begin(), vy.end(), 0) - vy.begin() - 1;
bfs(sx, sy);
if (isINF) {
cout << "INF" << endl;
return;
}
rep(i, MAX_X) {
rep(j, MAX_Y) {
if (visited[i][j]) {
// cout << i << " " << j << endl;
ans += (vx[i + 1] - vx[i]) * (vy[j + 1] - vy[j]);
}
}
}
cout << ans << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(50);
solve();
} | insert | 76 | 76 | 76 | 77 | TLE | |
p02680 | 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 REP(i, n) for (int i = 1; i < n; i++)
#define all(v) v.begin(), v.end()
#define P pair<int, int>
#define len(s) (int)s.size()
#define pb push_back
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
constexpr int mod = 1e9 + 7;
constexpr int inf = 3e18;
int N, M;
vector<int> xx, yy;
int A[1005], B[1005], C[1005];
int D[1005], E[1005], F[1005];
bool b[2005][2005], ng[2005][2005][4];
void idx(vector<int> &v, int &x) { x = lower_bound(all(v), x) - v.begin(); }
signed main() {
cin >> N >> M;
xx.pb(-inf);
xx.pb(inf);
xx.pb(0);
yy.pb(-inf);
yy.pb(inf);
yy.pb(0);
rep(i, N) {
cin >> A[i] >> B[i] >> C[i];
xx.pb(A[i]);
xx.pb(B[i]);
yy.pb(C[i]);
}
rep(i, M) {
cin >> D[i] >> E[i] >> F[i];
xx.pb(D[i]);
yy.pb(E[i]);
yy.pb(F[i]);
}
sort(all(xx));
xx.erase(unique(all(xx)), xx.end());
sort(all(yy));
yy.erase(unique(all(yy)), yy.end());
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
rep(i, N) {
idx(xx, A[i]);
idx(xx, B[i]);
idx(yy, C[i]);
for (int j = A[i]; j < B[i]; j++) {
ng[j][C[i]][2] = true;
ng[j][C[i] - 1][0] = true;
}
}
rep(i, M) {
idx(xx, D[i]);
idx(yy, E[i]);
idx(yy, F[i]);
for (int j = E[i]; j < F[i]; j++) {
ng[D[i]][j][3] = true;
ng[D[i] - 1][j][1] = true;
}
}
queue<P> que;
int x = lower_bound(all(xx), 0ll) - xx.begin();
int y = lower_bound(all(yy), 0ll) - yy.begin();
int ans = 0;
que.push({x, y});
while (!que.empty()) {
P p = que.front();
que.pop();
rep(i, 4) {
if (ng[p.first][p.second][i])
continue;
int nx = p.first + dx[i], ny = p.second + dy[i];
if (nx == 0 || nx == xx.size() - 1 || ny == 0 || ny == yy.size() - 1) {
cout << "INF" << endl;
return 0;
}
if (!b[nx][ny]) {
ans += (xx[nx + 1] - xx[nx]) * (yy[ny + 1] - yy[ny]);
b[nx][ny] = true;
que.push({nx, ny});
}
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i < n; i++)
#define all(v) v.begin(), v.end()
#define P pair<int, int>
#define len(s) (int)s.size()
#define pb push_back
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
constexpr int mod = 1e9 + 7;
constexpr int inf = 3e18;
int N, M;
vector<int> xx, yy;
int A[1005], B[1005], C[1005];
int D[1005], E[1005], F[1005];
bool b[4005][4005], ng[4005][4005][4];
void idx(vector<int> &v, int &x) { x = lower_bound(all(v), x) - v.begin(); }
signed main() {
cin >> N >> M;
xx.pb(-inf);
xx.pb(inf);
xx.pb(0);
yy.pb(-inf);
yy.pb(inf);
yy.pb(0);
rep(i, N) {
cin >> A[i] >> B[i] >> C[i];
xx.pb(A[i]);
xx.pb(B[i]);
yy.pb(C[i]);
}
rep(i, M) {
cin >> D[i] >> E[i] >> F[i];
xx.pb(D[i]);
yy.pb(E[i]);
yy.pb(F[i]);
}
sort(all(xx));
xx.erase(unique(all(xx)), xx.end());
sort(all(yy));
yy.erase(unique(all(yy)), yy.end());
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
rep(i, N) {
idx(xx, A[i]);
idx(xx, B[i]);
idx(yy, C[i]);
for (int j = A[i]; j < B[i]; j++) {
ng[j][C[i]][2] = true;
ng[j][C[i] - 1][0] = true;
}
}
rep(i, M) {
idx(xx, D[i]);
idx(yy, E[i]);
idx(yy, F[i]);
for (int j = E[i]; j < F[i]; j++) {
ng[D[i]][j][3] = true;
ng[D[i] - 1][j][1] = true;
}
}
queue<P> que;
int x = lower_bound(all(xx), 0ll) - xx.begin();
int y = lower_bound(all(yy), 0ll) - yy.begin();
int ans = 0;
que.push({x, y});
while (!que.empty()) {
P p = que.front();
que.pop();
rep(i, 4) {
if (ng[p.first][p.second][i])
continue;
int nx = p.first + dx[i], ny = p.second + dy[i];
if (nx == 0 || nx == xx.size() - 1 || ny == 0 || ny == yy.size() - 1) {
cout << "INF" << endl;
return 0;
}
if (!b[nx][ny]) {
ans += (xx[nx + 1] - xx[nx]) * (yy[ny + 1] - yy[ny]);
b[nx][ny] = true;
que.push({nx, ny});
}
}
}
cout << ans << endl;
}
| replace | 31 | 32 | 31 | 32 | 0 | |
p02680 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT \
cin.tie(0); \
ios::sync_with_stdio(false);
template <class T> inline bool chmax(T &a, T b) { return a = (a < b) ? b : a; }
template <class T> inline bool chmin(T &a, T b) { return a = (a > b) ? b : a; }
ll const INF = 1LL << 60;
ll const MOD = 1000000007;
const ll MAX_X = 1010;
const ll MAX_Y = 1010;
ll v_line[MAX_X][MAX_Y];
ll h_line[MAX_X][MAX_Y];
bool vis[MAX_X][MAX_Y];
int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
int main() {
INIT;
ll N, M;
cin >> N >> M;
vector<ll> A(N), B(N), C(N), D(M), E(M), F(M);
rep(i, N) { cin >> A[i] >> B[i] >> C[i]; }
rep(i, M) { cin >> D[i] >> E[i] >> F[i]; }
// 座標圧縮
vector<ll> x_dict, y_dict;
x_dict.pb(-INF);
x_dict.pb(INF);
x_dict.pb(0);
y_dict.pb(-INF);
y_dict.pb(INF);
y_dict.pb(0);
rep(i, N) {
x_dict.pb(A[i]);
x_dict.pb(B[i]);
y_dict.pb(C[i]);
}
rep(i, M) {
x_dict.pb(D[i]);
y_dict.pb(E[i]);
y_dict.pb(F[i]);
}
sort(ALL(x_dict));
x_dict.erase(unique(ALL(x_dict)), x_dict.end());
sort(ALL(y_dict));
y_dict.erase(unique(ALL(y_dict)), y_dict.end());
// repv(x_dict) { cout << *it << " "; }
// cout << endl;
// repv(y_dict) { cout << *it << " "; }
// cout << endl;
ll W = SZ(x_dict);
ll H = SZ(y_dict);
// imos法による線分の判定
rep(i, N) {
int a = lower_bound(ALL(x_dict), A[i]) - x_dict.begin();
int b = lower_bound(ALL(x_dict), B[i]) - x_dict.begin();
int c = lower_bound(ALL(y_dict), C[i]) - y_dict.begin();
// cout << "(" << A[i] << " -> " << B[i] << ", " << C[i] << ") = (" << a
// << " -> " << b << ", " << c << ")" << endl;
v_line[c][a]++;
v_line[c][b]--;
}
// cout << "----" << endl;
rep(i, M) {
int d = lower_bound(ALL(x_dict), D[i]) - x_dict.begin();
int e = lower_bound(ALL(y_dict), E[i]) - y_dict.begin();
int f = lower_bound(ALL(y_dict), F[i]) - y_dict.begin();
// cout << "(" << D[i] << ", " << E[i] << " -> " << F[i] << ") = (" << d
// << ", " << e << " -> " << f << ")" << endl;
h_line[e][d]++;
h_line[f][d]--;
}
rep(y, H) reps(x, 1, W) v_line[y][x] += v_line[y][x - 1];
rep(x, W) reps(y, 1, H) h_line[y][x] += h_line[y - 1][x];
// cout << "----" << endl;
// rep(y, H) {
// reps(x, 1, W) { cout << (v_line[y][x] == 1 ? '#' : '.') << " "; }
// cout << endl;
// }
// cout << "----" << endl;
// rep(y, H) {
// reps(x, 1, W) { cout << (h_line[y][x] == 1 ? '#' : '.') << " "; }
// cout << endl;
// }
// 座標圧縮により、x_dict, y_dictのindexを座標と再定義できる
// - 実際の面積を求めたい場合は、idx値から各dictの要素にアクセスし、
// - 前後の値を引くことにより面積を計算する
ll res = 0;
queue<pair<ll, ll>> que;
ll stx = lower_bound(ALL(x_dict), 0) - x_dict.begin();
ll sty = lower_bound(ALL(y_dict), 0) - y_dict.begin();
vis[sty][stx] = true;
que.push({stx, sty});
while (!que.empty()) {
ll ix, iy;
tie(ix, iy) = que.front();
que.pop();
if (ix == 0 || ix == W - 1) {
res = INF;
break;
}
if (iy == 0 || iy == H - 1) {
res = INF;
break;
}
res += (x_dict[ix + 1] - x_dict[ix]) * (y_dict[iy + 1] - y_dict[iy]);
rep(d, 4) {
ll ix2 = ix + dx[d];
ll iy2 = iy + dy[d];
if (0 <= ix2 && ix2 < W && 0 <= iy2 && iy2 < H && !vis[iy2][ix2]) {
if (ix == ix2) {
if (v_line[max(iy, iy2)][ix2])
continue;
} else {
if (h_line[iy][max(ix, ix2)])
continue;
}
vis[iy2][ix2] = true;
que.push({ix2, iy2});
}
}
}
if (res == INF)
cout << "INF" << endl;
else
cout << res << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT \
cin.tie(0); \
ios::sync_with_stdio(false);
template <class T> inline bool chmax(T &a, T b) { return a = (a < b) ? b : a; }
template <class T> inline bool chmin(T &a, T b) { return a = (a > b) ? b : a; }
ll const INF = 1LL << 60;
ll const MOD = 1000000007;
const ll MAX_X = 5010;
const ll MAX_Y = 5010;
ll v_line[MAX_X][MAX_Y];
ll h_line[MAX_X][MAX_Y];
bool vis[MAX_X][MAX_Y];
int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
int main() {
INIT;
ll N, M;
cin >> N >> M;
vector<ll> A(N), B(N), C(N), D(M), E(M), F(M);
rep(i, N) { cin >> A[i] >> B[i] >> C[i]; }
rep(i, M) { cin >> D[i] >> E[i] >> F[i]; }
// 座標圧縮
vector<ll> x_dict, y_dict;
x_dict.pb(-INF);
x_dict.pb(INF);
x_dict.pb(0);
y_dict.pb(-INF);
y_dict.pb(INF);
y_dict.pb(0);
rep(i, N) {
x_dict.pb(A[i]);
x_dict.pb(B[i]);
y_dict.pb(C[i]);
}
rep(i, M) {
x_dict.pb(D[i]);
y_dict.pb(E[i]);
y_dict.pb(F[i]);
}
sort(ALL(x_dict));
x_dict.erase(unique(ALL(x_dict)), x_dict.end());
sort(ALL(y_dict));
y_dict.erase(unique(ALL(y_dict)), y_dict.end());
// repv(x_dict) { cout << *it << " "; }
// cout << endl;
// repv(y_dict) { cout << *it << " "; }
// cout << endl;
ll W = SZ(x_dict);
ll H = SZ(y_dict);
// imos法による線分の判定
rep(i, N) {
int a = lower_bound(ALL(x_dict), A[i]) - x_dict.begin();
int b = lower_bound(ALL(x_dict), B[i]) - x_dict.begin();
int c = lower_bound(ALL(y_dict), C[i]) - y_dict.begin();
// cout << "(" << A[i] << " -> " << B[i] << ", " << C[i] << ") = (" << a
// << " -> " << b << ", " << c << ")" << endl;
v_line[c][a]++;
v_line[c][b]--;
}
// cout << "----" << endl;
rep(i, M) {
int d = lower_bound(ALL(x_dict), D[i]) - x_dict.begin();
int e = lower_bound(ALL(y_dict), E[i]) - y_dict.begin();
int f = lower_bound(ALL(y_dict), F[i]) - y_dict.begin();
// cout << "(" << D[i] << ", " << E[i] << " -> " << F[i] << ") = (" << d
// << ", " << e << " -> " << f << ")" << endl;
h_line[e][d]++;
h_line[f][d]--;
}
rep(y, H) reps(x, 1, W) v_line[y][x] += v_line[y][x - 1];
rep(x, W) reps(y, 1, H) h_line[y][x] += h_line[y - 1][x];
// cout << "----" << endl;
// rep(y, H) {
// reps(x, 1, W) { cout << (v_line[y][x] == 1 ? '#' : '.') << " "; }
// cout << endl;
// }
// cout << "----" << endl;
// rep(y, H) {
// reps(x, 1, W) { cout << (h_line[y][x] == 1 ? '#' : '.') << " "; }
// cout << endl;
// }
// 座標圧縮により、x_dict, y_dictのindexを座標と再定義できる
// - 実際の面積を求めたい場合は、idx値から各dictの要素にアクセスし、
// - 前後の値を引くことにより面積を計算する
ll res = 0;
queue<pair<ll, ll>> que;
ll stx = lower_bound(ALL(x_dict), 0) - x_dict.begin();
ll sty = lower_bound(ALL(y_dict), 0) - y_dict.begin();
vis[sty][stx] = true;
que.push({stx, sty});
while (!que.empty()) {
ll ix, iy;
tie(ix, iy) = que.front();
que.pop();
if (ix == 0 || ix == W - 1) {
res = INF;
break;
}
if (iy == 0 || iy == H - 1) {
res = INF;
break;
}
res += (x_dict[ix + 1] - x_dict[ix]) * (y_dict[iy + 1] - y_dict[iy]);
rep(d, 4) {
ll ix2 = ix + dx[d];
ll iy2 = iy + dy[d];
if (0 <= ix2 && ix2 < W && 0 <= iy2 && iy2 < H && !vis[iy2][ix2]) {
if (ix == ix2) {
if (v_line[max(iy, iy2)][ix2])
continue;
} else {
if (h_line[iy][max(ix, ix2)])
continue;
}
vis[iy2][ix2] = true;
que.push({ix2, iy2});
}
}
}
if (res == INF)
cout << "INF" << endl;
else
cout << res << endl;
return 0;
} | replace | 34 | 36 | 34 | 36 | 0 | |
p02681 | C++ | Runtime Error | #include <stdio.h>
#include <string.h>
int main(void) {
char s[10], t[10];
int len;
scanf("%s %s", s, t);
len = strlen(s);
for (int i = 0; i < len; i++) {
if (s[i] != t[i]) {
printf("No\n");
return 0;
}
}
printf("Yes\n");
return 0;
} | #include <stdio.h>
#include <string.h>
int main(void) {
char s[20], t[20];
int len;
scanf("%s %s", s, t);
len = strlen(s);
for (int i = 0; i < len; i++) {
if (s[i] != t[i]) {
printf("No\n");
return 0;
}
}
printf("Yes\n");
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02681 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main(void) {
string S, T;
cin >> S >> T;
return S == T.substr(0, S.length());
}
| #include <iostream>
using namespace std;
int main(void) {
string S, T;
cin >> S >> T;
if (S == T.substr(0, S.length())) {
cout << "Yes";
} else {
cout << "No";
}
return 0;
}
| replace | 7 | 8 | 7 | 13 | 1 | |
p02681 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main(void) {
char s[10], t[10];
scanf("%s%s", s, t);
if (strlen(s) + 1 == strlen(t)) {
for (int i = 0; i < strlen(s); i++) {
if (s[i] == t[i]) {
if (i == (strlen(s) - 1)) {
printf("Yes\n");
}
} else {
printf("No\n");
return 0;
}
}
} else {
printf("No\n");
}
return 0;
}
| #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main(void) {
char s[11], t[11];
scanf("%s%s", s, t);
if (strlen(s) + 1 == strlen(t)) {
for (int i = 0; i < strlen(s); i++) {
if (s[i] == t[i]) {
if (i == (strlen(s) - 1)) {
printf("Yes\n");
}
} else {
printf("No\n");
return 0;
}
}
} else {
printf("No\n");
}
return 0;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p02681 | C++ | Runtime Error | #include <iostream>
#include <string>
using namespace std;
int main() {
string x;
string n;
cin >> x >> n;
n.pop_back();
if (n == x) {
cout << "Yes"
<< "\n";
return true;
} else {
cout << "No"
<< "\n";
}
}
| #include <iostream>
#include <string>
using namespace std;
int main() {
string x;
string n;
cin >> x >> n;
n.pop_back();
if (n == x) {
cout << "Yes"
<< "\n";
} else {
cout << "No"
<< "\n";
}
}
| delete | 11 | 12 | 11 | 11 | 1 | |
p02681 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
string n;
cin >> n;
string t;
cin >> t;
int cnt = 0;
int N = n.length();
for (int i = 0; i <= N; i++) {
if (n.at(i) == t.at(i)) {
cnt++;
} else {
}
}
if (cnt == N) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
| #include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
string n;
cin >> n;
string t;
cin >> t;
int cnt = 0;
int N = n.length();
for (int i = 0; i < N; i++) {
if (n.at(i) == t.at(i)) {
cnt++;
} else {
}
}
if (cnt == N) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
| replace | 11 | 12 | 11 | 12 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 8) >= this->size() (which is 8)
|
p02681 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string S, T;
cin >> S >> T;
unsigned int i = 1;
while (S.at(i) == T.at(i)) {
i = i + 1;
if (i == S.size()) {
break;
}
}
if (i == S.size()) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string S, T;
cin >> S >> T;
unsigned int i = 0;
while (S.at(i) == T.at(i)) {
i = i + 1;
if (i == S.size()) {
break;
}
}
if (i == S.size()) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p02681 | Python | Runtime Error | s, t = input().split()
print("Yes" if s == t[:-1] else "No")
| s = input()
t = input()
print("Yes" if s == t[:-1] else "No")
| replace | 0 | 1 | 0 | 2 | ValueError: not enough values to unpack (expected 2, got 1) | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02681/Python/s074309875.py", line 1, in <module>
s, t = input().split()
ValueError: not enough values to unpack (expected 2, got 1)
|
p02681 | Python | Runtime Error | # A - Registration
def main():
S, T = map(int, open(0).read().split())
print("Yes" if T[:-1] == S else "No")
if __name__ == "__main__":
main()
| # A - Registration
def main():
S, T = open(0).read().split()
print("Yes" if T[:-1] == S else "No")
if __name__ == "__main__":
main()
| replace | 2 | 3 | 2 | 3 | ValueError: invalid literal for int() with base 10: 'chokudai' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02681/Python/s408863353.py", line 8, in <module>
main()
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02681/Python/s408863353.py", line 3, in main
S, T = map(int, open(0).read().split())
ValueError: invalid literal for int() with base 10: 'chokudai'
|
p02681 | Python | Runtime Error | #!/usr/bin/env python3
S = list(input())
T = list(input())
if len(T) == len(S) + 1:
flag = True
for i in len(S):
if S[i] != T[i]:
flag = False
if flag:
print("Yes")
else:
print("No")
else:
print("No")
| #!/usr/bin/env python3
S = list(input())
T = list(input())
if len(T) == len(S) + 1:
flag = True
for i in range(len(S)):
if S[i] != T[i]:
flag = False
if flag:
print("Yes")
else:
print("No")
else:
print("No")
| replace | 7 | 8 | 7 | 8 | TypeError: 'int' object is not iterable | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02681/Python/s140016351.py", line 8, in <module>
for i in len(S):
TypeError: 'int' object is not iterable
|
p02681 | Python | Runtime Error | S = input()
T = input()
if T.startwith("S"):
print("Yes")
else:
print("No")
| S = input()
T = input()
if T.startswith(S):
print("Yes")
else:
print("No")
| replace | 3 | 4 | 3 | 4 | AttributeError: 'str' object has no attribute 'startwith'. Did you mean: 'startswith'? | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02681/Python/s740360740.py", line 4, in <module>
if T.startwith('S'):
AttributeError: 'str' object has no attribute 'startwith'. Did you mean: 'startswith'?
|
p02681 | Python | Runtime Error | S, T = list(map(str, input().split()))
if (abs(len(T) - len(S)) == 1) and (T[:-1] == S):
print("Yes")
else:
print("No")
| S = list(map(str, input().split()))[0]
T = list(map(str, input().split()))[0]
if (abs(len(T) - len(S)) == 1) and (T[:-1] == S):
print("Yes")
else:
print("No")
| replace | 0 | 1 | 0 | 2 | ValueError: not enough values to unpack (expected 2, got 1) | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02681/Python/s417304047.py", line 1, in <module>
S, T = list(map(str, input().split()))
ValueError: not enough values to unpack (expected 2, got 1)
|
p02681 | Python | Runtime Error | s, t = map(str, input().split())
if s[: len(s)] == t[: len(s)]:
print("Yes")
else:
print("No")
| s = input()
t = input()
if s[: len(s)] == t[: len(s)]:
print("Yes")
else:
print("No")
| replace | 0 | 1 | 0 | 2 | ValueError: not enough values to unpack (expected 2, got 1) | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02681/Python/s756758064.py", line 1, in <module>
s, t = map(str, input().split())
ValueError: not enough values to unpack (expected 2, got 1)
|
p02681 | C++ | Runtime Error | #include <iostream>
#include <string>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < n; i++) // 普通のループ
#define REPTO(i, n) for (int i = 0; i <= n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--) // 逆ループ
#define FOR(i, m, n) for (int i = m; i < n; i++) // 最初の数値を指定
int strlen(char *s) {
int i = 0;
while (s[i] != '\0') {
i++;
}
return i;
}
int main() {
char S[10];
char T[10];
cin >> S >> T;
int ans = 0;
for (int i = 0; i < strlen(S); i++) {
if (S[i] == T[i]) {
} else {
ans = 1;
}
}
if (ans == 0) {
if (strlen(T) - strlen(S) == 1) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} else {
cout << "No" << endl;
}
return 0;
} | #include <iostream>
#include <string>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < n; i++) // 普通のループ
#define REPTO(i, n) for (int i = 0; i <= n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--) // 逆ループ
#define FOR(i, m, n) for (int i = m; i < n; i++) // 最初の数値を指定
int strlen(char *s) {
int i = 0;
while (s[i] != '\0') {
i++;
}
return i;
}
int main() {
char S[20];
char T[20];
cin >> S >> T;
int ans = 0;
for (int i = 0; i < strlen(S); i++) {
if (S[i] == T[i]) {
} else {
ans = 1;
}
}
if (ans == 0) {
if (strlen(T) - strlen(S) == 1) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} else {
cout << "No" << endl;
}
return 0;
} | replace | 21 | 23 | 21 | 23 | 0 | |
p02681 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string S, T;
cin >> S >> T;
int a = S.size();
char b = T.at(a + 1);
if (T == S + b) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string S, T;
cin >> S >> T;
int a = S.size();
char b = T.at(a);
if (T == S + b) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
| replace | 7 | 8 | 7 | 8 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 9) >= this->size() (which is 9)
|
p02681 | C++ | Runtime Error | #include <iostream>
using namespace std;
#include <string>
int main() {
string S, T;
cin >> S >> T;
for (int i = 0; i < S.length(); i++) {
if (S[i] != T[i]) {
cout << "No";
exit(1);
}
}
cout << "Yes";
}
| #include <iostream>
using namespace std;
#include <string>
int main() {
string S, T;
cin >> S >> T;
T.pop_back();
if (S == T)
cout << "Yes";
else
cout << "No";
} | replace | 7 | 14 | 7 | 12 | 0 | |
p02681 | C++ | Runtime Error | #include <cstdio>
#include <cstring>
using namespace std;
int main(void) {
int i, flg, n;
flg = 0;
char s[10], t[10];
scanf("%s", s);
scanf("%s", t);
n = strlen(s);
for (i = 0; i < n; i++) {
if (s[i] != t[i])
flg = 1;
}
if (flg == 1)
printf("No\n");
else
printf("Yes\n");
return 0;
}
| #include <cstdio>
#include <cstring>
using namespace std;
int main(void) {
int i, flg, n;
flg = 0;
char s[11], t[12];
scanf("%s", s);
scanf("%s", t);
n = strlen(s);
for (i = 0; i < n; i++) {
if (s[i] != t[i])
flg = 1;
}
if (flg == 1)
printf("No\n");
else
printf("Yes\n");
return 0;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p02681 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string s1, s2;
cin >> s1 >> s2;
s2.erase(s2.end());
if (s1 == s2) {
cout << "Yes";
} else {
cout << "No";
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s1, s2;
cin >> s1 >> s2;
s2.pop_back();
if (s1 == s2) {
cout << "Yes";
} else {
cout << "No";
}
} | replace | 6 | 7 | 6 | 7 | -11 | |
p02681 | C++ | Runtime Error | #include <iostream>
#include <string>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
t = t.erase(t[t.size() - 1]);
if (s == t) {
cout << "Yes";
} else {
cout << "No";
}
return 0;
} | #include <iostream>
#include <string>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
t = t.erase(t.size() - 1);
if (s == t) {
cout << "Yes";
} else {
cout << "No";
}
return 0;
} | replace | 7 | 8 | 7 | 8 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::erase: __pos (which is 122) > this->size() (which is 9)
|
p02681 | C++ | Runtime Error | #include <iostream>
#include <string>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
int len = t.length();
if (len != s.length() + 1) {
cout << "No" << endl;
return -1;
}
string u = t.substr(0, len - 1);
if (s != u) {
cout << "No" << endl;
return -1;
}
for (char c = 'a'; c <= 'z'; c++) {
if (t[len - 1] == c) {
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
return 0;
}
| #include <iostream>
#include <string>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
int len = t.length();
if (len != s.length() + 1) {
cout << "No" << endl;
return -1;
}
string u = t.substr(0, len - 1);
if (s != u) {
cout << "No" << endl;
return 0;
}
for (char c = 'a'; c <= 'z'; c++) {
if (t[len - 1] == c) {
cout << "Yes" << endl;
return 0;
}
}
cout << "No" << endl;
return 0;
}
| replace | 18 | 19 | 18 | 19 | 0 | |
p02682 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long LL;
typedef long double LD;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
LL a, b, c, k;
cin >> a >> b >> c >> k;
LL ans = 0;
while (k != 0) {
if (a != 0) {
a--;
ans++;
} else if (b != 0) {
b--;
} else {
ans--;
c--;
}
k--;
}
cout << ans << endl;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long LL;
typedef long double LD;
int main(void) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
LL a, b, c, k;
cin >> a >> b >> c >> k;
LL ans = 0;
if (a >= k) {
ans = k;
} else if (a + b >= k) {
ans = a;
} else {
ans = a - (k - a - b);
}
cout << ans << endl;
} | replace | 18 | 29 | 18 | 24 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main(void) {
long long one, zero, minus_one;
int k, amount = 0;
cin >> one >> zero >> minus_one >> k;
for (int i = 0; i < k; i++) {
if (one > 0) {
one -= 1;
amount += 1;
} else if (zero > 0) {
zero -= 1;
} else {
minus_one -= 1;
amount -= 1;
}
}
cout << amount << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main(void) {
long long one, zero, minus_one;
int k, amount = 0;
cin >> one >> zero >> minus_one >> k;
if (one >= k) {
amount = k;
} else if (one + zero >= k) {
amount = one;
} else {
amount = one - (k - (one + zero));
}
cout << amount << endl;
}
| replace | 6 | 17 | 6 | 12 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int A, B, C, K, ans = 0;
cin >> A >> B >> C >> K;
for (int i = 0; i < K; i++) {
if (A > 0) {
ans++;
A--;
} else if (B > 0) {
B--;
} else if (C > 0) {
ans--;
C--;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int A, B, C, K, ans = 0;
cin >> A >> B >> C >> K;
if (A > K)
cout << K << endl;
else if (A + B > K)
cout << A << endl;
else
cout << A - (K - A - B) << endl;
return 0;
} | replace | 12 | 24 | 12 | 19 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int a, b, c, n, s;
int main() {
cin >> a >> b >> c >> n;
for (int i = 1; i <= n; i++) {
if (a != 0)
a--, s++;
else if (b != 0)
b--;
else if (c != 0)
c--, s--;
}
cout << s;
}
| #include <bits/stdc++.h>
using namespace std;
int a, b, c, n, s;
int main() {
cin >> a >> b >> c >> n;
if (n <= a)
cout << n;
else if (n <= a + b)
cout << a;
else
cout << a - (n - a - b);
}
| replace | 5 | 14 | 5 | 11 | TLE | |
p02682 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
int main() {
int64_t a, b, c, k;
cin >> a >> b >> c >> k;
if ((a + b) >= k) {
cout << a << endl;
return -1;
}
int64_t d = k - (a + b);
if (c < d)
cout << a - c << endl;
else
cout << a - d << endl;
return 0;
}
| #include <iostream>
#include <vector>
using namespace std;
int main() {
int64_t a, b, c, k;
cin >> a >> b >> c >> k;
if ((a + b) >= k) {
if (a < k)
cout << a << endl;
else {
cout << k << endl;
}
return 0;
}
int64_t d = k - (a + b);
if (c < d)
cout << a - c << endl;
else
cout << a - d << endl;
return 0;
}
| replace | 10 | 12 | 10 | 16 | 255 | |
p02682 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, k, sum = 0;
cin >> a >> b >> c >> k;
while (k > 0) {
if (k >= a && a > 0) {
sum = sum + a;
k = k - a;
a = 0;
} else if (k < a && a > 0) {
sum = sum + k;
k = 0;
a = a - k;
} else if (k < b && a == 0 && b > 0) {
k = 0;
b = b - k;
} else if (k >= b && a == 0 && b > 0) {
k = k - b;
b = 0;
} else if (k >= c && a == 0 && b == 0 && c > 0) {
sum = sum - c;
c = 0;
k = k - c;
} else if (k < c && a == 0 && b == 0 && c > 0) {
sum = sum - k;
c = c - k;
k = 0;
}
}
cout << sum;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, k, sum = 0;
cin >> a >> b >> c >> k;
while (k > 0) {
if (k >= a && a > 0) {
sum = sum + a;
k = k - a;
a = 0;
} else if (k < a && a > 0) {
sum = sum + k;
k = 0;
a = a - k;
} else if (k < b && a == 0 && b > 0) {
k = 0;
b = b - k;
} else if (k >= b && a == 0 && b > 0) {
k = k - b;
b = 0;
} else if (k >= c && a == 0 && b == 0 && c > 0) {
sum = sum - c;
c = 0;
k = 0;
} else if (k < c && a == 0 && b == 0 && c > 0) {
sum = sum - k;
c = c - k;
k = 0;
}
}
cout << sum;
return 0;
} | replace | 27 | 28 | 27 | 28 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <iostream>
int main() {
int A, B, C, K;
std::cin >> A >> B >> C >> K;
int count = 0;
for (int i = 0; i < K; i++) {
if (A > 0) {
++count;
--A;
} else if (B > 0)
--B;
else
--count;
}
std::cout << count << std::endl;
} | #include <iostream>
int main() {
int A, B, C, K;
std::cin >> A >> B >> C >> K;
int count = 0;
if (K > A) {
count = A;
for (int i = 0; i < K - A - B; i++)
count--;
} else
count = K;
std::cout << count << std::endl;
} | replace | 7 | 16 | 7 | 14 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int a, b, c, d;
cin >> a >> b >> c >> d;
int ans = 0;
for (int i = 0; i < d; i++) {
if (a) {
a--;
ans++;
} else if (b) {
b--;
} else {
c--;
ans--;
}
}
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int a, b, c, d;
cin >> a >> b >> c >> d;
int ans = 0;
int x = min(a, d);
ans += x;
a -= x;
d -= x;
if (d) {
int y = min(b, d);
b -= y;
d -= y;
}
if (d) {
ans -= d;
}
cout << ans;
return 0;
}
| replace | 10 | 20 | 10 | 21 | TLE | |
p02682 | C++ | Time Limit Exceeded | // @prefix atcoder
// @description atcoder template
#include <bits/stdc++.h>
using namespace std;
#define int long long
// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
// rep
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cerr << #x << ": " << x << '\n'
#define DEBUGP(x) cerr << #x << ": " << x.first << " \t" << x.second << '\n'
#define INF (1ll << 60)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
const int MOD = 1e9 + 7;
int a, b, c, k;
signed main() {
cin >> a >> b >> c >> k;
int res = 0;
REP(i, k) {
if (k <= a) {
res = k;
} else if (k <= a + b) {
res = a;
} else {
res = a - (c - (a + b + c - k));
}
}
cout << res << endl;
return 0;
}
| // @prefix atcoder
// @description atcoder template
#include <bits/stdc++.h>
using namespace std;
#define int long long
// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
// rep
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cerr << #x << ": " << x << '\n'
#define DEBUGP(x) cerr << #x << ": " << x.first << " \t" << x.second << '\n'
#define INF (1ll << 60)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
const int MOD = 1e9 + 7;
int a, b, c, k;
signed main() {
cin >> a >> b >> c >> k;
int res = 0;
if (k <= a) {
res = k;
} else if (k <= a + b) {
res = a;
} else {
res = a - (c - (a + b + c - k));
}
cout << res << endl;
return 0;
}
| replace | 34 | 42 | 34 | 40 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, k;
int ans = 0;
cin >> a >> b >> c >> k;
for (int i = 0; i < k; ++i) {
if (a > 0) {
ans += 1;
--a;
} else if (b > 0) {
--b;
} else {
ans -= 1;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, k;
int ans = 0;
cin >> a >> b >> c >> k;
ans += min(a, k);
k = k - (a + b);
if (k > 0)
ans -= k;
cout << ans << endl;
}
| replace | 7 | 17 | 7 | 11 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, C, K;
int sum = 0;
cin >> A >> B >> C >> K;
for (int i = K; i > 0; i--) {
if (A > 0) {
sum++;
A--;
} else if (A == 0 && B > 0)
B--;
else
sum--;
}
cout << sum << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, C, K;
int sum = 0;
cin >> A >> B >> C >> K;
if (A > K)
cout << K << endl;
else if (A + B > K)
cout << A << endl;
else
cout << 2 * A + B - K << endl;
} | replace | 7 | 17 | 7 | 14 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
int main() {
int a, b, c, k;
cin >> a >> b >> c >> k;
int ans = 0;
for (int i = 0; i < k; i++) {
if (a > 0) {
ans += 1;
a--;
} else if (b > 0) {
b--;
} else if (c > 0) {
ans -= 1;
c--;
}
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
int main() {
int a, b, c, k;
cin >> a >> b >> c >> k;
int ans = 0;
if (k <= a) {
ans = k;
} else if (k <= a + b) {
ans = a;
} else {
ans = a - (k - a - b);
}
cout << ans << endl;
return 0;
} | replace | 18 | 28 | 18 | 24 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, C, K, ans;
cin >> A >> B >> C >> K;
ans = 0;
for (int i = 0; i < K; i++) {
if (A > 0) {
ans++;
A--;
} else if (B > 0) {
B--;
} else {
ans--;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, C, K, ans;
cin >> A >> B >> C >> K;
ans = 0;
if (A > K) {
ans = K;
} else if (A + B >= K) {
ans = A;
} else {
ans = A - (K - A - B);
}
cout << ans << endl;
return 0;
} | replace | 8 | 17 | 8 | 14 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define lli long long int
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lli a = 0, b = 0, c = 0, k = 0, count = 0;
cin >> a >> b >> c >> k;
while (k != 0) {
if (a != 0) {
count++;
a--;
} else if (b != 0) {
b--;
} else {
count--;
c--;
}
k--;
}
cout << count;
} | #include <bits/stdc++.h>
#define lli long long int
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
lli a = 0, b = 0, c = 0, k = 0, count = 0;
cin >> a >> b >> c >> k;
while (k != 0) {
if (a == k) {
count = a;
break;
}
if (a != 0) {
count++;
a--;
} else if (b != 0) {
b--;
} else {
count--;
c--;
}
k--;
}
cout << count;
} | insert | 19 | 19 | 19 | 23 | TLE | |
p02682 | C++ | Time Limit Exceeded |
#include <iostream>
using namespace std;
int main() {
int a, b, c, k, ans = 0;
cin >> a >> b >> c >> k;
while (1) {
if (k == 0) {
break;
}
if (a > 0) {
ans++;
a--;
k--;
continue;
}
if (b > 0) {
b--;
k--;
continue;
}
if (c > 0) {
ans--;
c--;
k--;
continue;
}
}
cout << ans << endl;
} |
#include <iostream>
using namespace std;
int main() {
int a, b, c, k, ans = 0;
cin >> a >> b >> c >> k;
if (a >= k && b == 0 && c == 0) {
cout << k << endl;
return 0;
}
while (1) {
if (k == 0) {
break;
}
if (a > 0) {
ans++;
a--;
k--;
continue;
}
if (b > 0) {
b--;
k--;
continue;
}
if (c > 0) {
ans--;
c--;
k--;
continue;
}
}
cout << ans << endl;
} | insert | 8 | 8 | 8 | 13 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int A, B, C, K;
cin >> A >> B >> C >> K;
ll sum = 0;
ll card = 0;
while (true) {
if (card == K)
break;
if (A > 0) {
sum += 1;
card++;
A--;
} else if (A == 0 && B > 0) {
card++;
B--;
} else if (A == 0 && B == 0 && C > 0) {
sum--;
card++;
C--;
}
}
cout << sum << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int A, B, C, K;
cin >> A >> B >> C >> K;
ll sum = 0;
if (K >= A) {
sum += A;
K = K - A;
} else {
sum += K;
cout << sum << endl;
return 0;
}
if (K >= B) {
K = K - B;
} else {
cout << sum << endl;
return 0;
}
if (K >= C) {
sum -= C;
K = K - C;
} else {
sum -= K;
cout << sum << endl;
return 0;
}
cout << sum << endl;
} | replace | 7 | 23 | 7 | 29 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, k;
cin >> a >> b >> c >> k;
int d = 0;
while (k) {
if (a) {
d++;
k--;
a--;
} else if (b) {
k--;
b--;
} else if (c) {
d--;
k--;
c--;
}
}
cout << d;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, k;
cin >> a >> b >> c >> k;
if (k <= a)
cout << k << endl;
else if (k <= a + b)
cout << a << endl;
else
cout << a - (k - a - b) << endl;
return 0;
}
| replace | 5 | 21 | 5 | 12 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(int argc, char const *argv[]) {
ll a, b, c, k;
scanf("%lld%lld%lld%lld", &a, &b, &c, &k);
vector<ll> v;
while (a--)
v.push_back(1);
while (b--)
v.push_back(0);
while (c--)
v.push_back(-1);
ll ans = 0;
for (int i = 0; i < k; ++i) {
ans += v[i];
}
printf("%lld\n", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(int argc, char const *argv[]) {
int a, b, c, k;
scanf("%d%d%d%d", &a, &b, &c, &k);
printf("%d\n", min(a, k) - max(0, k - a - b));
return 0;
}
| replace | 5 | 19 | 5 | 8 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <iostream>
#include <string>
using namespace std;
int main() {
int A, B, C, K, sum = 0;
cin >> A >> B >> C >> K;
while (1) {
if (A == 0 || K == 0) {
break;
}
sum++;
A--;
K--;
}
while (1) {
if (B == 0 || K == 0) {
break;
}
B--;
K--;
}
while (1) {
if (K == 0) {
break;
}
sum--;
}
cout << sum << endl;
return 0;
} | #include <iostream>
#include <string>
using namespace std;
int main() {
int A, B, C, K, sum = 0;
cin >> A >> B >> C >> K;
while (1) {
if (A == 0 || K == 0) {
break;
}
sum++;
A--;
K--;
}
while (1) {
if (B == 0 || K == 0) {
break;
}
B--;
K--;
}
while (1) {
if (K == 0) {
break;
}
sum--;
K--;
}
cout << sum << endl;
return 0;
} | insert | 28 | 28 | 28 | 29 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <iostream>
#include <stdio.h>
using namespace std;
int main(void) {
// Your code here!
long long int a, b, c, k, point = 0;
scanf("%lld %lld %lld %lld", &a, &b, &c, &k);
for (int i = 0; i < k; i++) {
if (a > 0) {
point++;
a--;
} else if (b > 0) {
b--;
} else {
point--;
c--;
}
}
printf("%lld", point);
}
| #include <iostream>
#include <stdio.h>
using namespace std;
int main(void) {
// Your code here!
long long int a, b, c, k, point = 0;
scanf("%lld %lld %lld %lld", &a, &b, &c, &k);
for (int i = 0; i < k; i++) {
if (a > 0) {
point++;
a--;
} else if (b > 0) {
b--;
} else {
point--;
}
}
printf("%lld", point);
}
| delete | 15 | 16 | 15 | 15 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <iostream>
#include <string>
using namespace std;
int main() {
int a, b, c, k;
int sum = 0;
cin >> a >> b >> c >> k;
for (int i = 0; i < k; i++) {
if (a != 0) {
sum += 1;
a -= 1;
} else if (b != 0) {
b -= 1;
} else {
sum -= 1;
}
}
cout << sum << endl;
return 0;
} | #include <iostream>
#include <string>
using namespace std;
int main() {
int a, b, c, k;
int sum = 0;
cin >> a >> b >> c >> k;
if (k <= a)
sum = k;
else if (k <= b)
sum = a;
else
sum = a - (k - a - b);
cout << sum << endl;
return 0;
} | replace | 8 | 18 | 8 | 14 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, c, k;
cin >> a >> b >> c >> k;
long long ans = 0;
for (int i = 0; i < k; i++) {
if (a > 0) {
a--;
ans++;
} else if (b > 0) {
b--;
} else {
c--;
ans--;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, c, k;
cin >> a >> b >> c >> k;
long long ans = 0;
if (k <= a)
cout << k << endl;
else if (k <= a + b)
cout << a << endl;
else
cout << a - (k - a - b) << endl;
} | replace | 7 | 19 | 7 | 13 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, C, K, sum = 0;
cin >> A >> B >> C >> K;
for (int i = 0; i < K; i++) {
if (A > 0) {
sum++;
A--;
} else if (B > 0) {
B--;
} else {
sum--;
}
}
cout << sum << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, C, K, sum = 0;
cin >> A >> B >> C >> K;
if (A >= K) {
sum = K;
} else if (A + B >= K) {
sum = A;
} else {
sum = A - (K - A - B);
}
cout << sum << endl;
return 0;
} | replace | 6 | 15 | 6 | 12 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
long a, b, c, k;
cin >> a >> b >> c >> k;
long sum = 0;
while (k > 0) {
if (a > 0) {
a--;
k--;
sum++;
} else if (b > 0) {
b--;
k--;
} else {
c--;
k--;
sum--;
}
}
cout << sum << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long a, b, c, k;
cin >> a >> b >> c >> k;
long sum = 0;
if (k > 0 && a > 0) {
int x = min(a, k);
sum += x;
k -= x;
}
if (k > 0 && b > 0) {
int x = min(b, k);
k -= x;
}
if (k > 0 && c > 0) {
int x = min(c, k);
sum -= x;
k -= x;
}
cout << sum << endl;
return 0;
}
| replace | 12 | 25 | 12 | 29 | TLE | |
p02682 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, k;
cin >> a >> b >> c >> k;
int r1 = k % a;
int r2 = r1 % b;
int r3 = r2 % b;
cout << r1 - r3 << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, k;
cin >> a >> b >> c >> k;
if (a >= k) {
cout << k << endl;
} else {
if (b >= k - a) {
cout << a << endl;
} else {
cout << a - (k - a - b) << endl;
}
}
}
| replace | 6 | 10 | 6 | 16 | 0 | |
p02682 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, k;
cin >> a >> b >> c >> k;
int d = 0;
int ans = -2000000001;
for (int i = 0; i <= a; i++) {
for (int j = 0; j <= b; j++) {
int l = k - (i + j);
d = 1 * i + -1 * l;
if (ans < d) {
ans = d;
}
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, k;
cin >> a >> b >> c >> k;
int ans = k < a ? k : a;
int l = k - a - b;
if (l > 0) {
ans -= l;
}
cout << ans << endl;
} | replace | 6 | 16 | 6 | 10 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, k;
int sum = 0;
cin >> a >> b >> c >> k;
for (int i = 0; i < k; i++) {
if (a != 0) {
a--;
sum++;
} else if (b != 0) {
b--;
} else {
sum--;
}
}
cout << sum << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t a, b, c, k;
int64_t sum = 0;
cin >> a >> b >> c >> k;
for (int i = 0; i < k; i++) {
if (a != 0) {
a--;
sum++;
} else if (b != 0) {
b--;
} else {
sum--;
}
}
cout << sum << endl;
}
| replace | 4 | 6 | 4 | 6 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll A, B, C, K;
cin >> A >> B >> C >> K;
ll result = 0;
for (ll i = 0; i < K; i++) {
// cout << result << "\n";
if (0 < A) {
result++;
A--;
continue;
}
if (0 < B) {
B--;
continue;
}
if (0 < C) {
result--;
C--;
continue;
}
}
cout << result;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll A, B, C, K;
cin >> A >> B >> C >> K;
ll result = 0;
if (K <= A) {
result = K;
} else if (K <= A + B) {
result = A;
} else {
result = A - (K - A - B);
}
cout << result;
return 0;
}
| replace | 10 | 26 | 10 | 16 | TLE | |
p02682 | Python | Runtime Error | A, B, C, K = map(int, input.split(" "))
if K <= A:
print(K)
else:
K = K - A
if K <= B:
print(A)
else:
K = K - B
print(A - K)
| A, B, C, K = map(int, input().split(" "))
if K <= A:
print(K)
else:
K = K - A
if K <= B:
print(A)
else:
K = K - B
print(A - K)
| replace | 0 | 1 | 0 | 1 | AttributeError: 'builtin_function_or_method' object has no attribute 'split' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02682/Python/s825415458.py", line 1, in <module>
A, B, C, K = map(int, input.split(" "))
AttributeError: 'builtin_function_or_method' object has no attribute 'split'
|
p02682 | Python | Time Limit Exceeded | A, B, C, K = map(int, input().split())
a = []
b = []
c = []
for x in range(A):
a.append(1)
for y in range(B):
b.append(0)
for z in range(C):
c.append(-1)
sum = 0
arr = a + b + c
for i in range(K):
sum += arr[i]
print(sum)
| A, B, C, K = map(int, input().split())
k = K
a = min(A, k)
k -= a
b = min(B, k)
k -= b
c = min(C, k)
print(a - c)
| replace | 1 | 15 | 1 | 8 | TLE | |
p02682 | Python | Time Limit Exceeded | a, b, c, k = map(int, input().split(" "))
cnt_a = 0
cnt_b = 0
cnt_c = 0
while k != 0:
if a > 0:
cnt_a += 1
a -= 1
k -= 1
elif b > 0:
cnt_b += 1
b -= 1
k -= 1
else:
cnt_c += 1
c -= 1
k -= 1
result = cnt_a * 1 + cnt_b * 0 + cnt_c * (-1)
print(result)
| a, b, c, k = map(int, input().split(" "))
cnt_a = 0
cnt_b = 0
cnt_c = 0
if (a > 0) & (a > k):
cnt_a = k
k = 0
else:
cnt_a = a
k = k - cnt_a
if (b > 0) & (b > k):
cnt_b = k
k = 0
else:
cnt_b = b
k = k - cnt_b
if c > 0:
cnt_c = k
result = cnt_a * 1 + cnt_b * 0 + cnt_c * (-1)
print(result)
| replace | 6 | 19 | 6 | 22 | TLE | |
p02682 | Python | Time Limit Exceeded | a, b, c, k = map(int, input().split())
ans = 0
for i in range(k):
if a != 0:
ans += 1
a += -1
continue
if b != 0:
ans += 0
b += -1
continue
if c != 0:
ans += -1
c += -1
continue
print(ans)
| a, b, c, k = map(int, input().split())
ans = 0
if a > k:
ans += 1 * k
k = 0
else:
ans += 1 * a
k -= a
if b > k:
ans += 0 * k
k = 0
else:
ans += 0 * b
k -= b
if c > k:
ans += -1 * k
k = 0
else:
ans += -1 * c
k -= c
print(ans)
| replace | 3 | 16 | 3 | 26 | TLE | |
p02682 | Python | Time Limit Exceeded | a, b, c, k = map(int, input().split())
ans = 0
while True:
flg = True
for i in range(a):
ans += 1
k -= 1
if k == 0:
flg = False
break
if not flg:
break
for i in range(b):
k -= 1
if k == 0:
flg = False
break
if not flg:
break
for i in range(c):
ans += -1
k -= 1
if k == 0:
flg = False
break
if not flg:
break
print(ans)
| a, b, c, k = map(int, input().split())
if k <= a:
print(k)
elif k <= a + b:
print(a)
else:
print(a - (k - a - b))
| replace | 2 | 37 | 2 | 8 | TLE | |
p02682 | Python | Time Limit Exceeded | a, b, c, k = map(int, input().split())
ans = 0
for i in range(k):
if a >= 1:
ans += 1
a -= 1
elif b >= 1:
b -= 1
pass
else:
ans -= 1
print(ans)
| a, b, c, k = map(int, input().split())
if k <= a:
print(k)
elif k - a > b:
print(-1 * ((k - a) - b) + a)
else:
print(a)
| replace | 2 | 14 | 2 | 8 | TLE | |
p02682 | Python | Runtime Error | A, B, C, K = map(int, input().spliit())
if K <= A:
print(K)
elif K <= A + B:
print(A)
else:
print(A - (K - (A + B)))
| A, B, C, K = map(int, input().split())
if K <= A:
print(K)
elif K <= A + B:
print(A)
else:
print(A - (K - (A + B)))
| replace | 0 | 1 | 0 | 1 | AttributeError: 'str' object has no attribute 'spliit'. Did you mean: 'split'? | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02682/Python/s025305163.py", line 1, in <module>
A, B, C, K = map(int, input().spliit())
AttributeError: 'str' object has no attribute 'spliit'. Did you mean: 'split'?
|
p02682 | Python | Runtime Error | def main():
A, B, C, K = map(int, input().split())
li = [1] * A
li += [0] * B
li += [-1] * C
print(sum(li[:K]))
if __name__ == "__main__":
main()
| def main():
A, B, _, K = map(int, input().split())
if A > K:
print(K)
quit()
print(A - max([0, K - A - B]))
if __name__ == "__main__":
main()
| replace | 1 | 6 | 1 | 6 | 0 | |
p02682 | Python | Runtime Error | A, B, C, K = (int(x) for x in input().split())
a = [1] * A
b = [0] * B
c = [-1] * C
X = a + b + c
print(sum(X[:K]))
| A, B, C, K = map(int, input().split())
if K <= A:
print(K)
elif K <= A + B:
print(A)
else:
print(2 * A + B - K)
| replace | 0 | 8 | 0 | 7 | 0 | |
p02682 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int k, a, b, c, sum = 0;
cin >> a >> b >> c >> k;
for (int i = 0; i < k; i++) {
if (a > 0) {
sum++;
a--;
} else if (a == 0 && b > 0)
b--;
else if (a == 0 && b == 0 && c > 0) {
sum--;
c--;
}
}
cout << sum << endl;
return 0;
}
| #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int k, a, b, c, sum = 0;
cin >> a >> b >> c >> k;
if (k >= a) {
k -= a;
sum += a;
} else {
sum = k;
k = 0;
}
if (k >= b) {
k -= b;
} else {
k = 0;
}
if (k != 0) {
sum -= k;
k = 0;
}
cout << sum << endl;
return 0;
} | replace | 12 | 22 | 12 | 29 | TLE | |
p02682 | C++ | Time Limit Exceeded |
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rrep(i, a, b) for (int i = a; i >= b; --i)
#define fore(i, a) for (auto &i : a)
#define INF INT_MAX / 2;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
// ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;
int cnt_digit(ll N) {
int digit = 0;
while (N > 0) {
N /= 10;
digit++;
}
return digit;
}
// 最大公約数計算
ll gcd(ll a, ll b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
// 最小公倍数の計算
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
return a / g * b;
}
struct union_find {
vector<int> par, r;
union_find(int n) {
par.resize(n);
r.resize(n);
init(n);
}
void init(int n) {
for (int i = 0; i < n; i++)
par[i] = i;
for (int i = 0; i < n; i++)
r[i] = 0;
}
int find(int x) {
if (par[x] == x)
return x;
else
return find(par[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (r[x] < r[y]) {
par[x] = y;
} else {
par[y] = x;
if (r[x] == r[y]) {
r[x]++;
}
}
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll a, b, c, k;
cin >> a >> b >> c >> k;
ll ans = 0;
rep(i, 0, k) {
if (a > 0) {
ans++;
a--;
} else if (a == 0 && b > 0) {
b--;
} else {
ans--;
c--;
}
}
cout << ans << endl;
} |
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rrep(i, a, b) for (int i = a; i >= b; --i)
#define fore(i, a) for (auto &i : a)
#define INF INT_MAX / 2;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
// ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;
int cnt_digit(ll N) {
int digit = 0;
while (N > 0) {
N /= 10;
digit++;
}
return digit;
}
// 最大公約数計算
ll gcd(ll a, ll b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
// 最小公倍数の計算
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
return a / g * b;
}
struct union_find {
vector<int> par, r;
union_find(int n) {
par.resize(n);
r.resize(n);
init(n);
}
void init(int n) {
for (int i = 0; i < n; i++)
par[i] = i;
for (int i = 0; i < n; i++)
r[i] = 0;
}
int find(int x) {
if (par[x] == x)
return x;
else
return find(par[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (r[x] < r[y]) {
par[x] = y;
} else {
par[y] = x;
if (r[x] == r[y]) {
r[x]++;
}
}
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll a, b, c, k;
cin >> a >> b >> c >> k;
ll ans = 0;
if (a >= k) {
ans = k;
} else if (a < k && a + b >= k) {
ans = a;
}
else if (a + b < k && c >= k - (a + b)) {
ans = a - (k - (a + b));
}
cout << ans << endl;
} | replace | 95 | 105 | 95 | 103 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, c, k, ans = 0;
cin >> a >> b >> c >> k;
long long total = a + b + c;
if (k >= total)
cout << a - c << endl;
else {
for (long long i = 0; i < k; i++) {
if (a != 0) {
ans++;
a--;
} else if (a == 0 && b != 0)
b--;
else if (a == 0 && b == 0 && c != 0) {
ans--;
c--;
} else if (a == 0 && b == 0 && c == 0)
break;
}
cout << ans << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, c, k, ans = 0;
cin >> a >> b >> c >> k;
long long total = a + b + c;
if (k >= total)
cout << a - c << endl;
else {
int some = 0;
some = k - a;
if (some > 0) {
ans = a;
for (long long i = 0; i < some; i++) {
if (b != 0)
b--;
else if (b == 0 && c != 0) {
ans--;
c--;
}
}
} else
ans = k;
cout << ans << endl;
}
} | replace | 10 | 22 | 10 | 24 | TLE | |
p02682 | C++ | Runtime Error | #include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
int main() {
ll a, b, c, k;
cin >> a >> b >> c >> k;
vector<ll> p(a + b + c);
for (ll i = 0; i < a; i++)
p[i] = 1;
for (ll i = a; i < a + b; i++)
p[i] = 0;
for (int i = a + b; i < a + b + c; i++)
p[i] = -1;
ll ans = 0;
rep(i, k) ans += p[i];
cout << ans << "\n";
return 0;
} | #include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
int main() {
ll a, b, c, k;
cin >> a >> b >> c >> k;
if (k <= a)
cout << k << "\n";
else {
if (k <= a + b)
cout << a << "\n";
else
cout << a + a + b - k << "\n";
}
return 0;
} | replace | 13 | 23 | 13 | 21 | 0 | |
p02682 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) \
{ \
for (auto i : x) { \
cout << i << " "; \
} \
cout << endl; \
}
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int A, B, C, K;
cin >> A >> B >> C >> K;
vector<int> X;
rep(i, A) X.push_back(1);
rep(i, B) X.push_back(0);
rep(i, C) X.push_back(-1);
int ans = 0;
rep(i, K) ans += X[i];
cout << ans << '\n';
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) \
{ \
for (auto i : x) { \
cout << i << " "; \
} \
cout << endl; \
}
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int A, B, C, K;
cin >> A >> B >> C >> K;
int ans = min(A, K);
K -= min(A, K);
if (K > 0) {
K -= min(B, K);
}
if (K > 0) {
ans -= K;
}
cout << ans << '\n';
return 0;
} | replace | 17 | 23 | 17 | 25 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main(void) {
ll a, b, c, k;
cin >> a >> b >> c >> k;
ll ans = 0;
for (int i = 0; i < k; i++) {
if (a != 0) {
ans++;
a--;
} else if (b != 0) {
b--;
} else if (c != 0) {
ans--;
c--;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main(void) {
ll a, b, c, k;
cin >> a >> b >> c >> k;
ll ans = 0;
if (a > k) {
cout << k << endl;
} else if (a + b >= k) {
cout << a << endl;
} else
cout << a - (k - a - b) << endl;
return 0;
}
| replace | 24 | 36 | 24 | 30 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define For(i, n1, n2) for (int i = (int)(n1); i < (int)(n2); i++)
int main() {
long long a, b, c, k;
long long ans = 0;
cin >> a >> b >> c >> k;
Rep(i, k) {
if (a > 0) {
ans++;
a--;
continue;
}
if (b > 0) {
b--;
continue;
}
if (c > 0) {
ans--;
c--;
continue;
}
}
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define For(i, n1, n2) for (int i = (int)(n1); i < (int)(n2); i++)
int main() {
int a, b, c, k;
int ans = 0;
cin >> a >> b >> c >> k;
Rep(i, k) {
if (a > 0) {
ans++;
a--;
continue;
}
if (b > 0) {
b--;
continue;
}
if (c > 0) {
ans--;
c--;
continue;
}
}
cout << ans;
} | replace | 6 | 8 | 6 | 8 | TLE | |
p02682 | 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 p = pair<int, int>;
int main() {
ll a, b, c, k;
cin >> a >> b >> c >> k;
ll s = 0;
rep(i, k) {
if (a > 0) {
s += 1;
a--;
} else if (b > 0) {
b--;
} else {
s -= 1;
c--;
}
}
cout << s << endl;
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>;
int main() {
ll a, b, c, k;
cin >> a >> b >> c >> k;
ll s = 0;
if (a >= k) {
s = k;
} else if (a + b >= k) {
s = a;
} else {
s = a - (k - a - b);
}
cout << s << endl;
return 0;
} | replace | 11 | 21 | 11 | 17 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ll long long
int main(void) {
ll a, b, c, k;
cin >> a >> b >> c >> k;
ll ans = 0;
rep(i, k) {
if (a > 0) {
ans++;
a--;
} else if (b > 0) {
b--;
} else {
ans--;
c--;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ll long long
int main(void) {
ll a, b, c, k;
cin >> a >> b >> c >> k;
ll ans = 0;
if (a >= k)
ans = k;
else if (a + b >= k)
ans = a;
else
ans = a - (k - a - b);
cout << ans << endl;
return 0;
} | replace | 10 | 21 | 10 | 16 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
int a, b, c, k;
cin >> a >> b >> c >> k;
int sum = 0, i = 0;
while (i < k) {
if (a-- > 0)
sum += 1;
else if (b-- > 0)
sum += 0;
else if (c-- > 0)
sum -= 1;
else
break;
i++;
}
cout << sum;
return 0;
} | #include <iostream>
using namespace std;
int main() {
int a, b, c, k;
cin >> a >> b >> c >> k;
int sum = 0, i = k;
if (a <= i) {
sum += a;
i -= a;
} else {
sum += i;
i -= i;
}
if (b <= i) {
i -= b;
} else {
i -= i;
}
if (c <= i) {
sum -= c;
i -= c;
} else {
sum -= i;
i -= i;
}
cout << sum;
return 0;
}
| replace | 7 | 18 | 7 | 29 | TLE | |
p02682 | C++ | Runtime Error | #include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
int a, b, c, k;
cin >> a >> b >> c >> k;
vector<long long> num(a + b + c);
rep(i, a) num.at(i) = 1;
rep(i, b) num.at(a + i) = 0;
rep(i, c) num.at(a + b + i) = -1;
long long ans = 0;
rep(i, k) ans += num.at(i);
cout << ans << endl;
}
| #include <bits/stdc++.h>
const double PI = acos(-1);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
int a, b, c, k;
cin >> a >> b >> c >> k;
if (k <= a)
cout << k << endl;
else if (k <= a + b)
cout << a << endl;
else
cout << a - (k - a - b) << endl;
}
| replace | 7 | 14 | 7 | 13 | 0 | |
p02682 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
long long A, B, C, K;
cin >> A >> B >> C >> K;
long long ans = 0;
while (K > 0) {
if (A > 0) {
--K;
--A;
++ans;
} else if (A == 0 && B > 0) {
--K;
--B;
} else if (B == 0 && C > 0) {
--K;
--C;
--ans;
}
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
long long A, B, C, K;
cin >> A >> B >> C >> K;
long long ans = 0;
if (A > K) {
ans += K;
K = 0;
} else {
ans += A;
K -= A;
}
if (K > 0) {
if (B > K) {
K = 0;
} else {
K -= B;
}
}
if (K > 0) {
if (C > K) {
ans -= K;
} else {
ans -= C;
}
}
cout << ans << endl;
return 0;
}
| replace | 12 | 24 | 12 | 33 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
long A, B, C, K, Ans = 0, count = 1;
cin >> A >> B >> C >> K;
for (int i = 1; i <= A; i++) {
if (count > K)
break;
Ans++;
count++;
}
for (int i = 1; i <= B; i++) {
if (count > K)
break;
count++;
}
for (int i = 1; i <= C; i++) {
if (count > K)
break;
Ans--;
count++;
}
cout << Ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long A, B, C, K, Ans = 0, count = 1;
cin >> A >> B >> C >> K;
for (int i = 1; i <= A; i++) {
if (count > K)
break;
Ans++;
count++;
}
count += B;
for (int i = 1; i <= C; i++) {
if (count > K)
break;
Ans--;
count++;
}
cout << Ans << endl;
return 0;
} | replace | 14 | 19 | 14 | 15 | TLE | |
p02682 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll A, B, C, K;
cin >> A >> B >> C >> K;
ll ans = 0;
for (size_t i = 1; i <= K; i++) {
if (A > 0) {
ans += 1;
A--;
} else if (B > 0) {
ans += 0;
B--;
} else if (C > 0) {
ans += -1;
C--;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll A, B, C, K;
cin >> A >> B >> C >> K;
ll ans = 0;
for (size_t i = 1; i <= K; i++) {
if (A <= 0 && B <= 0 && C <= 0) {
break;
}
if (A > 0) {
ans += 1;
A--;
} else if (B > 0) {
ans += 0;
B--;
} else if (C > 0) {
ans += -1;
C--;
}
}
cout << ans << endl;
}
| insert | 10 | 10 | 10 | 14 | TLE | |
p02682 | C++ | Time Limit Exceeded | #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define l(i, a, b) for (auto i = a; i < b; i++)
#define lr(i, a, b) for (auto i = a; i >= b; i--)
#define ll long long
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<ll, ll>
#define vl vector<long long>
#define se set<long long int>
#define pi pair<long long, long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define all(v) v.begin(), v.end()
#define in(x) cin >> x
#define o(x) cout << x
#define SYNC \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
using namespace std;
int main() {
SYNC ll a, b, c, k, sum = 0;
in(a) >> b >> c >> k;
l(i, 0, k) {
if (a > 0) {
sum += 1;
a--;
} else if (b > 0) {
sum += 0;
b--;
} else
sum -= 1;
}
o(sum);
}
| #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define l(i, a, b) for (auto i = a; i < b; i++)
#define lr(i, a, b) for (auto i = a; i >= b; i--)
#define ll long long
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<ll, ll>
#define vl vector<long long>
#define se set<long long int>
#define pi pair<long long, long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define all(v) v.begin(), v.end()
#define in(x) cin >> x
#define o(x) cout << x
#define SYNC \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
using namespace std;
int main() {
SYNC ll a, b, c, k, sum = 0;
in(a) >> b >> c >> k;
if (k == a + b + c) {
sum += (a - c);
} else if (k <= a + b && k >= a) {
sum += a;
} else if (k > a + b) {
sum += a;
k -= (a + b);
sum -= k;
} else if (k < a) {
sum += k;
}
o(sum);
}
| replace | 27 | 36 | 27 | 37 | TLE |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.