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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02644 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define FOR(i, a, b) for (auto i = a; i <= b; ++i)
#define REP(i, a, b) for (auto i = a; i < b; ++i)
#define FORI(i, a, b) \
for (auto i = a; i != b + 1 - 2 * (a > b); i += 1 - 2 * (a > b))
#define REPI(i, a, b) \
for (auto i = a - (a > b); i != b - (a > b); i += 1 - 2 * (a > b))
#define ALL(v) v.begin(), v.end()
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define eb(a, b) emplace_back(a, b)
#define fir first
#define sec second
#define what_is(x) cout << #x << " is " << x << endl;
#define type(x) typeid(x).name()
#define ms(arr, val) memset(arr, val, sizeof(arr))
#define min3(a, b, c) min(min(a, b), c)
#define max3(a, b, c) max(max(a, b), c)
#define PI acos(-1)
#define open_read freopen("christmas.in", "r", stdin)
#define open_write freopen("christmas.out", "w", stdout)
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<double, double> PDD;
typedef pair<int, int> PII;
typedef pair<int, PII> PIPII;
typedef pair<PII, PII> PPIIPII;
typedef pair<LL, LL> PLL;
typedef pair<ULL, ULL> PUU;
typedef pair<LL, PLL> PLPLL;
typedef pair<PLL, PLL> PPLLPLL;
typedef pair<int, LL> PIL;
typedef pair<LL, int> PLI;
template <typename T, typename T1>
ostream &operator<<(ostream &out, pair<T, T1> obj) {
out << "(" << obj.first << ", " << obj.second << ")";
return out;
}
template <typename T, typename T1>
ostream &operator<<(ostream &out, map<T, T1> cont) {
typename map<T, T1>::const_iterator itr = cont.begin();
typename map<T, T1>::const_iterator ends = cont.end();
for (; itr != ends; ++itr) {
out << *itr << " ";
}
out << endl;
return out;
}
template <typename T> ostream &operator<<(ostream &out, set<T> cont) {
typename set<T>::const_iterator itr = cont.begin();
typename set<T>::const_iterator ends = cont.end();
for (; itr != ends; ++itr) {
out << *itr << " ";
}
out << endl;
return out;
}
template <typename T> ostream &operator<<(ostream &out, multiset<T> cont) {
typename multiset<T>::const_iterator itr = cont.begin();
typename multiset<T>::const_iterator ends = cont.end();
for (; itr != ends; ++itr) {
out << *itr << " ";
}
out << endl;
return out;
}
template <typename T,
template <typename ELEM, typename ALLOC = allocator<ELEM>> class CONT>
ostream &operator<<(ostream &out, CONT<T> cont) {
typename CONT<T>::const_iterator itr = cont.begin();
typename CONT<T>::const_iterator ends = cont.end();
for (; itr != ends; ++itr) {
out << *itr << " ";
}
out << endl;
return out;
}
template <typename T, unsigned int N, typename CTy, typename CTr>
typename enable_if<!is_same<T, char>::value, basic_ostream<CTy, CTr> &>::type
operator<<(basic_ostream<CTy, CTr> &out, const T (&arr)[N]) {
REP(i, 0, N) { out << arr[i] << " "; }
out << endl;
return out;
}
template <typename T> T GCD(T a, T b) {
T min_v = min(a, b);
T max_v = max(a, b);
while (min_v) {
T temp = max_v % min_v;
max_v = min_v;
min_v = temp;
}
return max_v;
}
template <typename T> T LCM(T a, T b) { return (a * b) / gcd(a, b); }
template <typename T> T fastExpPow(T base, T exp, T mod) {
T res = 1;
while (exp) {
if (exp & 1) {
res *= base;
res %= mod;
}
exp >>= 1;
base *= base;
base %= mod;
}
return res % mod;
}
/*#################################################################################################################
###################################################################################################################
###################################################################################################################
#################################################################################################################*/
#define SIZE 1000010
int H, W, K, X1, Y1, X2, Y2;
vector<char> board[SIZE];
map<PIPII, int> minDist;
queue<PIPII> que;
bool invalid(PII pos) {
return pos.fir >= H || pos.fir < 0 || pos.sec >= W || pos.sec < 0 ||
board[pos.fir][pos.sec] == '@';
}
void bfs() {
que.push(mp(0, mp(X1, Y1)));
que.push(mp(1, mp(X1, Y1)));
minDist[mp(0, mp(X1, Y1))] = 0;
minDist[mp(1, mp(X1, Y1))] = 0;
while (!que.empty()) {
int type = que.front().fir;
PII pos = que.front().sec;
que.pop();
int currDist = minDist[mp(type, pos)];
FOR(t, 0, 1) {
for (int dir = -1; dir <= 1; dir += 2) {
FOR(i, 1, K) {
PII newPos = mp(pos.fir + i * dir * (int)(t == 0),
pos.sec + i * dir * (int)(t == 1));
if ((minDist.count(mp(t, newPos)) &&
minDist[mp(t, newPos)] < currDist + 1) ||
invalid(newPos)) {
break;
}
minDist[mp(t, newPos)] = currDist + 1;
que.push(mp(t, newPos));
}
}
}
}
}
int main() {
scanf("%d%d%d%d%d%d%d", &H, &W, &K, &X1, &Y1, &X2, &Y2);
--X1, --Y1, --X2, --Y2;
REP(i, 0, H) {
REP(j, 0, W) {
char ch;
scanf(" %c", &ch);
board[i].pb(ch);
}
}
bfs();
int answer = -1;
FOR(t, 0, 1) {
if (minDist.count(mp(t, mp(X2, Y2)))) {
answer = (answer == -1 ? minDist[mp(t, mp(X2, Y2))]
: min(answer, minDist[mp(t, mp(X2, Y2))]));
}
}
printf("%d\n", answer);
return 0;
}
| #include <bits/stdc++.h>
#define FOR(i, a, b) for (auto i = a; i <= b; ++i)
#define REP(i, a, b) for (auto i = a; i < b; ++i)
#define FORI(i, a, b) \
for (auto i = a; i != b + 1 - 2 * (a > b); i += 1 - 2 * (a > b))
#define REPI(i, a, b) \
for (auto i = a - (a > b); i != b - (a > b); i += 1 - 2 * (a > b))
#define ALL(v) v.begin(), v.end()
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define eb(a, b) emplace_back(a, b)
#define fir first
#define sec second
#define what_is(x) cout << #x << " is " << x << endl;
#define type(x) typeid(x).name()
#define ms(arr, val) memset(arr, val, sizeof(arr))
#define min3(a, b, c) min(min(a, b), c)
#define max3(a, b, c) max(max(a, b), c)
#define PI acos(-1)
#define open_read freopen("christmas.in", "r", stdin)
#define open_write freopen("christmas.out", "w", stdout)
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<double, double> PDD;
typedef pair<int, int> PII;
typedef pair<int, PII> PIPII;
typedef pair<PII, PII> PPIIPII;
typedef pair<LL, LL> PLL;
typedef pair<ULL, ULL> PUU;
typedef pair<LL, PLL> PLPLL;
typedef pair<PLL, PLL> PPLLPLL;
typedef pair<int, LL> PIL;
typedef pair<LL, int> PLI;
template <typename T, typename T1>
ostream &operator<<(ostream &out, pair<T, T1> obj) {
out << "(" << obj.first << ", " << obj.second << ")";
return out;
}
template <typename T, typename T1>
ostream &operator<<(ostream &out, map<T, T1> cont) {
typename map<T, T1>::const_iterator itr = cont.begin();
typename map<T, T1>::const_iterator ends = cont.end();
for (; itr != ends; ++itr) {
out << *itr << " ";
}
out << endl;
return out;
}
template <typename T> ostream &operator<<(ostream &out, set<T> cont) {
typename set<T>::const_iterator itr = cont.begin();
typename set<T>::const_iterator ends = cont.end();
for (; itr != ends; ++itr) {
out << *itr << " ";
}
out << endl;
return out;
}
template <typename T> ostream &operator<<(ostream &out, multiset<T> cont) {
typename multiset<T>::const_iterator itr = cont.begin();
typename multiset<T>::const_iterator ends = cont.end();
for (; itr != ends; ++itr) {
out << *itr << " ";
}
out << endl;
return out;
}
template <typename T,
template <typename ELEM, typename ALLOC = allocator<ELEM>> class CONT>
ostream &operator<<(ostream &out, CONT<T> cont) {
typename CONT<T>::const_iterator itr = cont.begin();
typename CONT<T>::const_iterator ends = cont.end();
for (; itr != ends; ++itr) {
out << *itr << " ";
}
out << endl;
return out;
}
template <typename T, unsigned int N, typename CTy, typename CTr>
typename enable_if<!is_same<T, char>::value, basic_ostream<CTy, CTr> &>::type
operator<<(basic_ostream<CTy, CTr> &out, const T (&arr)[N]) {
REP(i, 0, N) { out << arr[i] << " "; }
out << endl;
return out;
}
template <typename T> T GCD(T a, T b) {
T min_v = min(a, b);
T max_v = max(a, b);
while (min_v) {
T temp = max_v % min_v;
max_v = min_v;
min_v = temp;
}
return max_v;
}
template <typename T> T LCM(T a, T b) { return (a * b) / gcd(a, b); }
template <typename T> T fastExpPow(T base, T exp, T mod) {
T res = 1;
while (exp) {
if (exp & 1) {
res *= base;
res %= mod;
}
exp >>= 1;
base *= base;
base %= mod;
}
return res % mod;
}
/*#################################################################################################################
###################################################################################################################
###################################################################################################################
#################################################################################################################*/
#define SIZE 1000010
int H, W, K, X1, Y1, X2, Y2;
vector<char> board[SIZE];
map<PIPII, int> minDist;
queue<PIPII> que;
bool invalid(PII pos) {
return pos.fir >= H || pos.fir < 0 || pos.sec >= W || pos.sec < 0 ||
board[pos.fir][pos.sec] == '@';
}
void bfs() {
que.push(mp(0, mp(X1, Y1)));
que.push(mp(1, mp(X1, Y1)));
minDist[mp(0, mp(X1, Y1))] = 0;
minDist[mp(1, mp(X1, Y1))] = 0;
while (!que.empty()) {
int type = que.front().fir;
PII pos = que.front().sec;
que.pop();
int currDist = minDist[mp(type, pos)];
FOR(t, 0, 1) {
for (int dir = -1; dir <= 1; dir += 2) {
FOR(i, 1, K) {
PII newPos = mp(pos.fir + i * dir * (int)(t == 0),
pos.sec + i * dir * (int)(t == 1));
if (minDist.count(mp(t, newPos)) || invalid(newPos)) {
break;
}
if (minDist.count(mp(1 - t, newPos)) &&
minDist[mp(1 - t, newPos)] <= currDist) {
break;
}
minDist[mp(t, newPos)] = currDist + 1;
que.push(mp(t, newPos));
}
}
}
}
}
int main() {
scanf("%d%d%d%d%d%d%d", &H, &W, &K, &X1, &Y1, &X2, &Y2);
--X1, --Y1, --X2, --Y2;
REP(i, 0, H) {
REP(j, 0, W) {
char ch;
scanf(" %c", &ch);
board[i].pb(ch);
}
}
bfs();
int answer = -1;
FOR(t, 0, 1) {
if (minDist.count(mp(t, mp(X2, Y2)))) {
answer = (answer == -1 ? minDist[mp(t, mp(X2, Y2))]
: min(answer, minDist[mp(t, mp(X2, Y2))]));
}
}
printf("%d\n", answer);
return 0;
}
| replace | 174 | 177 | 174 | 180 | TLE | |
p02644 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
constexpr int INF = 1000000000;
constexpr int AREA_MAX = 100010;
char flatGrid[AREA_MAX];
set<int> byRow[AREA_MAX], byCol[AREA_MAX];
int main() {
int h, w, k;
scanf("%d %d %d", &h, &w, &k);
int x1, y1, x2, y2;
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
--x1, --y1, --x2, --y2;
for (int i = 0; i < h; ++i) {
scanf("%s", flatGrid + i * w);
}
auto getCell = [&h, &w](int i, int j) { return flatGrid[i * w + j]; };
auto deleteCell = [](int i, int j) {
byRow[i].erase(j);
byCol[j].erase(i);
};
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
byRow[i].insert(j);
byCol[j].insert(i);
}
}
vector<vector<int>> dist(h, vector<int>(w, -1));
queue<pair<int, int>> q;
q.emplace(x1, y1);
dist[x1][y1] = 0;
deleteCell(x1, y1);
while (!q.empty()) {
int cx, cy;
tie(cx, cy) = q.front();
q.pop();
// printf("visit %d %d %d\n", cx, cy, dist[cx][cy]);
int nx = cx, ny = cy;
auto updateCell = [&cx, &cy, &q, &deleteCell, &dist](int i, int j) {
// printf("updating %d %d from %d %d\n", i, j, cx,
//cy);
deleteCell(i, j);
dist[i][j] = dist[cx][cy] + 1;
q.emplace(i, j);
};
while (true) { // moving cy forward
auto ncell = byRow[nx].upper_bound(ny);
if (ncell == byRow[nx].end() || *ncell - cy > k ||
getCell(nx, *ncell) == '@')
break;
ny = *ncell;
updateCell(nx, ny);
}
nx = cx, ny = cy;
while (true) { // move cx forward
auto ncell = byCol[ny].upper_bound(nx);
if (ncell == byCol[ny].end() || *ncell - cx > k ||
getCell(*ncell, ny) == '@')
break;
nx = *ncell;
updateCell(nx, ny);
}
nx = cx, ny = cy;
while (true) { // move cy backward
auto ncell = byRow[nx].lower_bound(ny);
if (ncell == byRow[nx].begin())
break;
auto nbcell = prev(ncell, 1);
if (cy - *nbcell > k || getCell(nx, *nbcell) == '@')
break;
ny = *nbcell;
updateCell(nx, ny);
}
nx = cx, ny = cy;
while (true) { // move cx backward
auto ncell = byCol[ny].lower_bound(nx);
if (ncell == byCol[ny].begin())
break;
auto nbcell = prev(ncell, 1);
if (cx - *nbcell > k || getCell(*nbcell, ny) == '@')
break;
nx = *nbcell;
updateCell(nx, ny);
}
}
printf("%d\n", dist[x2][y2]);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
constexpr int INF = 1000000000;
constexpr int AREA_MAX = 1000010;
char flatGrid[AREA_MAX];
set<int> byRow[AREA_MAX], byCol[AREA_MAX];
int main() {
int h, w, k;
scanf("%d %d %d", &h, &w, &k);
int x1, y1, x2, y2;
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
--x1, --y1, --x2, --y2;
for (int i = 0; i < h; ++i) {
scanf("%s", flatGrid + i * w);
}
auto getCell = [&h, &w](int i, int j) { return flatGrid[i * w + j]; };
auto deleteCell = [](int i, int j) {
byRow[i].erase(j);
byCol[j].erase(i);
};
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
byRow[i].insert(j);
byCol[j].insert(i);
}
}
vector<vector<int>> dist(h, vector<int>(w, -1));
queue<pair<int, int>> q;
q.emplace(x1, y1);
dist[x1][y1] = 0;
deleteCell(x1, y1);
while (!q.empty()) {
int cx, cy;
tie(cx, cy) = q.front();
q.pop();
// printf("visit %d %d %d\n", cx, cy, dist[cx][cy]);
int nx = cx, ny = cy;
auto updateCell = [&cx, &cy, &q, &deleteCell, &dist](int i, int j) {
// printf("updating %d %d from %d %d\n", i, j, cx,
//cy);
deleteCell(i, j);
dist[i][j] = dist[cx][cy] + 1;
q.emplace(i, j);
};
while (true) { // moving cy forward
auto ncell = byRow[nx].upper_bound(ny);
if (ncell == byRow[nx].end() || *ncell - cy > k ||
getCell(nx, *ncell) == '@')
break;
ny = *ncell;
updateCell(nx, ny);
}
nx = cx, ny = cy;
while (true) { // move cx forward
auto ncell = byCol[ny].upper_bound(nx);
if (ncell == byCol[ny].end() || *ncell - cx > k ||
getCell(*ncell, ny) == '@')
break;
nx = *ncell;
updateCell(nx, ny);
}
nx = cx, ny = cy;
while (true) { // move cy backward
auto ncell = byRow[nx].lower_bound(ny);
if (ncell == byRow[nx].begin())
break;
auto nbcell = prev(ncell, 1);
if (cy - *nbcell > k || getCell(nx, *nbcell) == '@')
break;
ny = *nbcell;
updateCell(nx, ny);
}
nx = cx, ny = cy;
while (true) { // move cx backward
auto ncell = byCol[ny].lower_bound(nx);
if (ncell == byCol[ny].begin())
break;
auto nbcell = prev(ncell, 1);
if (cx - *nbcell > k || getCell(*nbcell, ny) == '@')
break;
nx = *nbcell;
updateCell(nx, ny);
}
}
printf("%d\n", dist[x2][y2]);
return 0;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p02644 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
// typedef vector<vector<ll>> Graph;
const ll mod = 1e9 + 7;
// const ll mod = 998244353;
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define dump(x) cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second
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 <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> v) {
os << "(" << v.first << ", " << v.second << ")";
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> v) {
for (int i = 0; i < (int)v.size(); i++) {
if (i > 0) {
os << " ";
}
os << v[i];
}
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<vector<T>> v) {
for (int i = 0; i < (int)v.size(); i++) {
if (i > 0) {
os << endl;
}
os << v[i];
}
return os;
}
template <typename T> void debug(vector<vector<T>> &v, ll h, ll w) {
for (ll i = 0; i < h; i++) {
cerr << v[i][0];
for (ll j = 1; j < w; j++)
cerr spa v[i][j];
cerr << endl;
}
};
template <typename T> void debug(vector<T> &v, ll n) {
if (n != 0)
cerr << v[0];
for (ll i = 1; i < n; i++)
cerr spa v[i];
cerr << endl;
};
string num2bit(ll num, ll len) {
string bit = "";
REP(i, len) { bit += char('0' + (num >> i & 1)); }
return bit;
}
struct P {
ll x, y;
P(ll x, ll y) : x(x), y(y){};
};
vector<ll> dx = {-1, 0, 1, 0};
vector<ll> dy = {0, -1, 0, 1};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll H, W, K;
cin >> H >> W >> K;
ll x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
x1--, y1--, x2--, y2--;
vector<string> c(H);
REP(i, H) cin >> c[i];
const ll INF = (1ll << 60);
vector<vector<ll>> dist(H, vector<ll>(W, INF));
queue<P> qu;
qu.emplace(x1, y1);
dist[x1][y1] = 0;
while (!qu.empty()) {
P p = qu.front();
qu.pop();
REP(dir, 4) {
for (int k = 1; k <= K; k++) {
ll nx = p.x + k * dx[dir];
ll ny = p.y + k * dy[dir];
if (nx < 0 or nx > H - 1 or ny < 0 or ny > W - 1)
break;
if (c[nx][ny] == '@')
break;
if (dist[nx][ny] != INF)
continue;
dist[nx][ny] = dist[p.x][p.y] + 1;
qu.emplace(nx, ny);
}
}
}
// debug(dist, H, W);
cout << (dist[x2][y2] == INF ? -1 : dist[x2][y2]) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
// typedef vector<vector<ll>> Graph;
const ll mod = 1e9 + 7;
// const ll mod = 998244353;
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define dump(x) cerr << #x << " = " << (x) << endl;
#define spa << " " <<
#define fi first
#define se second
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 <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> v) {
os << "(" << v.first << ", " << v.second << ")";
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> v) {
for (int i = 0; i < (int)v.size(); i++) {
if (i > 0) {
os << " ";
}
os << v[i];
}
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<vector<T>> v) {
for (int i = 0; i < (int)v.size(); i++) {
if (i > 0) {
os << endl;
}
os << v[i];
}
return os;
}
template <typename T> void debug(vector<vector<T>> &v, ll h, ll w) {
for (ll i = 0; i < h; i++) {
cerr << v[i][0];
for (ll j = 1; j < w; j++)
cerr spa v[i][j];
cerr << endl;
}
};
template <typename T> void debug(vector<T> &v, ll n) {
if (n != 0)
cerr << v[0];
for (ll i = 1; i < n; i++)
cerr spa v[i];
cerr << endl;
};
string num2bit(ll num, ll len) {
string bit = "";
REP(i, len) { bit += char('0' + (num >> i & 1)); }
return bit;
}
struct P {
ll x, y;
P(ll x, ll y) : x(x), y(y){};
};
vector<ll> dx = {-1, 0, 1, 0};
vector<ll> dy = {0, -1, 0, 1};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll H, W, K;
cin >> H >> W >> K;
ll x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
x1--, y1--, x2--, y2--;
vector<string> c(H);
REP(i, H) cin >> c[i];
const ll INF = (1ll << 60);
vector<vector<ll>> dist(H, vector<ll>(W, INF));
queue<P> qu;
qu.emplace(x1, y1);
dist[x1][y1] = 0;
while (!qu.empty()) {
P p = qu.front();
qu.pop();
REP(dir, 4) {
for (int k = 1; k <= K; k++) {
ll nx = p.x + k * dx[dir];
ll ny = p.y + k * dy[dir];
if (nx < 0 or nx > H - 1 or ny < 0 or ny > W - 1)
break;
if (c[nx][ny] == '@')
break;
if (dist[nx][ny] <= dist[p.x][p.y])
break;
if (dist[nx][ny] != INF)
continue;
dist[nx][ny] = dist[p.x][p.y] + 1;
qu.emplace(nx, ny);
}
}
}
// debug(dist, H, W);
cout << (dist[x2][y2] == INF ? -1 : dist[x2][y2]) << endl;
return 0;
} | insert | 121 | 121 | 121 | 123 | TLE | |
p02644 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
int H, W, K;
cin >> H >> W >> K;
vector<vector<int>> c(H + 2, vector<int>(W + 2));
vector<vector<int>> d(H + 2, vector<int>(W + 2, INF));
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
for (int i = 1; i <= H; i++) {
string s;
cin >> s;
for (int j = 1; j <= W; j++) {
c[i][j] = (s[j - 1] == '.' ? 1 : 0);
}
}
priority_queue<pair<int, pair<pair<int, int>, int>>,
vector<pair<int, pair<pair<int, int>, int>>>,
greater<pair<int, pair<pair<int, int>, int>>>>
que;
que.push(make_pair(0, make_pair(make_pair(x1, y1), -1)));
while (!que.empty()) {
int dist = que.top().first;
int x = que.top().second.first.first, y = que.top().second.first.second;
int dir = que.top().second.second;
que.pop();
if (x == x2 && y == y2) {
cout << dist << endl;
return 0;
}
if (dist > d[x][y])
continue;
for (int i = 0; i < 4; i++) {
if (i == dir)
continue;
int ddx = 0, ddy = 0;
while (true) {
ddx += dx[i], ddy += dy[i];
int tmp = (abs(ddx + ddy) + K - 1) / K;
if (c[x + ddx][y + ddy]) {
if (d[x + ddx][y + ddy] > dist + tmp) {
d[x + ddx][y + ddy] = dist + tmp;
que.push(make_pair(dist + tmp,
make_pair(make_pair(x + ddx, y + ddy), i)));
}
} else {
break;
}
}
}
}
cout << -1 << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
int H, W, K;
cin >> H >> W >> K;
vector<vector<int>> c(H + 2, vector<int>(W + 2));
vector<vector<int>> d(H + 2, vector<int>(W + 2, INF));
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
for (int i = 1; i <= H; i++) {
string s;
cin >> s;
for (int j = 1; j <= W; j++) {
c[i][j] = (s[j - 1] == '.' ? 1 : 0);
}
}
priority_queue<pair<int, pair<pair<int, int>, int>>,
vector<pair<int, pair<pair<int, int>, int>>>,
greater<pair<int, pair<pair<int, int>, int>>>>
que;
que.push(make_pair(0, make_pair(make_pair(x1, y1), -1)));
while (!que.empty()) {
int dist = que.top().first;
int x = que.top().second.first.first, y = que.top().second.first.second;
int dir = que.top().second.second;
que.pop();
if (x == x2 && y == y2) {
cout << dist << endl;
return 0;
}
if (dist > d[x][y])
continue;
for (int i = 0; i < 4; i++) {
if (i % 2 == dir % 2)
continue;
int ddx = 0, ddy = 0;
while (true) {
ddx += dx[i], ddy += dy[i];
int tmp = (abs(ddx + ddy) + K - 1) / K;
if (c[x + ddx][y + ddy]) {
if (d[x + ddx][y + ddy] > dist + tmp) {
d[x + ddx][y + ddy] = dist + tmp;
que.push(make_pair(dist + tmp,
make_pair(make_pair(x + ddx, y + ddy), i)));
}
} else {
break;
}
}
}
}
cout << -1 << endl;
} | replace | 41 | 42 | 41 | 42 | TLE | |
p02644 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using piii = pair<ll, pii>;
ll solve() {
ll H, W, K;
ll x1, y1, x2, y2;
cin >> H >> W >> K;
cin >> x1 >> y1 >> x2 >> y2;
x1--, y1--, x2--, y2--;
vector<string> C(H);
for (int i = 0; i < H; i++) {
cin >> C[i];
}
ll INF = 1LL << 60;
vector<vector<ll>> d(H, vector<ll>(W, INF));
pii st(x1, y1), ed(x2, y2);
vector<int> dx = {0, 1, 0, -1}, dy = {1, 0, -1, 0};
priority_queue<pair<ll, pii>, vector<pair<ll, pii>>, greater<>> q;
d[st.first][st.second] = 0;
q.push(piii(0LL, st));
while (!q.empty()) {
auto p = q.top();
ll c = p.first;
int px = p.second.first, py = p.second.second;
q.pop();
if (d[px][py] < c)
continue;
for (int ii = 0; ii < 4; ii++) {
int x = px, y = py;
for (int j = 0; j < K; j++) {
x += dx[ii], y += dy[ii];
if (x < 0 || x >= H || y < 0 || y >= W)
break;
if (C[x][y] == '@')
break;
if (d[x][y] <= d[px][py])
continue;
if (d[x][y] > d[px][py] + 1) {
d[x][y] = d[px][py] + 1;
q.push(piii(d[x][y], pii(x, y)));
}
}
}
}
ll ans = d[x2][y2];
if (ans == INF)
return -1;
return ans;
}
int main() {
auto ans = solve();
cout << ans << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using piii = pair<ll, pii>;
ll solve() {
ll H, W, K;
ll x1, y1, x2, y2;
cin >> H >> W >> K;
cin >> x1 >> y1 >> x2 >> y2;
x1--, y1--, x2--, y2--;
vector<string> C(H);
for (int i = 0; i < H; i++) {
cin >> C[i];
}
ll INF = 1LL << 60;
vector<vector<ll>> d(H, vector<ll>(W, INF));
pii st(x1, y1), ed(x2, y2);
vector<int> dx = {0, 1, 0, -1}, dy = {1, 0, -1, 0};
priority_queue<pair<ll, pii>, vector<pair<ll, pii>>, greater<>> q;
d[st.first][st.second] = 0;
q.push(piii(0LL, st));
while (!q.empty()) {
auto p = q.top();
ll c = p.first;
int px = p.second.first, py = p.second.second;
q.pop();
if (d[px][py] < c)
continue;
for (int ii = 0; ii < 4; ii++) {
int x = px, y = py;
for (int j = 0; j < K; j++) {
x += dx[ii], y += dy[ii];
if (x < 0 || x >= H || y < 0 || y >= W)
break;
if (C[x][y] == '@')
break;
if (d[x][y] <= d[px][py])
break;
if (d[x][y] > d[px][py] + 1) {
d[x][y] = d[px][py] + 1;
q.push(piii(d[x][y], pii(x, y)));
}
}
}
}
ll ans = d[x2][y2];
if (ans == INF)
return -1;
return ans;
}
int main() {
auto ans = solve();
cout << ans << "\n";
return 0;
} | replace | 40 | 41 | 40 | 41 | TLE | |
p02644 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x, y) x = max(x, y)
#define gmin(x, y) x = min(x, y)
#define gadd(x, y) x = add(x, y)
#define gmul(x, y) x = mul(x, y)
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
pii dir[4] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};
int h, w, k;
int sx, sy, gx, gy;
int bfs(vector<vi> &g) {
vector<vi> d(g.size(), vi(g[0].size()));
queue<pii> q;
int dist = 1;
q.push({sx, sy});
d[sx][sy] = 1;
while (q.size()) {
++dist;
int cnt = q.size();
while (cnt--) {
int x = q.front().first;
int y = q.front().second;
q.pop();
rep(i, 0, 4) {
int cx = x, cy = y;
rep(j, 0, k) {
cx += dir[i].first;
cy += dir[i].second;
if ((d[cx][cy] != 0 && d[cx][cy] < dist) || g[cx][cy] == 0) {
break;
}
d[cx][cy] = dist;
q.push({cx, cy});
}
}
}
}
int ans = d[gx][gy];
--ans;
return ans;
}
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
scanf("%d %d %d", &h, &w, &k);
vector<vi> g(h + 2, vi(w + 2));
scanf("%d %d %d %d", &sx, &sy, &gx, &gy);
rep(i, 1, h + 1) {
rep(j, 1, w + 1) {
char c;
scanf(" %c", &c);
g[i][j] = c == '.' ? 1 : 0;
}
}
int ans = bfs(g);
printf("%d\n", ans);
}
| #include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x, y) x = max(x, y)
#define gmin(x, y) x = min(x, y)
#define gadd(x, y) x = add(x, y)
#define gmul(x, y) x = mul(x, y)
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
pii dir[4] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};
int h, w, k;
int sx, sy, gx, gy;
int bfs(vector<vi> &g) {
vector<vi> d(g.size(), vi(g[0].size()));
queue<pii> q;
int dist = 1;
q.push({sx, sy});
d[sx][sy] = 1;
while (q.size()) {
++dist;
int cnt = q.size();
while (cnt--) {
int x = q.front().first;
int y = q.front().second;
q.pop();
rep(i, 0, 4) {
int cx = x, cy = y;
rep(j, 0, k) {
cx += dir[i].first;
cy += dir[i].second;
if ((d[cx][cy] != 0 && d[cx][cy] < dist) || g[cx][cy] == 0) {
break;
}
if (d[cx][cy] == 0) {
d[cx][cy] = dist;
q.push({cx, cy});
}
}
}
}
}
int ans = d[gx][gy];
--ans;
return ans;
}
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
scanf("%d %d %d", &h, &w, &k);
vector<vi> g(h + 2, vi(w + 2));
scanf("%d %d %d %d", &sx, &sy, &gx, &gy);
rep(i, 1, h + 1) {
rep(j, 1, w + 1) {
char c;
scanf(" %c", &c);
g[i][j] = c == '.' ? 1 : 0;
}
}
int ans = bfs(g);
printf("%d\n", ans);
}
| replace | 38 | 40 | 38 | 42 | TLE | |
p02644 | C++ | Time Limit Exceeded | #ifndef COMPETITIVE_HEADER
#pragma GCC optimize("Ofast")
#ifdef ONLINE_JUDGE
#pragma GCC target("avx512f")
#else
#pragma GCC target("avx")
#endif
//----------------------------
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define int ll
#define FOR(i, j, n) for (int i = (int)(j); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPS(i, n) for (int i = 1; i <= (int)(n); i++)
#define REPN(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define REPNS(i, n) for (int i = (int)(n); i > 0; i--)
#define I(n) scanf("%lld", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i, j) make_pair((i), (j))
#define eb(i, j) emplace_back((i), (j))
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
const int mod = 1000000007;
#endif
int h, w, k;
string s;
int x1, y1, x2, y2;
signed main() {
cin >> h >> w >> k;
cin >> x1 >> y1 >> x2 >> y2;
char table[h + 2][w + 2];
memset(table, '@', sizeof(table));
REP(i, h) {
cin >> s;
REP(j, w) { table[i + 1][j + 1] = s[j]; }
}
int ans[h + 2][w + 2];
REP(i, h + 2) REP(j, w + 2) ans[i][j] = INT_MAX / 2;
ans[x1][y1] = 0;
deque<pi> q;
q.emplace_back(x1, y1);
// REP(i,h+2) { REP(j,w+2) cerr << table[i][j]; cerr << endl; }
while (!q.empty()) {
auto pos = q.front();
q.pop_front();
int x = pos.first;
int y = pos.second;
int dist = ans[x][y];
REPS(ki, k) {
int xk = x - ki;
int yk = y;
if (table[xk][yk] == '@')
break;
if (ans[xk][yk] > dist + 1) {
q.emplace_back(xk, yk);
ans[xk][yk] = dist + 1;
}
}
REPS(ki, k) {
int xk = x + ki;
int yk = y;
if (table[xk][yk] == '@')
break;
if (ans[xk][yk] > dist + 1) {
q.emplace_back(xk, yk);
ans[xk][yk] = dist + 1;
}
}
REPS(ki, k) {
int xk = x;
int yk = y - ki;
if (table[xk][yk] == '@')
break;
if (ans[xk][yk] > dist + 1) {
q.emplace_back(xk, yk);
ans[xk][yk] = dist + 1;
}
}
REPS(ki, k) {
int xk = x;
int yk = y + ki;
if (table[xk][yk] == '@')
break;
if (ans[xk][yk] > dist + 1) {
q.emplace_back(xk, yk);
ans[xk][yk] = dist + 1;
}
}
}
cout << (ans[x2][y2] < INT_MAX / 2 ? ans[x2][y2] : -1) << endl;
} | #ifndef COMPETITIVE_HEADER
#pragma GCC optimize("Ofast")
#ifdef ONLINE_JUDGE
#pragma GCC target("avx512f")
#else
#pragma GCC target("avx")
#endif
//----------------------------
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define int ll
#define FOR(i, j, n) for (int i = (int)(j); i < (n); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPS(i, n) for (int i = 1; i <= (int)(n); i++)
#define REPN(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define REPNS(i, n) for (int i = (int)(n); i > 0; i--)
#define I(n) scanf("%lld", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i, j) make_pair((i), (j))
#define eb(i, j) emplace_back((i), (j))
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
const int mod = 1000000007;
#endif
int h, w, k;
string s;
int x1, y1, x2, y2;
signed main() {
cin >> h >> w >> k;
cin >> x1 >> y1 >> x2 >> y2;
char table[h + 2][w + 2];
memset(table, '@', sizeof(table));
REP(i, h) {
cin >> s;
REP(j, w) { table[i + 1][j + 1] = s[j]; }
}
int ans[h + 2][w + 2];
REP(i, h + 2) REP(j, w + 2) ans[i][j] = INT_MAX / 2;
ans[x1][y1] = 0;
deque<pi> q;
q.emplace_back(x1, y1);
// REP(i,h+2) { REP(j,w+2) cerr << table[i][j]; cerr << endl; }
while (!q.empty()) {
auto pos = q.front();
q.pop_front();
int x = pos.first;
int y = pos.second;
int dist = ans[x][y];
table[x][y] = '@';
REPS(ki, k) {
int xk = x - ki;
int yk = y;
if (table[xk][yk] == '@')
break;
if (ans[xk][yk] > dist + 1) {
q.emplace_back(xk, yk);
ans[xk][yk] = dist + 1;
}
}
REPS(ki, k) {
int xk = x + ki;
int yk = y;
if (table[xk][yk] == '@')
break;
if (ans[xk][yk] > dist + 1) {
q.emplace_back(xk, yk);
ans[xk][yk] = dist + 1;
}
}
REPS(ki, k) {
int xk = x;
int yk = y - ki;
if (table[xk][yk] == '@')
break;
if (ans[xk][yk] > dist + 1) {
q.emplace_back(xk, yk);
ans[xk][yk] = dist + 1;
}
}
REPS(ki, k) {
int xk = x;
int yk = y + ki;
if (table[xk][yk] == '@')
break;
if (ans[xk][yk] > dist + 1) {
q.emplace_back(xk, yk);
ans[xk][yk] = dist + 1;
}
}
}
cout << (ans[x2][y2] < INT_MAX / 2 ? ans[x2][y2] : -1) << endl;
} | insert | 71 | 71 | 71 | 72 | TLE | |
p02644 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll, ll>
#define vvll vector<vector<ll>>
#define pb push_back
#define sz(v) (ll)(v).size()
#define inf 1e18
#define md 1e9 + 7
#define all(v) (v).begin(), (v).end()
#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define tel(a) \
{ cout << a << "\n"; }
#define tell(a, b) \
{ cout << a << " | " << b << "\n"; }
#define telll(a, b, c) \
{ cout << a << " | " << b << " | " << c << "\n"; }
#define teln(v, n) \
{ \
cout << "v- "; \
rep(o, 0, n) cout << v[o] << " "; \
cout << "\n"; \
}
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
using namespace std;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define trace(...)
#endif
#define M 100010
ll dx[] = {1, -1, 0, 0};
ll dy[] = {0, 0, 1, -1};
int main() {
IOS;
ll h, w, k;
cin >> h >> w >> k;
ll x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
x1--, y1--, x2--, y2--;
ll a[h][w], d[h][w];
rep(i, 0, h) rep(j, 0, w) {
char c;
cin >> c;
a[i][j] = (c == '.');
d[i][j] = inf;
}
queue<pii> q;
q.push({x1, y1}), d[x1][y1] = 0;
while (!q.empty()) {
pii u = q.front();
q.pop();
ll x = u.fi, y = u.se;
rep(i, 0, 4) rep(j, 1, k + 1) {
ll nx = x + dx[i] * j, ny = y + dy[i] * j;
if (nx < 0 or ny < 0 or nx >= h or ny >= w)
continue;
if (!a[nx][ny])
break;
if (d[x][y] + 1 < d[nx][ny]) {
d[nx][ny] = d[x][y] + 1;
q.push({nx, ny});
}
}
}
ll ans = d[x2][y2];
cout << ((ans == inf) ? -1 : ans);
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll, ll>
#define vvll vector<vector<ll>>
#define pb push_back
#define sz(v) (ll)(v).size()
#define inf 1e18
#define md 1e9 + 7
#define all(v) (v).begin(), (v).end()
#define rep(i, a, b) for (ll i = a; i < b; ++i)
#define tel(a) \
{ cout << a << "\n"; }
#define tell(a, b) \
{ cout << a << " | " << b << "\n"; }
#define telll(a, b, c) \
{ cout << a << " | " << b << " | " << c << "\n"; }
#define teln(v, n) \
{ \
cout << "v- "; \
rep(o, 0, n) cout << v[o] << " "; \
cout << "\n"; \
}
#define IOS \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
using namespace std;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define trace(...)
#endif
#define M 100010
ll dx[] = {1, -1, 0, 0};
ll dy[] = {0, 0, 1, -1};
int main() {
IOS;
ll h, w, k;
cin >> h >> w >> k;
ll x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
x1--, y1--, x2--, y2--;
ll a[h][w], d[h][w];
rep(i, 0, h) rep(j, 0, w) {
char c;
cin >> c;
a[i][j] = (c == '.');
d[i][j] = inf;
}
queue<pii> q;
q.push({x1, y1}), d[x1][y1] = 0;
while (!q.empty()) {
pii u = q.front();
q.pop();
ll x = u.fi, y = u.se;
rep(i, 0, 4) rep(j, 1, k + 1) {
ll nx = x + dx[i] * j, ny = y + dy[i] * j;
if (nx < 0 or ny < 0 or nx >= h or ny >= w)
continue;
if (!a[nx][ny] or d[x][y] + 1 > d[nx][ny])
break;
if (d[x][y] + 1 < d[nx][ny]) {
d[nx][ny] = d[x][y] + 1;
q.push({nx, ny});
}
}
}
ll ans = d[x2][y2];
cout << ((ans == inf) ? -1 : ans);
return 0;
} | replace | 78 | 79 | 78 | 79 | TLE | |
p02644 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
#define ll long long int
#define pb push_back
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define per(i, j, n) for (ll i = j; i >= n; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vll;
vector<vector<char>> a;
vector<vector<ll>> dist, vis;
int main() {
ll n, m, k, x1, y1, x2, y2;
cin >> n >> m >> k >> x1 >> y1 >> x2 >> y2;
a = vector<vector<char>>(n + 1, vector<char>(m + 1));
vis = dist = vector<vector<ll>>(n + 1, vector<ll>(m + 1, 0));
rep(i, 1, n + 1) {
rep(j, 1, m + 1) { cin >> a[i][j]; }
}
queue<pair<ll, ll>> q;
q.push({x1, y1});
ll dirx[] = {0, 0, 1, -1};
ll diry[] = {1, -1, 0, 0};
dist[x1][y1] = 0;
vis[x1][y1] = 1;
while (!q.empty()) {
ll x0 = q.front().first;
ll y0 = q.front().second;
q.pop();
rep(i, 0, 4) {
rep(j, 1, k + 1) {
ll nx = x0 + j * dirx[i];
ll ny = y0 + j * diry[i];
if (nx > n || nx < 1 || ny > m || ny < 1)
break;
if (a[nx][ny] == '@')
break;
if (vis[nx][ny])
continue;
vis[nx][ny] = 1;
dist[nx][ny] = dist[x0][y0] + 1;
q.push({nx, ny});
if (nx == x2 && ny == y2) {
cout << dist[x2][y2];
return 0;
}
}
}
}
cout << -1 << endl;
}
| #include <bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
#define ll long long int
#define pb push_back
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define per(i, j, n) for (ll i = j; i >= n; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vll;
vector<vector<char>> a;
vector<vector<ll>> dist, vis;
int main() {
ll n, m, k, x1, y1, x2, y2;
cin >> n >> m >> k >> x1 >> y1 >> x2 >> y2;
a = vector<vector<char>>(n + 1, vector<char>(m + 1));
vis = dist = vector<vector<ll>>(n + 1, vector<ll>(m + 1, 0));
rep(i, 1, n + 1) {
rep(j, 1, m + 1) { cin >> a[i][j]; }
}
queue<pair<ll, ll>> q;
q.push({x1, y1});
ll dirx[] = {0, 0, 1, -1};
ll diry[] = {1, -1, 0, 0};
dist[x1][y1] = 0;
vis[x1][y1] = 1;
while (!q.empty()) {
ll x0 = q.front().first;
ll y0 = q.front().second;
q.pop();
rep(i, 0, 4) {
rep(j, 1, k + 1) {
ll nx = x0 + j * dirx[i];
ll ny = y0 + j * diry[i];
if (nx > n || nx < 1 || ny > m || ny < 1)
break;
if (a[nx][ny] == '@')
break;
if (vis[nx][ny] && dist[x0][y0] + 1 > dist[nx][ny])
break;
if (vis[nx][ny])
continue;
vis[nx][ny] = 1;
dist[nx][ny] = dist[x0][y0] + 1;
q.push({nx, ny});
if (nx == x2 && ny == y2) {
cout << dist[x2][y2];
return 0;
}
}
}
}
cout << -1 << endl;
}
| insert | 43 | 43 | 43 | 45 | TLE | |
p02644 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
for (int i = 0; i < sz(v); i++) {
os << v[i];
if (i < sz(v) - 1)
os << " ";
}
return os;
}
int main() {
int h, w, k;
cin >> h >> w >> k;
int sy, sx, gy, gx;
cin >> sy >> sx >> gy >> gx;
sy--, sx--, gy--, gx--;
auto c = make_vec<bool>(h, w);
rep(i, h) rep(j, w) {
char cr;
cin >> cr;
c[i][j] = (cr == '.');
}
vector<int> dy = {0, 1, 0, -1};
vector<int> dx = {1, 0, -1, 0};
using P = pair<int, int>;
queue<P> q;
q.push(P(sy, sx));
auto d = make_vec<int>(h, w);
rep(i, h) rep(j, w) d[i][j] = INF;
d[sy][sx] = 0;
while (sz(q)) {
auto [y, x] = q.front();
q.pop();
rep(dd, 4) {
int ny = y + dy[dd], nx = x + dx[dd];
while (0 <= ny && ny < h && 0 <= nx && nx < w && c[ny][nx] &&
abs(ny - y) <= k && abs(nx - x) <= k && d[ny][nx] > d[y][x]) {
q.push(P(ny, nx));
chmin(d[ny][nx], d[y][x] + 1);
if (P(ny, nx) == P(gy, gx)) {
cout << d[ny][nx] << endl;
return 0;
}
ny += dy[dd];
nx += dx[dd];
}
}
}
cout << -1 << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
for (int i = 0; i < sz(v); i++) {
os << v[i];
if (i < sz(v) - 1)
os << " ";
}
return os;
}
int main() {
int h, w, k;
cin >> h >> w >> k;
int sy, sx, gy, gx;
cin >> sy >> sx >> gy >> gx;
sy--, sx--, gy--, gx--;
auto c = make_vec<bool>(h, w);
rep(i, h) rep(j, w) {
char cr;
cin >> cr;
c[i][j] = (cr == '.');
}
vector<int> dy = {0, 1, 0, -1};
vector<int> dx = {1, 0, -1, 0};
using P = pair<int, int>;
queue<P> q;
q.push(P(sy, sx));
auto d = make_vec<int>(h, w);
rep(i, h) rep(j, w) d[i][j] = INF;
d[sy][sx] = 0;
while (sz(q)) {
auto [y, x] = q.front();
q.pop();
rep(dd, 4) {
int ny = y + dy[dd], nx = x + dx[dd];
while (0 <= ny && ny < h && 0 <= nx && nx < w && c[ny][nx] &&
abs(ny - y) <= k && abs(nx - x) <= k && d[ny][nx] > d[y][x]) {
if (d[ny][nx] == INF) {
q.push(P(ny, nx));
chmin(d[ny][nx], d[y][x] + 1);
}
if (P(ny, nx) == P(gy, gx)) {
cout << d[ny][nx] << endl;
return 0;
}
ny += dy[dd];
nx += dx[dd];
}
}
}
cout << -1 << endl;
}
| replace | 66 | 68 | 66 | 70 | TLE | |
p02644 | C++ | Time Limit Exceeded | // https://atcoder.jp/contests/abc170/tasks/abc170_f
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cerr << (#x) << " is " << (x) << endl;
#define endl '\n'
#define ll long long
#define pld pair<ld, ld>
#define pii pair<int, int>
#define fi first
#define se second
const vector<pii> dirs = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
ll H, W, K;
ll up(ll a, ll k = K) {
if (a % k == 0)
return a;
return a + k - (a % k);
}
struct State {
ll c;
int x, y;
int dir;
State(ll cc, int xx, int yy, int dirr) {
c = cc;
x = xx;
y = yy;
dir = dirr;
}
};
struct Compare {
bool operator()(State l, State r) { return l.c < r.c; }
};
signed main() {
ios::sync_with_stdio(0);
cin.sync_with_stdio(0);
cin.tie(0);
cin >> H >> W >> K;
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
char a[H + 5][W + 5];
vector<vector<vector<ll>>> cost(
4, vector<vector<ll>>(H + 3, vector<ll>(W + 3, LLONG_MAX - 500)));
for (int i = 0; i < H + 3; i++) {
for (int j = 0; j < W + 3; j++) {
a[i][j] = '@';
}
}
for (int i = 1; i <= H; i++) {
string s;
cin >> s;
for (ll j = 0; j < s.size(); j++) {
a[i][j + 1] = s[j];
}
}
priority_queue<State, vector<State>, Compare> pq;
for (int d = 0; d < 4; d++) {
cost[d][x1][y1] = 0;
pq.push(State(0, x1, y1, d));
}
while (!pq.empty()) {
State S = pq.top();
pq.pop();
int x = S.x;
int y = S.y;
ll c = S.c;
int d = S.dir;
if (c != cost[d][x][y])
continue;
if ((cost[d][x + dirs[d].fi][y + dirs[d].se] > c + 1) and
(a[x + dirs[d].fi][y + dirs[d].se] != '@')) {
cost[d][x + dirs[d].fi][y + dirs[d].se] = c + 1;
pq.push(State(c + 1, x + dirs[d].fi, y + dirs[d].se, d));
}
for (int di = 0; di < 4; di++) {
ll ne = up(c);
if (cost[di][x][y] > ne) {
cost[di][x][y] = ne;
pq.push(State(ne, x, y, di));
}
}
}
ll mi = LLONG_MAX - 500;
for (int d = 0; d < 4; d++) {
mi = min(mi, up(cost[d][x2][y2]));
}
if (mi == LLONG_MAX - 500) {
cout << -1 << endl;
} else {
cout << mi / K << endl;
}
}
| // https://atcoder.jp/contests/abc170/tasks/abc170_f
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cerr << (#x) << " is " << (x) << endl;
#define endl '\n'
#define ll long long
#define pld pair<ld, ld>
#define pii pair<int, int>
#define fi first
#define se second
const vector<pii> dirs = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
ll H, W, K;
ll up(ll a, ll k = K) {
if (a % k == 0)
return a;
return a + k - (a % k);
}
struct State {
ll c;
int x, y;
int dir;
State(ll cc, int xx, int yy, int dirr) {
c = cc;
x = xx;
y = yy;
dir = dirr;
}
};
struct Compare {
bool operator()(State l, State r) { return l.c > r.c; }
};
signed main() {
ios::sync_with_stdio(0);
cin.sync_with_stdio(0);
cin.tie(0);
cin >> H >> W >> K;
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
char a[H + 5][W + 5];
vector<vector<vector<ll>>> cost(
4, vector<vector<ll>>(H + 3, vector<ll>(W + 3, LLONG_MAX - 500)));
for (int i = 0; i < H + 3; i++) {
for (int j = 0; j < W + 3; j++) {
a[i][j] = '@';
}
}
for (int i = 1; i <= H; i++) {
string s;
cin >> s;
for (ll j = 0; j < s.size(); j++) {
a[i][j + 1] = s[j];
}
}
priority_queue<State, vector<State>, Compare> pq;
for (int d = 0; d < 4; d++) {
cost[d][x1][y1] = 0;
pq.push(State(0, x1, y1, d));
}
while (!pq.empty()) {
State S = pq.top();
pq.pop();
int x = S.x;
int y = S.y;
ll c = S.c;
int d = S.dir;
if (c != cost[d][x][y])
continue;
if ((cost[d][x + dirs[d].fi][y + dirs[d].se] > c + 1) and
(a[x + dirs[d].fi][y + dirs[d].se] != '@')) {
cost[d][x + dirs[d].fi][y + dirs[d].se] = c + 1;
pq.push(State(c + 1, x + dirs[d].fi, y + dirs[d].se, d));
}
for (int di = 0; di < 4; di++) {
ll ne = up(c);
if (cost[di][x][y] > ne) {
cost[di][x][y] = ne;
pq.push(State(ne, x, y, di));
}
}
}
ll mi = LLONG_MAX - 500;
for (int d = 0; d < 4; d++) {
mi = min(mi, up(cost[d][x2][y2]));
}
if (mi == LLONG_MAX - 500) {
cout << -1 << endl;
} else {
cout << mi / K << endl;
}
}
| replace | 34 | 35 | 34 | 35 | TLE | |
p02644 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int MAX = 1e6 + 10;
const int MOD = 1e9 + 7;
const int oo = 1e9;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
#define endl '\n'
int h, w, k;
cin >> h >> w >> k;
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
vector<vector<bool>> p(h + 2, vector<bool>(w + 2));
for (int i = 1; i <= h; i++) {
string s;
cin >> s;
for (int j = 1; j <= w; j++) {
p[i][j] = (s[j - 1] == '@') ? false : true;
}
}
int dir[4][2] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
vector<vector<int>> dis(h + 2, vector<int>(w + 2, -1));
vector<pair<int, int>> que;
que.push_back({x1, y1});
dis[x1][y1] = 0;
int front = 0;
while (front < que.size()) {
auto cur = que[front];
front++;
int cd = dis[cur.first][cur.second];
for (int d = 0; d < 4; d++) {
for (int t = 1; t <= k; t++) {
int x = cur.first + t * dir[d][0];
int y = cur.second + t * dir[d][1];
if (!p[x][y]) {
break;
}
if (dis[x][y] != -1) {
if (dis[x][y] <= cd)
break;
}
dis[x][y] = cd + 1;
que.push_back({x, y});
}
}
}
cout << dis[x2][y2] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int MAX = 1e6 + 10;
const int MOD = 1e9 + 7;
const int oo = 1e9;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
#define endl '\n'
int h, w, k;
cin >> h >> w >> k;
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
vector<vector<bool>> p(h + 2, vector<bool>(w + 2));
for (int i = 1; i <= h; i++) {
string s;
cin >> s;
for (int j = 1; j <= w; j++) {
p[i][j] = (s[j - 1] == '@') ? false : true;
}
}
int dir[4][2] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};
vector<vector<int>> dis(h + 2, vector<int>(w + 2, -1));
vector<pair<int, int>> que;
que.push_back({x1, y1});
dis[x1][y1] = 0;
int front = 0;
while (front < que.size()) {
auto cur = que[front];
front++;
int cd = dis[cur.first][cur.second];
for (int d = 0; d < 4; d++) {
for (int t = 1; t <= k; t++) {
int x = cur.first + t * dir[d][0];
int y = cur.second + t * dir[d][1];
if (!p[x][y]) {
break;
}
if (dis[x][y] != -1) {
if (dis[x][y] <= cd)
break;
else
continue;
}
dis[x][y] = cd + 1;
que.push_back({x, y});
}
}
}
cout << dis[x2][y2] << endl;
}
| insert | 47 | 47 | 47 | 49 | TLE | |
p02644 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int H, W, K;
int sx, sy, ex, ey;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int main(void) {
cin >> H >> W >> K;
vector<vector<char>> c(H, vector<char>(W));
vector<vector<int>> dp(H, vector<int>(W));
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
dp[i][j] = INT_MAX;
}
}
cin >> sx >> sy >> ex >> ey;
sx--;
sy--;
ex--;
ey--;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> c[i][j];
}
}
queue<pair<int, int>> q;
q.push({sx, sy});
dp[sx][sy] = 0;
while (!q.empty()) {
pair<int, int> pi = q.front();
q.pop();
for (int i = 0; i < 4; i++) {
for (int j = 1; j <= K; j++) {
int nx = pi.first + j * dx[i];
int ny = pi.second + j * dy[i];
if (nx < 0 || nx >= H || ny < 0 || ny >= W)
continue;
if (c[nx][ny] == '@')
break;
if (dp[nx][ny] > dp[pi.first][pi.second] + 1) {
q.push({nx, ny});
dp[nx][ny] = dp[pi.first][pi.second] + 1;
}
}
}
}
if (dp[ex][ey] == INT_MAX)
cout << -1 << endl;
else
cout << dp[ex][ey] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int H, W, K;
int sx, sy, ex, ey;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int main(void) {
cin >> H >> W >> K;
vector<vector<char>> c(H, vector<char>(W));
vector<vector<int>> dp(H, vector<int>(W));
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
dp[i][j] = INT_MAX;
}
}
cin >> sx >> sy >> ex >> ey;
sx--;
sy--;
ex--;
ey--;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
cin >> c[i][j];
}
}
queue<pair<int, int>> q;
q.push({sx, sy});
dp[sx][sy] = 0;
while (!q.empty()) {
pair<int, int> pi = q.front();
q.pop();
for (int i = 0; i < 4; i++) {
for (int j = 1; j <= K; j++) {
int nx = pi.first + j * dx[i];
int ny = pi.second + j * dy[i];
if (nx < 0 || nx >= H || ny < 0 || ny >= W)
continue;
if (c[nx][ny] == '@' || dp[nx][ny] <= dp[pi.first][pi.second])
break;
if (dp[nx][ny] > dp[pi.first][pi.second] + 1) {
q.push({nx, ny});
dp[nx][ny] = dp[pi.first][pi.second] + 1;
}
}
}
}
if (dp[ex][ey] == INT_MAX)
cout << -1 << endl;
else
cout << dp[ex][ey] << endl;
return 0;
}
| replace | 38 | 39 | 38 | 39 | TLE | |
p02644 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())
int main() {
ll h, w, k;
cin >> h >> w >> k;
ll x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
x1--, x2--, y1--, y2--;
vector<string> s(h);
REP(i, h) { cin >> s[i]; }
vector<vector<ll>> dist(h, vector<ll>(w, -1));
queue<P> q;
q.push({x1, y1});
dist[x1][y1] = 0;
vector<ll> d = {0, 1, 0, -1};
while (!q.empty()) {
P p = q.front();
q.pop();
ll cx = p.first, cy = p.second;
REP(i, 4) {
FOR(j, 1, k + 1) {
ll nx = cx + j * d[i], ny = cy + j * d[i ^ 1];
if (nx < 0 || nx >= h || ny < 0 || ny >= w) {
break;
}
if (s[nx][ny] == '@') {
break;
}
if (dist[nx][ny] != -1 && dist[nx][ny] <= dist[cx][cy]) {
break;
}
dist[nx][ny] = dist[cx][cy] + 1;
q.push({nx, ny});
}
}
}
cout << dist[x2][y2] << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())
int main() {
ll h, w, k;
cin >> h >> w >> k;
ll x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
x1--, x2--, y1--, y2--;
vector<string> s(h);
REP(i, h) { cin >> s[i]; }
vector<vector<ll>> dist(h, vector<ll>(w, -1));
queue<P> q;
q.push({x1, y1});
dist[x1][y1] = 0;
vector<ll> d = {0, 1, 0, -1};
while (!q.empty()) {
P p = q.front();
q.pop();
ll cx = p.first, cy = p.second;
REP(i, 4) {
FOR(j, 1, k + 1) {
ll nx = cx + j * d[i], ny = cy + j * d[i ^ 1];
if (nx < 0 || nx >= h || ny < 0 || ny >= w) {
break;
}
if (s[nx][ny] == '@') {
break;
}
if (dist[nx][ny] != -1 && dist[nx][ny] <= dist[cx][cy]) {
break;
}
if (dist[nx][ny] == -1) {
dist[nx][ny] = dist[cx][cy] + 1;
q.push({nx, ny});
}
}
}
}
cout << dist[x2][y2] << endl;
} | replace | 44 | 46 | 44 | 49 | TLE | |
p02644 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x) \
sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \
c i) {
sim > struct rge {
c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i;
ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
const int mod = 998244353;
const int MX = (int)2e5;
void add_self(int &x, int y) {
x += y;
if (x >= mod)
x -= mod;
}
void sub_self(int &x, int y) {
x -= y;
if (x < 0)
x += mod;
}
void mul(int &x, int y) { x = x * 1LL * y % mod; }
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int n, m, k;
cin >> n >> m >> k;
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
x1--, y1--, x2--, y2--;
vector<vector<char>> g(n, vector<char>(m));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> g[i][j];
}
}
// up, down, left, right
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
vector<vector<bool>> vis(n, vector<bool>(m));
vector<vector<int>> best(n, vector<int>(m, 1e9));
best[x1][y1] = 0;
queue<array<int, 2>> q;
q.push({x1, y1});
while (!q.empty()) {
auto cur = q.front();
q.pop();
int x = cur[0];
int y = cur[1];
vis[x][y] = true;
for (int dir = 0; dir < 4; ++dir) {
int cntr = k;
while (cntr--) {
int nx = x + (k - cntr) * dx[dir];
int ny = y + (k - cntr) * dy[dir];
if (nx >= 0 && nx < n && ny >= 0 && ny < m && g[nx][ny] == '.') {
if (best[x][y] + 1 <= best[nx][ny] && !vis[nx][ny]) {
best[nx][ny] = best[x][y] + 1;
q.push({nx, ny});
} else
break;
} else
break;
}
}
}
int res = best[x2][y2];
if (res == (int)1e9)
res = -1;
cout << res << endl;
return 0;
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x) \
sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \
c i) {
sim > struct rge {
c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i;
ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
const int mod = 998244353;
const int MX = (int)2e5;
void add_self(int &x, int y) {
x += y;
if (x >= mod)
x -= mod;
}
void sub_self(int &x, int y) {
x -= y;
if (x < 0)
x += mod;
}
void mul(int &x, int y) { x = x * 1LL * y % mod; }
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int n, m, k;
cin >> n >> m >> k;
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
x1--, y1--, x2--, y2--;
vector<vector<char>> g(n, vector<char>(m));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> g[i][j];
}
}
// up, down, left, right
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
vector<vector<bool>> vis(n, vector<bool>(m));
vector<vector<int>> best(n, vector<int>(m, 1e9));
best[x1][y1] = 0;
queue<array<int, 2>> q;
q.push({x1, y1});
while (!q.empty()) {
auto cur = q.front();
q.pop();
int x = cur[0];
int y = cur[1];
if (vis[x][y])
continue;
vis[x][y] = true;
for (int dir = 0; dir < 4; ++dir) {
int cntr = k;
while (cntr--) {
int nx = x + (k - cntr) * dx[dir];
int ny = y + (k - cntr) * dy[dir];
if (nx >= 0 && nx < n && ny >= 0 && ny < m && g[nx][ny] == '.') {
if (best[x][y] + 1 <= best[nx][ny] && !vis[nx][ny]) {
best[nx][ny] = best[x][y] + 1;
q.push({nx, ny});
} else
break;
} else
break;
}
}
}
int res = best[x2][y2];
if (res == (int)1e9)
res = -1;
cout << res << endl;
return 0;
}
| insert | 101 | 101 | 101 | 105 | TLE | |
p02644 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
int n, m, k, x1, x2, h1, y2;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> k >> x1 >> h1 >> x2 >> y2;
x1--;
h1--;
x2--;
y2--;
char grid[n + 10][m + 10];
int dist[n + 10][m + 10];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> grid[i][j];
queue<pair<int, int>> q;
q.push(make_pair(x1, h1));
memset(dist, 0x3f, sizeof(dist));
dist[x1][h1] = 0;
while (!q.empty()) {
int nx = q.front().first;
int ny = q.front().second;
if (nx == x2 && ny == y2) {
cout << dist[nx][ny] << endl;
return 0;
}
q.pop();
for (int i = 0; i < 4; i++) {
for (int j = 1; j <= k; j++) {
int tx = nx + dx[i] * j;
int ty = ny + dy[i] * j;
if (tx >= 0 && tx < n && ty >= 0 && ty < m) {
if (grid[tx][ty] == '@')
break;
if (dist[tx][ty] > 1e7) {
dist[tx][ty] = dist[nx][ny] + 1;
q.push(make_pair(tx, ty));
}
} else
break;
}
}
}
cout << -1 << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};
int n, m, k, x1, x2, h1, y2;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> k >> x1 >> h1 >> x2 >> y2;
x1--;
h1--;
x2--;
y2--;
char grid[n + 10][m + 10];
int dist[n + 10][m + 10];
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> grid[i][j];
queue<pair<int, int>> q;
q.push(make_pair(x1, h1));
memset(dist, 0x3f, sizeof(dist));
dist[x1][h1] = 0;
while (!q.empty()) {
int nx = q.front().first;
int ny = q.front().second;
if (nx == x2 && ny == y2) {
cout << dist[nx][ny] << endl;
return 0;
}
q.pop();
for (int i = 0; i < 4; i++) {
for (int j = 1; j <= k; j++) {
int tx = nx + dx[i] * j;
int ty = ny + dy[i] * j;
if (tx >= 0 && tx < n && ty >= 0 && ty < m) {
if (grid[tx][ty] == '@')
break;
if (dist[tx][ty] > 1e7) {
dist[tx][ty] = dist[nx][ny] + 1;
q.push(make_pair(tx, ty));
}
if (dist[tx][ty] <= dist[nx][ny])
break;
} else
break;
}
}
}
cout << -1 << endl;
return 0;
}
| insert | 41 | 41 | 41 | 43 | TLE | |
p02644 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define debug(n) cerr << #n << ':' << n << endl;
#define dline cerr << __LINE__ << endl;
using ll = long long;
template <class T, class U> using P = pair<T, U>;
template <class T> using Heap = priority_queue<T>;
template <class T> using heaP = priority_queue<T, vector<T>, greater<T>>;
template <class T, class U> using umap = unordered_map<T, U>;
template <class T> using uset = unordered_set<T>;
template <class T> bool ChangeMax(T &a, const T &b) {
if (a >= b)
return false;
a = b;
return true;
}
template <class T> bool ChangeMin(T &a, const T &b) {
if (a <= b)
return false;
a = b;
return true;
}
template <class T, size_t N, class U> void Fill(T (&a)[N], const U &v) {
fill((U *)a, (U *)(a + N), v);
}
template <class T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &e : v)
is >> e;
return is;
}
int main() {
int h, w, k;
cin >> h >> w >> k;
int sr, sc, gr, gc;
cin >> sr >> sc >> gr >> gc;
sr--;
sc--;
gr--;
gc--;
static string s[1000000];
for (int i = 0; i < h; ++i)
cin >> s[i];
vector<vector<int>> dis(h, vector<int>(w, -1));
int mr[] = {-1, 0, 1, 0};
int mc[] = {0, 1, 0, -1};
queue<P<int, int>> que;
que.emplace(sr, sc);
dis[sr][sc] = 0;
while (!que.empty()) {
auto now = que.front();
que.pop();
for (int i = 0; i < 4; ++i) {
for (int j = 1; j <= k; ++j) {
int nr = now.first + mr[i] * j;
int nc = now.second + mc[i] * j;
if (nr >= h || nr < 0 || nc >= w || nc < 0 || s[nr][nc] == '@')
break;
if (dis[nr][nc] != -1 && dis[nr][nc] <= dis[now.first][now.second])
break;
dis[nr][nc] = dis[now.first][now.second] + 1;
que.emplace(nr, nc);
}
}
}
cout << dis[gr][gc] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define debug(n) cerr << #n << ':' << n << endl;
#define dline cerr << __LINE__ << endl;
using ll = long long;
template <class T, class U> using P = pair<T, U>;
template <class T> using Heap = priority_queue<T>;
template <class T> using heaP = priority_queue<T, vector<T>, greater<T>>;
template <class T, class U> using umap = unordered_map<T, U>;
template <class T> using uset = unordered_set<T>;
template <class T> bool ChangeMax(T &a, const T &b) {
if (a >= b)
return false;
a = b;
return true;
}
template <class T> bool ChangeMin(T &a, const T &b) {
if (a <= b)
return false;
a = b;
return true;
}
template <class T, size_t N, class U> void Fill(T (&a)[N], const U &v) {
fill((U *)a, (U *)(a + N), v);
}
template <class T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &e : v)
is >> e;
return is;
}
int main() {
int h, w, k;
cin >> h >> w >> k;
int sr, sc, gr, gc;
cin >> sr >> sc >> gr >> gc;
sr--;
sc--;
gr--;
gc--;
static string s[1000000];
for (int i = 0; i < h; ++i)
cin >> s[i];
vector<vector<int>> dis(h, vector<int>(w, -1));
int mr[] = {-1, 0, 1, 0};
int mc[] = {0, 1, 0, -1};
queue<P<int, int>> que;
que.emplace(sr, sc);
dis[sr][sc] = 0;
while (!que.empty()) {
auto now = que.front();
que.pop();
for (int i = 0; i < 4; ++i) {
for (int j = 1; j <= k; ++j) {
int nr = now.first + mr[i] * j;
int nc = now.second + mc[i] * j;
if (nr >= h || nr < 0 || nc >= w || nc < 0 || s[nr][nc] == '@')
break;
if (dis[nr][nc] != -1 && dis[nr][nc] <= dis[now.first][now.second])
break;
if (dis[nr][nc] == dis[now.first][now.second] + 1)
continue;
dis[nr][nc] = dis[now.first][now.second] + 1;
que.emplace(nr, nc);
}
}
}
cout << dis[gr][gc] << endl;
return 0;
}
| insert | 67 | 67 | 67 | 69 | TLE | |
p02644 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define RFOR(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define RITR(x, c) for (__typeof(c.rbegin()) x = c.rbegin(); x != c.rend(); x++)
#define setp(n) fixed << setprecision(n)
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;
}
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll, ll>
#define pi pair<int, int>
#define all(a) (a.begin()), (a.end())
#define rall(a) (a.rbegin()), (a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert
using namespace std;
int H, W, K;
const int INF = INT_MAX;
//-------------------------------------------------
//--Grid BFS
//-------------------------------------------------
template <typename T>
vector<vector<int>> gBFS(int si, int sj, vector<T> &field) {
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int h = field.size();
int w = field[0].size();
using P = pair<int, int>;
queue<P> que;
que.emplace(si, sj);
vector<vector<int>> dist(h, vector<int>(w, INF));
dist[si][sj] = 0;
while (que.size()) {
int x, y;
tie(y, x) = que.front();
que.pop();
for (int i = 0; i < 4; i++) {
FOR(j, 1, K) {
int tx = x + j * dx[i];
int ty = y + j * dy[i];
if (!(0 <= tx && tx < w && 0 <= ty && ty < h))
break;
if (field[ty][tx] == '@')
break;
// if (dist[ty][tx]<dist[y][x]+1) break;
if (dist[ty][tx] != INF)
continue;
dist[ty][tx] = dist[y][x] + 1;
que.emplace(ty, tx);
}
}
}
return dist;
}
//-------------------------------------------------
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> H >> W >> K;
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
vector<string> f(H);
rep(i, H) cin >> f[i];
auto dist = gBFS(x1 - 1, y1 - 1, f);
// rep(i,H){
// rep(j,W){
// if (dist[i][j]!=INF){
// cout<<dist[i][j]<<" ";
// }else{
// cout<<"I ";
// }
// }cout<<endl;
// }
if (dist[x2 - 1][y2 - 1] != INF) {
cout << dist[x2 - 1][y2 - 1] << endl;
} else {
cout << "-1\n";
}
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define RFOR(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define ITR(x, c) for (__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define RITR(x, c) for (__typeof(c.rbegin()) x = c.rbegin(); x != c.rend(); x++)
#define setp(n) fixed << setprecision(n)
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;
}
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll, ll>
#define pi pair<int, int>
#define all(a) (a.begin()), (a.end())
#define rall(a) (a.rbegin()), (a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert
using namespace std;
int H, W, K;
const int INF = INT_MAX;
//-------------------------------------------------
//--Grid BFS
//-------------------------------------------------
template <typename T>
vector<vector<int>> gBFS(int si, int sj, vector<T> &field) {
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int h = field.size();
int w = field[0].size();
using P = pair<int, int>;
queue<P> que;
que.emplace(si, sj);
vector<vector<int>> dist(h, vector<int>(w, INF));
dist[si][sj] = 0;
while (que.size()) {
int x, y;
tie(y, x) = que.front();
que.pop();
for (int i = 0; i < 4; i++) {
FOR(j, 1, K) {
int tx = x + j * dx[i];
int ty = y + j * dy[i];
if (!(0 <= tx && tx < w && 0 <= ty && ty < h))
break;
if (field[ty][tx] == '@')
break;
if (dist[ty][tx] < dist[y][x] + 1)
break;
if (dist[ty][tx] != INF)
continue;
dist[ty][tx] = dist[y][x] + 1;
que.emplace(ty, tx);
}
}
}
return dist;
}
//-------------------------------------------------
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> H >> W >> K;
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
vector<string> f(H);
rep(i, H) cin >> f[i];
auto dist = gBFS(x1 - 1, y1 - 1, f);
// rep(i,H){
// rep(j,W){
// if (dist[i][j]!=INF){
// cout<<dist[i][j]<<" ";
// }else{
// cout<<"I ";
// }
// }cout<<endl;
// }
if (dist[x2 - 1][y2 - 1] != INF) {
cout << dist[x2 - 1][y2 - 1] << endl;
} else {
cout << "-1\n";
}
return 0;
}
| replace | 71 | 72 | 71 | 73 | TLE | |
p02644 | C++ | Time Limit Exceeded | #include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int H, w, k, X, Y, xx, yy, maxx = 23333333;
int q[4] = {-1, 0, 1, 0};
int p[4] = {0, 1, 0, -1};
vector<int> l[3];
int main(void) {
cin >> H >> w >> k >> xx >> yy >> X >> Y;
xx--;
yy--;
X--;
Y--;
char c[H][w];
int f[H][w];
for (int i = 0; i < H; i++) {
for (int j = 0; j < w; j++) {
cin >> c[i][j];
f[i][j] = maxx;
}
}
int h = 0, r = 1;
l[0].push_back(xx);
l[1].push_back(yy);
l[2].push_back(0);
f[xx][yy] = 0;
while (h < r) {
for (int i = 0; i < 4; i++) {
int x1 = l[0][h], y1 = l[1][h];
for (int j = 0; j < k; j++) {
x1 += q[i];
y1 += p[i];
if (x1 < 0 || x1 >= H || y1 < 0 || y1 >= w || c[x1][y1] == '@' ||
f[x1][y1] < l[2][h] + 1)
break;
f[x1][y1] = l[2][h] + 1;
l[0].push_back(x1);
l[1].push_back(y1);
l[2].push_back(l[2][h] + 1);
r++;
}
}
h++;
}
if (f[X][Y] == maxx)
cout << "-1" << endl;
else
cout << f[X][Y] << endl;
return 0;
}
| #include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int H, w, k, X, Y, xx, yy, maxx = 23333333;
int q[4] = {-1, 0, 1, 0};
int p[4] = {0, 1, 0, -1};
vector<int> l[3];
int main(void) {
cin >> H >> w >> k >> xx >> yy >> X >> Y;
xx--;
yy--;
X--;
Y--;
char c[H][w];
int f[H][w];
for (int i = 0; i < H; i++) {
for (int j = 0; j < w; j++) {
cin >> c[i][j];
f[i][j] = maxx;
}
}
int h = 0, r = 1;
l[0].push_back(xx);
l[1].push_back(yy);
l[2].push_back(0);
f[xx][yy] = 0;
while (h < r) {
for (int i = 0; i < 4; i++) {
int x1 = l[0][h], y1 = l[1][h];
for (int j = 0; j < k; j++) {
x1 += q[i];
y1 += p[i];
if (x1 < 0 || x1 >= H || y1 < 0 || y1 >= w || c[x1][y1] == '@' ||
f[x1][y1] < l[2][h] + 1)
break;
if (f[x1][y1] > l[2][h] + 1) {
f[x1][y1] = l[2][h] + 1;
l[0].push_back(x1);
l[1].push_back(y1);
l[2].push_back(l[2][h] + 1);
r++;
}
}
}
h++;
}
if (f[X][Y] == maxx)
cout << "-1" << endl;
else
cout << f[X][Y] << endl;
return 0;
}
| replace | 36 | 41 | 36 | 43 | TLE | |
p02644 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <typename T1, typename T2> bool chmin(T1 &a, T2 b) {
if (a <= b)
return 0;
a = b;
return 1;
}
template <typename T1, typename T2> bool chmax(T1 &a, T2 b) {
if (a >= b)
return 0;
a = b;
return 1;
}
int dx[4] = {0, 1, -1, 0};
int dy[4] = {1, 0, 0, -1};
long double eps = 1e-9;
long double pi = acos(-1);
ll mod = 1e9 + 7;
template <typename T> void add(T &a, T b) { a = (a + b) % mod; }
template <typename T> void sub(T &a, T b) { a = (a + mod - b) % mod; }
class UnionFind {
public:
// 親の番号を格納する。親だった場合は-(その集合のサイズ)
vector<int> parent;
UnionFind(int N) { parent = vector<int>(N, -1); }
int root(int A) {
if (parent[A] < 0)
return A;
return parent[A] = root(parent[A]);
}
int size(int A) { return -parent[root(A)]; }
bool unite(int A, int B) {
A = root(A), B = root(B);
if (A == B)
return false;
if (size(A) < size(B))
swap(A, B);
parent[A] += parent[B];
parent[B] = A;
return true;
}
bool same(int A, int B) { return root(A) == root(B); }
};
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20);
int h, w, a;
cin >> h >> w >> a;
int sx, sy, gx, gy;
cin >> sx >> sy >> gx >> gy;
sx--, sy--, gx--, gy--;
string s[h];
for (int i = 0; i < h; i++)
cin >> s[i];
s[sx][sy] = 'S';
s[gx][gy] = 'G';
UnionFind uni(h * w);
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (s[i][j] == '@')
continue;
for (int k = 0; k < 4; k++) {
int x = i + dx[k];
int y = j + dy[k];
if (x >= 0 && y >= 0 && x < h && y < w) {
if (s[x][y] == '@')
continue;
uni.unite(i * w + j, x * w + y);
}
}
}
}
if (uni.same(sx * w + sy, gx * w + gy) == false) {
cout << -1 << endl;
return 0;
}
int d[h][w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
d[i][j] = 1e9;
}
}
queue<array<int, 5>> q;
q.push({0, sx, sy, -1, 0});
while (q.size()) {
array<int, 5> p = q.front();
q.pop();
int x = p[1], y = p[2], dist = p[0];
int r = p[3], ok = (p[4] == a);
if (d[x][y] < dist)
continue;
for (int i = 0; i < 4; i++) {
if (i + r == 3)
continue;
if (i == r && !ok)
continue;
for (int k = 1; k <= a; k++) {
int nx = x + k * dx[i];
int ny = y + k * dy[i];
if (nx >= h || ny >= w)
break;
if (nx >= 0 && ny >= 0) {
if (s[nx][ny] == '@')
break;
if (d[nx][ny] <= dist)
continue;
chmin(d[nx][ny], dist + 1);
if (s[nx][ny] == 'G') {
cout << dist + 1 << endl;
return 0;
}
q.push({dist + 1, nx, ny, i, k});
}
}
}
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <typename T1, typename T2> bool chmin(T1 &a, T2 b) {
if (a <= b)
return 0;
a = b;
return 1;
}
template <typename T1, typename T2> bool chmax(T1 &a, T2 b) {
if (a >= b)
return 0;
a = b;
return 1;
}
int dx[4] = {0, 1, -1, 0};
int dy[4] = {1, 0, 0, -1};
long double eps = 1e-9;
long double pi = acos(-1);
ll mod = 1e9 + 7;
template <typename T> void add(T &a, T b) { a = (a + b) % mod; }
template <typename T> void sub(T &a, T b) { a = (a + mod - b) % mod; }
class UnionFind {
public:
// 親の番号を格納する。親だった場合は-(その集合のサイズ)
vector<int> parent;
UnionFind(int N) { parent = vector<int>(N, -1); }
int root(int A) {
if (parent[A] < 0)
return A;
return parent[A] = root(parent[A]);
}
int size(int A) { return -parent[root(A)]; }
bool unite(int A, int B) {
A = root(A), B = root(B);
if (A == B)
return false;
if (size(A) < size(B))
swap(A, B);
parent[A] += parent[B];
parent[B] = A;
return true;
}
bool same(int A, int B) { return root(A) == root(B); }
};
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(20);
int h, w, a;
cin >> h >> w >> a;
int sx, sy, gx, gy;
cin >> sx >> sy >> gx >> gy;
sx--, sy--, gx--, gy--;
string s[h];
for (int i = 0; i < h; i++)
cin >> s[i];
s[sx][sy] = 'S';
s[gx][gy] = 'G';
UnionFind uni(h * w);
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (s[i][j] == '@')
continue;
for (int k = 0; k < 4; k++) {
int x = i + dx[k];
int y = j + dy[k];
if (x >= 0 && y >= 0 && x < h && y < w) {
if (s[x][y] == '@')
continue;
uni.unite(i * w + j, x * w + y);
}
}
}
}
if (uni.same(sx * w + sy, gx * w + gy) == false) {
cout << -1 << endl;
return 0;
}
int d[h][w];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
d[i][j] = 1e9;
}
}
queue<array<int, 5>> q;
q.push({0, sx, sy, -1, 0});
while (q.size()) {
array<int, 5> p = q.front();
q.pop();
int x = p[1], y = p[2], dist = p[0];
int r = p[3], ok = (p[4] == a);
if (d[x][y] < dist)
continue;
for (int i = 0; i < 4; i++) {
if (i + r == 3)
continue;
if (i == r && !ok)
continue;
for (int k = 1; k <= a; k++) {
int nx = x + k * dx[i];
int ny = y + k * dy[i];
if (nx >= h || ny >= w)
break;
if (nx >= 0 && ny >= 0) {
if (s[nx][ny] == '@')
break;
if (d[nx][ny] <= dist + 1)
continue;
chmin(d[nx][ny], dist + 1);
if (s[nx][ny] == 'G') {
cout << dist + 1 << endl;
return 0;
}
q.push({dist + 1, nx, ny, i, k});
}
}
}
}
} | replace | 117 | 118 | 117 | 118 | TLE | |
p02644 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
using piii = pair<int, pair<int, int>>;
const int N = 1000005;
char g[N];
// char g[N][N];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
bool check(vector<vector<int>> &g, int y, int x, int qy, int qx) {
if (y == qy) {
if (x < qx)
swap(x, qx);
for (int i = qx; i <= x; ++i)
if (g[y][i] == '@')
return false;
} else {
if (y < qy)
swap(y, qy);
for (int i = qy; i <= y; ++i)
if (g[i][x] == '@')
return false;
}
}
int h, w, k;
int xa, ya, xb, yb;
// xa, ya
int dijkstra(vector<vector<char>> &g, vector<vector<int>> &st,
pair<int, int> s) {
vector<vector<int>> dist(h, vector<int>(w, 0x3f3f3f3f));
priority_queue<piii, vector<piii>, greater<piii>> heap;
heap.push({0, s});
// cout << h << "---" << w << endl;
// cout << s.second << "---" << s.first << endl;
dist[s.first][s.second] = 0;
while (heap.size()) {
auto t = heap.top();
heap.pop();
int dis = t.first, x = t.second.first, y = t.second.second;
if (x == xb && y == yb)
return dis;
if (st[x][y])
continue;
st[x][y] = true;
for (int i = 0; i < 4; ++i) {
for (int j = 1; j <= k; ++j) {
int qy = y + dy[i] * j;
int qx = x + dx[i] * j;
if (qy < 0 || qy >= w || qx < 0 || qx >= h || g[qx][qy] == '@')
break;
// 中间也需要检测一下
// if (!check(g, y, x, qy, qx)) continue;
if (dist[qx][qy] > dist[x][y] + 1) {
// printf("(%d, %d)\n", qy, qx);
dist[qx][qy] = dis + 1;
heap.push({dist[qx][qy], {qx, qy}});
} else if (dist[qx][qy] <= dist[x][y])
break;
}
}
}
if (dist[xb][yb] == 0x3f3f3f3f)
return -1;
return dist[xb][yb];
}
int main() {
freopen("in.txt", "r", stdin);
scanf("%d%d%d", &h, &w, &k);
scanf("%d%d%d%d", &xa, &ya, &xb, &yb);
--xa, --ya;
--xb, --yb;
vector<vector<char>> maze(h, vector<char>(w, 0));
vector<vector<int>> st(h, vector<int>(w, 0));
for (int i = 0; i < h; ++i) {
scanf("%s", g);
for (int j = 0; j < w; ++j)
maze[i][j] = g[j];
}
// check(maze, 0, 3, 1, 3);
int res = dijkstra(maze, st, {xa, ya});
printf("%d\n", res);
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
using piii = pair<int, pair<int, int>>;
const int N = 1000005;
char g[N];
// char g[N][N];
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
bool check(vector<vector<int>> &g, int y, int x, int qy, int qx) {
if (y == qy) {
if (x < qx)
swap(x, qx);
for (int i = qx; i <= x; ++i)
if (g[y][i] == '@')
return false;
} else {
if (y < qy)
swap(y, qy);
for (int i = qy; i <= y; ++i)
if (g[i][x] == '@')
return false;
}
}
int h, w, k;
int xa, ya, xb, yb;
// xa, ya
int dijkstra(vector<vector<char>> &g, vector<vector<int>> &st,
pair<int, int> s) {
vector<vector<int>> dist(h, vector<int>(w, 0x3f3f3f3f));
priority_queue<piii, vector<piii>, greater<piii>> heap;
heap.push({0, s});
// cout << h << "---" << w << endl;
// cout << s.second << "---" << s.first << endl;
dist[s.first][s.second] = 0;
while (heap.size()) {
auto t = heap.top();
heap.pop();
int dis = t.first, x = t.second.first, y = t.second.second;
if (x == xb && y == yb)
return dis;
if (st[x][y])
continue;
st[x][y] = true;
for (int i = 0; i < 4; ++i) {
for (int j = 1; j <= k; ++j) {
int qy = y + dy[i] * j;
int qx = x + dx[i] * j;
if (qy < 0 || qy >= w || qx < 0 || qx >= h || g[qx][qy] == '@')
break;
// 中间也需要检测一下
// if (!check(g, y, x, qy, qx)) continue;
if (dist[qx][qy] > dist[x][y] + 1) {
// printf("(%d, %d)\n", qy, qx);
dist[qx][qy] = dis + 1;
heap.push({dist[qx][qy], {qx, qy}});
} else if (dist[qx][qy] <= dist[x][y])
break;
}
}
}
if (dist[xb][yb] == 0x3f3f3f3f)
return -1;
return dist[xb][yb];
}
int main() {
// freopen("in.txt", "r", stdin);
scanf("%d%d%d", &h, &w, &k);
scanf("%d%d%d%d", &xa, &ya, &xb, &yb);
--xa, --ya;
--xb, --yb;
vector<vector<char>> maze(h, vector<char>(w, 0));
vector<vector<int>> st(h, vector<int>(w, 0));
for (int i = 0; i < h; ++i) {
scanf("%s", g);
for (int j = 0; j < w; ++j)
maze[i][j] = g[j];
}
// check(maze, 0, 3, 1, 3);
int res = dijkstra(maze, st, {xa, ya});
printf("%d\n", res);
return 0;
} | replace | 78 | 79 | 78 | 79 | -11 | |
p02644 | C++ | Time Limit Exceeded | // #include <bits/stdc++.h>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long>> vvll, vvLL;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define mod (ll)(1e9 + 7)
#define FIX(a) ((a) % mod + mod) % mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define fi first
#define se second
#define pb push_back
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll h, w, k;
cin >> h >> w >> k;
vll s(2), g(2);
REP(i, 2) {
cin >> s[i];
s[i]--;
}
REP(i, 2) {
cin >> g[i];
g[i]--;
}
vector<vector<vector<pair<ll, ll>>>> c(
h, vector<vector<pair<ll, ll>>>(
w, vector<pair<ll, ll>>(4, make_pair(INF, INF))));
REP(i, h) {
string ci;
cin >> ci;
REP(j, w) {
if (ci[j] == '@') {
REP(l, 4) { c[i][j][l] = make_pair(-1LL, -1LL); }
}
}
}
REP(i, 4) { c[s[0]][s[1]][i] = make_pair(0, k); }
queue<pair<ll, ll>> q;
q.push(make_pair(s[0], s[1]));
while (!q.empty()) {
auto now = q.front();
q.pop();
REP(i, 4) {
// 行く方向
ll ni = now.fi + dy[i];
ll nj = now.se + dx[i];
if (ni < 0 || ni >= h || nj < 0 || nj >= w)
continue;
if (c[ni][nj][0] == make_pair(-1LL, -1LL))
continue;
REP(j, 4) {
// 来た方向
if (i == j && c[now.fi][now.se][i].se > 0 &&
c[now.fi][now.se][j].fi < INF) {
ll tf = c[now.fi][now.se][i].fi;
ll ts = c[now.fi][now.se][i].se - 1;
if ((tf < c[ni][nj][j].fi) ||
(tf == c[ni][nj][j].fi && ts > c[ni][nj][j].se)) {
c[ni][nj][j].fi = tf;
c[ni][nj][j].se = ts;
q.push(make_pair(ni, nj));
}
} else {
ll tf = c[now.fi][now.se][j].fi + 1;
ll ts = k - 1;
if ((tf <= c[ni][nj][i].fi)) {
c[ni][nj][i].fi = tf;
c[ni][nj][i].se = ts;
q.push(make_pair(ni, nj));
}
}
}
}
}
ll ans = LLINF;
REP(i, 4) { ans = min(ans, c[g[0]][g[1]][i].fi); }
if (ans == INF) {
cout << -1 << endl;
} else {
cout << ans + 1 << endl;
}
return 0;
} | // #include <bits/stdc++.h>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long>> vvll, vvLL;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define mod (ll)(1e9 + 7)
#define FIX(a) ((a) % mod + mod) % mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define fi first
#define se second
#define pb push_back
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll h, w, k;
cin >> h >> w >> k;
vll s(2), g(2);
REP(i, 2) {
cin >> s[i];
s[i]--;
}
REP(i, 2) {
cin >> g[i];
g[i]--;
}
vector<vector<vector<pair<ll, ll>>>> c(
h, vector<vector<pair<ll, ll>>>(
w, vector<pair<ll, ll>>(4, make_pair(INF, INF))));
REP(i, h) {
string ci;
cin >> ci;
REP(j, w) {
if (ci[j] == '@') {
REP(l, 4) { c[i][j][l] = make_pair(-1LL, -1LL); }
}
}
}
REP(i, 4) { c[s[0]][s[1]][i] = make_pair(0, k); }
queue<pair<ll, ll>> q;
q.push(make_pair(s[0], s[1]));
while (!q.empty()) {
auto now = q.front();
q.pop();
REP(i, 4) {
// 行く方向
ll ni = now.fi + dy[i];
ll nj = now.se + dx[i];
if (ni < 0 || ni >= h || nj < 0 || nj >= w)
continue;
if (c[ni][nj][0] == make_pair(-1LL, -1LL))
continue;
REP(j, 4) {
// 来た方向
if (i == j && c[now.fi][now.se][i].se > 0 &&
c[now.fi][now.se][j].fi < INF) {
ll tf = c[now.fi][now.se][i].fi;
ll ts = c[now.fi][now.se][i].se - 1;
if ((tf < c[ni][nj][j].fi) ||
(tf == c[ni][nj][j].fi && ts > c[ni][nj][j].se)) {
c[ni][nj][j].fi = tf;
c[ni][nj][j].se = ts;
q.push(make_pair(ni, nj));
}
} else {
ll tf = c[now.fi][now.se][j].fi + 1;
ll ts = k - 1;
if ((tf < c[ni][nj][i].fi) ||
(tf == c[ni][nj][i].fi && ts > c[ni][nj][i].se)) {
c[ni][nj][i].fi = tf;
c[ni][nj][i].se = ts;
q.push(make_pair(ni, nj));
}
}
}
}
}
ll ans = LLINF;
REP(i, 4) { ans = min(ans, c[g[0]][g[1]][i].fi); }
if (ans == INF) {
cout << -1 << endl;
} else {
cout << ans + 1 << endl;
}
return 0;
} | replace | 87 | 88 | 87 | 89 | TLE | |
p02644 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
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 (a > b) {
a = b;
return true;
}
return false;
}
template <class T> T div_floor(T a, T b) {
if (b < 0)
a *= -1, b *= -1;
return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T> T div_ceil(T a, T b) {
if (b < 0)
a *= -1, b *= -1;
return a > 0 ? (a - 1) / b + 1 : a / b;
}
constexpr lint mod = 1e9 + 7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int main() {
int h, w, K, sx, sy, gx, gy;
scanf("%d%d%d%d%d%d%d", &h, &w, &K, &sx, &sy, &gx, &gy);
--sx;
--sy;
--gx;
--gy;
char c[h][w];
rep(i, h) rep(j, w) scanf(" %c", &c[i][j]);
int d[h][w];
queue<pii> que;
rep(i, h) rep(j, w) d[i][j] = mod;
d[sx][sy] = 0;
que.emplace(sx, sy);
while (!que.empty()) {
auto [x, y] = que.front();
que.pop();
rep(i, 4) {
For(k, 1, K + 1) {
int nx = x + dx[i] * k, ny = y + dy[i] * k;
if (nx < 0 || h <= nx || ny < 0 || w <= ny || c[nx][ny] != '.' ||
d[nx][ny] <= d[x][y])
break;
d[nx][ny] = d[x][y] + 1;
que.emplace(nx, ny);
}
}
}
printf("%d\n", d[gx][gy] < mod ? d[gx][gy] : -1);
} | #include <bits/stdc++.h>
#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
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 (a > b) {
a = b;
return true;
}
return false;
}
template <class T> T div_floor(T a, T b) {
if (b < 0)
a *= -1, b *= -1;
return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T> T div_ceil(T a, T b) {
if (b < 0)
a *= -1, b *= -1;
return a > 0 ? (a - 1) / b + 1 : a / b;
}
constexpr lint mod = 1e9 + 7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int main() {
int h, w, K, sx, sy, gx, gy;
scanf("%d%d%d%d%d%d%d", &h, &w, &K, &sx, &sy, &gx, &gy);
--sx;
--sy;
--gx;
--gy;
char c[h][w];
rep(i, h) rep(j, w) scanf(" %c", &c[i][j]);
int d[h][w];
queue<pii> que;
rep(i, h) rep(j, w) d[i][j] = mod;
d[sx][sy] = 0;
que.emplace(sx, sy);
while (!que.empty()) {
auto [x, y] = que.front();
que.pop();
rep(i, 4) {
For(k, 1, K + 1) {
int nx = x + dx[i] * k, ny = y + dy[i] * k;
if (nx < 0 || h <= nx || ny < 0 || w <= ny || c[nx][ny] != '.' ||
d[nx][ny] <= d[x][y])
break;
if (chmin(d[nx][ny], d[x][y] + 1))
que.emplace(nx, ny);
}
}
}
printf("%d\n", d[gx][gy] < mod ? d[gx][gy] : -1);
} | replace | 68 | 70 | 68 | 70 | TLE | |
p02644 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001001001001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
int H, W;
long long K;
cin >> H >> W >> K;
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
--x1;
--y1;
--x2;
--y2;
vector<vector<char>> c(H, vector<char>(W));
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j)
cin >> c[i][j];
}
vector<vector<int>> dist(H, vector<int>(W, INF));
dist[x1][y1] = 0;
queue<pair<int, int>> Q;
Q.emplace(x1, y1);
while (!Q.empty()) {
auto [x, y] = Q.front();
Q.pop();
for (int i = 0; i < 4; ++i) {
for (int j = 1; j <= K; ++j) {
int nx = x + dx[i] * j, ny = y + dy[i] * j;
if (nx < 0 || nx >= H || ny < 0 || ny >= W || c[nx][ny] == '@' ||
dist[nx][ny] <= dist[x][y])
break;
dist[nx][ny] = dist[x][y] + 1;
Q.emplace(nx, ny);
}
}
}
cout << (dist[x2][y2] == INF ? -1 : dist[x2][y2]) << '\n';
}
| #include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001001001001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main() {
int H, W;
long long K;
cin >> H >> W >> K;
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
--x1;
--y1;
--x2;
--y2;
vector<vector<char>> c(H, vector<char>(W));
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j)
cin >> c[i][j];
}
vector<vector<int>> dist(H, vector<int>(W, INF));
dist[x1][y1] = 0;
queue<pair<int, int>> Q;
Q.emplace(x1, y1);
while (!Q.empty()) {
auto [x, y] = Q.front();
Q.pop();
for (int i = 0; i < 4; ++i) {
for (int j = 1; j <= K; ++j) {
int nx = x + dx[i] * j, ny = y + dy[i] * j;
if (nx < 0 || nx >= H || ny < 0 || ny >= W || c[nx][ny] == '@' ||
dist[nx][ny] <= dist[x][y])
break;
if (dist[nx][ny] == INF) {
dist[nx][ny] = dist[x][y] + 1;
Q.emplace(nx, ny);
}
}
}
}
cout << (dist[x2][y2] == INF ? -1 : dist[x2][y2]) << '\n';
}
| replace | 38 | 40 | 38 | 42 | TLE | |
p02644 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int MAX = 1000000;
constexpr int inf = 1 << 30;
int h, w, k;
int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
cin >> h >> w >> k;
vector<string> m(h);
int sx, sy, gx, gy;
cin >> sy >> sx >> gy >> gx;
sx--;
sy--;
gx--;
gy--;
for (auto &a : m)
cin >> a;
vector<vector<int>> f(h + 5, vector<int>(w + 5, inf));
priority_queue<tuple<int, int, int>> q;
q.push({0, sy, sx});
f[sy][sx] = 0;
while (!q.empty()) {
auto cur = q.top();
q.pop();
int y = get<1>(cur);
int x = get<2>(cur);
int cost = -get<0>(cur);
for (auto d :
initializer_list<pair<int, int>>{{-1, 0}, {0, 1}, {1, 0}, {0, -1}}) {
for (int i = 1; i <= k; ++i) {
int dy = y + d.first * i;
int dx = x + d.second * i;
if (dy < 0 or dy > h - 1 or dx < 0 or dx > w - 1 or m[dy][dx] == '@')
break;
if (f[dy][dx] > cost + 1) {
f[dy][dx] = cost + 1;
q.push({-f[dy][dx], dy, dx});
}
}
}
}
if (f[gy][gx] == inf)
cout << -1 << endl;
else
cout << f[gy][gx] << endl;
return 0;
} | #include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int MAX = 1000000;
constexpr int inf = 1 << 30;
int h, w, k;
int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
cin >> h >> w >> k;
vector<string> m(h);
int sx, sy, gx, gy;
cin >> sy >> sx >> gy >> gx;
sx--;
sy--;
gx--;
gy--;
for (auto &a : m)
cin >> a;
vector<vector<int>> f(h + 5, vector<int>(w + 5, inf));
priority_queue<tuple<int, int, int>> q;
q.push({0, sy, sx});
f[sy][sx] = 0;
while (!q.empty()) {
auto cur = q.top();
q.pop();
int y = get<1>(cur);
int x = get<2>(cur);
int cost = -get<0>(cur);
for (auto d :
initializer_list<pair<int, int>>{{-1, 0}, {0, 1}, {1, 0}, {0, -1}}) {
for (int i = 1; i <= k; ++i) {
int dy = y + d.first * i;
int dx = x + d.second * i;
if (dy < 0 or dy > h - 1 or dx < 0 or dx > w - 1 or m[dy][dx] == '@')
break;
if (f[dy][dx] > cost + 1) {
f[dy][dx] = cost + 1;
q.push({-f[dy][dx], dy, dx});
} else if (f[dy][dx] < cost + 1)
break;
}
}
}
if (f[gy][gx] == inf)
cout << -1 << endl;
else
cout << f[gy][gx] << endl;
return 0;
} | replace | 43 | 44 | 43 | 45 | TLE | |
p02644 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const vector<int> dx = {1, -1, 0, 0}, dy = {0, 0, 1, -1};
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int H, W, K;
cin >> H >> W >> K;
int sx, sy, gx, gy;
// cin >> sx >> sy >> gx >> gy;
cin >> sy >> sx >> gy >> gx;
sx--, sy--, gx--, gy--;
vector<string> S(H);
for (int i = 0; i < H; i++) {
cin >> S[i];
}
vector<vector<int>> D(H, vector<int>(W, INF));
D[sy][sx] = 0;
priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>,
greater<pair<int, pair<int, int>>>>
que;
que.push(make_pair(0, make_pair(sy, sx)));
while (!que.empty()) {
auto q = que.top();
que.pop();
int d = q.first, y = q.second.first, x = q.second.second;
if (d > D[y][x])
continue;
for (int i = 0; i < 4; i++) {
int ny = y, nx = x;
for (int k = 0; k < K; k++) {
ny += dy[i], nx += dx[i];
if (ny < 0 || ny >= H || nx < 0 || nx >= W)
break;
if (S[ny][nx] == '@')
break;
if (chmin(D[ny][nx], d + 1)) {
que.push(make_pair(D[ny][nx], make_pair(ny, nx)));
}
}
}
}
if (D[gy][gx] == INF) {
cout << -1 << '\n';
} else {
cout << D[gy][gx] << '\n';
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const vector<int> dx = {1, -1, 0, 0}, dy = {0, 0, 1, -1};
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int H, W, K;
cin >> H >> W >> K;
int sx, sy, gx, gy;
// cin >> sx >> sy >> gx >> gy;
cin >> sy >> sx >> gy >> gx;
sx--, sy--, gx--, gy--;
vector<string> S(H);
for (int i = 0; i < H; i++) {
cin >> S[i];
}
vector<vector<int>> D(H, vector<int>(W, INF));
D[sy][sx] = 0;
priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>,
greater<pair<int, pair<int, int>>>>
que;
que.push(make_pair(0, make_pair(sy, sx)));
while (!que.empty()) {
auto q = que.top();
que.pop();
int d = q.first, y = q.second.first, x = q.second.second;
if (d > D[y][x])
continue;
for (int i = 0; i < 4; i++) {
int ny = y, nx = x;
for (int k = 0; k < K; k++) {
ny += dy[i], nx += dx[i];
if (ny < 0 || ny >= H || nx < 0 || nx >= W)
break;
if (S[ny][nx] == '@')
break;
if (D[ny][nx] < D[y][x] + 1)
break;
if (chmin(D[ny][nx], d + 1)) {
que.push(make_pair(D[ny][nx], make_pair(ny, nx)));
}
}
}
}
if (D[gy][gx] == INF) {
cout << -1 << '\n';
} else {
cout << D[gy][gx] << '\n';
}
return 0;
}
| insert | 48 | 48 | 48 | 50 | TLE | |
p02644 | C++ | Time Limit Exceeded | /*
* Author: heyuhhh
* Created Time: 2020/6/22 14:05:49
*/
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
#define dbg(args...) \
do { \
cout << #args << " -> "; \
err(args); \
} while (0)
void err() { std::cout << std::endl; }
template <typename T, typename... Args> void err(T a, Args... args) {
std::cout << a << ' ';
err(args...);
}
template <template <typename...> class T, typename t, typename... A>
void err(const T<t> &arg, const A &...args) {
for (auto &v : arg)
std::cout << v << ' ';
err(args...);
}
#else
#define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
// head
const int N = 1e5 + 5;
int n, m, k;
struct node {
int x, y;
int cost;
int r;
int dir;
bool operator<(const node &A) const {
if (cost == A.cost)
return r > A.r;
return cost > A.cost;
}
};
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
void run() {
cin >> n >> m >> k;
int sx, sy, ex, ey;
cin >> sx >> sy >> ex >> ey;
--sx, --sy;
--ex, --ey;
vector<string> s(n);
for (int i = 0; i < n; i++) {
cin >> s[i];
}
priority_queue<node> q;
vector<vector<vector<int>>> dis(n,
vector<vector<int>>(m, vector<int>(4, INF)));
vector<vector<vector<bool>>> vis(
n, vector<vector<bool>>(m, vector<bool>(4, false)));
for (int i = 0; i < 4; i++) {
dis[sx][sy][i] = 0;
q.push(node{sx, sy, 0, 0, i});
}
while (!q.empty()) {
node now = q.top();
q.pop();
int x = now.x, y = now.y;
int cost = now.cost, r = now.r;
int dir = now.dir;
if (vis[x][y][dir])
continue;
vis[x][y][dir] = true;
dis[x][y][dir] = cost + (r > 0 ? 1 : 0);
for (int d = 0; d < 4; d++) {
int nx = x + dx[d], ny = y + dy[d];
if (nx >= 0 && nx < n && ny >= 0 && ny < m && s[nx][ny] != '@') {
if (d == dir && r < k) {
q.push(node{nx, ny, cost, r + 1, d});
} else {
q.push(node{nx, ny, cost + 1, 1, d});
}
}
}
for (int i = 0; i < 4; i++)
if (i != dir) {
q.push(node{x, y, dis[x][y][dir], 0, i});
}
}
int ans = INF;
for (int i = 0; i < 4; i++) {
ans = min(ans, dis[ex][ey][i]);
}
if (ans == INF)
ans = -1;
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(20);
run();
return 0;
} | /*
* Author: heyuhhh
* Created Time: 2020/6/22 14:05:49
*/
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
#define dbg(args...) \
do { \
cout << #args << " -> "; \
err(args); \
} while (0)
void err() { std::cout << std::endl; }
template <typename T, typename... Args> void err(T a, Args... args) {
std::cout << a << ' ';
err(args...);
}
template <template <typename...> class T, typename t, typename... A>
void err(const T<t> &arg, const A &...args) {
for (auto &v : arg)
std::cout << v << ' ';
err(args...);
}
#else
#define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
// head
const int N = 1e5 + 5;
int n, m, k;
struct node {
int x, y;
int cost;
int r;
int dir;
bool operator<(const node &A) const {
if (cost == A.cost)
return r > A.r;
return cost > A.cost;
}
};
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
void run() {
cin >> n >> m >> k;
int sx, sy, ex, ey;
cin >> sx >> sy >> ex >> ey;
--sx, --sy;
--ex, --ey;
vector<string> s(n);
for (int i = 0; i < n; i++) {
cin >> s[i];
}
priority_queue<node> q;
vector<vector<vector<int>>> dis(n,
vector<vector<int>>(m, vector<int>(4, INF)));
vector<vector<vector<bool>>> vis(
n, vector<vector<bool>>(m, vector<bool>(4, false)));
for (int i = 0; i < 4; i++) {
dis[sx][sy][i] = 0;
q.push(node{sx, sy, 0, 0, i});
}
while (!q.empty()) {
node now = q.top();
q.pop();
int x = now.x, y = now.y;
int cost = now.cost, r = now.r;
int dir = now.dir;
if (vis[x][y][dir])
continue;
vis[x][y][dir] = true;
dis[x][y][dir] = cost + (r > 0 ? 1 : 0);
for (int d = 0; d < 4; d++) {
int nx = x + dx[d], ny = y + dy[d];
if (nx >= 0 && nx < n && ny >= 0 && ny < m && s[nx][ny] != '@') {
if (d == dir && r < k) {
q.push(node{nx, ny, cost, r + 1, d});
} else {
q.push(node{nx, ny, cost + 1, 1, d});
}
}
}
}
int ans = INF;
for (int i = 0; i < 4; i++) {
ans = min(ans, dis[ex][ey][i]);
}
if (ans == INF)
ans = -1;
cout << ans << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(20);
run();
return 0;
} | delete | 106 | 110 | 106 | 106 | TLE | |
p02644 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
using ll = long long;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1 << 30;
const ll mod = 1000000007LL;
int main() {
int H, W, K, A, B, C, D;
cin >> H >> W >> K >> A >> B >> C >> D;
A--;
B--;
C--;
D--;
vector<string> g(H);
for (int i = 0; i < H; i++)
cin >> g[i];
vector<vector<int>> d(H, vector<int>(W, -1));
queue<tuple<int, int, int>> bfs;
bfs.push(make_tuple(A, B, -1));
d[A][B] = 0;
while (!bfs.empty()) {
tuple<int, int, int> p = bfs.front();
bfs.pop();
if (get<2>(p) != 1) {
for (int i = 1; i <= K; i++) {
int nx = get<0>(p) + i;
int ny = get<1>(p);
if (nx >= H)
break;
if (g[nx][ny] == '@')
break;
if (d[nx][ny] != -1)
continue;
bfs.push(make_tuple(nx, ny, 0));
d[nx][ny] = d[get<0>(p)][get<1>(p)] + 1;
}
}
if (get<2>(p) != 0) {
for (int i = 1; i <= K; i++) {
int nx = get<0>(p) - i;
int ny = get<1>(p);
if (nx < 0)
break;
if (g[nx][ny] == '@')
break;
if (d[nx][ny] != -1)
continue;
bfs.push(make_tuple(nx, ny, 1));
d[nx][ny] = d[get<0>(p)][get<1>(p)] + 1;
}
}
if (get<2>(p) != 3) {
for (int i = 1; i <= K; i++) {
int nx = get<0>(p);
int ny = get<1>(p) + i;
if (ny >= W)
break;
if (g[nx][ny] == '@')
break;
if (d[nx][ny] != -1)
continue;
bfs.push(make_tuple(nx, ny, 2));
d[nx][ny] = d[get<0>(p)][get<1>(p)] + 1;
}
}
if (get<2>(p) != 2) {
for (int i = 1; i <= K; i++) {
int nx = get<0>(p);
int ny = get<1>(p) - i;
if (ny < 0)
break;
if (g[nx][ny] == '@')
break;
if (d[nx][ny] != -1)
continue;
bfs.push(make_tuple(nx, ny, 3));
d[nx][ny] = d[get<0>(p)][get<1>(p)] + 1;
}
}
}
cout << d[C][D] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
using ll = long long;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1 << 30;
const ll mod = 1000000007LL;
int main() {
int H, W, K, A, B, C, D;
cin >> H >> W >> K >> A >> B >> C >> D;
A--;
B--;
C--;
D--;
vector<string> g(H);
for (int i = 0; i < H; i++)
cin >> g[i];
vector<vector<int>> d(H, vector<int>(W, -1));
queue<tuple<int, int, int>> bfs;
bfs.push(make_tuple(A, B, -1));
d[A][B] = 0;
while (!bfs.empty() && d[C][D] == -1) {
tuple<int, int, int> p = bfs.front();
bfs.pop();
if (get<2>(p) != 1) {
for (int i = 1; i <= K; i++) {
int nx = get<0>(p) + i;
int ny = get<1>(p);
if (nx >= H)
break;
if (g[nx][ny] == '@')
break;
if (d[nx][ny] != -1)
continue;
bfs.push(make_tuple(nx, ny, 0));
d[nx][ny] = d[get<0>(p)][get<1>(p)] + 1;
}
}
if (get<2>(p) != 0) {
for (int i = 1; i <= K; i++) {
int nx = get<0>(p) - i;
int ny = get<1>(p);
if (nx < 0)
break;
if (g[nx][ny] == '@')
break;
if (d[nx][ny] != -1)
continue;
bfs.push(make_tuple(nx, ny, 1));
d[nx][ny] = d[get<0>(p)][get<1>(p)] + 1;
}
}
if (get<2>(p) != 3) {
for (int i = 1; i <= K; i++) {
int nx = get<0>(p);
int ny = get<1>(p) + i;
if (ny >= W)
break;
if (g[nx][ny] == '@')
break;
if (d[nx][ny] != -1)
continue;
bfs.push(make_tuple(nx, ny, 2));
d[nx][ny] = d[get<0>(p)][get<1>(p)] + 1;
}
}
if (get<2>(p) != 2) {
for (int i = 1; i <= K; i++) {
int nx = get<0>(p);
int ny = get<1>(p) - i;
if (ny < 0)
break;
if (g[nx][ny] == '@')
break;
if (d[nx][ny] != -1)
continue;
bfs.push(make_tuple(nx, ny, 3));
d[nx][ny] = d[get<0>(p)][get<1>(p)] + 1;
}
}
}
cout << d[C][D] << endl;
}
| replace | 39 | 40 | 39 | 40 | TLE | |
p02644 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
int H, W, K;
cin >> H >> W >> K;
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
string M[H];
x1--;
y1--;
x2--;
y2--;
for (int i = 0; i < H; i++)
cin >> M[i];
int dist[H][W];
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
dist[i][j] = INT_MAX / 2;
}
}
queue<pair<int, pair<int, int>>> pq;
dist[x1][y1] = 0;
pq.push(make_pair(0, make_pair(x1, y1)));
while (!pq.empty()) {
pair<int, pair<int, int>> top = pq.front();
pq.pop();
int di = -top.first;
int curX = top.second.first;
int curY = top.second.second;
if (curX == x2 && curY == y2) {
cout << di << endl;
return 0;
}
if (dist[curX][curY] < di)
continue;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
for (int i = 0; i < 4; i++) {
for (int d = 1; d <= K; d++) {
int nx = curX + dx[i] * d;
int ny = curY + dy[i] * d;
if (nx < 0 || ny < 0 || nx >= H || ny >= W)
break;
if (M[nx][ny] == '@')
break;
if (dist[nx][ny] > di + 1) {
dist[nx][ny] = di + 1;
pq.push(make_pair(-di - 1, make_pair(nx, ny)));
}
}
}
}
cout << -1 << endl;
return 0;
}
| #include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
int H, W, K;
cin >> H >> W >> K;
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
string M[H];
x1--;
y1--;
x2--;
y2--;
for (int i = 0; i < H; i++)
cin >> M[i];
int dist[H][W];
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
dist[i][j] = INT_MAX / 2;
}
}
queue<pair<int, pair<int, int>>> pq;
dist[x1][y1] = 0;
pq.push(make_pair(0, make_pair(x1, y1)));
while (!pq.empty()) {
pair<int, pair<int, int>> top = pq.front();
pq.pop();
int di = -top.first;
int curX = top.second.first;
int curY = top.second.second;
if (curX == x2 && curY == y2) {
cout << di << endl;
return 0;
}
if (dist[curX][curY] < di)
continue;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
for (int i = 0; i < 4; i++) {
for (int d = 1; d <= K; d++) {
int nx = curX + dx[i] * d;
int ny = curY + dy[i] * d;
if (nx < 0 || ny < 0 || nx >= H || ny >= W)
break;
if (M[nx][ny] == '@')
break;
if (dist[nx][ny] == di) {
break;
}
if (dist[nx][ny] > di + 1) {
dist[nx][ny] = di + 1;
pq.push(make_pair(-di - 1, make_pair(nx, ny)));
}
}
}
}
cout << -1 << endl;
return 0;
}
| insert | 66 | 66 | 66 | 69 | TLE | |
p02644 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;
const double PI = 3.14159265358979323846;
#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))
#define rep(i, N) for (int i = 0; i < N; ++i)
#define CEIL(x, y) (((x) + (y)-1) / (y))
#define MOD 1000000007ULL
#define IN(l, r, x) ((l) <= (x) && (x) < (r))
using P = pair<s64, int>;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
s64 h, w, k;
cin >> h >> w >> k;
int si, sj, ti, tj;
cin >> si >> sj >> ti >> tj;
--si, --sj, --ti, --tj;
vector<string> field(h);
rep(i, h) cin >> field[i];
const s64 inf = 1e18;
vector<vector<bool>> reached(h, vector<bool>(w, false));
vs64 d(h * w, inf);
auto id = [&](int i, int j) { return i * w + j; };
queue<int> q;
q.push(id(si, sj));
d[id(si, sj)] = 0;
reached[si][sj] = true;
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, -1, 0, 1};
while (!q.empty()) {
int from = q.front();
q.pop();
int fi = from / w;
int fj = from % w;
rep(i, 4) {
rep(j, k) {
s64 ni = fi + dy[i] * (j + 1);
s64 nj = fj + dx[i] * (j + 1);
if (!(IN(0, h, ni) && IN(0, w, nj)))
break;
int to = id(ni, nj);
if (d[to] < d[from] + 1 || field[ni][nj] == '@')
break;
reached[ni][nj] = true;
d[to] = d[from] + 1;
q.push(to);
}
}
}
s64 ans = d[id(ti, tj)];
if (!reached[ti][tj])
cout << "-1\n";
else
cout << ans << "\n";
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;
const double PI = 3.14159265358979323846;
#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))
#define rep(i, N) for (int i = 0; i < N; ++i)
#define CEIL(x, y) (((x) + (y)-1) / (y))
#define MOD 1000000007ULL
#define IN(l, r, x) ((l) <= (x) && (x) < (r))
using P = pair<s64, int>;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
s64 h, w, k;
cin >> h >> w >> k;
int si, sj, ti, tj;
cin >> si >> sj >> ti >> tj;
--si, --sj, --ti, --tj;
vector<string> field(h);
rep(i, h) cin >> field[i];
const s64 inf = 1e18;
vector<vector<bool>> reached(h, vector<bool>(w, false));
vs64 d(h * w, inf);
auto id = [&](int i, int j) { return i * w + j; };
queue<int> q;
q.push(id(si, sj));
d[id(si, sj)] = 0;
reached[si][sj] = true;
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, -1, 0, 1};
while (!q.empty()) {
int from = q.front();
q.pop();
int fi = from / w;
int fj = from % w;
rep(i, 4) {
rep(j, k) {
s64 ni = fi + dy[i] * (j + 1);
s64 nj = fj + dx[i] * (j + 1);
if (!(IN(0, h, ni) && IN(0, w, nj)))
break;
int to = id(ni, nj);
if (d[to] < d[from] + 1 || field[ni][nj] == '@')
break;
if (d[to] != inf)
continue;
reached[ni][nj] = true;
d[to] = d[from] + 1;
q.push(to);
}
}
}
s64 ans = d[id(ti, tj)];
if (!reached[ti][tj])
cout << "-1\n";
else
cout << ans << "\n";
return 0;
}
| insert | 80 | 80 | 80 | 82 | TLE | |
p02644 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, m, k;
vector<vector<char>> mat;
vector<vector<int>> dist;
set<int> r[N], c[N];
void bfs(int x1, int y1, int x2, int y2) {
dist.assign(n, vector<int>(m, -1));
dist[x1][y1] = 0;
queue<pair<int, int>> q;
r[x1].erase(y1);
c[y1].erase(x1);
q.emplace(x1, y1);
while (!q.empty()) {
int x, y;
tie(x, y) = q.front();
q.pop();
{
auto it = r[x].lower_bound(y);
while (it != r[x].end() and *it - y <= k) {
if (mat[x][*it] == '@')
break;
if (dist[x][*it] == -1) {
dist[x][*it] = dist[x][y] + 1;
q.emplace(x, *it);
}
it = r[x].erase(it);
}
while (it != r[x].begin()) {
it--;
if (y - *it > k or mat[x][*it] == '@')
break;
if (dist[x][*it] == -1) {
dist[x][*it] = dist[x][y] + 1;
q.emplace(x, *it);
}
it = r[x].erase(it);
}
}
{
auto it = c[y].lower_bound(x);
while (it != c[y].end() and *it - x <= k) {
if (mat[*it][y] == '@')
break;
if (dist[*it][y] == -1) {
dist[*it][y] = dist[x][y] + 1;
q.emplace(*it, y);
}
it = c[y].erase(it);
}
while (it != c[y].begin()) {
it--;
if (x - *it > k)
break;
if (mat[*it][y] == '@')
break;
if (dist[*it][y] == -1) {
dist[*it][y] = dist[x][y] + 1;
q.emplace(*it, y);
}
it = c[y].erase(it);
}
}
}
}
int main() {
scanf("%d %d %d", &n, &m, &k);
int x1, y1, x2, y2;
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
mat.assign(n, vector<char>(m));
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
scanf(" %c", &mat[i][j]);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
r[i].insert(j);
c[j].insert(i);
}
x1--, y1--, x2--, y2--;
bfs(x1, y1, x2, y2);
printf("%d\n", dist[x2][y2]);
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 1000006;
int n, m, k;
vector<vector<char>> mat;
vector<vector<int>> dist;
set<int> r[N], c[N];
void bfs(int x1, int y1, int x2, int y2) {
dist.assign(n, vector<int>(m, -1));
dist[x1][y1] = 0;
queue<pair<int, int>> q;
r[x1].erase(y1);
c[y1].erase(x1);
q.emplace(x1, y1);
while (!q.empty()) {
int x, y;
tie(x, y) = q.front();
q.pop();
{
auto it = r[x].lower_bound(y);
while (it != r[x].end() and *it - y <= k) {
if (mat[x][*it] == '@')
break;
if (dist[x][*it] == -1) {
dist[x][*it] = dist[x][y] + 1;
q.emplace(x, *it);
}
it = r[x].erase(it);
}
while (it != r[x].begin()) {
it--;
if (y - *it > k or mat[x][*it] == '@')
break;
if (dist[x][*it] == -1) {
dist[x][*it] = dist[x][y] + 1;
q.emplace(x, *it);
}
it = r[x].erase(it);
}
}
{
auto it = c[y].lower_bound(x);
while (it != c[y].end() and *it - x <= k) {
if (mat[*it][y] == '@')
break;
if (dist[*it][y] == -1) {
dist[*it][y] = dist[x][y] + 1;
q.emplace(*it, y);
}
it = c[y].erase(it);
}
while (it != c[y].begin()) {
it--;
if (x - *it > k)
break;
if (mat[*it][y] == '@')
break;
if (dist[*it][y] == -1) {
dist[*it][y] = dist[x][y] + 1;
q.emplace(*it, y);
}
it = c[y].erase(it);
}
}
}
}
int main() {
scanf("%d %d %d", &n, &m, &k);
int x1, y1, x2, y2;
scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
mat.assign(n, vector<char>(m));
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
scanf(" %c", &mat[i][j]);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
r[i].insert(j);
c[j].insert(i);
}
x1--, y1--, x2--, y2--;
bfs(x1, y1, x2, y2);
printf("%d\n", dist[x2][y2]);
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p02644 | C++ | Time Limit Exceeded | // header{{{
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
// #include<boost/multiprecision/cpp_int.hpp>
// #include<boost/math/common_factor_rt.hpp>
// #include<boost/multiprecision/cpp_dec_float.hpp>
using namespace std;
// using namespace boost;
// using namespace multiprecision;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define all(x) (x).begin(), (x).end()
#define Fixed fixed << setprecision(12)
#define int int64_t
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
template <class A, class B> inline bool chmax(A &a, const B &b) {
return b > a && (a = b, true);
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
return b < a && (a = b, true);
}
template <class T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A, B>;
inline int square(int a) { return a * a; }
inline int updiv(int a, int b) { return (a + b - 1) / b; }
template <class A, class B> inline int Max(const A &a, const B &b) {
return (a < b ? b : a);
}
template <class A, class B> inline int Min(const A &a, const B &b) {
return (a > b ? b : a);
}
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};
//}}}
signed main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int h, w, k, sy, sx, gy, gx;
cin >> h >> w >> k >> sy >> sx >> gy >> gx;
--sy;
--sx;
--gy;
--gx;
vector<string> mat(h);
rep(i, h) { cin >> mat[i]; }
auto inside = [&](int y, int x) {
return (0 <= y && 0 <= x && y < h && x < w);
};
vector<vector<int>> min_cost(h, vector<int>(w, LINF));
// queue<pair<int, int> > que;
min_heap<tuple<int, int, int>> pq;
min_cost[sy][sx] = 0;
// que.emplace(sy, sx);
pq.emplace(0, sy, sx);
while (!pq.empty()) {
// auto [y, x] = que.front();
auto [v, y, x] = pq.top();
// que.pop();
pq.pop();
if (min_cost[y][x] < v)
continue;
rep(i, 4) {
int ny = y, nx = x;
rep(j, k) {
ny += dy[i];
nx += dx[i];
if (inside(ny, nx) && mat[ny][nx] != '@') {
if (chmin(min_cost[ny][nx], min_cost[y][x] + 1)) {
pq.emplace(min_cost[ny][nx], ny, nx);
}
} else {
break;
}
}
}
}
if (min_cost[gy][gx] == LINF) {
cout << -1 << '\n';
} else {
cout << min_cost[gy][gx] << '\n';
}
return (0);
}
| // header{{{
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
// #include<boost/multiprecision/cpp_int.hpp>
// #include<boost/math/common_factor_rt.hpp>
// #include<boost/multiprecision/cpp_dec_float.hpp>
using namespace std;
// using namespace boost;
// using namespace multiprecision;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define all(x) (x).begin(), (x).end()
#define Fixed fixed << setprecision(12)
#define int int64_t
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
template <class A, class B> inline bool chmax(A &a, const B &b) {
return b > a && (a = b, true);
}
template <class A, class B> inline bool chmin(A &a, const B &b) {
return b < a && (a = b, true);
}
template <class T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A, B>;
inline int square(int a) { return a * a; }
inline int updiv(int a, int b) { return (a + b - 1) / b; }
template <class A, class B> inline int Max(const A &a, const B &b) {
return (a < b ? b : a);
}
template <class A, class B> inline int Min(const A &a, const B &b) {
return (a > b ? b : a);
}
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};
//}}}
signed main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
int h, w, k, sy, sx, gy, gx;
cin >> h >> w >> k >> sy >> sx >> gy >> gx;
--sy;
--sx;
--gy;
--gx;
vector<string> mat(h);
rep(i, h) { cin >> mat[i]; }
auto inside = [&](int y, int x) {
return (0 <= y && 0 <= x && y < h && x < w);
};
vector<vector<int>> min_cost(h, vector<int>(w, LINF));
// queue<pair<int, int> > que;
min_heap<tuple<int, int, int>> pq;
min_cost[sy][sx] = 0;
// que.emplace(sy, sx);
pq.emplace(0, sy, sx);
while (!pq.empty()) {
// auto [y, x] = que.front();
auto [v, y, x] = pq.top();
// que.pop();
pq.pop();
if (min_cost[y][x] < v)
continue;
rep(i, 4) {
int ny = y, nx = x;
rep(j, k) {
ny += dy[i];
nx += dx[i];
if (inside(ny, nx) && mat[ny][nx] != '@') {
if (chmin(min_cost[ny][nx], min_cost[y][x] + 1)) {
pq.emplace(min_cost[ny][nx], ny, nx);
} else if (min_cost[ny][nx] != min_cost[y][x] + 1) {
break;
}
} else {
break;
}
}
}
}
if (min_cost[gy][gx] == LINF) {
cout << -1 << '\n';
} else {
cout << min_cost[gy][gx] << '\n';
}
return (0);
}
| insert | 89 | 89 | 89 | 91 | TLE | |
p02644 | C++ | Time Limit Exceeded | /*input
1 6 4
1 1 1 6
......
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <unistd.h>
#define rep(i, j, n) for (i = j; i < n; i++)
#define repi(i, j, n) for (i = j; i > n; i--)
#define inf 1e9
#define M 1000000007
#define pie 3.141592653589793238
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define UQ(x) (x).resize(distance((x).begin(), unique(all((x)))))
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64
rnd64(chrono::high_resolution_clock::now().time_since_epoch().count());
ll power(ll a, ll m, ll mod) {
ll ans = 1;
while (m) {
if (m % 2) {
ans *= a;
ans %= (mod);
}
a = (a * a) % (mod);
m >>= 1;
}
return ans;
}
void init(ll *a, ll n, ll val) {
for (ll i = 0; i < n; i++)
a[i] = val;
}
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};
void solve() {
ll i, j, _;
ll h, w, k, x, y;
cin >> h >> w >> k;
char ch;
ll x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2, --x1, --x2, --y1, --y2;
ll a[h][w];
ll b[h][w];
rep(i, 0, h) {
rep(j, 0, w) {
cin >> ch;
a[i][j] = (ch == '.');
b[i][j] = inf;
}
}
if (!a[x1][y1] || !a[x2][y2]) {
cout << -1 << endl;
return;
}
b[x1][y1] = 0;
list<pll> queue;
queue.pb({x1, y1});
while (!queue.empty()) {
pll z = queue.front();
queue.pop_front();
rep(i, 0, 4) {
x = z.F, y = z.S;
rep(j, 0, k) {
x += dx[i], y += +dy[i];
if (x < 0 || y < 0 || x > h - 1 || y > w - 1 || !a[x][y])
break;
if (b[x][y] < b[z.F][z.S] + 1)
break;
b[x][y] = b[z.F][z.S] + 1;
queue.pb({x, y});
}
}
}
// rep(i,0,h){
// rep(j,0,w)cout<<b[i][j]<<' ';cout<<endl;
// }
cout << ((b[x2][y2] == inf) ? -1 : b[x2][y2]) << endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll T = 1;
// cin>>T;
while (T--) {
solve();
}
return 0;
}
| /*input
1 6 4
1 1 1 6
......
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <unistd.h>
#define rep(i, j, n) for (i = j; i < n; i++)
#define repi(i, j, n) for (i = j; i > n; i--)
#define inf 1e9
#define M 1000000007
#define pie 3.141592653589793238
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define UQ(x) (x).resize(distance((x).begin(), unique(all((x)))))
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64
rnd64(chrono::high_resolution_clock::now().time_since_epoch().count());
ll power(ll a, ll m, ll mod) {
ll ans = 1;
while (m) {
if (m % 2) {
ans *= a;
ans %= (mod);
}
a = (a * a) % (mod);
m >>= 1;
}
return ans;
}
void init(ll *a, ll n, ll val) {
for (ll i = 0; i < n; i++)
a[i] = val;
}
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};
void solve() {
ll i, j, _;
ll h, w, k, x, y;
cin >> h >> w >> k;
char ch;
ll x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2, --x1, --x2, --y1, --y2;
ll a[h][w];
ll b[h][w];
rep(i, 0, h) {
rep(j, 0, w) {
cin >> ch;
a[i][j] = (ch == '.');
b[i][j] = inf;
}
}
if (!a[x1][y1] || !a[x2][y2]) {
cout << -1 << endl;
return;
}
b[x1][y1] = 0;
list<pll> queue;
queue.pb({x1, y1});
while (!queue.empty()) {
pll z = queue.front();
queue.pop_front();
rep(i, 0, 4) {
x = z.F, y = z.S;
rep(j, 0, k) {
x += dx[i], y += +dy[i];
if (x < 0 || y < 0 || x > h - 1 || y > w - 1 || !a[x][y])
break;
if (b[x][y] < b[z.F][z.S] + 1)
break;
if (b[x][y] < inf)
continue;
b[x][y] = b[z.F][z.S] + 1;
queue.pb({x, y});
}
}
}
// rep(i,0,h){
// rep(j,0,w)cout<<b[i][j]<<' ';cout<<endl;
// }
cout << ((b[x2][y2] == inf) ? -1 : b[x2][y2]) << endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll T = 1;
// cin>>T;
while (T--) {
solve();
}
return 0;
}
| insert | 93 | 93 | 93 | 95 | TLE | |
p02644 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
// template {{{
#define range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r)-1; i >= (int)(l); (i) -= 1)
#define whole(f, x, ...) \
([&](decltype((x)) container) { \
return (f)(begin(container), end(container), ##__VA_ARGS__); \
})(x)
#define rwhole(f, x, ...) \
([&](decltype((x)) container) { \
return (f)(rbegin(container), rend(container), ##__VA_ARGS__); \
})(x)
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
// constexpr i32 mod = 998244353;
constexpr i32 mod = 1e9 + 7;
constexpr i32 inf = 1001001001;
constexpr i64 infll = 1001001001001001001ll;
constexpr int dx[] = {0, -1, 1, 0, -1, 1, -1, 1};
constexpr int dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};
struct IoSetup {
IoSetup(int x = 15) {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(x);
cerr << fixed << setprecision(x);
}
} iosetup;
template <typename T = i64> T input() {
T x;
cin >> x;
return x;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); }
return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (T &in : v)
is >> in;
return is;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T> vector<T> make_vector(size_t a, T b) {
return vector<T>(a, b);
}
template <typename... Ts> auto make_vector(size_t a, Ts... ts) {
return vector<decltype(make_vector(ts...))>(a, make_vector(ts...));
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
// }}}
void solver() {
int h, w, k;
cin >> h >> w >> k;
int sy = input() - 1, sx = input() - 1, gy = input() - 1, gx = input() - 1;
vector<string> cs(h);
for (auto &c : cs)
cin >> c;
auto dp = make_vector(h, w, inf);
dp[sy][sx] = 0;
queue<pair<int, int>> que;
que.emplace(sy, sx);
auto used = make_vector(h, w, 2, false);
while (!que.empty()) {
auto p = que.front();
que.pop();
int x, y;
tie(y, x) = p;
range(d, 0, 4) {
range(t, 1, k + 1) {
int nx = x + dx[d] * t;
int ny = y + dy[d] * t;
if (nx < 0 || w <= nx || ny < 0 || h <= ny) {
break;
}
if (cs[ny][nx] == '@')
break;
if (dp[y][x] >= dp[ny][nx])
break;
dp[ny][nx] = dp[y][x] + 1;
que.emplace(ny, nx);
}
}
}
if (dp[gy][gx] == inf) {
cout << -1 << endl;
} else {
cout << dp[gy][gx] << endl;
}
}
signed main(int argc, char *argv[]) { solver(); }
| #include <bits/stdc++.h>
using namespace std;
// template {{{
#define range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r)-1; i >= (int)(l); (i) -= 1)
#define whole(f, x, ...) \
([&](decltype((x)) container) { \
return (f)(begin(container), end(container), ##__VA_ARGS__); \
})(x)
#define rwhole(f, x, ...) \
([&](decltype((x)) container) { \
return (f)(rbegin(container), rend(container), ##__VA_ARGS__); \
})(x)
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
// constexpr i32 mod = 998244353;
constexpr i32 mod = 1e9 + 7;
constexpr i32 inf = 1001001001;
constexpr i64 infll = 1001001001001001001ll;
constexpr int dx[] = {0, -1, 1, 0, -1, 1, -1, 1};
constexpr int dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};
struct IoSetup {
IoSetup(int x = 15) {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(x);
cerr << fixed << setprecision(x);
}
} iosetup;
template <typename T = i64> T input() {
T x;
cin >> x;
return x;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); }
return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (T &in : v)
is >> in;
return is;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T> vector<T> make_vector(size_t a, T b) {
return vector<T>(a, b);
}
template <typename... Ts> auto make_vector(size_t a, Ts... ts) {
return vector<decltype(make_vector(ts...))>(a, make_vector(ts...));
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
// }}}
void solver() {
int h, w, k;
cin >> h >> w >> k;
int sy = input() - 1, sx = input() - 1, gy = input() - 1, gx = input() - 1;
vector<string> cs(h);
for (auto &c : cs)
cin >> c;
auto dp = make_vector(h, w, inf);
dp[sy][sx] = 0;
queue<pair<int, int>> que;
que.emplace(sy, sx);
auto used = make_vector(h, w, 2, false);
while (!que.empty()) {
auto p = que.front();
que.pop();
int x, y;
tie(y, x) = p;
range(d, 0, 4) {
range(t, 1, k + 1) {
int nx = x + dx[d] * t;
int ny = y + dy[d] * t;
if (nx < 0 || w <= nx || ny < 0 || h <= ny) {
break;
}
if (cs[ny][nx] == '@')
break;
if (dp[y][x] >= dp[ny][nx])
break;
if (dp[ny][nx] > dp[y][x] + 1) {
dp[ny][nx] = dp[y][x] + 1;
que.emplace(ny, nx);
}
}
}
}
if (dp[gy][gx] == inf) {
cout << -1 << endl;
} else {
cout << dp[gy][gx] << endl;
}
}
signed main(int argc, char *argv[]) { solver(); }
| replace | 120 | 122 | 120 | 124 | TLE | |
p02644 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define __ \
ios_base::sync_with_stdio(0); \
cin.tie(0);
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define forn(i, a, n) for (int i = a; i < n; i++)
typedef long long int lli;
typedef long double Double;
typedef pair<int, int> pii;
typedef pair<pii, int> iii;
typedef vector<int> vi;
typedef vector<vi> vvi;
vector<pii> mov = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
const Double inf = 100000000.0;
int main() {
__ int n, m, k;
cin >> n >> m >> k;
int xs, ys, xf, yf;
cin >> xs >> ys >> xf >> yf;
vector<vector<bool>> a(n + 1, vector<bool>(m + 1));
vector<vector<vector<Double>>> dist(
n + 1, vector<vector<Double>>(m + 1, vector<Double>(2, inf)));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
char c;
cin >> c;
if (c == '.')
a[i][j] = true;
}
}
Double div = 1.0 / Double(k);
dist[xs][ys][0] = dist[xs][ys][1] = 0.0;
priority_queue<pair<Double, iii>> q;
for (auto e : mov) {
int f = (e.se != 0) ? 1 : 0;
int x = xs + e.fi, y = ys + e.se;
if (x >= 1 && x <= n && y >= 1 && y <= m) {
if (a[x][y]) {
dist[x][y][f] = div;
q.push(pair<Double, iii>(-dist[x][y][f], iii(pii(x, y), f)));
}
}
}
// meto og
// f = 1 de izq a der o der a izq
// al cambio de direccion viene el ceil
while (!q.empty()) {
int xa = q.top().se.fi.fi;
int ya = q.top().se.fi.se;
Double d = -q.top().fi;
int of = q.top().se.se;
q.pop();
if (d != dist[xa][ya][of])
continue;
// movi
for (auto e : mov) {
int x = xa + e.fi, y = ya + e.se;
int f = (e.se != 0) ? 1 : 0;
if (x >= 1 && x <= n && y >= 1 && y <= m && a[x][y]) {
Double currd = dist[xa][ya][of];
if (f != of)
currd = ceil(currd);
if (currd + div <= dist[x][y][f]) {
dist[x][y][f] = currd + div;
q.push(pair<Double, iii>(-dist[x][y][f], iii(pii(x, y), f)));
}
}
}
}
/*
cout << "distancias\n";
for(int i=1; i <=n; i++){
for(int j=1; j <=m; j++){
if(dist[i][j]== inf){
cout << "oooo ";
continue;
}
cout << fixed << setprecision(4) << dist[i][j] << " ";
}
cout << endl;
}
*/
// al final ceil al resultado
Double mini = min(dist[xf][yf][0], dist[xf][yf][1]);
if (mini == inf) {
cout << -1 << endl;
} else {
cout << ceil(mini) << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define __ \
ios_base::sync_with_stdio(0); \
cin.tie(0);
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define forn(i, a, n) for (int i = a; i < n; i++)
typedef long long int lli;
typedef long double Double;
typedef pair<int, int> pii;
typedef pair<pii, int> iii;
typedef vector<int> vi;
typedef vector<vi> vvi;
vector<pii> mov = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
const Double inf = 100000000.0;
int main() {
__ int n, m, k;
cin >> n >> m >> k;
int xs, ys, xf, yf;
cin >> xs >> ys >> xf >> yf;
vector<vector<bool>> a(n + 1, vector<bool>(m + 1));
vector<vector<vector<Double>>> dist(
n + 1, vector<vector<Double>>(m + 1, vector<Double>(2, inf)));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
char c;
cin >> c;
if (c == '.')
a[i][j] = true;
}
}
Double div = 1.0 / Double(k);
dist[xs][ys][0] = dist[xs][ys][1] = 0.0;
priority_queue<pair<Double, iii>> q;
for (auto e : mov) {
int f = (e.se != 0) ? 1 : 0;
int x = xs + e.fi, y = ys + e.se;
if (x >= 1 && x <= n && y >= 1 && y <= m) {
if (a[x][y]) {
dist[x][y][f] = div;
q.push(pair<Double, iii>(-dist[x][y][f], iii(pii(x, y), f)));
}
}
}
// meto og
// f = 1 de izq a der o der a izq
// al cambio de direccion viene el ceil
while (!q.empty()) {
int xa = q.top().se.fi.fi;
int ya = q.top().se.fi.se;
Double d = -q.top().fi;
int of = q.top().se.se;
q.pop();
if (d != dist[xa][ya][of])
continue;
// movi
for (auto e : mov) {
int x = xa + e.fi, y = ya + e.se;
int f = (e.se != 0) ? 1 : 0;
if (x >= 1 && x <= n && y >= 1 && y <= m && a[x][y]) {
Double currd = dist[xa][ya][of];
if (f != of)
currd = ceil(currd);
if (currd + div < dist[x][y][f]) {
dist[x][y][f] = currd + div;
q.push(pair<Double, iii>(-dist[x][y][f], iii(pii(x, y), f)));
}
}
}
}
/*
cout << "distancias\n";
for(int i=1; i <=n; i++){
for(int j=1; j <=m; j++){
if(dist[i][j]== inf){
cout << "oooo ";
continue;
}
cout << fixed << setprecision(4) << dist[i][j] << " ";
}
cout << endl;
}
*/
// al final ceil al resultado
Double mini = min(dist[xf][yf][0], dist[xf][yf][1]);
if (mini == inf) {
cout << -1 << endl;
} else {
cout << ceil(mini) << endl;
}
return 0;
}
| replace | 67 | 68 | 67 | 68 | TLE | |
p02644 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int h, w, k;
cin >> h >> w >> k;
++k;
int xb, yb, xe, ye;
cin >> xb >> yb >> xe >> ye;
--xb;
--yb;
--xe;
--ye;
vector<vector<char>> rec(h, vector<char>(w));
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
cin >> rec[i][j];
}
}
vector<vector<int>> dis(h, vector<int>(w, 1 << 30));
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};
queue<vector<int>> que;
que.push({xb, yb});
dis[xb][yb] = 0;
while (!que.empty()) {
int x = que.front()[0], y = que.front()[1];
que.pop();
for (int r = 0; r < 4; ++r) {
int u = x, v = y, s = dis[x][y] + 1;
for (int d = 1; d < k; ++d) {
u += dx[r];
v += dy[r];
if (0 <= u && u < h && 0 <= v && v < w && rec[u][v] == '.') {
if (dis[u][v] > s) {
dis[u][v] = s;
que.push({u, v});
}
} else {
break;
}
}
}
}
if (dis[xe][ye] == 1 << 30) {
cout << -1 << endl;
} else {
cout << dis[xe][ye] << endl;
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int h, w, k;
cin >> h >> w >> k;
++k;
int xb, yb, xe, ye;
cin >> xb >> yb >> xe >> ye;
--xb;
--yb;
--xe;
--ye;
vector<vector<char>> rec(h, vector<char>(w));
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
cin >> rec[i][j];
}
}
vector<vector<int>> dis(h, vector<int>(w, 1 << 30));
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};
queue<vector<int>> que;
que.push({xb, yb});
dis[xb][yb] = 0;
while (!que.empty()) {
int x = que.front()[0], y = que.front()[1];
que.pop();
for (int r = 0; r < 4; ++r) {
int u = x, v = y, s = dis[x][y] + 1;
for (int d = 1; d < k; ++d) {
u += dx[r];
v += dy[r];
if (0 <= u && u < h && 0 <= v && v < w && rec[u][v] == '.') {
if (dis[u][v] > s) {
dis[u][v] = s;
que.push({u, v});
} else if (dis[u][v] < s) {
break;
}
} else {
break;
}
}
}
}
if (dis[xe][ye] == 1 << 30) {
cout << -1 << endl;
} else {
cout << dis[xe][ye] << endl;
}
return 0;
} | insert | 41 | 41 | 41 | 43 | TLE | |
p02644 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int h, w, k, x1, Y1, x2, y2, mx[] = {0, 1, 0, -1}, my[] = {1, 0, -1, 0};
string mp[100005];
struct node {
int x, y, v;
} q[5000005];
int main() {
cin >> h >> w >> k >> x1 >> Y1 >> x2 >> y2;
for (int i = 1; i <= h; i++)
cin >> mp[i];
int d[h + 10][w + 10];
for (int i = 1; i <= h; i++)
for (int j = 1; j <= w; j++)
d[i][j] = inf;
d[x1][Y1] = 0;
int l = 1, r = 1;
node x;
x.x = x1;
x.y = Y1;
x.v = 0;
q[1] = x;
while (l <= r) {
node x = q[l++];
if (x.v != d[x.x][x.y])
continue;
if (x.x == x2 && x.y == y2) {
cout << d[x2][y2] << endl;
return 0;
}
for (int i = 0; i < 4; i++) {
for (int j = 1; j <= k; j++) {
int nx = x.x + j * mx[i], ny = x.y + j * my[i];
if (nx >= 1 && nx <= h && ny >= 1 && ny <= w && mp[nx][ny - 1] == '.') {
if (d[nx][ny] > d[x.x][x.y] + 1) {
d[nx][ny] = d[x.x][x.y] + 1;
node xx;
xx.x = nx;
xx.y = ny;
xx.v = d[nx][ny];
q[++r] = xx;
}
if (d[nx][ny] < d[x.x][x.y])
break;
} else
break;
}
}
}
cout << -1 << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int h, w, k, x1, Y1, x2, y2, mx[] = {0, 1, 0, -1}, my[] = {1, 0, -1, 0};
string mp[100005];
struct node {
int x, y, v;
} q[5000005];
int main() {
cin >> h >> w >> k >> x1 >> Y1 >> x2 >> y2;
for (int i = 1; i <= h; i++)
cin >> mp[i];
int d[h + 10][w + 10];
for (int i = 1; i <= h; i++)
for (int j = 1; j <= w; j++)
d[i][j] = inf;
d[x1][Y1] = 0;
int l = 1, r = 1;
node x;
x.x = x1;
x.y = Y1;
x.v = 0;
q[1] = x;
while (l <= r) {
node x = q[l++];
if (x.v != d[x.x][x.y])
continue;
if (x.x == x2 && x.y == y2) {
cout << d[x2][y2] << endl;
return 0;
}
for (int i = 0; i < 4; i++) {
for (int j = 1; j <= k; j++) {
int nx = x.x + j * mx[i], ny = x.y + j * my[i];
if (nx >= 1 && nx <= h && ny >= 1 && ny <= w && mp[nx][ny - 1] == '.') {
if (d[nx][ny] > d[x.x][x.y] + 1) {
d[nx][ny] = d[x.x][x.y] + 1;
node xx;
xx.x = nx;
xx.y = ny;
xx.v = d[nx][ny];
q[++r] = xx;
}
if (d[nx][ny] <= d[x.x][x.y])
break;
} else
break;
}
}
}
cout << -1 << '\n';
return 0;
}
| replace | 47 | 48 | 47 | 48 | TLE | |
p02645 | C++ | Runtime Error | #include "bits/stdc++.h"
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int n, m;
cin >> n >> m;
vector<vector<int>> a(n + 1);
int b, c;
rep(i, m) {
cin >> b >> c;
a[b].push_back(c);
a[c].push_back(b);
}
vector<int> o(n + 1), ma(n + 1, -1);
queue<int> q;
int qq, l, ans = 0, k;
rep(i, n) {
k = 0;
if (ma[i + 1] == -1) {
ma[i + 1] = 0;
q.push(i + 1);
while (q.size() != 0) {
qq = q.front();
q.pop();
l = a[qq].size();
rep(j, l) {
if (ma[a[qq][j]] == -1) {
q.push(a[qq][j]);
ma[a[qq][j]] = 3;
o[a[qq][j]] = qq;
} else {
if (a[qq][j] != o[qq]) {
// cout << qq << endl;
k = 1;
}
}
}
}
if (k == 0) {
++ans;
}
}
}
cout << ans << 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() {
string s;
cin >> s;
string s2;
s2 = s.substr(0, 3);
cout << s2 << endl;
return 0;
} | replace | 7 | 49 | 7 | 12 | 0 | |
p02645 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> d(k);
int tmp;
vector<int> a(n);
rep(i, k) {
cin >> d.at(i);
rep(j, d.at(i)) {
cin >> tmp;
a.at((int)tmp - 1) = 1;
}
}
int count = 0;
rep(i, n) {
if (a.at(i) == 0) {
count++;
}
}
cout << count << endl;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
string s;
cin >> s;
cout << s[0] << s[1] << s[2] << endl;
} | replace | 5 | 24 | 5 | 8 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p02645 | Python | Runtime Error | import random
S = input()
A = random.randint(0, len(S) - 2)
print(S[A] + S[A + 1] + S[A + 2])
| import random
S = input()
A = random.randint(0, len(S) - 3)
print(S[A] + S[A + 1] + S[A + 2])
| replace | 4 | 5 | 4 | 5 | 0 | |
p02645 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define _CRT_SECURE_NO_DEPRECATE
#define ll long long
#define nl '\n' // NL - sign of new line
#define upc(str, c) str[c] = toupper(str[c]); // make single char uppercase
#define lowerc(str, c) str[c] = tolower(str[c]); // make single char lowercase
#define ups(str) \
transform(str.begin(), str.end(), str.begin(), \
::toupper); // make entire string uppercase
#define lowers(str) \
transform(str.begin(), str.end(), str.begin(), \
::tolower); // make entire string lowercase
#define ps(x, y) \
fixed << setprecision(y) << x // usage: t=1.1234; cout << ps(t,4); // it means
// it will print 4 decimal places.
#define vi vector<int> // create vector of int numbers
#define vs vector<string> // create vector of int numbers
#define eb emplace_back
#define rev(v) reverse(v.begin(), v.end()) // reverse the vector
#define mii std::map<int, int>
#define multimii std::multimap<int, int>
#define mss map<string, string>
#define w(t) \
unsigned int t; \
cin >> t; \
while (t--) // usage: create quickly number of test
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void c_p_c() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
//==================================6
//==================================
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
c_p_c();
//--------------------------------
char s[3];
cin >> s;
cout << s[0] << s[1] << s[2];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define _CRT_SECURE_NO_DEPRECATE
#define ll long long
#define nl '\n' // NL - sign of new line
#define upc(str, c) str[c] = toupper(str[c]); // make single char uppercase
#define lowerc(str, c) str[c] = tolower(str[c]); // make single char lowercase
#define ups(str) \
transform(str.begin(), str.end(), str.begin(), \
::toupper); // make entire string uppercase
#define lowers(str) \
transform(str.begin(), str.end(), str.begin(), \
::tolower); // make entire string lowercase
#define ps(x, y) \
fixed << setprecision(y) << x // usage: t=1.1234; cout << ps(t,4); // it means
// it will print 4 decimal places.
#define vi vector<int> // create vector of int numbers
#define vs vector<string> // create vector of int numbers
#define eb emplace_back
#define rev(v) reverse(v.begin(), v.end()) // reverse the vector
#define mii std::map<int, int>
#define multimii std::multimap<int, int>
#define mss map<string, string>
#define w(t) \
unsigned int t; \
cin >> t; \
while (t--) // usage: create quickly number of test
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void c_p_c() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
//==================================6
//==================================
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
c_p_c();
//--------------------------------
string s;
cin >> s;
cout << s[0] << s[1] << s[2];
return 0;
} | replace | 51 | 52 | 51 | 52 | 0 | |
p02645 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
cout << S.at(1) << S.at(2) << S.at(3) << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
cout << S.at(0) << S.at(1) << S.at(2) << endl;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p02645 | Python | Runtime Error | import random
S = input()
rand = random.randrange(0, len(S) - 1)
print(S[rand] + S[rand + 1] + S[rand + 2])
| import random
S = input()
rand = random.randrange(0, len(S) - 2)
print(S[rand] + S[rand + 1] + S[rand + 2])
| replace | 3 | 4 | 3 | 4 | 0 | |
p02645 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main() {
string s;
cin >> s;
string k;
int N = s.size();
int p = rand() % N;
k = s.at(p) + s.at(p + 1) + s.at(p + 2);
cout << k << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main() {
string s;
cin >> s;
string a, b, c;
a = s.at(0);
b = s.at(1);
c = s.at(2);
cout << a << b << c << endl;
}
| replace | 7 | 12 | 7 | 13 | 0 | |
p02645 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int n;
cin >> s >> n;
cout << s.substr(n, 3) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int n;
cin >> s >> n;
cout << s.substr(0, 3) << endl;
return 0;
} | replace | 7 | 8 | 7 | 8 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::substr: __pos (which is 18446744072974021345) > this->size() (which is 9)
|
p02645 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main(void) {
char s[3];
cin >> s;
cout << s[0] << s[1] << s[2] << endl;
}
| #include <iostream>
using namespace std;
int main(void) {
char s[20];
cin >> s;
cout << s[0] << s[1] << s[2] << endl;
} | replace | 3 | 4 | 3 | 4 | -6 | *** stack smashing detected ***: terminated
|
p02645 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
string ans = 0;
for (int i = 0; i < s.length() - 2; i++) {
if (s[i] != s[i + 1] and s[i + 1] != s[i + 2] and s[i] != s[i + 2]) {
ans += s[i];
ans += s[i + 1];
ans += s[i + 2];
break;
}
}
if (ans.length() != 0)
cout << ans << endl;
else {
cout << s[0] << s[1] << s[2] << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
string ans = "";
for (int i = 0; i < s.length() - 2; i++) {
if (s[i] != s[i + 1] and s[i + 1] != s[i + 2] and s[i] != s[i + 2]) {
ans += s[i];
ans += s[i + 1];
ans += s[i + 2];
break;
}
}
if (ans.length() != 0)
cout << ans << endl;
else {
cout << s[0] << s[1] << s[2] << endl;
}
return 0;
}
| replace | 7 | 8 | 7 | 8 | -6 | terminate called after throwing an instance of 'std::logic_error'
what(): basic_string: construction from null is not valid
|
p02645 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
// i: index, n: size, a: start, b: end
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
// x: container(array, vector etc..)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000000 // 10^12
#define MOD 10000007 // 10^9+7
#define MAXR 100000 // 10^5
#define PB push_back
#define MP make_pair
#define F first
#define S second
signed main() {
string s;
cin >> s;
string nickName;
int maxStartIndex = s.length() - 3;
srand((unsigned int)time(NULL));
int startIndex = rand() % maxStartIndex;
FOR(i, startIndex, startIndex + 2) { nickName += s[i]; }
cout << nickName << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
// i: index, n: size, a: start, b: end
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
// x: container(array, vector etc..)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000000 // 10^12
#define MOD 10000007 // 10^9+7
#define MAXR 100000 // 10^5
#define PB push_back
#define MP make_pair
#define F first
#define S second
signed main() {
string s;
cin >> s;
string nickName;
int maxStartIndex = s.length() - 3;
srand((unsigned int)time(NULL));
int startIndex = 0;
if (maxStartIndex != 0) {
startIndex = rand() % maxStartIndex;
}
FOR(i, startIndex, startIndex + 2) { nickName += s[i]; }
cout << nickName << endl;
return 0;
}
| replace | 50 | 51 | 50 | 54 | 0 | |
p02645 | Python | Runtime Error | s = input()
print(s[3])
| s = input()
print(s[:3])
| replace | 1 | 2 | 1 | 2 | 0 | |
p02645 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#include <random>
#include <string>
int main() {
string s, ans;
getline(cin, s);
int a = s.size();
int i = rand() % a - 2;
ans = s.substr(i, 3);
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#include <random>
#include <string>
int main() {
string s, ans;
getline(cin, s);
int a = s.size();
int i = rand() % (a - 2);
ans = s.substr(i, 3);
cout << ans << endl;
} | replace | 9 | 10 | 9 | 10 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::substr: __pos (which is 18446744073709551615) > this->size() (which is 9)
|
p02645 | Python | Runtime Error | print(input().split().index("0") + 1)
| print(input()[:3])
| replace | 0 | 1 | 0 | 1 | ValueError: '0' is not in list | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02645/Python/s112750711.py", line 1, in <module>
print(input().split().index("0") + 1)
ValueError: '0' is not in list
|
p02646 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define Pb push_back
#define Mp make_pair
#define ff first
#define ss second
#define Max(x, y, z) max(x, max(y, z))
#define Min(x, y, z) min(x, min(y, z))
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN
#define endl "\n"
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define db1(x) cout << #x << " : " << x << endl;
#define db2(x, y) cout << #x << " : " << x << "\t" << #y << " : " << y << endl;
#define db3(x, y, z) \
cout << #x << " : " << x << "\t" << #y << " : " << y << "\t" << #z << " : " \
<< z << endl;
typedef long long int ll;
typedef long double ld;
const int N = 1e5 + 5;
const int inf = INT_MAX;
const int MOD = 1e9 + 7;
void solve() {
ll a, b, v, w, t;
cin >> a >> v >> b >> w >> t;
if (a < b && v <= w) {
cout << "NO";
return;
}
ll tt = abs(a - b) / abs(v - w);
if (tt <= t) {
cout << "YES";
} else {
cout << "NO";
}
}
int32_t main() {
IOS;
// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
// cout<<"Case #"<<i<<": ";
solve();
}
return 0;
}
/*==============================================================================================================================================================*/
| #include <bits/stdc++.h>
using namespace std;
#define Pb push_back
#define Mp make_pair
#define ff first
#define ss second
#define Max(x, y, z) max(x, max(y, z))
#define Min(x, y, z) min(x, min(y, z))
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN
#define endl "\n"
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define db1(x) cout << #x << " : " << x << endl;
#define db2(x, y) cout << #x << " : " << x << "\t" << #y << " : " << y << endl;
#define db3(x, y, z) \
cout << #x << " : " << x << "\t" << #y << " : " << y << "\t" << #z << " : " \
<< z << endl;
typedef long long int ll;
typedef long double ld;
const int N = 1e5 + 5;
const int inf = INT_MAX;
const int MOD = 1e9 + 7;
void solve() {
ll a, b, v, w, t;
cin >> a >> v >> b >> w >> t;
ll d1 = abs(a - b);
ll d2 = (v - w) * 1LL * t;
if (d1 <= d2) {
cout << "YES";
} else {
cout << "NO";
}
}
int32_t main() {
IOS;
// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
// cout<<"Case #"<<i<<": ";
solve();
}
return 0;
}
/*==============================================================================================================================================================*/
| replace | 33 | 39 | 33 | 36 | 0 | |
p02646 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
int main() {
ll a, b, v, w, t;
cin >> a >> v >> b >> w >> t;
ll dist = max(a - b, b - a);
ll sekkin = v - w;
bool kotae = false;
if (dist % sekkin == 0) {
for (int i = 0; i < t; i++) {
dist -= sekkin;
if (dist == 0) {
kotae = true;
}
}
}
if (kotae) {
cout << "YES" << endl;
}
else {
cout << "NO" << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
int main() {
ll a, b, v, w, t;
cin >> a >> v >> b >> w >> t;
ll dist = max(a - b, b - a);
ll sekkin = v - w;
bool kotae = false;
for (int i = 0; i < t; i++) {
dist -= sekkin;
if (dist <= 0) {
kotae = true;
}
}
if (kotae) {
cout << "YES" << endl;
}
else {
cout << "NO" << endl;
}
}
| replace | 15 | 23 | 15 | 19 | 0 | |
p02646 | C++ | Runtime Error | #include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define F first
#define S second
#define migmig \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define ll long long
#define ld long double
#define pii pair<int, int>
#define bug(x) cout << "passed " << x << endl;
#define ashar(x, y, z) \
cout << setprecision(x) << fixed << y; \
if (z == 1) \
cout << "\n";
#define ppi pair<pair<int, int>, int>
long long const inf = 3e18, linf = 2e9, mod = 1e9 + 7, inf2 = 1e12;
int const mxn = 5e5 + 10;
ll poww(ll a, ll b, ll md) {
return (!b ? 1
: (b & 1 ? a * poww(a * a % md, b / 2, md) % md
: poww(a * a % md, b / 2, md) % md));
}
int main() {
int a, b, v, w, t;
;
cin >> a >> v >> b >> w >> t;
long long dis = abs(a - b);
long long s = (v - w);
if (dis == 0)
cout << "YES";
else if (s >= 0 and ((s == 0 and dis == 0) or dis / s + (dis % s > 1) <= t))
cout << "YES";
else
cout << "NO";
}
| #include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define F first
#define S second
#define migmig \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define ll long long
#define ld long double
#define pii pair<int, int>
#define bug(x) cout << "passed " << x << endl;
#define ashar(x, y, z) \
cout << setprecision(x) << fixed << y; \
if (z == 1) \
cout << "\n";
#define ppi pair<pair<int, int>, int>
long long const inf = 3e18, linf = 2e9, mod = 1e9 + 7, inf2 = 1e12;
int const mxn = 5e5 + 10;
ll poww(ll a, ll b, ll md) {
return (!b ? 1
: (b & 1 ? a * poww(a * a % md, b / 2, md) % md
: poww(a * a % md, b / 2, md) % md));
}
int main() {
int a, b, v, w, t;
;
cin >> a >> v >> b >> w >> t;
long long dis = abs(a - b);
long long s = (v - w);
if (dis == 0)
cout << "YES";
else if (s <= 0)
cout << "NO";
else if (dis / s + (dis % s > 0) <= t)
cout << "YES";
else
cout << "NO";
}
| replace | 35 | 36 | 35 | 38 | 0 | |
p02646 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
int main(void) {
ll a, b, v, w, t;
cin >> a >> v >> b >> w >> t;
cout << (abs(a - b) / (v - w) <= t ? "YES" : "NO") << endl;
return 0;
}
| #include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
int main(void) {
ll a, b, v, w, t;
cin >> a >> v >> b >> w >> t;
cout << (abs(a - b) <= (v - w) * t ? "YES" : "NO") << endl;
return 0;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p02646 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int A, V, B, W, T = 0;
cin >> A >> V >> B >> W >> T;
int X = B - A;
if (B > A && V >= W && (B - A) / (V - W) <= T) {
cout << "YES" << endl;
} else if (X == 0) {
cout << "YES" << endl;
} else if (B > A && W >= V && (B - A) / (V - W) <= T) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long a, v, b, w, p;
cin >> a >> v >> b >> w >> p;
long long wdnmd = abs(b - a);
long long xswl = (v - w) * p;
if (wdnmd <= xswl) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
| replace | 4 | 12 | 4 | 9 | 0 | |
p02646 | C++ | Runtime Error | /*
*****
@Author: Harith Insider
*****
*/
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define ff first
#define ss second
#define fastio \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
using namespace std;
void solve() {
ll x1, x2, t1, t2, t;
cin >> x1 >> t1 >> x2 >> t2 >> t;
ll v = abs(x1 - x2) / abs(t2 - t1);
if (v > 0 and v <= t)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
int main() {
fastio;
solve();
} | /*
*****
@Author: Harith Insider
*****
*/
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define ff first
#define ss second
#define fastio \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
using namespace std;
void solve() {
ll x1, x2, t1, t2, t;
cin >> x1 >> t1 >> x2 >> t2 >> t;
ll a = abs(x1 - x2);
ll b = (t1 - t2) * t;
if (a <= b)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
int main() {
fastio;
solve();
}
| replace | 19 | 21 | 19 | 22 | 0 | |
p02646 | C++ | Runtime Error | /*
* author :Sadik Hassan
*
*/
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define nl "\n"
#define pb push_back
#define fi first
#define se second
#define PI (acos(-1.0))
#define _SAD() \
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), \
cout << fixed << setprecision(20);
#define rep(i, n) for (int i = 0; i < n; i++)
#define SZ(s) s.size()
#define SRT(x, y) sort(x, x + y)
#define REV(a, b) reverse(a, a + b)
#define VSRT(x) sort(x.begin(), x.end())
#define VREV(x) reverse(x.begin(), x.end())
#define w(t) \
int t; \
cin >> t; \
while (t--)
#define TSFL(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define TSFH(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;
/*---------------------------------------------------------------------*/
const int N = 2e5 + 10;
const int INF = (int)1e9 + 5;
int main() {
_SAD()
int a, b, m, n, t;
cin >> a >> m >> b >> n >> t;
a = abs(a - b);
m -= n;
if ((a + m - 1) / m <= t && m > 0)
cout << "YES";
else
cout << "NO";
return 0;
}
| /*
* author :Sadik Hassan
*
*/
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define nl "\n"
#define pb push_back
#define fi first
#define se second
#define PI (acos(-1.0))
#define _SAD() \
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0), \
cout << fixed << setprecision(20);
#define rep(i, n) for (int i = 0; i < n; i++)
#define SZ(s) s.size()
#define SRT(x, y) sort(x, x + y)
#define REV(a, b) reverse(a, a + b)
#define VSRT(x) sort(x.begin(), x.end())
#define VREV(x) reverse(x.begin(), x.end())
#define w(t) \
int t; \
cin >> t; \
while (t--)
#define TSFL(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define TSFH(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;
/*---------------------------------------------------------------------*/
const int N = 2e5 + 10;
const int INF = (int)1e9 + 5;
int main() {
_SAD()
int a, b, m, n, t;
cin >> a >> m >> b >> n >> t;
a = abs(a - b);
m -= n;
if (m <= 0)
cout << "NO";
else if ((a + m - 1) / m <= t)
cout << "YES";
else
cout << "NO";
return 0;
}
| replace | 42 | 43 | 42 | 45 | 0 | |
p02646 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
bool solve() {
int a, v, b, w, t;
cin >> a >> v >> b >> w >> t;
int dist = abs(b - a);
int dv = (v - w);
if (dv < 0)
return false;
int steps = dist / dv;
if (dist % dv)
++steps;
if (steps <= t)
return true;
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout << fixed;
if (solve()) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
bool solve() {
int a, v, b, w, t;
cin >> a >> v >> b >> w >> t;
int dist = abs(b - a);
int dv = (v - w);
if (dv <= 0)
return false;
int steps = dist / dv;
if (dist % dv)
++steps;
if (steps <= t)
return true;
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout << fixed;
if (solve()) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p02646 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
#define pri(str) cout << str << endl
using ll = long long;
using P = pair<int, int>;
const ll MX = 1e18;
const long double PI = acos(-1);
int main() {
ll a, b, v, w, t;
cin >> a >> v >> b >> w >> t;
ll ans = (a - b) / (w - v);
if (w - v != 0 && ans <= t && ans > 0 && (a - b) % (w - v) == 0)
pri("YES");
else
pri("NO");
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
#define pri(str) cout << str << endl
using ll = long long;
using P = pair<int, int>;
const ll MX = 1e18;
const long double PI = acos(-1);
int main() {
ll a, b, v, w, t;
cin >> a >> v >> b >> w >> t;
if (abs(a - b) <= t * (v - w))
pri("YES");
else
pri("NO");
return 0;
}
| replace | 13 | 15 | 13 | 14 | 0 | |
p02646 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
ll a, b;
ll v, w;
cin >> a >> v;
cin >> b >> w;
ll t;
cin >> t;
puts((abs(a - b) / (v - w)) <= t ? "YES" : "NO");
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
ll a, b;
ll v, w;
cin >> a >> v;
cin >> b >> w;
ll t;
cin >> t;
ll t1 = abs(a - b);
ll t2 = (v - w) * t;
if (t1 <= t2) {
cout << "YES";
} else {
cout << "NO";
}
return 0;
} | replace | 11 | 12 | 11 | 18 | 0 | |
p02646 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e7 + 5;
const int maxm = 5e5 + 5;
const ll inf = 2147483647;
int main() {
ll a, v, b, w, t;
int f = 0;
cin >> a >> v >> b >> w >> t;
ll d = abs(a - b);
ll k = abs(v - w);
if (d / k <= t) {
cout << "YES";
return 0;
}
cout << "NO";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e7 + 5;
const int maxm = 5e5 + 5;
const ll inf = 2147483647;
int main() {
ll a, v, b, w, t;
int f = 0;
cin >> a >> v >> b >> w >> t;
if (abs(a - b) <= (v - w) * t) {
cout << "YES";
return 0;
}
cout << "NO";
return 0;
}
| replace | 11 | 14 | 11 | 13 | 0 | |
p02646 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define forr(i, n) for (int i = n; i >= 0; i--)
#define all(x) x.begin(), x.end()
const int MAXN = 1e5 + 5;
void fio() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main() {
fio();
vector<pair<LL, LL>> v(2);
forn(i, 2) cin >> v[i].fi >> v[i].se;
LL t;
cin >> t;
sort(all(v));
LL vi = -v[1].se + v[0].se;
if (v[1].fi == v[0].fi) {
cout << "YES" << endl;
return 0;
}
if (vi < 0 && v[1].fi != v[0].fi) {
cout << "NO" << endl;
return 0;
}
if (t >= ((v[1].fi - v[0].fi) / (vi)) && vi >= ((v[1].fi - v[0].fi) / (t))) {
cout << "YES" << endl;
} else
cout << "NO" << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define forr(i, n) for (int i = n; i >= 0; i--)
#define all(x) x.begin(), x.end()
const int MAXN = 1e5 + 5;
void fio() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main() {
fio();
vector<pair<LL, LL>> v(2);
forn(i, 2) cin >> v[i].fi >> v[i].se;
LL t;
cin >> t;
LL vi = v[0].se - v[1].se;
if (vi * t >= (abs(v[0].fi - v[1].fi))) {
cout << "YES" << endl;
} else
cout << "NO" << endl;
return 0;
}
| replace | 24 | 35 | 24 | 26 | 0 | |
p02646 | C++ | Runtime Error | #pragma GCC optimize("-Ofast", "-funroll-all-loops")
#include <bits/stdc++.h>
// #define int long long
using namespace std;
int a, b, v, w, t;
signed main() {
cin >> a >> v >> b >> w >> t;
if (w >= v)
puts("NO");
else if (abs(a - b) <= 1LL * t * (v - w))
return puts("YES");
else
puts("NO");
return 0;
}
| #pragma GCC optimize("-Ofast", "-funroll-all-loops")
#include <bits/stdc++.h>
// #define int long long
using namespace std;
int a, b, v, w, t;
signed main() {
cin >> a >> v >> b >> w >> t;
if (w >= v)
puts("NO");
else if (abs(a - b) <= 1LL * t * (v - w))
puts("YES");
else
puts("NO");
return 0;
}
| replace | 10 | 11 | 10 | 11 | 4 | |
p02646 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
int main() {
ll a, v, b, w, t;
cin >> a >> v >> b >> w >> t;
ll T = (b - a + v - w - 1) / (v - w);
if (T > 0 && T <= t)
cout << "YES" << endl;
else
cout << "NO" << 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>;
const int MOD = 1000000007;
int main() {
ll a, v, b, w, t;
cin >> a >> v >> b >> w >> t;
ll dis;
if (a < b)
dis = b - a + (w - v) * t;
else
dis = a - b + (w - v) * t;
if (dis <= 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
| replace | 10 | 12 | 10 | 16 | 0 | |
p02646 | C++ | Runtime Error |
/**
* Coded by : lucky_21
* --------Lokesh Singh
**/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class T>
using oset =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define fix fixed << setprecision(10)
#define rep(i, a, b) for (int i = int(a); i <= int(b); i++)
#define repb(i, b, a) for (int i = int(b); i >= int(a); i--)
#define FastIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
typedef double db;
typedef long long ll;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
signed main() {
FastIO;
ll a, b, c, d, t;
cin >> a >> b >> c >> d >> t;
if ((c - a) <= (b - d) * t and (c - a) % (b - d) == 0)
return cout << "YES", 0;
cout << "NO";
return 0;
}
|
/**
* Coded by : lucky_21
* --------Lokesh Singh
**/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <class T>
using oset =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define F first
#define S second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define fix fixed << setprecision(10)
#define rep(i, a, b) for (int i = int(a); i <= int(b); i++)
#define repb(i, b, a) for (int i = int(b); i >= int(a); i--)
#define FastIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
typedef double db;
typedef long long ll;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
signed main() {
FastIO;
ll a, b, c, d, t;
cin >> a >> b >> c >> d >> t;
if (a < c) {
return cout << ((c - a) <= (b - d) * t ? "YES" : "NO"), 0;
}
cout << ((a - c) <= (b - d) * t ? "YES" : "NO");
return 0;
}
| replace | 38 | 41 | 38 | 42 | 0 | |
p02646 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
long long a, v, b, w, t;
cin >> a >> v >> b >> w >> t;
long long x = a - b;
if (x < 0) {
x *= -1;
}
if (((x / (v - w)) <= t) && (x / (v - w)) > 0)
cout << "YES";
else {
cout << "NO";
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long a, v, b, w, t;
cin >> a >> v >> b >> w >> t;
long long x = a - b;
if (x < 0) {
x *= -1;
}
if ((x <= t * (v - w)) && (v - w) > 0)
cout << "YES";
else {
cout << "NO";
}
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p02646 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll a, v;
cin >> a >> v;
ll b, w;
cin >> b >> w;
ll t;
cin >> t;
if (abs(a - b) / (v - w) <= t)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll a, v;
cin >> a >> v;
ll b, w;
cin >> b >> w;
ll t;
cin >> t;
if (abs(a - b) <= (v - w) * t)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
| replace | 13 | 14 | 13 | 14 | 0 | |
p02646 | C++ | Runtime Error | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define inf 0x3f3f3f3f
const int maxn = 3000050;
using namespace std;
typedef long long ll;
int main() {
ll a, b, v, w, t;
cin >> a >> v >> b >> w >> t;
if (a == b) {
cout << "Yes";
return 0;
}
if ((v <= w && a < b) || abs(a - b) % abs(v - w)) {
cout << "No";
} else {
if (t >= abs(a - b) / abs(v - w)) {
cout << "Yes";
} else
cout << "No";
}
return 0;
} | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#define inf 0x3f3f3f3f
const int maxn = 3000050;
using namespace std;
typedef long long ll;
int main() {
ll A, V;
cin >> A >> V;
ll B, W;
cin >> B >> W;
ll T;
cin >> T;
ll D = abs(A - B);
ll D2 = (V - W) * T;
puts(D <= D2 ? "YES" : "NO");
} | replace | 11 | 26 | 11 | 20 | 0 | |
p02646 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
using namespace std;
int main() {
int A, V, B, W, T;
scanf("%lld%lld%lld%lld%lld", &A, &V, &B, &W, &T);
if (abs(A - B) > (V - W) * T) {
printf("NO\n");
} else
printf("YES\n");
} | #include <algorithm>
#include <cstdio>
using namespace std;
int main() {
long long A, V, B, W, T;
scanf("%lld%lld%lld%lld%lld", &A, &V, &B, &W, &T);
if (abs(A - B) > (V - W) * T) {
printf("NO\n");
} else
printf("YES\n");
} | replace | 4 | 5 | 4 | 5 | -6 | *** stack smashing detected ***: terminated
|
p02646 | Python | Time Limit Exceeded | a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
ans = "NO"
for i in range(t):
if a < b:
a += v
b += w
else:
a -= v
b -= w
if a == b:
ans = "YES"
break
print(ans)
| a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if abs(a - b) <= (v - w) * t:
print("YES")
else:
print("NO")
| replace | 3 | 15 | 3 | 7 | TLE | |
p02647 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
rep(i, n) cin >> a[i];
rep(j, k) {
vector<int> b(n + 1);
rep(i, n) {
int l, r;
l = max(0, i - a[i]);
r = min(n + 1, i + a[i]);
++b[l];
--b[r + 1];
}
rep(i, n + 1) b[i + 1] += b[i];
b.pop_back();
if (a == b)
break;
else
a = b;
}
rep(i, n) {
cout << a[i];
if (i != n - 1)
cout << " ";
else
cout << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
rep(i, n) cin >> a[i];
rep(j, k) {
vector<int> b(n + 1);
rep(i, n) {
int l, r;
l = max(0, i - a[i]);
r = min(n, i + a[i]);
++b[l];
--b[r + 1];
}
rep(i, n + 1) b[i + 1] += b[i];
b.pop_back();
if (a == b)
break;
else
a = b;
}
rep(i, n) {
cout << a[i];
if (i != n - 1)
cout << " ";
else
cout << endl;
}
return 0;
} | replace | 17 | 18 | 17 | 18 | 0 | |
p02647 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define rint register int
#define re register
#define pb(x) push_back(x);
#define ce(x) cout << x << '\n';
using db = long double;
using pll = pair<ll, ll>;
#define scan(a, n) \
for (int i = 0; i < n; i++) \
cin >> a[i];
#define rep(i, x, n, inc) for (i = x; i < n; i += inc)
#define repr(i, x, n, inc) for (i = x; i > n; i += inc)
#define all(a) (a).begin(), (a).end()
#define unique_sort(x) \
sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))
#define mp(a, b) make_pair(a, b)
#define ff first
#define ss second
#define hell 1000000007
#define infl LLONG_MAX
#define Foxen(i, s) for (i = s.begin(); i != s.end(); i++)
#define Fill(s, v) memset(s, v, sizeof(s))
#define cout_p(x, p) \
cout << fixed << setprecision((p)) << x << endl // print with precision
#define tc(tt) \
ll tt; \
cin >> tt; \
for (ll _tt = 0; _tt < tt; _tt++) // testcase
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll t, i, x, j, y, z, k, n;
cin >> n >> k;
ll a[n], b[n];
scan(a, n);
rep(j, 0, k, 1) {
memset(b, 0, sizeof(b));
rep(i, 0, n, 1) {
ll mi = max(0LL, i - a[i]), mx = min(n - 1, i + a[i]);
b[mi]++;
b[mx + 1]--;
}
bool br = true;
rep(i, 1, n, 1) {
b[i] += b[i - 1];
br = br && (a[i] == b[i]);
}
rep(i, 0, n, 1) {
if (a[i] != b[i])
br = false;
a[i] = b[i];
}
if (br)
break;
}
rep(i, 0, n, 1) cout << a[i] << " ";
}
| #include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define rint register int
#define re register
#define pb(x) push_back(x);
#define ce(x) cout << x << '\n';
using db = long double;
using pll = pair<ll, ll>;
#define scan(a, n) \
for (int i = 0; i < n; i++) \
cin >> a[i];
#define rep(i, x, n, inc) for (i = x; i < n; i += inc)
#define repr(i, x, n, inc) for (i = x; i > n; i += inc)
#define all(a) (a).begin(), (a).end()
#define unique_sort(x) \
sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))
#define mp(a, b) make_pair(a, b)
#define ff first
#define ss second
#define hell 1000000007
#define infl LLONG_MAX
#define Foxen(i, s) for (i = s.begin(); i != s.end(); i++)
#define Fill(s, v) memset(s, v, sizeof(s))
#define cout_p(x, p) \
cout << fixed << setprecision((p)) << x << endl // print with precision
#define tc(tt) \
ll tt; \
cin >> tt; \
for (ll _tt = 0; _tt < tt; _tt++) // testcase
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll t, i, x, j, y, z, k, n;
cin >> n >> k;
ll a[n], b[n + 1];
scan(a, n);
rep(j, 0, k, 1) {
memset(b, 0, sizeof(b));
rep(i, 0, n, 1) {
ll mi = max(0LL, i - a[i]), mx = min(n - 1, i + a[i]);
b[mi]++;
b[mx + 1]--;
}
bool br = true;
rep(i, 1, n, 1) {
b[i] += b[i - 1];
br = br && (a[i] == b[i]);
}
rep(i, 0, n, 1) {
if (a[i] != b[i])
br = false;
a[i] = b[i];
}
if (br)
break;
}
rep(i, 0, n, 1) cout << a[i] << " ";
}
| replace | 51 | 52 | 51 | 52 | TLE | |
p02647 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define rint register int
#define re register
#define pb(x) push_back(x);
#define ce(x) cout << x << '\n';
using db = long double;
using pll = pair<ll, ll>;
#define scan(a, n) \
for (int i = 0; i < n; i++) \
cin >> a[i];
#define rep(i, x, n, inc) for (i = x; i < n; i += inc)
#define repr(i, x, n, inc) for (i = x; i > n; i += inc)
#define all(a) (a).begin(), (a).end()
#define unique_sort(x) \
sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))
#define mp(a, b) make_pair(a, b)
#define ff first
#define ss second
#define hell 1000000007
#define infl LLONG_MAX
#define Foxen(i, s) for (i = s.begin(); i != s.end(); i++)
#define Fill(s, v) memset(s, v, sizeof(s))
#define cout_p(x, p) \
cout << fixed << setprecision((p)) << x << endl // print with precision
#define tc(tt) \
ll tt; \
cin >> tt; \
for (ll _tt = 0; _tt < tt; _tt++) // testcase
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll t, i, x, j, y, z, k, n;
cin >> n >> k;
ll a[n], b[n];
scan(a, n);
rep(j, 0, k, 1) {
memset(b, 0, sizeof(b));
rep(i, 0, n, 1) {
ll mi = max(0LL, i - a[i]), mx = min(n - 1, i + a[i]);
b[mi]++;
b[mx + 1]--;
}
bool br = a[0] == b[0];
rep(i, 1, n, 1) {
b[i] += b[i - 1];
br = br && (a[i] == b[i]);
}
if (br)
break;
rep(i, 0, n, 1) a[i] = b[i];
}
rep(i, 0, n, 1) cout << a[i] << " ";
}
| #include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define rint register int
#define re register
#define pb(x) push_back(x);
#define ce(x) cout << x << '\n';
using db = long double;
using pll = pair<ll, ll>;
#define scan(a, n) \
for (int i = 0; i < n; i++) \
cin >> a[i];
#define rep(i, x, n, inc) for (i = x; i < n; i += inc)
#define repr(i, x, n, inc) for (i = x; i > n; i += inc)
#define all(a) (a).begin(), (a).end()
#define unique_sort(x) \
sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))
#define mp(a, b) make_pair(a, b)
#define ff first
#define ss second
#define hell 1000000007
#define infl LLONG_MAX
#define Foxen(i, s) for (i = s.begin(); i != s.end(); i++)
#define Fill(s, v) memset(s, v, sizeof(s))
#define cout_p(x, p) \
cout << fixed << setprecision((p)) << x << endl // print with precision
#define tc(tt) \
ll tt; \
cin >> tt; \
for (ll _tt = 0; _tt < tt; _tt++) // testcase
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll t, i, x, j, y, z, k, n;
cin >> n >> k;
ll a[n], b[n];
scan(a, n);
rep(j, 0, min(51LL, k), 1) {
memset(b, 0, sizeof(b));
rep(i, 0, n, 1) {
ll mi = max(0LL, i - a[i]), mx = min(n - 1, i + a[i]);
b[mi]++;
b[mx + 1]--;
}
bool br = a[0] == b[0];
rep(i, 1, n, 1) {
b[i] += b[i - 1];
br = br && (a[i] == b[i]);
}
if (br)
break;
rep(i, 0, n, 1) a[i] = b[i];
}
rep(i, 0, n, 1) cout << a[i] << " ";
}
| replace | 54 | 55 | 54 | 55 | TLE | |
p02647 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < min(k, 50); i++) {
vector<int> imos(n); // I'll begin the imos method
for (int j = 0; j < n; j++) {
int l = max(0, j - a[j]);
int r = min(n - 1, j + a[j]);
imos[l]++;
// if(r+1 < n){
imos[r + 1]--;
//}
}
for (int k = 0; k < n; k++) {
if (k > 0) {
imos[k] += imos[k - 1];
}
}
/*for(int l = 0; l < n; l++){
a[l] = imos[l];
}*/
a = imos;
}
for (int i = 0; i < n; i++) {
cout << a[i] << " ";
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < min(k, 50); i++) {
vector<int> imos(n); // I'll begin the imos method
for (int j = 0; j < n; j++) {
int l = max(0, j - a[j]);
int r = min(n - 1, j + a[j]);
imos[l]++;
if (r + 1 <= n - 1) {
imos[r + 1]--;
}
}
for (int k = 0; k < n; k++) {
if (k > 0) {
imos[k] += imos[k - 1];
}
}
/*for(int l = 0; l < n; l++){
a[l] = imos[l];
}*/
a = imos;
}
for (int i = 0; i < n; i++) {
cout << a[i] << " ";
}
} | replace | 17 | 20 | 17 | 20 | 0 | |
p02647 | C++ | Runtime Error | #include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int INFint = 1e9 + 1;
const ll INFll = (ll)1e18 + 1;
ll MOD = 1e9 + 7;
int main() {
int N, K;
cin >> N >> K;
vector<int> A(N);
for (int i(0); i < N; i++) {
cin >> A[i];
}
vector<int> now = A;
for (int i(0); i < K; i++) {
vector<int> B(N);
for (int j(0); j < N; j++) {
B[max(0, j - A[j])]++;
if (j + A[j] < N) {
B[j + A[j] + 1]--;
}
}
for (int j(1); j < N; j++) {
B[j] += B[j - 1];
}
A = B;
bool flag = true;
for (int j(0); j < N; j++) {
if (A[j] != N)
flag = false;
}
if (flag)
break;
}
for (int i(0); i < N; i++) {
cout << A[i] << " ";
}
cout << endl;
return 0;
}
| #include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int INFint = 1e9 + 1;
const ll INFll = (ll)1e18 + 1;
ll MOD = 1e9 + 7;
int main() {
int N, K;
cin >> N >> K;
vector<int> A(N);
for (int i(0); i < N; i++) {
cin >> A[i];
}
vector<int> now = A;
for (int i(0); i < K; i++) {
vector<int> B(N);
for (int j(0); j < N; j++) {
B[max(0, j - A[j])]++;
if (j + A[j] + 1 < N) {
B[j + A[j] + 1]--;
}
}
for (int j(1); j < N; j++) {
B[j] += B[j - 1];
}
A = B;
bool flag = true;
for (int j(0); j < N; j++) {
if (A[j] != N)
flag = false;
}
if (flag)
break;
}
for (int i(0); i < N; i++) {
cout << A[i] << " ";
}
cout << endl;
return 0;
}
| replace | 20 | 21 | 20 | 21 | 0 | |
p02647 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
// #define int long long
typedef long long ll;
// const int INF = 2e9;
// const ll INF = 9e18;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N, K;
cin >> N >> K;
vector<int> A(N);
for (int i = 0; i < N; i++)
cin >> A[i];
vector<int> state(N + 1);
for (int k = 0; k < K; k++) {
for (int i = 0; i < N + 1; i++) {
state[i] = 0;
}
for (int i = 0; i < N; i++) {
if (i - A[i] < 0)
state[0]++;
else
state[i - A[i]]++;
if (i + 1 + A[i] > N)
state[N]--;
else
state[i + 1 + A[i]]--;
}
for (int i = 0; i < N; i++) {
state[i + 1] += state[i];
}
for (int i = 0; i < N; i++) {
A[i] = state[i];
}
}
for (int i = 0; i < N; i++) {
cout << A[i];
if (i == N - 1)
cout << "\n";
else
cout << " ";
}
} | #include <bits/stdc++.h>
using namespace std;
// #define int long long
typedef long long ll;
// const int INF = 2e9;
// const ll INF = 9e18;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N, K;
cin >> N >> K;
vector<int> A(N);
for (int i = 0; i < N; i++)
cin >> A[i];
vector<int> state(N + 1);
for (int k = 0; k < min(K, 50); k++) {
for (int i = 0; i < N + 1; i++) {
state[i] = 0;
}
for (int i = 0; i < N; i++) {
if (i - A[i] < 0)
state[0]++;
else
state[i - A[i]]++;
if (i + 1 + A[i] > N)
state[N]--;
else
state[i + 1 + A[i]]--;
}
for (int i = 0; i < N; i++) {
state[i + 1] += state[i];
}
for (int i = 0; i < N; i++) {
A[i] = state[i];
}
}
for (int i = 0; i < N; i++) {
cout << A[i];
if (i == N - 1)
cout << "\n";
else
cout << " ";
}
} | replace | 17 | 18 | 17 | 18 | TLE | |
p02647 | C++ | Runtime Error | #include <iostream>
#define DIM 100005
using namespace std;
int n, i, k, ok;
int a[DIM], b[DIM];
int main() {
cin >> n >> k;
for (i = 1; i <= n; i++) {
cin >> a[i];
}
for (; k; k--) {
for (i = 1; i <= n; i++) {
b[max(1, i - a[i])]++;
b[min(n + 1, i + a[i] + 1)]--;
}
for (i = 1; i <= n; i++) {
b[i] += b[i - 1];
}
ok = 0;
for (i = 1; i <= n; i++) {
a[i] = b[i];
b[i] = 0;
if (a[i] != n) {
ok = 1;
}
}
if (ok == 0) {
break;
}
}
for (i = 1; i <= n; i++) {
cout << a[i] << " ";
}
}
| #include <iostream>
#define DIM 200005
using namespace std;
int n, i, k, ok;
int a[DIM], b[DIM];
int main() {
cin >> n >> k;
for (i = 1; i <= n; i++) {
cin >> a[i];
}
for (; k; k--) {
for (i = 1; i <= n; i++) {
b[max(1, i - a[i])]++;
b[min(n + 1, i + a[i] + 1)]--;
}
for (i = 1; i <= n; i++) {
b[i] += b[i - 1];
}
ok = 0;
for (i = 1; i <= n; i++) {
a[i] = b[i];
b[i] = 0;
if (a[i] != n) {
ok = 1;
}
}
if (ok == 0) {
break;
}
}
for (i = 1; i <= n; i++) {
cout << a[i] << " ";
}
}
| replace | 1 | 2 | 1 | 2 | 0 | |
p02647 | C++ | Time Limit Exceeded | // #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 ll INF = 1e18;
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, -1, 0, 0, 1, 1, -1, -1};
vector<ll> dy = {0, 0, 1, -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());
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
ll res = 0, buf = 0;
bool judge = true;
ll n, k;
cin >> n >> k;
vector<ll> a(n);
rep(i, 0, n) cin >> a[i];
rep(i, 0, k) {
vector<ll> b(n);
rep(j, 0, n) { rep(o, max(j - a[j], 0LL), min(j + a[j] + 1, n)) b[o]++; }
if (a == b) {
// cout<<i<<endl;
break;
}
a = b;
}
debug(a, n);
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 ll INF = 1e18;
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, -1, 0, 0, 1, 1, -1, -1};
vector<ll> dy = {0, 0, 1, -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());
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
ll res = 0, buf = 0;
bool judge = true;
ll n, k;
cin >> n >> k;
vector<ll> a(n);
rep(i, 0, n) cin >> a[i];
rep(i, 0, k) {
vector<ll> b(n + 1);
rep(j, 0, n) {
b[max(j - a[j], 0LL)]++;
b[min(j + a[j] + 1, n)]--;
}
rep(i, 0, n) b[i + 1] += b[i];
// debug(b,n+1);
b.resize(n);
if (a == b) {
// cout<<i<<endl;
break;
}
a = b;
}
debug(a, n);
return 0;
} | replace | 123 | 125 | 123 | 131 | TLE | |
p02647 | C++ | Time Limit Exceeded | #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
namespace utils {
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
template <class T, class Compare>
using p_queue = priority_queue<T, vector<T>, Compare>;
template <class T> using min_queue = p_queue<T, greater<T>>;
template <class T> using max_queue = p_queue<T, less<T>>;
template <class T> inline bool UPMIN(T &X, const T &A) {
if (X > A) {
X = A;
return true;
}
return false;
}
template <class T> inline bool UPMAX(T &X, const T &A) {
if (X < A) {
X = A;
return true;
}
return false;
}
template <class T> vector<T> VEC(int n, T t) { return vector<T>(n, t); }
template <class... Ts> auto VEC(int n, Ts... ts) {
return vector<decltype(VEC(ts...))>(n, VEC(ts...));
}
template <class S, class T> istream &operator>>(istream &is, tuple<S, T> &t) {
return is >> get<0>(t) >> get<1>(t);
}
template <class S, class T, class U>
istream &operator>>(istream &is, tuple<S, T, U> &t) {
return is >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template <class S, class T>
ostream &operator<<(ostream &os, const tuple<S, T> &t) {
return os << get<0>(t) << ' ' << get<1>(t);
}
template <class S, class T, class U>
ostream &operator<<(ostream &os, const tuple<S, T, U> &t) {
return os << get<0>(t) << ' ' << get<1>(t) << ' ' << get<2>(t);
}
template <class T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &&x : v) {
is >> x;
}
return is;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
auto p = v.begin();
assert(p != v.end());
os << *p++;
while (p != v.end()) {
os << ' ' << *p++;
}
return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<vector<T>> &v) {
auto p = v.begin();
assert(p != v.end());
os << *p++;
while (p != v.end()) {
os << '\n' << *p++;
}
return os;
}
template <class... Ts>
ostream &operator<<(ostream &os, const vector<tuple<Ts...>> &v) {
auto p = v.begin();
assert(p != v.end());
os << *p++;
while (p != v.end()) {
os << '\n' << *p++;
}
return os;
}
constexpr long long INFLL = 1'000'000'000'000'000'000ll;
constexpr int INF = 1'000'000'000;
constexpr double PI = 3.14'159'265'358'973;
constexpr double EPS = 1e-10;
} // namespace utils
using namespace utils;
template <class Monoid> class SegmentTree {
using Func = std::function<Monoid(Monoid, Monoid)>;
int N;
std::vector<Monoid> segment, lazy;
const Func op;
const Monoid id;
public:
SegmentTree(int n) : op([](ll a, ll b) { return a + b; }), id(0) {
N = 1;
while (N < n)
N *= 2;
segment.assign(2 * N, id);
lazy.assign(2 * N, 0);
}
void set(int k, const Monoid &a) { segment[k + N] = a; }
void build() {
for (int k = N - 1; k > 0; --k) {
segment[k] = op(segment[2 * k], segment[2 * k + 1]);
} // end k
}
void eval(int k, int l, int r) {
if (lazy[k] != 0) {
segment[k] += lazy[k];
// 最下段かどうかのチェックをしよう
// 子ノードは親ノードの 1/2 の範囲であるため、
// 伝播させるときは半分にする
if (r - l > 1) {
lazy[2 * k + 1] += lazy[k] / 2;
lazy[2 * k + 2] += lazy[k] / 2;
}
// 伝播が終わったので、自ノードの遅延配列を空にする
lazy[k] = 0;
}
}
void update(int k, const Monoid &a) {
k += N;
segment[k] = a;
while (k /= 2) {
segment[k] = op(segment[k * 2], segment[k * 2 + 1]);
}
}
void update_range(int a, int b, Monoid x, int k = 0, int l = 0, int r = -1) {
if (r < 0)
r = N;
eval(k, l, r);
// 範囲外なら何もしない
if (b <= l || r <= a)
return;
// 完全に被覆しているならば、遅延配列に値を入れた後に評価
if (a <= l && r <= b) {
lazy[k] += (r - l) * x;
eval(k, l, r);
}
// そうでないならば、子ノードの値を再帰的に計算して、
// 計算済みの値をもらってくる
else {
update_range(a, b, x, 2 * k + 1, l, (l + r) / 2);
update_range(a, b, x, 2 * k + 2, (l + r) / 2, r);
segment[k] = segment[2 * k + 1] + segment[2 * k + 2];
}
}
// -> op [a,b)
Monoid query(unsigned a, unsigned b) {
Monoid L = id, R = id;
for (a += N, b += N; a < b; a >>= 1u, b >>= 1u) {
if (a & 1u)
L = op(L, segment[a++]);
if (b & 1u)
R = op(segment[--b], R);
} // end i
return op(L, R);
}
Monoid operator[](const int &k) const { return segment[k + N]; }
};
class solver {
istream &is;
ostream &os;
public:
solver(istream &I, ostream &O) : is(I), os(O) {}
ll N, K;
vector<ll> A;
bool input() {
is >> N >> K;
A.resize(N);
is >> A;
return !!is;
}
void run();
};
int main(int argc, char *argv[]) {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << setprecision(16) << scientific;
#ifdef XELMH
string test_cases = "test_C.txt";
cerr << test_cases << " -->" << endl;
auto fs = fstream(test_cases, fstream::in);
int loop = 0;
while (fs) {
loop++;
cout << '#' << loop << "#------\n";
solver(fs, cout).run();
}
if (loop <= 1) {
cout << "===" << endl;
while (cin)
solver(cin, cout).run();
}
#else
solver(cin, cout).run();
#endif
return 0;
}
void solver::run() {
if (!input())
return;
while (K > 0) {
if (*min_element(ALL(A)) == N)
break;
// cout << A << endl;
auto sum = VEC(N + 1, 0ll);
for (int i = 0; i < N; ++i) {
int r = min(N, A[i] + i + 1);
int l = max(0ll, i - A[i]);
sum[l]++;
sum[r]--;
} // end i
for (int i = 1; i < sum.size(); ++i) {
sum[i] += sum[i - 1];
} // end i
A = move(sum);
K--;
}
for (int i = 0; i < N; ++i) {
cout << A[i] << ' ';
} // end i
}
| #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
namespace utils {
#define ALL(x) begin(x), end(x)
#define RALL(x) rbegin(x), rend(x)
template <class T, class Compare>
using p_queue = priority_queue<T, vector<T>, Compare>;
template <class T> using min_queue = p_queue<T, greater<T>>;
template <class T> using max_queue = p_queue<T, less<T>>;
template <class T> inline bool UPMIN(T &X, const T &A) {
if (X > A) {
X = A;
return true;
}
return false;
}
template <class T> inline bool UPMAX(T &X, const T &A) {
if (X < A) {
X = A;
return true;
}
return false;
}
template <class T> vector<T> VEC(int n, T t) { return vector<T>(n, t); }
template <class... Ts> auto VEC(int n, Ts... ts) {
return vector<decltype(VEC(ts...))>(n, VEC(ts...));
}
template <class S, class T> istream &operator>>(istream &is, tuple<S, T> &t) {
return is >> get<0>(t) >> get<1>(t);
}
template <class S, class T, class U>
istream &operator>>(istream &is, tuple<S, T, U> &t) {
return is >> get<0>(t) >> get<1>(t) >> get<2>(t);
}
template <class S, class T>
ostream &operator<<(ostream &os, const tuple<S, T> &t) {
return os << get<0>(t) << ' ' << get<1>(t);
}
template <class S, class T, class U>
ostream &operator<<(ostream &os, const tuple<S, T, U> &t) {
return os << get<0>(t) << ' ' << get<1>(t) << ' ' << get<2>(t);
}
template <class T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &&x : v) {
is >> x;
}
return is;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
auto p = v.begin();
assert(p != v.end());
os << *p++;
while (p != v.end()) {
os << ' ' << *p++;
}
return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<vector<T>> &v) {
auto p = v.begin();
assert(p != v.end());
os << *p++;
while (p != v.end()) {
os << '\n' << *p++;
}
return os;
}
template <class... Ts>
ostream &operator<<(ostream &os, const vector<tuple<Ts...>> &v) {
auto p = v.begin();
assert(p != v.end());
os << *p++;
while (p != v.end()) {
os << '\n' << *p++;
}
return os;
}
constexpr long long INFLL = 1'000'000'000'000'000'000ll;
constexpr int INF = 1'000'000'000;
constexpr double PI = 3.14'159'265'358'973;
constexpr double EPS = 1e-10;
} // namespace utils
using namespace utils;
template <class Monoid> class SegmentTree {
using Func = std::function<Monoid(Monoid, Monoid)>;
int N;
std::vector<Monoid> segment, lazy;
const Func op;
const Monoid id;
public:
SegmentTree(int n) : op([](ll a, ll b) { return a + b; }), id(0) {
N = 1;
while (N < n)
N *= 2;
segment.assign(2 * N, id);
lazy.assign(2 * N, 0);
}
void set(int k, const Monoid &a) { segment[k + N] = a; }
void build() {
for (int k = N - 1; k > 0; --k) {
segment[k] = op(segment[2 * k], segment[2 * k + 1]);
} // end k
}
void eval(int k, int l, int r) {
if (lazy[k] != 0) {
segment[k] += lazy[k];
// 最下段かどうかのチェックをしよう
// 子ノードは親ノードの 1/2 の範囲であるため、
// 伝播させるときは半分にする
if (r - l > 1) {
lazy[2 * k + 1] += lazy[k] / 2;
lazy[2 * k + 2] += lazy[k] / 2;
}
// 伝播が終わったので、自ノードの遅延配列を空にする
lazy[k] = 0;
}
}
void update(int k, const Monoid &a) {
k += N;
segment[k] = a;
while (k /= 2) {
segment[k] = op(segment[k * 2], segment[k * 2 + 1]);
}
}
void update_range(int a, int b, Monoid x, int k = 0, int l = 0, int r = -1) {
if (r < 0)
r = N;
eval(k, l, r);
// 範囲外なら何もしない
if (b <= l || r <= a)
return;
// 完全に被覆しているならば、遅延配列に値を入れた後に評価
if (a <= l && r <= b) {
lazy[k] += (r - l) * x;
eval(k, l, r);
}
// そうでないならば、子ノードの値を再帰的に計算して、
// 計算済みの値をもらってくる
else {
update_range(a, b, x, 2 * k + 1, l, (l + r) / 2);
update_range(a, b, x, 2 * k + 2, (l + r) / 2, r);
segment[k] = segment[2 * k + 1] + segment[2 * k + 2];
}
}
// -> op [a,b)
Monoid query(unsigned a, unsigned b) {
Monoid L = id, R = id;
for (a += N, b += N; a < b; a >>= 1u, b >>= 1u) {
if (a & 1u)
L = op(L, segment[a++]);
if (b & 1u)
R = op(segment[--b], R);
} // end i
return op(L, R);
}
Monoid operator[](const int &k) const { return segment[k + N]; }
};
class solver {
istream &is;
ostream &os;
public:
solver(istream &I, ostream &O) : is(I), os(O) {}
ll N, K;
vector<ll> A;
bool input() {
is >> N >> K;
A.resize(N);
is >> A;
return !!is;
}
void run();
};
int main(int argc, char *argv[]) {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << setprecision(16) << scientific;
#ifdef XELMH
string test_cases = "test_C.txt";
cerr << test_cases << " -->" << endl;
auto fs = fstream(test_cases, fstream::in);
int loop = 0;
while (fs) {
loop++;
cout << '#' << loop << "#------\n";
solver(fs, cout).run();
}
if (loop <= 1) {
cout << "===" << endl;
while (cin)
solver(cin, cout).run();
}
#else
solver(cin, cout).run();
#endif
return 0;
}
void solver::run() {
if (!input())
return;
if (K > 100)
K = 100;
while (K > 0) {
if (*min_element(ALL(A)) == N)
break;
// cout << A << endl;
auto sum = VEC(N + 1, 0ll);
for (int i = 0; i < N; ++i) {
int r = min(N, A[i] + i + 1);
int l = max(0ll, i - A[i]);
sum[l]++;
sum[r]--;
} // end i
for (int i = 1; i < sum.size(); ++i) {
sum[i] += sum[i - 1];
} // end i
A = move(sum);
K--;
}
for (int i = 0; i < N; ++i) {
cout << A[i] << ' ';
} // end i
}
| insert | 261 | 261 | 261 | 263 | TLE | |
p02647 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define VIEW(x) \
do { \
cerr << #x << ": "; \
for (auto i : x) \
cerr << i << " "; \
cerr << endl; \
} while (0)
#define ALL(x) (x).begin(), (x).end()
template <class T> bool umax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool umin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val) {
fill((T *)array, (T *)(array + N), val);
}
template <typename T> void FILL(vector<T> &v, const T &x) {
fill(v.begin(), v.end(), x);
}
template <typename T> void FILL(vector<vector<T>> &v, const T &x) {
for (auto &i : v)
fill(i.begin(), i.end(), x);
}
vector<int> Imos(int mx, vector<pair<int, int>> area) {
/* O(mx + area.size()) */
vector<int> d(mx + 2), sum(mx + 1);
for (auto a : area) {
assert(a.first <= a.second);
d[a.first]++, d[a.second + 1]--; /* inclusive (a.first, a.second) */
}
sum[0] = d[0];
for (int i = 1; i <= mx; ++i)
sum[i] = sum[i - 1] + d[i];
return sum;
}
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
rep(i, n) cin >> a[i];
rep(r, k) {
vector<int> d(n + 1);
rep(i, n) {
int l = max(i - a[i], 0), r = min(i + a[i], n);
d[l]++;
d[r + 1]--;
}
a[0] = d[0];
rep(i, 1, n) a[i] = a[i - 1] + d[i];
bool all_n = true;
rep(i, n) if (a[i] != n) {
all_n = false;
break;
}
if (all_n)
break;
}
rep(i, n) cout << a[i] << ((i == n - 1) ? "\n" : " ");
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define VIEW(x) \
do { \
cerr << #x << ": "; \
for (auto i : x) \
cerr << i << " "; \
cerr << endl; \
} while (0)
#define ALL(x) (x).begin(), (x).end()
template <class T> bool umax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool umin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val) {
fill((T *)array, (T *)(array + N), val);
}
template <typename T> void FILL(vector<T> &v, const T &x) {
fill(v.begin(), v.end(), x);
}
template <typename T> void FILL(vector<vector<T>> &v, const T &x) {
for (auto &i : v)
fill(i.begin(), i.end(), x);
}
vector<int> Imos(int mx, vector<pair<int, int>> area) {
/* O(mx + area.size()) */
vector<int> d(mx + 2), sum(mx + 1);
for (auto a : area) {
assert(a.first <= a.second);
d[a.first]++, d[a.second + 1]--; /* inclusive (a.first, a.second) */
}
sum[0] = d[0];
for (int i = 1; i <= mx; ++i)
sum[i] = sum[i - 1] + d[i];
return sum;
}
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
rep(i, n) cin >> a[i];
rep(r, k) {
vector<int> d(n + 1);
rep(i, n) {
int l = max(i - a[i], 0), r = min(i + a[i], n - 1);
d[l]++;
d[r + 1]--;
}
a[0] = d[0];
rep(i, 1, n) a[i] = a[i - 1] + d[i];
bool all_n = true;
rep(i, n) if (a[i] != n) {
all_n = false;
break;
}
if (all_n)
break;
}
rep(i, n) cout << a[i] << ((i == n - 1) ? "\n" : " ");
}
| replace | 64 | 65 | 64 | 65 | 0 | |
p02647 | C++ | Runtime Error | // Date: 2020-06-13
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define IO \
freopen("in.txt", "r", stdin); \
freopen("out.txt", "w", stdout)
#define FIO \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define rep(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for (int i = int(b); i >= int(a); --i)
#define D(x) cout << #x << " = " << x << endl;
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)x.size())
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {
LL a = 1;
while (y) {
if (y & 1)
a = a * x % MOD;
x = x * x % MOD;
y >>= 1;
}
return a;
}
int a[N], b[N];
int main() {
FIO;
int n, k;
cin >> n >> k;
rep(i, 1, n) cin >> a[i];
while (k--) {
int cnt = 0;
rep(i, 0, n + 1) b[i] = 0;
rep(i, 1, n) {
b[i - a[i]]++;
b[i + a[i] + 1]--;
}
rep(i, 1, n) {
b[i] += b[i - 1];
a[i] = b[i];
if (a[i] == n)
++cnt;
}
if (cnt == n)
break;
}
rep(i, 1, n) cout << a[i] << " ";
return 0;
} | // Date: 2020-06-13
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
#define IO \
freopen("in.txt", "r", stdin); \
freopen("out.txt", "w", stdout)
#define FIO \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0)
#define rep(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define per(i, b, a) for (int i = int(b); i >= int(a); --i)
#define D(x) cout << #x << " = " << x << endl;
#define mem(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)x.size())
#define mk make_pair
#define pb push_back
#define fi first
#define se second
const LL INF = 1e18;
const LL mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10;
template <typename T> void chkmax(T &x, T y) { x = max(x, y); }
template <typename T> void chkmin(T &x, T y) { x = min(x, y); }
LL qpow(LL x, LL y, LL MOD) {
LL a = 1;
while (y) {
if (y & 1)
a = a * x % MOD;
x = x * x % MOD;
y >>= 1;
}
return a;
}
int a[N], b[N];
int main() {
FIO;
int n, k;
cin >> n >> k;
rep(i, 1, n) cin >> a[i];
while (k--) {
int cnt = 0;
rep(i, 0, n + 1) b[i] = 0;
rep(i, 1, n) {
b[max(0, i - a[i])]++;
b[min(n + 1, i + a[i] + 1)]--;
}
rep(i, 1, n) {
b[i] += b[i - 1];
a[i] = b[i];
if (a[i] == n)
++cnt;
}
if (cnt == n)
break;
}
rep(i, 1, n) cout << a[i] << " ";
return 0;
} | replace | 54 | 56 | 54 | 56 | 0 | |
p02647 | C++ | Time Limit Exceeded |
#if 1
#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdint>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
auto &in = std::cin;
auto &out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI =
3.141592653589793238462643383279502884197169399375105820974944;
template <typename T, typename U>
std::enable_if_t<std::rank<T>::value == 0> fill_all(T &arr, const U &v) {
arr = v;
}
template <typename ARR, typename U>
std::enable_if_t<std::rank<ARR>::value != 0> fill_all(ARR &arr, const U &v) {
for (auto &i : arr) {
fill_all(i, v);
}
}
int64_t N, K;
int64_t A[300000];
int64_t R[300000];
int64_t L[300000];
int main() {
using std::endl;
in.sync_with_stdio(false);
out.sync_with_stdio(false);
in.tie(nullptr);
out.tie(nullptr);
in >> N >> K;
for (size_t i = 1; i <= N; i++) {
in >> A[i];
}
for (int32_t iKKKK = 0; iKKKK < K; iKKKK++) {
fill_all(R, 0);
fill_all(L, 0);
for (int64_t i = 1; i <= N; i++) {
R[i] += 1;
R[std::min(i + A[i], N + 2) + 1] -= 1;
}
for (int64_t i = 1; i <= N; i++) {
L[i] -= 1;
L[std::max(i - A[i], (int64_t)0)] += 1;
}
for (int64_t i = 1; i <= N; i++) {
R[i] += R[i - 1];
}
for (int64_t i = 1; i <= N; i++) {
L[i] += L[i - 1];
}
for (int64_t i = 1; i <= N; i++) {
A[i] = R[i] + L[i];
}
bool cont = false;
for (int64_t i = 1; i <= N; i++) {
if (A[i] <= N) {
cont = true;
}
}
if (!cont) {
break;
}
}
for (int64_t i = 1; i < N; i++) {
out << A[i] << ' ';
}
out << A[N] << endl;
return 0;
}
#endif
|
#if 1
#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <cstdint>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
auto &in = std::cin;
auto &out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI =
3.141592653589793238462643383279502884197169399375105820974944;
template <typename T, typename U>
std::enable_if_t<std::rank<T>::value == 0> fill_all(T &arr, const U &v) {
arr = v;
}
template <typename ARR, typename U>
std::enable_if_t<std::rank<ARR>::value != 0> fill_all(ARR &arr, const U &v) {
for (auto &i : arr) {
fill_all(i, v);
}
}
int64_t N, K;
int64_t A[300000];
int64_t R[300000];
int64_t L[300000];
int main() {
using std::endl;
in.sync_with_stdio(false);
out.sync_with_stdio(false);
in.tie(nullptr);
out.tie(nullptr);
in >> N >> K;
for (size_t i = 1; i <= N; i++) {
in >> A[i];
}
for (int32_t iKKKK = 0; iKKKK < K; iKKKK++) {
fill_all(R, 0);
fill_all(L, 0);
for (int64_t i = 1; i <= N; i++) {
R[i] += 1;
R[std::min(i + A[i], N + 2) + 1] -= 1;
}
for (int64_t i = 1; i <= N; i++) {
L[i] -= 1;
L[std::max(i - A[i], (int64_t)0)] += 1;
}
for (int64_t i = 1; i <= N; i++) {
R[i] += R[i - 1];
}
for (int64_t i = 1; i <= N; i++) {
L[i] += L[i - 1];
}
for (int64_t i = 1; i <= N; i++) {
A[i] = R[i] + L[i];
}
bool cont = false;
for (int64_t i = 1; i <= N; i++) {
if (A[i] < N) {
cont = true;
}
}
if (!cont) {
break;
}
}
for (int64_t i = 1; i < N; i++) {
out << A[i] << ' ';
}
out << A[N] << endl;
return 0;
}
#endif
| replace | 84 | 85 | 84 | 85 | TLE | |
p02647 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
vector<int> A(N);
for (auto &a : A)
cin >> a;
for (int i = 0; i < K; i++) {
vector<int> B(N + 1);
for (int j = 0; j < N; j++) {
B[max(j - A[j], 0)]++;
B[min(j + A[j] + 1, N)]--;
}
for (int j = 1; j <= N; j++) {
B[j] += B[j - 1];
}
swap(A, B);
if (*min_element(A.begin(), A.end()) == N)
break;
}
for (int i = 0; i < N; i++) {
cout << A[i] << " \n"[i == N - 1];
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
vector<int> A(N);
for (auto &a : A)
cin >> a;
for (int i = 0; i < K; i++) {
vector<int> B(N + 1);
for (int j = 0; j < N; j++) {
B[max(j - A[j], 0)]++;
B[min(j + A[j] + 1, N)]--;
}
for (int j = 1; j <= N; j++) {
B[j] += B[j - 1];
}
B.pop_back();
swap(A, B);
if (*min_element(A.begin(), A.end()) == N)
break;
}
for (int i = 0; i < N; i++) {
cout << A[i] << " \n"[i == N - 1];
}
}
| insert | 18 | 18 | 18 | 19 | TLE | |
p02647 | C++ | Time Limit Exceeded | #include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int gcd(int a, int b) {
if (a % b == 0) {
return (b);
} else {
return (gcd(b, a % b));
}
}
int mod = 1000000000 + 7;
vector<int> v;
class Calc {
// 宣言
long long a;
public:
// 素因数分解
void decompositPrime(long long a);
};
/*
* 素因数分解
*/
void Calc::decompositPrime(long long n) {
// 割る数の初期値
a = 2;
// √n ≧ a ( n ≧ a * a ) の間ループ処理
while (n >= a * a) {
// a で割り切れたら、a は素因数
// そして、割られる数を a で割る
// a で割り切れなかったら、 a を 1 増加させる
if (n % a == 0) {
// printf("%d * ", a);
v.push_back(a);
n /= a;
} else {
a++;
}
}
// 最後に残った n は素因数
v.push_back(n);
// printf("%d\n", n);
}
int main() {
// std::stack<int> stack;
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int cnt = min(k, (int)log(200000) + 1);
for (int i = 0; i < k; i++) {
vector<int> b(n, 0);
for (int j = 0; j < n; j++) {
int left = max(0, j - a[j]);
int right = min(n - 1, j + a[j]);
b[left]++;
if (right < n - 1) {
b[right + 1]--;
}
}
for (int j = 1; j < n; j++) {
b[j] += b[j - 1];
}
a = b;
}
for (int i = 0; i < n - 1; i++) {
cout << a[i] << " ";
}
cout << a[n - 1] << endl;
// cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <array>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int gcd(int a, int b) {
if (a % b == 0) {
return (b);
} else {
return (gcd(b, a % b));
}
}
int mod = 1000000000 + 7;
vector<int> v;
class Calc {
// 宣言
long long a;
public:
// 素因数分解
void decompositPrime(long long a);
};
/*
* 素因数分解
*/
void Calc::decompositPrime(long long n) {
// 割る数の初期値
a = 2;
// √n ≧ a ( n ≧ a * a ) の間ループ処理
while (n >= a * a) {
// a で割り切れたら、a は素因数
// そして、割られる数を a で割る
// a で割り切れなかったら、 a を 1 増加させる
if (n % a == 0) {
// printf("%d * ", a);
v.push_back(a);
n /= a;
} else {
a++;
}
}
// 最後に残った n は素因数
v.push_back(n);
// printf("%d\n", n);
}
int main() {
// std::stack<int> stack;
int n, k;
cin >> n >> k;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int cnt = min(k, (int)log(200000) + 1);
for (int i = 0; i < k; i++) {
vector<int> b(n, 0);
for (int j = 0; j < n; j++) {
int left = max(0, j - a[j]);
int right = min(n - 1, j + a[j]);
b[left]++;
if (right < n - 1) {
b[right + 1]--;
}
}
for (int j = 1; j < n; j++) {
b[j] += b[j - 1];
}
if (a == b) {
break;
}
a = b;
}
for (int i = 0; i < n - 1; i++) {
cout << a[i] << " ";
}
cout << a[n - 1] << endl;
// cout << ans << endl;
return 0;
}
| insert | 74 | 74 | 74 | 77 | TLE | |
p02647 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
for (auto &e : t)
fill_v(e, v);
}
ll N, K;
vll imos(vll A) {
vll table(N + 1);
for (ll i = 0; i < N; i++) {
table[max(0LL, i - A[i])]++;
table[min((ll)(N), i + A[i] + 1)]--;
}
// cout<<table[0]<<" ";
for (ll i = 1; i < N; i++) {
table[i] += table[i - 1];
// cout<<table[i]<<" ";
}
// cout<<endl;
return table;
}
vll solve(function<vll(vll)> func, vll x) {
if (K == 1) {
return func(x);
}
if (K == 0) {
return x;
}
if (K % 2 == 1) {
K--;
return func(solve(func, x));
} else {
auto func2 = [&func](vll t) { return func(func(t)); };
K /= 2;
return solve(func2, x);
}
}
int main() {
cin >> N >> K;
vll A(N);
for (size_t i = 0; i < N; i++) {
cin >> A[i];
}
/* for (size_t i = 0; i < N; i++)
{
A = imos(A);
}
*/
auto ans = solve(imos, A);
for (size_t i = 0; i < N; i++) {
cout << ans[i] << " ";
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
for (auto &e : t)
fill_v(e, v);
}
ll N, K;
vll imos(vll A) {
vll table(N + 1);
for (ll i = 0; i < N; i++) {
table[max(0LL, i - A[i])]++;
table[min((ll)(N), i + A[i] + 1)]--;
}
// cout<<table[0]<<" ";
for (ll i = 1; i < N; i++) {
table[i] += table[i - 1];
// cout<<table[i]<<" ";
}
// cout<<endl;
return table;
}
vll solve(function<vll(vll)> func, vll x) {
if (K == 1) {
return func(x);
}
if (K == 0) {
return x;
}
if (K % 2 == 1) {
K--;
return func(solve(func, x));
} else {
auto func2 = [&func](vll t) { return func(func(t)); };
K /= 2;
return solve(func2, x);
}
}
int main() {
cin >> N >> K;
vll A(N);
for (size_t i = 0; i < N; i++) {
cin >> A[i];
}
/* for (size_t i = 0; i < N; i++)
{
A = imos(A);
}
*/
chmin(K, 50LL);
auto ans = solve(imos, A);
for (size_t i = 0; i < N; i++) {
cout << ans[i] << " ";
}
return 0;
} | insert | 83 | 83 | 83 | 84 | TLE | |
p02647 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
vector<int> b(N, N);
vector<int> B(N);
while (1) {
for (int i = 0; i < N; i++) {
int a = A[i];
for (int j = max(0, i - a); j <= min(N - 1, i + a); j++) {
B[j]++;
}
}
K--;
if (K <= 0 || B == b)
break;
A = B;
B = vector<int>(N);
}
for (int i = 0; i < N; i++) {
if (i)
cout << " ";
cout << B[i];
}
cout << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
vector<int> b(N, N);
vector<int> B(N);
while (1) {
for (int i = 0; i < N; i++) {
int l = max(0, i - A[i]);
int r = min(N - 1, i + A[i]);
B[l]++;
if (r + 1 < N)
B[r + 1]--;
}
for (int i = 1; i < N; i++) {
B[i] += B[i - 1];
}
K--;
if (K <= 0 || B == b)
break;
A = B;
B = vector<int>(N);
}
for (int i = 0; i < N; i++) {
if (i)
cout << " ";
cout << B[i];
}
cout << endl;
}
| replace | 15 | 19 | 15 | 23 | TLE | |
p02647 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
#define LL long long
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair
using namespace std;
const LL MOD = 1e9 + 7;
int n, k, a[100010], b[100010];
int main() {
cin >> n >> k;
rep(i, n) scanf("%d", &a[i]);
rep(i, k) {
memset(b, 0, sizeof(b));
rep(j, n) {
b[max(0, j - a[j])]++;
b[min(n, j + a[j] + 1)]--;
}
int cur = 0, ok = 1;
rep(j, n) {
cur += b[j];
if (cur < n)
ok = 0;
a[j] = cur;
}
if (ok)
break;
}
rep(i, n) printf("%d ", a[i]);
cout << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, n) for (int i = 1; i <= n; i++)
#define LL long long
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair
using namespace std;
const LL MOD = 1e9 + 7;
int n, k, a[200010], b[200010];
int main() {
cin >> n >> k;
rep(i, n) scanf("%d", &a[i]);
rep(i, k) {
memset(b, 0, sizeof(b));
rep(j, n) {
b[max(0, j - a[j])]++;
b[min(n, j + a[j] + 1)]--;
}
int cur = 0, ok = 1;
rep(j, n) {
cur += b[j];
if (cur < n)
ok = 0;
a[j] = cur;
}
if (ok)
break;
}
rep(i, n) printf("%d ", a[i]);
cout << endl;
return 0;
} | replace | 15 | 16 | 15 | 16 | 0 | |
p02647 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main(void) {
int N, K;
cin >> N >> K;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
while (K--) {
if (count(A.begin(), A.end() - 1, N) == N)
break;
vector<int> tmp(N + 1);
for (int i = 0; i < N; i++) {
tmp[max(0, i - A[i])]++;
tmp[min(N, i + A[i] + 1)]--;
}
tmp.pop_back();
partial_sum(tmp.begin(), tmp.end(), A.begin());
}
for (auto e : A) {
cout << e << endl;
}
return 0;
}
| #include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main(void) {
int N, K;
cin >> N >> K;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
while (K--) {
if (count(A.begin(), A.end(), N) == N)
break;
vector<int> tmp(N + 1);
for (int i = 0; i < N; i++) {
tmp[max(0, i - A[i])]++;
tmp[min(N, i + A[i] + 1)]--;
}
tmp.pop_back();
partial_sum(tmp.begin(), tmp.end(), A.begin());
}
for (auto e : A) {
cout << e << endl;
}
return 0;
}
| replace | 16 | 17 | 16 | 17 | TLE | |
p02647 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main(void) {
int N, K;
cin >> N >> K;
vector<int> A(N + 1);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
while (K--) {
vector<int> tmp(N + 1);
for (int i = 0; i < N; i++) {
tmp[max(0, i - A[i])]++;
tmp[min(N, i + A[i]) + 1]--;
}
partial_sum(tmp.begin(), tmp.end(), tmp.begin());
A = tmp;
if (count(A.begin(), A.end() - 1, N) == N)
break;
}
for (int i = 0; i < N; i++) {
cout << A[i] << endl;
}
return 0;
}
| #include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;
int main(void) {
int N, K;
cin >> N >> K;
vector<int> A(N + 1);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
while (K--) {
vector<int> tmp(N + 1);
for (int i = 0; i < N; i++) {
tmp[max(0, i - A[i])]++;
tmp[min(N, i + A[i] + 1)]--;
}
partial_sum(tmp.begin(), tmp.end(), tmp.begin());
A = tmp;
if (count(A.begin(), A.end() - 1, N) == N)
break;
}
for (int i = 0; i < N; i++) {
cout << A[i] << endl;
}
return 0;
}
| replace | 19 | 20 | 19 | 20 | 0 | |
p02647 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
using ll = long long;
using P = pair<int, int>;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
ll n, k;
int main() {
cin >> n >> k;
vector<ll> A(n, 0);
for (int i = 0; i < n; ++i) {
cin >> A.at(i);
}
while (k--) {
vector<ll> B(400400, 0);
for (int i = 0; i < n; ++i) {
ll left = i - A.at(i);
ll right = i + A.at(i);
B.at(max(0LL, left))++;
B.at(right + 1)--;
}
for (int i = 0; i < n; ++i) {
B.at(i + 1) += B.at(i);
}
A = B;
}
for (int i = 0; i < n; ++i) {
if (i == n - 1)
cout << A.at(i) << endl;
else
cout << A.at(i) << " ";
}
} | #include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
using ll = long long;
using P = pair<int, int>;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
ll n, k;
int main() {
cin >> n >> k;
vector<ll> A(n, 0);
for (int i = 0; i < n; ++i) {
cin >> A.at(i);
}
for (int i = 0; i < min(k, 45LL); ++i) {
vector<ll> B(400400, 0);
for (int i = 0; i < n; ++i) {
ll left = i - A.at(i);
ll right = i + A.at(i);
B.at(max(0LL, left))++;
B.at(right + 1)--;
}
for (int i = 0; i < n; ++i) {
B.at(i + 1) += B.at(i);
}
A = B;
}
for (int i = 0; i < n; ++i) {
if (i == n - 1)
cout << A.at(i) << endl;
else
cout << A.at(i) << " ";
}
}
| replace | 30 | 31 | 30 | 31 | TLE | |
p02647 | C++ | Runtime Error | // raja1999
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
// setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
// setfill - cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
// setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
// cout.precision(x) cout<<fixed<<val; // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;
#define f(i, a, b) for (i = a; i < b; i++)
#define rep(i, n) f(i, 0, n)
#define fd(i, a, b) for (i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vector<ll>
#define ss second
#define ff first
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sz(a) a.size()
#define inf (1000 * 1000 * 1000 + 5)
#define all(a) a.begin(), a.end()
#define tri pair<int, pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000 * 1000 * 1000 + 7)
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int, vi, greater<int>>
// #define int ll
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
// std::ios::sync_with_stdio(false);
int arr[100005];
vi v;
int k;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
int n = 100000, i, t, l, r, fl = 0, x;
cin >> n >> k;
rep(i, n) {
cin >> x;
v.pb(x);
}
t = k;
while (t--) {
fl = 0;
rep(i, v.size()) {
l = max(0, i - v[i]);
r = min(n - 1, i + v[i]);
arr[l]++;
arr[r + 1]--;
}
rep(i, n) {
arr[i] = i > 0 ? arr[i - 1] + arr[i] : arr[i];
v[i] = arr[i];
if (v[i] != n) {
fl = 1;
}
}
rep(i, n) { arr[i] = 0; }
if (fl == 0) {
break;
}
}
rep(i, n) { cout << v[i] << " "; }
cout << endl;
return 0;
} | // raja1999
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
// setbase - cout << setbase (16)a; cout << 100 << endl; Prints 64
// setfill - cout << setfill ('x') << setw (5); cout << 77 <<endl;prints xxx77
// setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
// cout.precision(x) cout<<fixed<<val; // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;
#define f(i, a, b) for (i = a; i < b; i++)
#define rep(i, n) f(i, 0, n)
#define fd(i, a, b) for (i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vector<ll>
#define ss second
#define ff first
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sz(a) a.size()
#define inf (1000 * 1000 * 1000 + 5)
#define all(a) a.begin(), a.end()
#define tri pair<int, pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000 * 1000 * 1000 + 7)
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int, vi, greater<int>>
// #define int ll
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
// std::ios::sync_with_stdio(false);
int arr[200005];
vi v;
int k;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
int n = 100000, i, t, l, r, fl = 0, x;
cin >> n >> k;
rep(i, n) {
cin >> x;
v.pb(x);
}
t = k;
while (t--) {
fl = 0;
rep(i, v.size()) {
l = max(0, i - v[i]);
r = min(n - 1, i + v[i]);
arr[l]++;
arr[r + 1]--;
}
rep(i, n) {
arr[i] = i > 0 ? arr[i - 1] + arr[i] : arr[i];
v[i] = arr[i];
if (v[i] != n) {
fl = 1;
}
}
rep(i, n) { arr[i] = 0; }
if (fl == 0) {
break;
}
}
rep(i, n) { cout << v[i] << " "; }
cout << endl;
return 0;
} | replace | 58 | 59 | 58 | 59 | 0 | |
p02647 | Python | Time Limit Exceeded | import sys
import numpy as np
from numba import njit
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**8)
INF = float("inf")
MOD = 10**9 + 7
@njit("i8[:](i8,i8,i8[:])", cache=True)
def func(n, k, A):
for _ in range(k):
B = np.zeros(n + 1, np.int64)
for i, a in enumerate(A):
B[max(0, i - a)] += 1
B[min(i + a + 1, n)] -= 1
A = B.cumsum()[:-1]
return A
def main():
N, K = map(int, readline().split())
A = np.array(readline().split(), np.int64)
ans = func(N, K, A)
print(*ans)
if __name__ == "__main__":
main()
| import sys
import numpy as np
from numba import njit
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10**8)
INF = float("inf")
MOD = 10**9 + 7
@njit("i8[:](i8,i8,i8[:])", cache=True)
def func(n, k, A):
for _ in range(k):
B = np.zeros(n + 1, np.int64)
for i, a in enumerate(A):
B[max(0, i - a)] += 1
B[min(i + a + 1, n)] -= 1
A = B.cumsum()[:-1]
if np.all(A == n):
break
return A
def main():
N, K = map(int, readline().split())
A = np.array(readline().split(), np.int64)
ans = func(N, K, A)
print(*ans)
if __name__ == "__main__":
main()
| insert | 19 | 19 | 19 | 21 | TLE | |
p02647 | Python | Time Limit Exceeded | import sys
sys.setrecursionlimit(10**7)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K = map(int, input().split())
A = list(map(int, input().split()))
K = min(K, 50)
for _ in range(K):
imos = [0] * (N + 1)
for i in range(N):
a = A[i]
s = max(0, i - a)
e = min(N, i + a + 1)
imos[s] += 1
imos[e] -= 1
nxt = [0] * N
t = 0
for i in range(N):
t += imos[i]
nxt[i] = t
A = nxt
print(" ".join(map(str, A)))
| import sys
sys.setrecursionlimit(10**7)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K = map(int, input().split())
A = list(map(int, input().split()))
K = min(K, 100)
for _ in range(K):
imos = [0] * (N + 1)
for i in range(N):
a = A[i]
s = max(0, i - a)
e = min(N, i + a + 1)
imos[s] += 1
imos[e] -= 1
nxt = [0] * N
t = 0
for i in range(N):
t += imos[i]
nxt[i] = t
A = nxt
print(" ".join(map(str, A)))
| replace | 11 | 12 | 11 | 12 | TLE | |
p02647 | C++ | Runtime Error | /*
* じょえチャンネル
* 高評価・チャンネル登録よろしくおねがいします!
* https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
*/
#include <bits/stdc++.h>
// GCC
#define _GLIBCXX_DEBUG
// Clang
// #define _LIBCPP_DEBUG 0
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#define f(i, n) for (int i = 0; i < (n); i++)
// here!!!
// define int long long !!!!!
#define int long long
// define int long long !!!!!
#define mod (int)((1e9) + 7)
// constexpr int mod = 998244353ll;
#ifdef int
#define inf (int)(3e18)
#else
#define inf (int)(5e8)
#endif
#define intt long long
#define itn long long
#define P pair<long long, 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 smallpriority_queue(x) priority_queue<x, vector<x>, greater<x>>
using namespace std;
// Library
// モッドパウ
inline int modpow(int x, int y, int m = mod) {
int res = 1;
while (y) {
if (y & 1) {
res *= x;
res %= m;
}
x = x * x % m;
y /= 2;
}
return res;
}
int mypow(int x, int y) {
int res = 1;
while (y) {
if (y % 2) {
res *= x;
}
x = x * x;
y /= 2;
}
return res;
}
// is the number (x) a prime number?
bool prime(int x) {
if (!x || x == 1) {
return false;
}
for (int i = 2; i * i <= x; i++) {
if (!(x % i)) {
return false;
}
}
return true;
}
// saidai-kouyakusuu
inline int gcd(int x, int y) {
if (!y) {
return x;
}
return gcd(y, x % y);
}
// number of keta
int keta(int x) {
int ans = 0;
while (x) {
x /= 10;
ans++;
}
return ans;
}
// sum of keta
int ketasum(int x) {
int ans = 0;
while (x) {
ans += x % 10;
x /= 10;
}
return ans;
}
inline int lcm(int x, int y) {
int ans = x / gcd(x, y) * y;
return ans;
}
int twobeki(int x) {
int ans = 0;
while (1) {
if (!(x & 1)) {
ans++;
x /= 2;
} else {
break;
}
}
return ans;
}
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;
}
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
#define fin(i) scanf("%lld", &i)
#define fout(i) printf("%lld", i)
#define fendl printf("\n")
int kai(int x, int y) {
int res = 1;
for (int i = x - y + 1; i <= x; i++) {
res *= i;
res %= mod;
}
return res;
}
int comb(int x, int y) {
if (y > x)
return 0;
// cout<<kai(x, y)<<' '<<modpow(kai(y, y), mod - 2)<<endl;
return kai(x, y) * modpow(kai(y, y), mod - 2) % mod;
}
// Library-End
#define vecin(v) \
for (int i = 0; i < v.size(); i++) \
scanf("%lld", &v[i]);
#define vecout(v) \
{ \
for (int i = 0; i < (int)v.size(); i++) \
printf("%lld ", v[i]); \
printf("\n"); \
}
// template<typename T, typename U>
// class SegTree {
// protected:
// unsigned int n = 1, rank = 0;
// std::vector<T> node;
// T nodee;
// virtual T nodef(const T&, const T&)const = 0;
// public:
// SegTree(unsigned int m, T init, T nodee):nodee(nodee) {
// while (n < m) {
// n *= 2;
// rank++;
// }
// node.resize(2 * n);
// for (unsigned int i = n; i < 2 * n; i++)node[i] = init;
// }
// SegTree(const std::vector<T>& initvec, T nodee):nodee(nodee) {
// unsigned int m = initvec.size();
// while (n < m) {
// n *= 2;
// rank++;
// }
// node.resize(2 * n);
// for (unsigned int i = n; i < 2 * n; i++) {
// if (i - n < m)node[i] = initvec[i - n];
// }
// }
// virtual void update(int i, U x) {
// i += n;
// node[i] = x;
// while (i != 1) {
// i >>= 1;
// node[i] = nodef(node[2 * i], node[2 * i + 1]);
// }
// }
// virtual T query(int l, int r) {
// l += n; r += n;
// int ls = nodee, rs = nodee;
// while (l < r) {
// if (l & 1) {
// ls = nodef(ls, node[l]);
// l++;
// }
// if (r & 1) {
// r--;
// rs = nodef(node[r], rs);
// }
// l >>= 1; r >>= 1;
// }
// return nodef(ls, rs);
// }
// virtual T operator[](const int& x) {
// return node[n + x];
// }
// void fill(T x) {
// std::fill(all(node), x);
// }
// void print() {
// rep(i, n)std::cout << operator[](i) << " ";
// std::cout << std::endl;
// }
// };
// class RSQ :public SegTree<int, int> {
// int nodef(const int& lhs,const int& rhs){return lhs+rhs;}
// public:
// RSQ(int size, const int& def = 0) :SegTree<int, int>(size, def, 0) {}
// RSQ(const std::vector<int>& initvec) :SegTree<int, int>(initvec, 0) {}
// };
// class RMiQ :public SegTree<int, int> {
// int nodef(const int& lhs,const int& rhs){return std::min(lhs,rhs);}
// public:
// RMiQ(int size, const int& def = 0) :SegTree<int, int>(size, def, 0) {}
// RMiQ(const std::vector<int>& initvec) :SegTree<int, int>(initvec, 0) {}
// };
// class RMaQ :public SegTree<int, int> {
// int nodef(const int& lhs,const int& rhs){return std::max(lhs,rhs);}
// public:
// RMaQ(int size, const int& def = 0) :SegTree<int, int>(size, def, 0) {}
// RMaQ(const std::vector<int>& initvec) :SegTree<int, int>(initvec, 0) {}
// };
// template<typename T, typename U>
// class IntervalSegTree :public SegTree<T, U> {
// protected:
// using SegTree<T, U>::n;
// using SegTree<T, U>::rank;
// using SegTree<T, U>::node;
// using SegTree<T, U>::nodef;
// using SegTree<T, U>::nodee;
// std::vector<U> lazy;
// std::vector<bool> lazyflag;
// std::vector<int> width;
// virtual void lazyf(U&, const U&) = 0;
// virtual void updf(T&, const U&, const unsigned int&) = 0;
// void eval(int k) {
// for (int i = rank; i > 0; i--) {
// int nk = k >> i;
// if (lazyflag[nk]) {
// updf(node[2 * nk], lazy[nk], width[2 * nk]);
// updf(node[2 * nk + 1], lazy[nk], width[2 * nk + 1]);
// if (lazyflag[2 * nk])lazyf(lazy[2 * nk], lazy[nk]);
// else lazy[2 * nk] = lazy[nk];
// if (lazyflag[2 * nk + 1])lazyf(lazy[2 * nk + 1], lazy[nk]);
// else lazy[2 * nk + 1] = lazy[nk];
// lazyflag[2 * nk] = lazyflag[2 * nk + 1] = true;
// lazyflag[nk] = false;
// }
// }
// }
// public:
// IntervalSegTree(unsigned int m, T init, T nodee) :SegTree<T, U>(m, init,
// nodee) {
// lazy.resize(2 * n); lazyflag.resize(2 * n); width.resize(2 * n);
// width[1] = n;
// for (unsigned int i = 2; i < 2 * n; i++) {
// width[i] = width[i >> 1] >> 1;
// }
// }
// IntervalSegTree(T nodee, const std::vector<T>& initvec) :SegTree<T,
// U>(initvec, nodee) {
// lazy.resize(2 * n); lazyflag.resize(2 * n); width.resize(2 * n);
// width[1] = n;
// for (unsigned int i = 2; i < 2 * n; i++) {
// width[i] = width[i >> 1] >> 1;
// }
// }
// void update(int i, U x) {
// i += n;
// eval(i);
// updf(node[i], x, width[i]);
// if (lazyflag[i])lazyf(lazy[i], x);
// else {
// lazyflag[i] = true;
// lazy[i] = x;
// }
// while (i /= 2)node[i] = nodef(node[2 * i], node[2 * i + 1]);
// }
// void update(int l, int r, U x) {
// l += n; r += n;
// int nl = l, nr = r;
// while (!(nl & 1))nl >>= 1;
// while (!(nr & 1))nr >>= 1;
// nr--;
// eval(nl); eval(nr);
// while (l < r) {
// if (l & 1) {
// updf(node[l], x, width[l]);
// if (lazyflag[l])lazyf(lazy[l], x);
// else {
// lazyflag[l] = true;
// lazy[l] = x;
// }
// l++;
// }
// if (r & 1) {
// r--;
// updf(node[r], x, width[r]);
// if (lazyflag[r])lazyf(lazy[r], x);
// else {
// lazyflag[r] = true;
// lazy[r] = x;
// }
// }
// l >>= 1; r >>= 1;
// }
// while (nl >>= 1)node[nl] = nodef(node[2 * nl], node[2 * nl + 1]);
// while (nr >>= 1)node[nr] = nodef(node[2 * nr], node[2 * nr + 1]);
// }
// T query(int l, int r) {
// l += n; r += n;
// eval(l); eval(r - 1);
// int ls = nodee, rs = nodee;
// while (l < r) {
// if (l & 1) {
// ls = nodef(ls, node[l]);
// l++;
// }
// if (r & 1) {
// r--;
// rs = nodef(node[r], rs);
// }
// l >>= 1; r >>= 1;
// }
// return nodef(ls, rs);
// }
// T operator[](const int& x) {
// eval(n + x);
// return node[n + x];
// }
// T queryForAll() {
// return node[1];
// }
// };
// class RAQRSQ :public IntervalSegTree<int, int> {
// int nodef(const int& a, const int& b)const { return a + b; }
// void lazyf(int& a, const int& b) { a += b; }
// void updf(int& a, const int& b, const unsigned int& width) { a += width *
// b; }
// public:
// RAQRSQ(int size, const int& def = 0) :IntervalSegTree<int, int>(size,
// def, 0) {
// for (int i = n - 1; i > 0; i--)node[i] = nodef(node[2 * i], node[2 *
// i + 1]);
// }
// RAQRSQ(const std::vector<int>& initvec) :IntervalSegTree<int,
// int>((int)0, initvec) {
// for (int i = n - 1; i > 0; i--)node[i] = nodef(node[2 * i], node[2 *
// i + 1]);
// }
// };
// class RAQRMiQ :public IntervalSegTree<int, int> {
// int nodef(const int& a, const int& b)const { return std::min(a, b); }
// void lazyf(int& a, const int& b) { a += b; }
// void updf(int& a, const int& b, const unsigned int& width) { a += b; }
// public:
// RAQRMiQ(int size, const int& def = 0) :IntervalSegTree<int, int>(size,
// def, inf) {
// for (int i = n - 1; i > 0; i--)node[i] = nodef(node[2 * i], node[2 *
// i + 1]);
// }
// RAQRMiQ(const std::vector<int>& initvec) :IntervalSegTree<int, int>(inf,
// initvec) {
// for (int i = n - 1; i > 0; i--)node[i] = nodef(node[2 * i], node[2 *
// i + 1]);
// }
// };
// class RAQRMaQ :public IntervalSegTree<int, int> {
// int nodef(const int& a, const int& b)const { return std::max(a, b); }
// void lazyf(int& a, const int& b) { a += b; }
// void updf(int& a, const int& b, const unsigned int& width) { a += b; }
// public:
// RAQRMaQ(unsigned int size, const int& def = 0) :IntervalSegTree<int,
// int>(size, def, -inf) {
// for (int i = n - 1; i > 0; i--)node[i] = nodef(node[2 * i], node[2 *
// i + 1]);
// }
// RAQRMaQ(const std::vector<int>& initvec) :IntervalSegTree<int, int>(-inf,
// initvec) {
// for (int i = n - 1; i > 0; i--)node[i] = nodef(node[2 * i], node[2 *
// i + 1]);
// }
// };
// class RUQRSQ :public IntervalSegTree<int, int> {
// int nodef(const int& a, const int& b)const { return a + b; }
// void lazyf(int& a, const int& b) { a = b; }
// void updf(int& a, const int& b, const unsigned int& width) { a = width *
// b; }
// public:
// RUQRSQ(int size, const int& def = 0) :IntervalSegTree<int, int>(size,
// def, 0) {
// for (int i = n - 1; i > 0; i--)node[i] = nodef(node[2 * i], node[2 *
// i + 1]);
// }
// RUQRSQ(const std::vector<int>& initvec) :IntervalSegTree<int,
// int>((int)0, initvec) {
// for (int i = n - 1; i > 0; i--)node[i] = nodef(node[2 * i], node[2 *
// i + 1]);
// }
// };
// class RUQRMiQ :public IntervalSegTree<int, int> {
// int nodef(const int& a, const int& b)const { return std::min(a, b); }
// void lazyf(int& a, const int& b) { a = b; }
// void updf(int& a, const int& b, const unsigned int& width) { a = b; }
// public:
// RUQRMiQ(int size, const int& def = 0) :IntervalSegTree<int, int>(size,
// def, inf) {
// for (int i = n - 1; i > 0; i--)node[i] = nodef(node[2 * i], node[2 *
// i + 1]);
// }
// RUQRMiQ(const std::vector<int>& initvec) :IntervalSegTree<int, int>(inf,
// initvec) {
// for (int i = n - 1; i > 0; i--)node[i] = nodef(node[2 * i], node[2 *
// i + 1]);
// }
// };
// class RUQRMaQ :public IntervalSegTree<int, int> {
// int nodef(const int& a, const int& b)const { return std::max(a, b); }
// void lazyf(int& a, const int& b) { a = b; }
// void updf(int& a, const int& b, const unsigned int& width) { a = b; }
// public:
// RUQRMaQ(int size, const int& def = 0) :IntervalSegTree<int, int>(size,
// def, -inf) {
// for (int i = n - 1; i > 0; i--)node[i] = nodef(node[2 * i], node[2 *
// i + 1]);
// }
// RUQRMaQ(const std::vector<int>& initvec) :IntervalSegTree<int, int>(-inf,
// initvec) {
// for (int i = n - 1; i > 0; i--)node[i] = nodef(node[2 * i], node[2 *
// i + 1]);
// }
// };
// SegTree
template <class T> class SegTree {
int n; // 葉の数
vector<T> data; // データを格納するvector
T def; // 初期値かつ単位元
function<T(T, T)> operation; // 区間クエリで使う処理
function<T(T, T)> update; // 点更新で使う処理
// 区間[a,b)の総和。ノードk=[l,r)に着目している。
T _query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return def; // 交差しない
if (a <= l && r <= b)
return data[k]; // a,l,r,bの順で完全に含まれる
else {
T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子
T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子
return operation(c1, c2);
}
}
public:
// _n:必要サイズ, _def:初期値かつ単位元, _operation:クエリ関数,
// _update:更新関数
SegTree(size_t _n, T _def, function<T(T, T)> _operation,
function<T(T, T)> _update)
: def(_def), operation(_operation), update(_update) {
n = 1;
while (n < _n) {
n *= 2;
}
data = vector<T>(2 * n - 1, def);
}
// 場所i(0-indexed)の値をxで更新
void change(int i, T x) {
i += n - 1;
data[i] = update(data[i], x);
while (i > 0) {
i = (i - 1) / 2;
data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
}
}
// [a, b)の区間クエリを実行
T query(int a, int b) { return _query(a, b, 0, 0, n); }
// 添字でアクセス
T operator[](int i) { return data[i + n - 1]; }
};
#define R_MIN ([](long long a, long long b) { return min(a, b); })
#define R_MAX ([](long long a, long long b) { return max(a, b); })
#define R_SUM ([](long long a, long long b) { return a + b; })
#define NORMAL_UPDATE ([](long long a, long long b) { return b; })
#define ADD_UPDATE ([](long long a, long long b) { return a + b; })
#define MINUS_UPDATE ([](long long a, long long b) { return a - b; }
class Union_Find {
vector<int> par;
vector<int> rankmy;
vector<int> ookisa;
public:
Union_Find(int size) {
par = vector<int>(size);
rankmy = vector<int>(size);
ookisa = vector<int>(size);
for (int i = 0; i < size; i++) {
par[i] = i;
ookisa[i] = 1;
}
}
int find(int x) {
if (par[x] == x) {
return x;
}
return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y) {
return;
}
if (rankmy[x] < rankmy[y]) {
par[x] = y;
ookisa[y] += ookisa[x];
ookisa[x] = 0;
} else {
par[y] = x;
ookisa[x] += ookisa[y];
ookisa[y] = 0;
if (rankmy[x] == rankmy[y]) {
rankmy[x]++;
}
}
}
int size(int i) {
i = find(i);
return ookisa[i];
}
bool same(int x, int y) { return find(x) == find(y); }
};
class BIT {
vector<int> data;
int size = 0;
public:
BIT(int _size) {
data = vector<int>(_size + 1);
size = _size;
}
void add(int i, int x) {
while (i <= size) {
data[i] += x;
i += i & -i;
}
}
int sum(int i) {
assert(i <= size);
int s = 0;
while (i > 0) {
s += data[i];
i -= i & -i;
}
return s;
}
int lower_bound(int x) {
if (x <= 0) {
return 0;
} else {
int i = 0;
int r = 1;
while (r < size)
r = r << 1;
for (int len = r; len > 0; len = len >> 1) {
if (i + len < size && data[i + len] < x) {
x -= data[i + len];
i += len;
}
}
return i + 1;
}
}
};
// Union-Find-End
int perm[1000005];
void init_perm() {
perm[0] = 1;
REP(i, 1000000) { perm[i] = perm[i - 1] * i % mod; }
}
int nCk(int x, int y) {
return perm[x] * modpow(perm[x - y], mod - 2) % mod *
modpow(perm[y], mod - 2) % mod;
}
double kyori(pair<int, int> f, pair<int, int> s) {
double ans = 0;
double t = fabs(f.first - s.first);
double y = fabs(f.second - s.second);
ans = sqrt(t * t + y * y);
return ans;
}
inline string stringmax(string &x, string &y) {
if (x.size() > y.size()) {
return x;
}
if (x.size() < y.size()) {
return y;
}
rep(i, x.size()) {
if (x[i] > y[i]) {
return x;
}
if (x[i] < y[i]) {
return y;
}
}
return x;
}
vector<int> RollingHash(string &s, string &t) {
vector<int> ans;
__int128 h = 0, hamod = 0, ki = 0, kim = 0, hikaku = 0, one = 0;
one = 1;
ki = 1000000007ll;
hamod = (one << 61) - 1;
kim = 1;
rep(i, t.size()) {
hikaku *= ki;
h *= ki;
kim *= ki;
hikaku += t[i];
h += s[i];
hikaku %= hamod;
h %= hamod;
kim %= hamod;
}
rep(i, (int)s.size() - (int)t.size() + 1) {
if (h == hikaku) {
ans.emplace_back(i);
}
h *= ki;
h %= hamod;
h += s[i + (int)t.size()];
h %= hamod;
h += hamod;
h -= s[i] * kim % hamod;
h %= hamod;
}
return ans;
}
struct edge {
int to;
int length;
edge(int _to, int _length) {
to = _to;
length = _length;
}
};
vector<int> djkstra(vector<vector<edge>> &road, int start) {
vector<int> kyo(road.size(), inf);
smallpriority_queue(P) q;
q.push({0, start});
kyo[start] = 0;
while (q.size()) {
int x = q.top().second;
itn now = q.top().first;
q.pop();
if (kyo[x] < now) {
continue;
}
for (auto &i : road[x]) {
if (kyo[i.to] > now + i.length) {
kyo[i.to] = now + i.length;
q.push({kyo[i.to], i.to});
}
}
}
return kyo;
}
#define endl "\n" // interactive の時に注意!!!
#define printd cout << fixed << setprecision(10)
int n, k, a[200004], imos[100][200004];
signed main() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cin >> n >> k;
REP(i, n) {
cin >> a[i];
imos[0][max(0ll, i - a[i])]++;
imos[0][min(n + 1, i + a[i] + 1)]--;
}
REP(j, k) {
bool yaru = 0;
REP(i, n) {
imos[j - 1][i] += imos[j - 1][i - 1];
if (imos[j - 1][j] < n) {
yaru = 1;
}
}
if (!yaru) {
REP(i, n) { cout << imos[j - 1][i] << ' '; }
cout << endl;
return 0;
}
REP(i, n) {
imos[j][max(1ll, i - imos[j - 1][i])]++;
imos[j][min(n + 1, i + imos[j - 1][i] + 1)]--;
}
}
REP(i, n) { cout << imos[min(k - 1, 100ll)][i] << ' '; }
cout << endl;
}
| /*
* じょえチャンネル
* 高評価・チャンネル登録よろしくおねがいします!
* https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
*/
#include <bits/stdc++.h>
// GCC
#define _GLIBCXX_DEBUG
// Clang
// #define _LIBCPP_DEBUG 0
// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#define f(i, n) for (int i = 0; i < (n); i++)
// here!!!
// define int long long !!!!!
#define int long long
// define int long long !!!!!
#define mod (int)((1e9) + 7)
// constexpr int mod = 998244353ll;
#ifdef int
#define inf (int)(3e18)
#else
#define inf (int)(5e8)
#endif
#define intt long long
#define itn long long
#define P pair<long long, 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 smallpriority_queue(x) priority_queue<x, vector<x>, greater<x>>
using namespace std;
// Library
// モッドパウ
inline int modpow(int x, int y, int m = mod) {
int res = 1;
while (y) {
if (y & 1) {
res *= x;
res %= m;
}
x = x * x % m;
y /= 2;
}
return res;
}
int mypow(int x, int y) {
int res = 1;
while (y) {
if (y % 2) {
res *= x;
}
x = x * x;
y /= 2;
}
return res;
}
// is the number (x) a prime number?
bool prime(int x) {
if (!x || x == 1) {
return false;
}
for (int i = 2; i * i <= x; i++) {
if (!(x % i)) {
return false;
}
}
return true;
}
// saidai-kouyakusuu
inline int gcd(int x, int y) {
if (!y) {
return x;
}
return gcd(y, x % y);
}
// number of keta
int keta(int x) {
int ans = 0;
while (x) {
x /= 10;
ans++;
}
return ans;
}
// sum of keta
int ketasum(int x) {
int ans = 0;
while (x) {
ans += x % 10;
x /= 10;
}
return ans;
}
inline int lcm(int x, int y) {
int ans = x / gcd(x, y) * y;
return ans;
}
int twobeki(int x) {
int ans = 0;
while (1) {
if (!(x & 1)) {
ans++;
x /= 2;
} else {
break;
}
}
return ans;
}
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;
}
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
#define fin(i) scanf("%lld", &i)
#define fout(i) printf("%lld", i)
#define fendl printf("\n")
int kai(int x, int y) {
int res = 1;
for (int i = x - y + 1; i <= x; i++) {
res *= i;
res %= mod;
}
return res;
}
int comb(int x, int y) {
if (y > x)
return 0;
// cout<<kai(x, y)<<' '<<modpow(kai(y, y), mod - 2)<<endl;
return kai(x, y) * modpow(kai(y, y), mod - 2) % mod;
}
// Library-End
#define vecin(v) \
for (int i = 0; i < v.size(); i++) \
scanf("%lld", &v[i]);
#define vecout(v) \
{ \
for (int i = 0; i < (int)v.size(); i++) \
printf("%lld ", v[i]); \
printf("\n"); \
}
// template<typename T, typename U>
// class SegTree {
// protected:
// unsigned int n = 1, rank = 0;
// std::vector<T> node;
// T nodee;
// virtual T nodef(const T&, const T&)const = 0;
// public:
// SegTree(unsigned int m, T init, T nodee):nodee(nodee) {
// while (n < m) {
// n *= 2;
// rank++;
// }
// node.resize(2 * n);
// for (unsigned int i = n; i < 2 * n; i++)node[i] = init;
// }
// SegTree(const std::vector<T>& initvec, T nodee):nodee(nodee) {
// unsigned int m = initvec.size();
// while (n < m) {
// n *= 2;
// rank++;
// }
// node.resize(2 * n);
// for (unsigned int i = n; i < 2 * n; i++) {
// if (i - n < m)node[i] = initvec[i - n];
// }
// }
// virtual void update(int i, U x) {
// i += n;
// node[i] = x;
// while (i != 1) {
// i >>= 1;
// node[i] = nodef(node[2 * i], node[2 * i + 1]);
// }
// }
// virtual T query(int l, int r) {
// l += n; r += n;
// int ls = nodee, rs = nodee;
// while (l < r) {
// if (l & 1) {
// ls = nodef(ls, node[l]);
// l++;
// }
// if (r & 1) {
// r--;
// rs = nodef(node[r], rs);
// }
// l >>= 1; r >>= 1;
// }
// return nodef(ls, rs);
// }
// virtual T operator[](const int& x) {
// return node[n + x];
// }
// void fill(T x) {
// std::fill(all(node), x);
// }
// void print() {
// rep(i, n)std::cout << operator[](i) << " ";
// std::cout << std::endl;
// }
// };
// class RSQ :public SegTree<int, int> {
// int nodef(const int& lhs,const int& rhs){return lhs+rhs;}
// public:
// RSQ(int size, const int& def = 0) :SegTree<int, int>(size, def, 0) {}
// RSQ(const std::vector<int>& initvec) :SegTree<int, int>(initvec, 0) {}
// };
// class RMiQ :public SegTree<int, int> {
// int nodef(const int& lhs,const int& rhs){return std::min(lhs,rhs);}
// public:
// RMiQ(int size, const int& def = 0) :SegTree<int, int>(size, def, 0) {}
// RMiQ(const std::vector<int>& initvec) :SegTree<int, int>(initvec, 0) {}
// };
// class RMaQ :public SegTree<int, int> {
// int nodef(const int& lhs,const int& rhs){return std::max(lhs,rhs);}
// public:
// RMaQ(int size, const int& def = 0) :SegTree<int, int>(size, def, 0) {}
// RMaQ(const std::vector<int>& initvec) :SegTree<int, int>(initvec, 0) {}
// };
// template<typename T, typename U>
// class IntervalSegTree :public SegTree<T, U> {
// protected:
// using SegTree<T, U>::n;
// using SegTree<T, U>::rank;
// using SegTree<T, U>::node;
// using SegTree<T, U>::nodef;
// using SegTree<T, U>::nodee;
// std::vector<U> lazy;
// std::vector<bool> lazyflag;
// std::vector<int> width;
// virtual void lazyf(U&, const U&) = 0;
// virtual void updf(T&, const U&, const unsigned int&) = 0;
// void eval(int k) {
// for (int i = rank; i > 0; i--) {
// int nk = k >> i;
// if (lazyflag[nk]) {
// updf(node[2 * nk], lazy[nk], width[2 * nk]);
// updf(node[2 * nk + 1], lazy[nk], width[2 * nk + 1]);
// if (lazyflag[2 * nk])lazyf(lazy[2 * nk], lazy[nk]);
// else lazy[2 * nk] = lazy[nk];
// if (lazyflag[2 * nk + 1])lazyf(lazy[2 * nk + 1], lazy[nk]);
// else lazy[2 * nk + 1] = lazy[nk];
// lazyflag[2 * nk] = lazyflag[2 * nk + 1] = true;
// lazyflag[nk] = false;
// }
// }
// }
// public:
// IntervalSegTree(unsigned int m, T init, T nodee) :SegTree<T, U>(m, init,
// nodee) {
// lazy.resize(2 * n); lazyflag.resize(2 * n); width.resize(2 * n);
// width[1] = n;
// for (unsigned int i = 2; i < 2 * n; i++) {
// width[i] = width[i >> 1] >> 1;
// }
// }
// IntervalSegTree(T nodee, const std::vector<T>& initvec) :SegTree<T,
// U>(initvec, nodee) {
// lazy.resize(2 * n); lazyflag.resize(2 * n); width.resize(2 * n);
// width[1] = n;
// for (unsigned int i = 2; i < 2 * n; i++) {
// width[i] = width[i >> 1] >> 1;
// }
// }
// void update(int i, U x) {
// i += n;
// eval(i);
// updf(node[i], x, width[i]);
// if (lazyflag[i])lazyf(lazy[i], x);
// else {
// lazyflag[i] = true;
// lazy[i] = x;
// }
// while (i /= 2)node[i] = nodef(node[2 * i], node[2 * i + 1]);
// }
// void update(int l, int r, U x) {
// l += n; r += n;
// int nl = l, nr = r;
// while (!(nl & 1))nl >>= 1;
// while (!(nr & 1))nr >>= 1;
// nr--;
// eval(nl); eval(nr);
// while (l < r) {
// if (l & 1) {
// updf(node[l], x, width[l]);
// if (lazyflag[l])lazyf(lazy[l], x);
// else {
// lazyflag[l] = true;
// lazy[l] = x;
// }
// l++;
// }
// if (r & 1) {
// r--;
// updf(node[r], x, width[r]);
// if (lazyflag[r])lazyf(lazy[r], x);
// else {
// lazyflag[r] = true;
// lazy[r] = x;
// }
// }
// l >>= 1; r >>= 1;
// }
// while (nl >>= 1)node[nl] = nodef(node[2 * nl], node[2 * nl + 1]);
// while (nr >>= 1)node[nr] = nodef(node[2 * nr], node[2 * nr + 1]);
// }
// T query(int l, int r) {
// l += n; r += n;
// eval(l); eval(r - 1);
// int ls = nodee, rs = nodee;
// while (l < r) {
// if (l & 1) {
// ls = nodef(ls, node[l]);
// l++;
// }
// if (r & 1) {
// r--;
// rs = nodef(node[r], rs);
// }
// l >>= 1; r >>= 1;
// }
// return nodef(ls, rs);
// }
// T operator[](const int& x) {
// eval(n + x);
// return node[n + x];
// }
// T queryForAll() {
// return node[1];
// }
// };
// class RAQRSQ :public IntervalSegTree<int, int> {
// int nodef(const int& a, const int& b)const { return a + b; }
// void lazyf(int& a, const int& b) { a += b; }
// void updf(int& a, const int& b, const unsigned int& width) { a += width *
// b; }
// public:
// RAQRSQ(int size, const int& def = 0) :IntervalSegTree<int, int>(size,
// def, 0) {
// for (int i = n - 1; i > 0; i--)node[i] = nodef(node[2 * i], node[2 *
// i + 1]);
// }
// RAQRSQ(const std::vector<int>& initvec) :IntervalSegTree<int,
// int>((int)0, initvec) {
// for (int i = n - 1; i > 0; i--)node[i] = nodef(node[2 * i], node[2 *
// i + 1]);
// }
// };
// class RAQRMiQ :public IntervalSegTree<int, int> {
// int nodef(const int& a, const int& b)const { return std::min(a, b); }
// void lazyf(int& a, const int& b) { a += b; }
// void updf(int& a, const int& b, const unsigned int& width) { a += b; }
// public:
// RAQRMiQ(int size, const int& def = 0) :IntervalSegTree<int, int>(size,
// def, inf) {
// for (int i = n - 1; i > 0; i--)node[i] = nodef(node[2 * i], node[2 *
// i + 1]);
// }
// RAQRMiQ(const std::vector<int>& initvec) :IntervalSegTree<int, int>(inf,
// initvec) {
// for (int i = n - 1; i > 0; i--)node[i] = nodef(node[2 * i], node[2 *
// i + 1]);
// }
// };
// class RAQRMaQ :public IntervalSegTree<int, int> {
// int nodef(const int& a, const int& b)const { return std::max(a, b); }
// void lazyf(int& a, const int& b) { a += b; }
// void updf(int& a, const int& b, const unsigned int& width) { a += b; }
// public:
// RAQRMaQ(unsigned int size, const int& def = 0) :IntervalSegTree<int,
// int>(size, def, -inf) {
// for (int i = n - 1; i > 0; i--)node[i] = nodef(node[2 * i], node[2 *
// i + 1]);
// }
// RAQRMaQ(const std::vector<int>& initvec) :IntervalSegTree<int, int>(-inf,
// initvec) {
// for (int i = n - 1; i > 0; i--)node[i] = nodef(node[2 * i], node[2 *
// i + 1]);
// }
// };
// class RUQRSQ :public IntervalSegTree<int, int> {
// int nodef(const int& a, const int& b)const { return a + b; }
// void lazyf(int& a, const int& b) { a = b; }
// void updf(int& a, const int& b, const unsigned int& width) { a = width *
// b; }
// public:
// RUQRSQ(int size, const int& def = 0) :IntervalSegTree<int, int>(size,
// def, 0) {
// for (int i = n - 1; i > 0; i--)node[i] = nodef(node[2 * i], node[2 *
// i + 1]);
// }
// RUQRSQ(const std::vector<int>& initvec) :IntervalSegTree<int,
// int>((int)0, initvec) {
// for (int i = n - 1; i > 0; i--)node[i] = nodef(node[2 * i], node[2 *
// i + 1]);
// }
// };
// class RUQRMiQ :public IntervalSegTree<int, int> {
// int nodef(const int& a, const int& b)const { return std::min(a, b); }
// void lazyf(int& a, const int& b) { a = b; }
// void updf(int& a, const int& b, const unsigned int& width) { a = b; }
// public:
// RUQRMiQ(int size, const int& def = 0) :IntervalSegTree<int, int>(size,
// def, inf) {
// for (int i = n - 1; i > 0; i--)node[i] = nodef(node[2 * i], node[2 *
// i + 1]);
// }
// RUQRMiQ(const std::vector<int>& initvec) :IntervalSegTree<int, int>(inf,
// initvec) {
// for (int i = n - 1; i > 0; i--)node[i] = nodef(node[2 * i], node[2 *
// i + 1]);
// }
// };
// class RUQRMaQ :public IntervalSegTree<int, int> {
// int nodef(const int& a, const int& b)const { return std::max(a, b); }
// void lazyf(int& a, const int& b) { a = b; }
// void updf(int& a, const int& b, const unsigned int& width) { a = b; }
// public:
// RUQRMaQ(int size, const int& def = 0) :IntervalSegTree<int, int>(size,
// def, -inf) {
// for (int i = n - 1; i > 0; i--)node[i] = nodef(node[2 * i], node[2 *
// i + 1]);
// }
// RUQRMaQ(const std::vector<int>& initvec) :IntervalSegTree<int, int>(-inf,
// initvec) {
// for (int i = n - 1; i > 0; i--)node[i] = nodef(node[2 * i], node[2 *
// i + 1]);
// }
// };
// SegTree
template <class T> class SegTree {
int n; // 葉の数
vector<T> data; // データを格納するvector
T def; // 初期値かつ単位元
function<T(T, T)> operation; // 区間クエリで使う処理
function<T(T, T)> update; // 点更新で使う処理
// 区間[a,b)の総和。ノードk=[l,r)に着目している。
T _query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return def; // 交差しない
if (a <= l && r <= b)
return data[k]; // a,l,r,bの順で完全に含まれる
else {
T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子
T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子
return operation(c1, c2);
}
}
public:
// _n:必要サイズ, _def:初期値かつ単位元, _operation:クエリ関数,
// _update:更新関数
SegTree(size_t _n, T _def, function<T(T, T)> _operation,
function<T(T, T)> _update)
: def(_def), operation(_operation), update(_update) {
n = 1;
while (n < _n) {
n *= 2;
}
data = vector<T>(2 * n - 1, def);
}
// 場所i(0-indexed)の値をxで更新
void change(int i, T x) {
i += n - 1;
data[i] = update(data[i], x);
while (i > 0) {
i = (i - 1) / 2;
data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
}
}
// [a, b)の区間クエリを実行
T query(int a, int b) { return _query(a, b, 0, 0, n); }
// 添字でアクセス
T operator[](int i) { return data[i + n - 1]; }
};
#define R_MIN ([](long long a, long long b) { return min(a, b); })
#define R_MAX ([](long long a, long long b) { return max(a, b); })
#define R_SUM ([](long long a, long long b) { return a + b; })
#define NORMAL_UPDATE ([](long long a, long long b) { return b; })
#define ADD_UPDATE ([](long long a, long long b) { return a + b; })
#define MINUS_UPDATE ([](long long a, long long b) { return a - b; }
class Union_Find {
vector<int> par;
vector<int> rankmy;
vector<int> ookisa;
public:
Union_Find(int size) {
par = vector<int>(size);
rankmy = vector<int>(size);
ookisa = vector<int>(size);
for (int i = 0; i < size; i++) {
par[i] = i;
ookisa[i] = 1;
}
}
int find(int x) {
if (par[x] == x) {
return x;
}
return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y) {
return;
}
if (rankmy[x] < rankmy[y]) {
par[x] = y;
ookisa[y] += ookisa[x];
ookisa[x] = 0;
} else {
par[y] = x;
ookisa[x] += ookisa[y];
ookisa[y] = 0;
if (rankmy[x] == rankmy[y]) {
rankmy[x]++;
}
}
}
int size(int i) {
i = find(i);
return ookisa[i];
}
bool same(int x, int y) { return find(x) == find(y); }
};
class BIT {
vector<int> data;
int size = 0;
public:
BIT(int _size) {
data = vector<int>(_size + 1);
size = _size;
}
void add(int i, int x) {
while (i <= size) {
data[i] += x;
i += i & -i;
}
}
int sum(int i) {
assert(i <= size);
int s = 0;
while (i > 0) {
s += data[i];
i -= i & -i;
}
return s;
}
int lower_bound(int x) {
if (x <= 0) {
return 0;
} else {
int i = 0;
int r = 1;
while (r < size)
r = r << 1;
for (int len = r; len > 0; len = len >> 1) {
if (i + len < size && data[i + len] < x) {
x -= data[i + len];
i += len;
}
}
return i + 1;
}
}
};
// Union-Find-End
int perm[1000005];
void init_perm() {
perm[0] = 1;
REP(i, 1000000) { perm[i] = perm[i - 1] * i % mod; }
}
int nCk(int x, int y) {
return perm[x] * modpow(perm[x - y], mod - 2) % mod *
modpow(perm[y], mod - 2) % mod;
}
double kyori(pair<int, int> f, pair<int, int> s) {
double ans = 0;
double t = fabs(f.first - s.first);
double y = fabs(f.second - s.second);
ans = sqrt(t * t + y * y);
return ans;
}
inline string stringmax(string &x, string &y) {
if (x.size() > y.size()) {
return x;
}
if (x.size() < y.size()) {
return y;
}
rep(i, x.size()) {
if (x[i] > y[i]) {
return x;
}
if (x[i] < y[i]) {
return y;
}
}
return x;
}
vector<int> RollingHash(string &s, string &t) {
vector<int> ans;
__int128 h = 0, hamod = 0, ki = 0, kim = 0, hikaku = 0, one = 0;
one = 1;
ki = 1000000007ll;
hamod = (one << 61) - 1;
kim = 1;
rep(i, t.size()) {
hikaku *= ki;
h *= ki;
kim *= ki;
hikaku += t[i];
h += s[i];
hikaku %= hamod;
h %= hamod;
kim %= hamod;
}
rep(i, (int)s.size() - (int)t.size() + 1) {
if (h == hikaku) {
ans.emplace_back(i);
}
h *= ki;
h %= hamod;
h += s[i + (int)t.size()];
h %= hamod;
h += hamod;
h -= s[i] * kim % hamod;
h %= hamod;
}
return ans;
}
struct edge {
int to;
int length;
edge(int _to, int _length) {
to = _to;
length = _length;
}
};
vector<int> djkstra(vector<vector<edge>> &road, int start) {
vector<int> kyo(road.size(), inf);
smallpriority_queue(P) q;
q.push({0, start});
kyo[start] = 0;
while (q.size()) {
int x = q.top().second;
itn now = q.top().first;
q.pop();
if (kyo[x] < now) {
continue;
}
for (auto &i : road[x]) {
if (kyo[i.to] > now + i.length) {
kyo[i.to] = now + i.length;
q.push({kyo[i.to], i.to});
}
}
}
return kyo;
}
#define endl "\n" // interactive の時に注意!!!
#define printd cout << fixed << setprecision(10)
int n, k, a[200004], imos[100][200004];
signed main() {
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cin >> n >> k;
REP(i, n) {
cin >> a[i];
imos[0][max(0ll, i - a[i])]++;
imos[0][min(n + 1, i + a[i] + 1)]--;
}
REP(j, k) {
bool yaru = 0;
REP(i, n) {
imos[j - 1][i] += imos[j - 1][i - 1];
if (imos[j - 1][i] < n) {
yaru = 1;
}
}
if (!yaru) {
REP(i, n) { cout << imos[j - 1][i] << ' '; }
cout << endl;
return 0;
}
REP(i, n) {
imos[j][max(1ll, i - imos[j - 1][i])]++;
imos[j][min(n + 1, i + imos[j - 1][i] + 1)]--;
}
}
REP(i, n) { cout << imos[min(k - 1, 100ll)][i] << ' '; }
cout << endl;
}
| replace | 740 | 741 | 740 | 741 | -11 | |
p02647 | Python | Runtime Error | N, K = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(min(K, 50)):
lamp = [0 for i in range(N + 1)]
for i in range(N):
lamp[max(0, i - A[i])] += 1
lamp[min(N, i + A[i] + 1)] -= 1
for i in range(N):
lamp[i] += lamp[i - 1]
A = lamp
[print(A[i], end=" ") for i in range(N)]
print()
| N, K = map(int, input().split())
A = list(map(int, input().split()))
for _ in range(min(K, 50)):
lamp = [0 for i in range(N + 1)]
for i in range(N):
lamp[max(0, i - A[i])] += 1
lamp[min(N, i + A[i] + 1)] -= 1
for i in range(1, N + 1):
lamp[i] += lamp[i - 1]
A = lamp
[print(A[i], end=" ") for i in range(N)]
print()
| replace | 9 | 10 | 9 | 10 | 0 | |
p02647 | C++ | Time Limit Exceeded | #pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for (int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
constexpr ll mod = 1e9 + 7;
constexpr int inf = INT32_MAX / 2;
constexpr ll INF = LLONG_MAX / 2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */
/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */
/* --------------------ライブラリ-------------------- */
ll fact(int i) { // 階乗
if (i == 0)
return 1;
return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) { // 最大公約数
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { // 最小公倍数
return a * b / gcd(a, b);
}
int keta(ll n) { // 桁数を求める
if (n == 0)
return 1;
int count = 0;
while (n != 0) {
n /= 10;
count++;
}
return count;
}
ll ketasum(ll n) { // 各桁の和
ll sum = 0;
while (n != 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
int n, k;
cin >> n >> k;
vi a(n);
// vi table(n);
vi set(n, 0);
rep(i, n) {
cin >> a[i];
/*table[max(i-a[i],0LL)]++;
table[min(i+a[i],n-1)]--;
if(i>0) table[i]+=table[i-1];*/
}
rep(j, k) {
if (j > 0)
a = set;
fill(set.begin(), set.end(), 0);
rep(i, n) {
set[max(i - a[i], 0LL)]++;
if (i + a[i] < n - 1)
set[i + a[i] + 1]--;
// cout << set[i] << ' ';
}
rep1(i, n - 1) set[i] += set[i - 1];
// for(int i = )
// for(auto p:set) cout << p << ' ';cout << endl;
}
for (auto p : set)
cout << p << ' ';
return 0;
} | #pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for (int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
constexpr ll mod = 1e9 + 7;
constexpr int inf = INT32_MAX / 2;
constexpr ll INF = LLONG_MAX / 2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */
/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */
/* --------------------ライブラリ-------------------- */
ll fact(int i) { // 階乗
if (i == 0)
return 1;
return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) { // 最大公約数
if (b == 0)
return a;
return gcd(b, a % b);
}
ll lcm(ll a, ll b) { // 最小公倍数
return a * b / gcd(a, b);
}
int keta(ll n) { // 桁数を求める
if (n == 0)
return 1;
int count = 0;
while (n != 0) {
n /= 10;
count++;
}
return count;
}
ll ketasum(ll n) { // 各桁の和
ll sum = 0;
while (n != 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
int n, k;
cin >> n >> k;
vi a(n);
// vi table(n);
vi set(n, 0);
rep(i, n) {
cin >> a[i];
/*table[max(i-a[i],0LL)]++;
table[min(i+a[i],n-1)]--;
if(i>0) table[i]+=table[i-1];*/
}
chmin(k, 1000LL);
rep(j, k) {
if (j > 0)
a = set;
fill(set.begin(), set.end(), 0);
rep(i, n) {
set[max(i - a[i], 0LL)]++;
if (i + a[i] < n - 1)
set[i + a[i] + 1]--;
// cout << set[i] << ' ';
}
rep1(i, n - 1) set[i] += set[i - 1];
// for(int i = )
// for(auto p:set) cout << p << ' ';cout << endl;
}
for (auto p : set)
cout << p << ' ';
return 0;
} | insert | 92 | 92 | 92 | 93 | TLE | |
p02647 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define FOR(i, n, m) for (ll i = (n); i < (ll)(m); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll inf = 1000000000;
constexpr ll mod = 1000000007;
constexpr long double eps = 1e-6;
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
os << to_string(p.first) << " " << to_string(p.second);
return os;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
REP(i, v.size()) {
if (i)
os << " ";
os << v[i];
}
return os;
}
struct modint {
ll n;
public:
modint(const ll n = 0) : n((n % mod + mod) % mod) {}
static modint pow(modint a, int m) {
modint r = 1;
while (m > 0) {
if (m & 1) {
r *= a;
}
a = (a * a);
m /= 2;
}
return r;
}
modint &operator++() {
*this += 1;
return *this;
}
modint &operator--() {
*this -= 1;
return *this;
}
modint operator++(int) {
modint ret = *this;
*this += 1;
return ret;
}
modint operator--(int) {
modint ret = *this;
*this -= 1;
return ret;
}
modint operator~() const { return (this->pow(n, mod - 2)); } // inverse
friend bool operator==(const modint &lhs, const modint &rhs) {
return lhs.n == rhs.n;
}
friend bool operator<(const modint &lhs, const modint &rhs) {
return lhs.n < rhs.n;
}
friend bool operator>(const modint &lhs, const modint &rhs) {
return lhs.n > rhs.n;
}
friend modint &operator+=(modint &lhs, const modint &rhs) {
lhs.n += rhs.n;
if (lhs.n >= mod)
lhs.n -= mod;
return lhs;
}
friend modint &operator-=(modint &lhs, const modint &rhs) {
lhs.n -= rhs.n;
if (lhs.n < 0)
lhs.n += mod;
return lhs;
}
friend modint &operator*=(modint &lhs, const modint &rhs) {
lhs.n = (lhs.n * rhs.n) % mod;
return lhs;
}
friend modint &operator/=(modint &lhs, const modint &rhs) {
lhs.n = (lhs.n * (~rhs).n) % mod;
return lhs;
}
friend modint operator+(const modint &lhs, const modint &rhs) {
return modint(lhs.n + rhs.n);
}
friend modint operator-(const modint &lhs, const modint &rhs) {
return modint(lhs.n - rhs.n);
}
friend modint operator*(const modint &lhs, const modint &rhs) {
return modint(lhs.n * rhs.n);
}
friend modint operator/(const modint &lhs, const modint &rhs) {
return modint(lhs.n * (~rhs).n);
}
};
istream &operator>>(istream &is, modint m) {
is >> m.n;
return is;
}
ostream &operator<<(ostream &os, modint m) {
os << m.n;
return os;
}
#define MAX_N 1010101
long long extgcd(long long a, long long b, long long &x, long long &y) {
long long d = a;
if (b != 0) {
d = extgcd(b, a % b, y, x);
y -= (a / b) * x;
} else {
x = 1;
y = 0;
}
return d;
}
long long mod_inverse(long long a, long long m) {
long long x, y;
if (extgcd(a, m, x, y) == 1)
return (m + x % m) % m;
else
return -1;
}
vector<long long> fact(MAX_N + 1, inf);
long long mod_fact(long long n, long long &e) {
if (fact[0] == inf) {
fact[0] = 1;
if (MAX_N != 0)
fact[1] = 1;
for (ll i = 2; i <= MAX_N; ++i) {
fact[i] = (fact[i - 1] * i) % mod;
}
}
e = 0;
if (n == 0)
return 1;
long long res = mod_fact(n / mod, e);
e += n / mod;
if ((n / mod) % 2 != 0)
return (res * (mod - fact[n % mod])) % mod;
return (res * fact[n % mod]) % mod;
}
// return nCk
long long mod_comb(long long n, long long k) {
if (n < 0 || k < 0 || n < k)
return 0;
long long e1, e2, e3;
long long a1 = mod_fact(n, e1), a2 = mod_fact(k, e2),
a3 = mod_fact(n - k, e3);
if (e1 > e2 + e3)
return 0;
return (a1 * mod_inverse((a2 * a3) % mod, mod)) % mod;
}
using mi = modint;
mi mod_pow(mi a, ll n) {
mi ret = 1;
mi tmp = a;
while (n > 0) {
if (n % 2)
ret *= tmp;
tmp = tmp * tmp;
n /= 2;
}
return ret;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
using ld = long double;
ll n, k;
vector<ll> a;
ll sum() {
ll sum_val = 0;
REP(i, n) sum_val += a[i];
return sum_val;
}
void update() {
vector<ll> imo(n + 1, 0);
REP(i, n) {
ll l = i, r = min(i + a[i] + 1, n);
imo[l]++;
imo[r]--;
l = max(0LL, i - a[i]);
r = i;
imo[l]++;
imo[r]--;
}
FOR(i, 1, n + 1) imo[i] += imo[i - 1];
REP(i, n) a[i] = imo[i];
return;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
a.resize(n);
REP(i, n) cin >> a[i];
REP(i, k) {
if (sum() == n * n)
continue;
update();
}
cout << a << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define FOR(i, n, m) for (ll i = (n); i < (ll)(m); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll inf = 1000000000;
constexpr ll mod = 1000000007;
constexpr long double eps = 1e-6;
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
os << to_string(p.first) << " " << to_string(p.second);
return os;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
REP(i, v.size()) {
if (i)
os << " ";
os << v[i];
}
return os;
}
struct modint {
ll n;
public:
modint(const ll n = 0) : n((n % mod + mod) % mod) {}
static modint pow(modint a, int m) {
modint r = 1;
while (m > 0) {
if (m & 1) {
r *= a;
}
a = (a * a);
m /= 2;
}
return r;
}
modint &operator++() {
*this += 1;
return *this;
}
modint &operator--() {
*this -= 1;
return *this;
}
modint operator++(int) {
modint ret = *this;
*this += 1;
return ret;
}
modint operator--(int) {
modint ret = *this;
*this -= 1;
return ret;
}
modint operator~() const { return (this->pow(n, mod - 2)); } // inverse
friend bool operator==(const modint &lhs, const modint &rhs) {
return lhs.n == rhs.n;
}
friend bool operator<(const modint &lhs, const modint &rhs) {
return lhs.n < rhs.n;
}
friend bool operator>(const modint &lhs, const modint &rhs) {
return lhs.n > rhs.n;
}
friend modint &operator+=(modint &lhs, const modint &rhs) {
lhs.n += rhs.n;
if (lhs.n >= mod)
lhs.n -= mod;
return lhs;
}
friend modint &operator-=(modint &lhs, const modint &rhs) {
lhs.n -= rhs.n;
if (lhs.n < 0)
lhs.n += mod;
return lhs;
}
friend modint &operator*=(modint &lhs, const modint &rhs) {
lhs.n = (lhs.n * rhs.n) % mod;
return lhs;
}
friend modint &operator/=(modint &lhs, const modint &rhs) {
lhs.n = (lhs.n * (~rhs).n) % mod;
return lhs;
}
friend modint operator+(const modint &lhs, const modint &rhs) {
return modint(lhs.n + rhs.n);
}
friend modint operator-(const modint &lhs, const modint &rhs) {
return modint(lhs.n - rhs.n);
}
friend modint operator*(const modint &lhs, const modint &rhs) {
return modint(lhs.n * rhs.n);
}
friend modint operator/(const modint &lhs, const modint &rhs) {
return modint(lhs.n * (~rhs).n);
}
};
istream &operator>>(istream &is, modint m) {
is >> m.n;
return is;
}
ostream &operator<<(ostream &os, modint m) {
os << m.n;
return os;
}
#define MAX_N 1010101
long long extgcd(long long a, long long b, long long &x, long long &y) {
long long d = a;
if (b != 0) {
d = extgcd(b, a % b, y, x);
y -= (a / b) * x;
} else {
x = 1;
y = 0;
}
return d;
}
long long mod_inverse(long long a, long long m) {
long long x, y;
if (extgcd(a, m, x, y) == 1)
return (m + x % m) % m;
else
return -1;
}
vector<long long> fact(MAX_N + 1, inf);
long long mod_fact(long long n, long long &e) {
if (fact[0] == inf) {
fact[0] = 1;
if (MAX_N != 0)
fact[1] = 1;
for (ll i = 2; i <= MAX_N; ++i) {
fact[i] = (fact[i - 1] * i) % mod;
}
}
e = 0;
if (n == 0)
return 1;
long long res = mod_fact(n / mod, e);
e += n / mod;
if ((n / mod) % 2 != 0)
return (res * (mod - fact[n % mod])) % mod;
return (res * fact[n % mod]) % mod;
}
// return nCk
long long mod_comb(long long n, long long k) {
if (n < 0 || k < 0 || n < k)
return 0;
long long e1, e2, e3;
long long a1 = mod_fact(n, e1), a2 = mod_fact(k, e2),
a3 = mod_fact(n - k, e3);
if (e1 > e2 + e3)
return 0;
return (a1 * mod_inverse((a2 * a3) % mod, mod)) % mod;
}
using mi = modint;
mi mod_pow(mi a, ll n) {
mi ret = 1;
mi tmp = a;
while (n > 0) {
if (n % 2)
ret *= tmp;
tmp = tmp * tmp;
n /= 2;
}
return ret;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
using ld = long double;
ll n, k;
vector<ll> a;
ll sum() {
ll sum_val = 0;
REP(i, n) sum_val += a[i];
return sum_val;
}
void update() {
vector<ll> imo(n + 1, 0);
REP(i, n) {
ll l = i, r = min(i + a[i] + 1, n);
imo[l]++;
imo[r]--;
l = max(0LL, i - a[i]);
r = i;
imo[l]++;
imo[r]--;
}
FOR(i, 1, n + 1) imo[i] += imo[i - 1];
REP(i, n) a[i] = imo[i];
return;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
a.resize(n);
REP(i, n) cin >> a[i];
REP(i, k) {
if (sum() == n * n)
break;
update();
}
cout << a << endl;
return 0;
}
| replace | 229 | 230 | 229 | 230 | TLE | |
p02647 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define sz(s) (int)(s.size())
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(), v.end()
#define watch(x) cout << (#x) << " = " << x << endl
const int dr[]{-1, -1, 0, 1, 1, 1, 0, -1};
const int dc[]{0, 1, 1, 1, 0, -1, -1, -1};
#if __cplusplus >= 201402L
template <typename T> vector<T> create(size_t n) { return vector<T>(n); }
template <typename T, typename... Args> auto create(size_t n, Args... args) {
return vector<decltype(create<T>(args...))>(n, create<T>(args...));
}
#endif
void run() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifdef EZZAT
freopen("input.in", "r", stdin);
// freopen("output.out", "w", stdout);
#else
#endif
}
int main() {
run();
int n, k;
cin >> n >> k;
vector<int> v(n + 1), up(n + 1);
for (int i = 0; i < n; i++)
cin >> v[i];
while (k--) {
for (int i = 0; i < n; i++) {
up[max(i - v[i], 0)]++;
up[min(i + v[i] + 1, n)]--;
}
int sum = 0;
for (int i = 0; i < n; i++) {
v[i] = (sum += up[i]);
up[i] = 0;
}
if (*min_element(all(v)) == n)
break;
}
for (int i = 0; i < n; i++)
cout << v[i] << ' ';
}
| #include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define sz(s) (int)(s.size())
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(), v.end()
#define watch(x) cout << (#x) << " = " << x << endl
const int dr[]{-1, -1, 0, 1, 1, 1, 0, -1};
const int dc[]{0, 1, 1, 1, 0, -1, -1, -1};
#if __cplusplus >= 201402L
template <typename T> vector<T> create(size_t n) { return vector<T>(n); }
template <typename T, typename... Args> auto create(size_t n, Args... args) {
return vector<decltype(create<T>(args...))>(n, create<T>(args...));
}
#endif
void run() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifdef EZZAT
freopen("input.in", "r", stdin);
// freopen("output.out", "w", stdout);
#else
#endif
}
int main() {
run();
int n, k;
cin >> n >> k;
vector<int> v(n), up(n + 1);
for (int i = 0; i < n; i++)
cin >> v[i];
while (k--) {
for (int i = 0; i < n; i++) {
up[max(i - v[i], 0)]++;
up[min(i + v[i] + 1, n)]--;
}
int sum = 0;
for (int i = 0; i < n; i++) {
v[i] = (sum += up[i]);
up[i] = 0;
}
if (*min_element(all(v)) == n)
break;
}
for (int i = 0; i < n; i++)
cout << v[i] << ' ';
}
| replace | 33 | 34 | 33 | 34 | TLE | |
p02647 | C++ | Time Limit Exceeded | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
const ll MOD = 1000000007;
const double pi = acos(-1);
int main() {
ll N, K;
cin >> N >> K;
vector<ll> A(N);
rep(i, N) { cin >> A.at(i); }
rep(i, min(K, (ll)1000)) {
vector<ll> hoge(N, 0);
vector<ll> sirusi(N, 0);
rep(i, N) {
sirusi.at(max((ll)0, i - A.at(i)))++;
if (i + A.at(i) < N - 1) {
sirusi.at(i + A.at(i) + 1)--;
}
}
rep(i, N) {
if (i == 0) {
hoge.at(0) = sirusi.at(0);
continue;
}
hoge.at(i) = hoge.at(i - 1) + sirusi.at(i);
}
A = hoge;
}
rep(i, N) {
if (i != 0) {
cout << " ";
}
cout << A.at(i);
}
cout << endl;
return 0;
}
| #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
const ll MOD = 1000000007;
const double pi = acos(-1);
int main() {
ll N, K;
cin >> N >> K;
vector<ll> A(N);
rep(i, N) { cin >> A.at(i); }
rep(i, min(K, (ll)100)) {
vector<ll> hoge(N, 0);
vector<ll> sirusi(N, 0);
rep(i, N) {
sirusi.at(max((ll)0, i - A.at(i)))++;
if (i + A.at(i) < N - 1) {
sirusi.at(i + A.at(i) + 1)--;
}
}
rep(i, N) {
if (i == 0) {
hoge.at(0) = sirusi.at(0);
continue;
}
hoge.at(i) = hoge.at(i - 1) + sirusi.at(i);
}
A = hoge;
}
rep(i, N) {
if (i != 0) {
cout << " ";
}
cout << A.at(i);
}
cout << endl;
return 0;
}
| replace | 13 | 14 | 13 | 14 | TLE |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.