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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02725 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long int
#define F(i, j, k, in) for (int i = j; i < k; i += in)
#define DF(i, j, k, in) for (int i = j; i >= k; i -= in)
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define PB push_back
#define ub upper_bound
#define lb lower_bound
#define ins insert
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll K, N, A[10000], sec[10000];
cin >> K >> N;
F(i, 0, N, 1)
cin >> A[i];
ll j = 0;
F(i, 0, N - 1, 1) {
sec[j] = A[i + 1] - A[i];
j++;
}
sec[j] = K - (A[N - 1] - A[0]);
ll mini = INT_MAX, sum = 0, sumi;
F(i, 0, j + 1, 1) { sum += sec[i]; }
F(i, 0, j + 1, 1) {
sumi = sum - sec[i];
if (mini > sumi) {
mini = sumi;
}
}
cout << mini;
return 0;
}
| #include <bits/stdc++.h>
#define ll long long int
#define F(i, j, k, in) for (int i = j; i < k; i += in)
#define DF(i, j, k, in) for (int i = j; i >= k; i -= in)
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define PB push_back
#define ub upper_bound
#define lb lower_bound
#define ins insert
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll K, N, A[1000000], sec[1000000];
cin >> K >> N;
F(i, 0, N, 1)
cin >> A[i];
ll j = 0;
F(i, 0, N - 1, 1) {
sec[j] = A[i + 1] - A[i];
j++;
}
sec[j] = K - (A[N - 1] - A[0]);
ll mini = INT_MAX, sum = 0, sumi;
F(i, 0, j + 1, 1) { sum += sec[i]; }
F(i, 0, j + 1, 1) {
sumi = sum - sec[i];
if (mini > sumi) {
mini = sumi;
}
}
cout << mini;
return 0;
}
| replace | 15 | 16 | 15 | 16 | 0 | |
p02725 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X) \
{}
#define ARDEB(i, X) \
{}
#define END \
{}
#endif
typedef long long ll;
typedef pair<int, int> P;
struct edge {
int to, cost;
};
int ceil2(int a, int b) {
if (a % b) {
return a / b + 1;
} else {
return a / b;
}
}
using namespace std;
int k, n;
int a[111111];
signed main() {
cin >> k >> n;
rep(i, n) cin >> a[i];
a[n] = a[0] + k;
int ans = 0;
rep(i, n) { ans = max(a[i + 1] - a[i], ans); }
cout << k - ans << endl;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X) \
{}
#define ARDEB(i, X) \
{}
#define END \
{}
#endif
typedef long long ll;
typedef pair<int, int> P;
struct edge {
int to, cost;
};
int ceil2(int a, int b) {
if (a % b) {
return a / b + 1;
} else {
return a / b;
}
}
using namespace std;
int k, n;
int a[211111];
signed main() {
cin >> k >> n;
rep(i, n) cin >> a[i];
a[n] = a[0] + k;
int ans = 0;
rep(i, n) { ans = max(a[i + 1] - a[i], ans); }
cout << k - ans << endl;
}
| replace | 50 | 51 | 50 | 51 | 0 | |
p02725 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int a[100005];
int k, n;
cin >> k >> n;
a[0] = 0;
a[n + 1] = k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int ans = a[n] - a[1];
for (int i = 1; i <= n; i++) {
ans = min(ans, k - (a[i + 1] - a[i]));
ans = min(ans, k - (a[i] - a[i - 1]));
}
printf("%d\n", ans);
}
| #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int a[200005];
int k, n;
cin >> k >> n;
a[0] = 0;
a[n + 1] = k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
int ans = a[n] - a[1];
for (int i = 1; i <= n; i++) {
ans = min(ans, k - (a[i + 1] - a[i]));
ans = min(ans, k - (a[i] - a[i - 1]));
}
printf("%d\n", ans);
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p02725 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int K, N;
cin >> K >> N;
int house[20010];
int ans = 0;
for (int i = 0; i < N; i++) {
cin >> house[i];
}
for (int i = 0; i < N - 1; i++) {
ans = max(house[i + 1] - house[i], ans);
}
ans = max(K - house[N - 1] + house[0], ans);
cout << K - ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int K, N;
cin >> K >> N;
int house[200010];
int ans = 0;
for (int i = 0; i < N; i++) {
cin >> house[i];
}
for (int i = 0; i < N - 1; i++) {
ans = max(house[i + 1] - house[i], ans);
}
ans = max(K - house[N - 1] + house[0], ans);
cout << K - ans << endl;
return 0;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p02725 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int K, N;
vector<int> A(N);
cin >> K >> N;
for (int i = 0; i < N; i++)
cin >> A[i];
int ans = A[N - 1] - A[0];
for (int i = 0; i < N - 1; i++) {
if (K - (A[i + 1] - A[i]) < ans)
ans = K - (A[i + 1] - A[i]);
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long long K, N;
vector<long long> A(N);
cin >> K >> N;
for (int i = 0; i < N; i++)
cin >> A[i];
int ans = A[N - 1] - A[0];
for (int i = 0; i < N - 1; i++) {
if (K - (A[i + 1] - A[i]) < ans)
ans = K - (A[i + 1] - A[i]);
}
cout << ans << endl;
}
| replace | 5 | 7 | 5 | 7 | -6 | terminate called after throwing an instance of 'std::length_error'
what(): cannot create std::vector larger than max_size()
|
p02725 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int K, N;
cin >> K >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A.at(i);
}
sort(A.begin(), A.end());
reverse(A.begin(), A.end());
int distance = K - A.at(0) + A.at(N - 1);
for (int i = 0; i < N; i++) {
if (distance < A.at(i) - A.at(i + 1)) {
distance = A.at(i) - A.at(i + 1);
}
}
int ans = K - distance;
printf("%d", ans);
} | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int K, N;
cin >> K >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A.at(i);
}
sort(A.begin(), A.end());
reverse(A.begin(), A.end());
int distance = K - A.at(0) + A.at(N - 1);
for (int i = 0; i < N - 1; i++) {
if (distance < A.at(i) - A.at(i + 1)) {
distance = A.at(i) - A.at(i + 1);
}
}
int ans = K - distance;
printf("%d", ans);
} | replace | 12 | 13 | 12 | 13 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 3) >= this->size() (which is 3)
|
p02725 | C++ | Runtime Error | #define __LOCAL_DEBUG__
#include <bits/stdc++.h>
using namespace std;
#ifdef __LOCAL_DEBUG__
#define _debug(x) \
{ cerr << "\033[94m" << __func__ << " " << #x << ": " << (x) << "\n\033[0m"; }
#else
#define _debug(x) \
{ ((void)0); }
#endif
#define rep(i, n) for (int i = (0); i < (n); i++)
#define repp(i, a, b) for (int i = (a); i < (b); i++)
#define CLR(x, v) memset(x, v, sizeof(x))
#define all(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
template <class T> inline void amin(T &x, const T &y) {
if (y < x)
x = y;
}
template <class T> inline void amax(T &x, const T &y) {
if (x < y)
x = y;
}
using ll = signed long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int MAXN = 700;
const int N = 100005;
// #define __LOCAL_DEBUG__
int n, k;
int a[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
scanf("%d%d", &n, &k);
repp(i, 1, k + 1) scanf("%d", a + i);
a[0] = a[k];
int ma = 0;
repp(i, 1, k + 1) amax(ma, (a[i] - a[i - 1] + n) % n);
printf("%d\n", n - ma);
return 0;
}
| #define __LOCAL_DEBUG__
#include <bits/stdc++.h>
using namespace std;
#ifdef __LOCAL_DEBUG__
#define _debug(x) \
{ cerr << "\033[94m" << __func__ << " " << #x << ": " << (x) << "\n\033[0m"; }
#else
#define _debug(x) \
{ ((void)0); }
#endif
#define rep(i, n) for (int i = (0); i < (n); i++)
#define repp(i, a, b) for (int i = (a); i < (b); i++)
#define CLR(x, v) memset(x, v, sizeof(x))
#define all(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
template <class T> inline void amin(T &x, const T &y) {
if (y < x)
x = y;
}
template <class T> inline void amax(T &x, const T &y) {
if (x < y)
x = y;
}
using ll = signed long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int MAXN = 700;
const int N = 200005;
// #define __LOCAL_DEBUG__
int n, k;
int a[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
scanf("%d%d", &n, &k);
repp(i, 1, k + 1) scanf("%d", a + i);
a[0] = a[k];
int ma = 0;
repp(i, 1, k + 1) amax(ma, (a[i] - a[i - 1] + n) % n);
printf("%d\n", n - ma);
return 0;
}
| replace | 35 | 36 | 35 | 36 | 0 | |
p02725 | C++ | Runtime Error | #include <bits/stdc++.h>
#define f(i, a, b) for (ll i = a; i < (ll)b; i++)
#define af(i, a, b) for (ll i = a; i >= (ll)b; i--)
#define rep(i, a, b, k) for (ll i = a; i < b; i += k)
#define arep(i, a, b, k) for (ll i = a; i >= b; i -= k)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort(a.begin(), a.end())
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define inter \
ios::sync_with_stdio(false); \
cin.tie(nullptr); \
cout.tie(nullptr)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
const ll MAX = 3e3 + 100;
ll a[MAX];
int main() {
fastio;
ll n, k, ans = 0;
cin >> k >> n;
f(i, 0, n) cin >> a[i];
sort(a, a + n);
ll x = a[0];
f(i, 0, n - 1) a[i] = a[i + 1] - a[i];
a[n - 1] = k - a[n - 1] + x;
sort(a, a + n);
ll sum = 0;
f(i, 0, n - 1) sum += a[i];
cout << sum << endl;
return 0;
} | #include <bits/stdc++.h>
#define f(i, a, b) for (ll i = a; i < (ll)b; i++)
#define af(i, a, b) for (ll i = a; i >= (ll)b; i--)
#define rep(i, a, b, k) for (ll i = a; i < b; i += k)
#define arep(i, a, b, k) for (ll i = a; i >= b; i -= k)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort(a.begin(), a.end())
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define inter \
ios::sync_with_stdio(false); \
cin.tie(nullptr); \
cout.tie(nullptr)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
const ll MAX = 3e5 + 100;
ll a[MAX];
int main() {
fastio;
ll n, k, ans = 0;
cin >> k >> n;
f(i, 0, n) cin >> a[i];
sort(a, a + n);
ll x = a[0];
f(i, 0, n - 1) a[i] = a[i + 1] - a[i];
a[n - 1] = k - a[n - 1] + x;
sort(a, a + n);
ll sum = 0;
f(i, 0, n - 1) sum += a[i];
cout << sum << endl;
return 0;
} | replace | 28 | 29 | 28 | 29 | 0 | |
p02725 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define pi pair<ll, ll>
using namespace std;
const ll N = 100010;
ll dis(ll x, ll y, ll n) { return n - min(abs(x - y), n - abs(x - y)); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n, m;
cin >> n >> m;
ll ar[m];
for (ll i = 0; i < m; ++i) {
cin >> ar[i];
}
ll ans = INT_MAX;
for (ll i = 0; i < n; ++i) {
ans = min(ans, dis(ar[i], ar[(i + 1) % m], n));
ans = min(ans, dis(ar[i], ar[(i - 1 + m) % m], n));
}
cout << ans;
return (0);
}
| #include <bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define pi pair<ll, ll>
using namespace std;
const ll N = 100010;
ll dis(ll x, ll y, ll n) { return n - min(abs(x - y), n - abs(x - y)); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n, m;
cin >> n >> m;
ll ar[m];
for (ll i = 0; i < m; ++i) {
cin >> ar[i];
}
ll ans = INT_MAX;
for (ll i = 0; i < m; ++i) {
ans = min(ans, dis(ar[i], ar[(i + 1) % m], n));
ans = min(ans, dis(ar[i], ar[(i - 1 + m) % m], n));
}
cout << ans;
return (0);
}
| replace | 24 | 25 | 24 | 25 | 0 | |
p02725 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int n, k;
int a[MAXN];
const int MOD = 1e9 + 7;
int main() {
cin >> k >> n;
int maxVal = -1;
cin >> a[0];
for (int i = 1; i < n; i++) {
cin >> a[i];
maxVal = max(maxVal, a[i] - a[i - 1]);
}
maxVal = max(maxVal, k - a[n - 1] + a[0]);
cout << k - maxVal;
} | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
int n, k;
int a[MAXN];
const int MOD = 1e9 + 7;
int main() {
cin >> k >> n;
int maxVal = -1;
cin >> a[0];
for (int i = 1; i < n; i++) {
cin >> a[i];
maxVal = max(maxVal, a[i] - a[i - 1]);
}
maxVal = max(maxVal, k - a[n - 1] + a[0]);
cout << k - maxVal;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02725 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long k, maX, ans, n, i;
long long a[100000];
int main() {
cin >> i >> n;
for (k = 1; k <= n; k++) {
cin >> a[k];
}
sort(a + 1, a + 1 + n);
for (k = 2; k <= n; k++) {
maX = max(a[k] - a[k - 1], maX);
}
maX = max(maX, a[1] - a[n] + i);
cout << i - maX;
} | #include <bits/stdc++.h>
using namespace std;
long long k, maX, ans, n, i;
long long a[10000000];
int main() {
cin >> i >> n;
for (k = 1; k <= n; k++) {
cin >> a[k];
}
sort(a + 1, a + 1 + n);
for (k = 2; k <= n; k++) {
maX = max(a[k] - a[k - 1], maX);
}
maX = max(maX, a[1] - a[n] + i);
cout << i - maX;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02725 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define MOD 1000000007
#define A first
#define B second
#define all(x) (x).begin(), (x).end
typedef long long ll;
inline int mulmd(ll a, ll b) {
ll ret = (a * b) % MOD;
return (int)ret;
}
inline int power(ll x, ll y, int m) {
ll res = 1;
x = x % m;
while (y > 0) {
if (y & 1) {
res = mulmd(res, x);
}
y = y >> 1;
x = mulmd(x, x);
}
return (int)res;
}
inline int submd(ll a, ll b) {
ll ret = (a - b);
if (ret < 0)
ret += MOD;
return (int)ret;
}
inline int addmd(ll a, ll b) {
ll ret = (a + b) % MOD;
return (int)ret;
}
inline int invPow(ll a) { return power(a, MOD - 2, MOD); }
inline int divmd(ll a, ll b) {
ll ret = mulmd(a, invPow(b));
return (int)ret;
}
const int N = 1e5 + 5;
int arr[N];
void solve() {
int k, n;
cin >> k >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
vector<int> diff;
for (int i = 1; i < n; i++) {
diff.push_back(arr[i] - arr[i - 1]);
}
diff.push_back(k - arr[n - 1] + arr[0]);
sort(diff.begin(), diff.end());
int ans = k - diff[diff.size() - 1];
cout << ans;
}
int main() {
int t;
t = 1;
// cin >> t;
while (t--) {
solve();
}
}
| #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define MOD 1000000007
#define A first
#define B second
#define all(x) (x).begin(), (x).end
typedef long long ll;
inline int mulmd(ll a, ll b) {
ll ret = (a * b) % MOD;
return (int)ret;
}
inline int power(ll x, ll y, int m) {
ll res = 1;
x = x % m;
while (y > 0) {
if (y & 1) {
res = mulmd(res, x);
}
y = y >> 1;
x = mulmd(x, x);
}
return (int)res;
}
inline int submd(ll a, ll b) {
ll ret = (a - b);
if (ret < 0)
ret += MOD;
return (int)ret;
}
inline int addmd(ll a, ll b) {
ll ret = (a + b) % MOD;
return (int)ret;
}
inline int invPow(ll a) { return power(a, MOD - 2, MOD); }
inline int divmd(ll a, ll b) {
ll ret = mulmd(a, invPow(b));
return (int)ret;
}
const int N = 2e5 + 5;
int arr[N];
void solve() {
int k, n;
cin >> k >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
vector<int> diff;
for (int i = 1; i < n; i++) {
diff.push_back(arr[i] - arr[i - 1]);
}
diff.push_back(k - arr[n - 1] + arr[0]);
sort(diff.begin(), diff.end());
int ans = k - diff[diff.size() - 1];
cout << ans;
}
int main() {
int t;
t = 1;
// cin >> t;
while (t--) {
solve();
}
}
| replace | 60 | 61 | 60 | 61 | 0 | |
p02725 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef string str;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef map<str, int> mapsi;
typedef map<str, int>::iterator mapsitr;
typedef map<int, int> mint;
typedef map<ll, ll> mll;
typedef set<int> si;
typedef set<ll> sll;
typedef si ::iterator sitr;
typedef si ::reverse_iterator rsitr;
typedef sll ::iterator sltr;
typedef sll ::reverse_iterator rsltr;
#define mset multiset
typedef mset<int> msi;
typedef mset<ll> msll;
typedef msi ::iterator msitr;
typedef msi ::reverse_iterator msritr;
typedef msll ::iterator msltr;
typedef msll ::reverse_iterator mslritr;
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
#define ordered_multiset \
tree<int, null_type, less_equal<int>, rb_tree_tag, \
tree_order_statistics_node_update>
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
#define fbo find_by_order
#define ook order_of_key
#define all(x) (x).begin(), x.end()
char to_upper(char x) {
if (97 <= int(x) && int(x) <= 122)
return char(x - 32);
if (65 <= int(x) && int(x) <= 90)
return x;
return -1;
}
char to_lower(char x) {
if (97 <= int(x) && int(x) <= 122)
return x;
if (65 <= int(x) && int(x) <= 90)
return char(x + 32);
return -1;
}
int numerize(char x) {
if (48 <= int(x) && int(x) <= 57)
return int(x - '0');
if (97 <= int(x) && int(x) <= 122)
return int(x - 96);
if (65 <= int(x) && int(x) <= 90)
return int(x - 64);
return -1;
}
bool isect(int l1, int r1, int l2, int r2) {
pii p1, p2;
p1 = mp(l1, r1);
p2 = mp(l2, r2);
if (p1 > p2)
swap(p1, p2);
if (p2.fi <= p1.se)
return true;
else
return false;
}
ll quickpow(ll num1, ll num2, ll MOD) {
if (num2 == 0)
return 1 % MOD;
else if (num2 == 1)
return num1 % MOD;
else {
ll temp = quickpow(num1, num2 / 2, MOD);
ll res = ((temp % MOD) * (temp % MOD)) % MOD;
if (num2 % 2 == 1)
res = ((res % MOD) * (num1 % MOD)) % MOD;
return res;
}
}
ll invmod(ll num, ll MOD) { return quickpow(num, MOD - 2, MOD); }
ll gcd(ll num1, ll num2) {
if (num1 < num2)
swap(num1, num2);
ll num3 = num1 % num2;
while (num3 > 0) {
num1 = num2;
num2 = num3;
num3 = num1 % num2;
}
return num2;
}
ll lcm(ll num1, ll num2) { return (ll)(num1 / __gcd(num1, num2)) * num2; }
// end of Template
int n, k;
int mx = 0;
int a[100010];
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> k >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (i > 1)
mx = max(mx, a[i] - a[i - 1]);
}
mx = max(mx, (k - a[n]) + a[1]);
int ans = k - mx;
cout << ans << newl;
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef string str;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef map<str, int> mapsi;
typedef map<str, int>::iterator mapsitr;
typedef map<int, int> mint;
typedef map<ll, ll> mll;
typedef set<int> si;
typedef set<ll> sll;
typedef si ::iterator sitr;
typedef si ::reverse_iterator rsitr;
typedef sll ::iterator sltr;
typedef sll ::reverse_iterator rsltr;
#define mset multiset
typedef mset<int> msi;
typedef mset<ll> msll;
typedef msi ::iterator msitr;
typedef msi ::reverse_iterator msritr;
typedef msll ::iterator msltr;
typedef msll ::reverse_iterator mslritr;
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
#define ordered_multiset \
tree<int, null_type, less_equal<int>, rb_tree_tag, \
tree_order_statistics_node_update>
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
#define fbo find_by_order
#define ook order_of_key
#define all(x) (x).begin(), x.end()
char to_upper(char x) {
if (97 <= int(x) && int(x) <= 122)
return char(x - 32);
if (65 <= int(x) && int(x) <= 90)
return x;
return -1;
}
char to_lower(char x) {
if (97 <= int(x) && int(x) <= 122)
return x;
if (65 <= int(x) && int(x) <= 90)
return char(x + 32);
return -1;
}
int numerize(char x) {
if (48 <= int(x) && int(x) <= 57)
return int(x - '0');
if (97 <= int(x) && int(x) <= 122)
return int(x - 96);
if (65 <= int(x) && int(x) <= 90)
return int(x - 64);
return -1;
}
bool isect(int l1, int r1, int l2, int r2) {
pii p1, p2;
p1 = mp(l1, r1);
p2 = mp(l2, r2);
if (p1 > p2)
swap(p1, p2);
if (p2.fi <= p1.se)
return true;
else
return false;
}
ll quickpow(ll num1, ll num2, ll MOD) {
if (num2 == 0)
return 1 % MOD;
else if (num2 == 1)
return num1 % MOD;
else {
ll temp = quickpow(num1, num2 / 2, MOD);
ll res = ((temp % MOD) * (temp % MOD)) % MOD;
if (num2 % 2 == 1)
res = ((res % MOD) * (num1 % MOD)) % MOD;
return res;
}
}
ll invmod(ll num, ll MOD) { return quickpow(num, MOD - 2, MOD); }
ll gcd(ll num1, ll num2) {
if (num1 < num2)
swap(num1, num2);
ll num3 = num1 % num2;
while (num3 > 0) {
num1 = num2;
num2 = num3;
num3 = num1 % num2;
}
return num2;
}
ll lcm(ll num1, ll num2) { return (ll)(num1 / __gcd(num1, num2)) * num2; }
// end of Template
int n, k;
int mx = 0;
int a[200010];
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> k >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
if (i > 1)
mx = max(mx, a[i] - a[i - 1]);
}
mx = max(mx, (k - a[n]) + a[1]);
int ans = k - mx;
cout << ans << newl;
}
| replace | 125 | 126 | 125 | 126 | 0 | |
p02725 | C++ | Runtime Error | /*
NO
TIME
TO
DIE
--007
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
// #include <boost/functional/hash.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
lli mod = 998244353;
#define OS // single input use oeis
lli INF = 1e17;
lli eps = 1e-8;
#define IO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define sqr(x) (x) * (x)
#define bip(n) __builtin_popcountll(n) // no of ones bit in binary!!
#define bictz(n) __builtin_ctzll(n) // no of trailing zeroes in binary!!
#define biclz(n) __builtin_clzll(n) // no of leading zeroes in binary!!
#define bffs(n) __builtin_ffsll(n) // index of first one bit!!
typedef pair<lli, lli> ll;
#define mem1(a, x) fill(&a[0], &a[0] + sizeof(a) / sizeof(a[0]), x)
#define mem2(a, x) fill(&a[0][0], &a[0][0] + sizeof(a) / sizeof(a[0][0]), x)
#define mem3(a, x) \
fill(&a[0][0][0], &a[0][0][0] + sizeof(a) / sizeof(a[0][0][0]), x)
#define fi1 ifstream fin("input.txt")
#define of1 ofstream fout("output.txt")
int fmx(int x, int y) { return (((y - x) >> (31)) & (x ^ y)) ^ y; }
int fmi(int x, int y) { return (((y - x) >> (31)) & (x ^ y)) ^ x; }
typedef tree<lli, null_type, less<lli>, rb_tree_tag,
tree_order_statistics_node_update>
ost;
lli n, z, k, x, m, d, y, q, b, c;
const double pi = 3.14159265358979323846;
// double dp[100005];
// bool cmp
lli dp[200005];
lli back[200005];
lli ans[200005];
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
IO;
OS;
cin >> k >> n;
lli a[n + 1];
lli mx = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
if (i == 1)
mx = max(mx, a[1] + k - a[n]);
else
mx = max(mx, a[i] - a[i - 1]);
}
cout << k - mx;
} | /*
NO
TIME
TO
DIE
--007
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
// #include <boost/functional/hash.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
lli mod = 998244353;
#define OS // single input use oeis
lli INF = 1e17;
lli eps = 1e-8;
#define IO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define sqr(x) (x) * (x)
#define bip(n) __builtin_popcountll(n) // no of ones bit in binary!!
#define bictz(n) __builtin_ctzll(n) // no of trailing zeroes in binary!!
#define biclz(n) __builtin_clzll(n) // no of leading zeroes in binary!!
#define bffs(n) __builtin_ffsll(n) // index of first one bit!!
typedef pair<lli, lli> ll;
#define mem1(a, x) fill(&a[0], &a[0] + sizeof(a) / sizeof(a[0]), x)
#define mem2(a, x) fill(&a[0][0], &a[0][0] + sizeof(a) / sizeof(a[0][0]), x)
#define mem3(a, x) \
fill(&a[0][0][0], &a[0][0][0] + sizeof(a) / sizeof(a[0][0][0]), x)
#define fi1 ifstream fin("input.txt")
#define of1 ofstream fout("output.txt")
int fmx(int x, int y) { return (((y - x) >> (31)) & (x ^ y)) ^ y; }
int fmi(int x, int y) { return (((y - x) >> (31)) & (x ^ y)) ^ x; }
typedef tree<lli, null_type, less<lli>, rb_tree_tag,
tree_order_statistics_node_update>
ost;
lli n, z, k, x, m, d, y, q, b, c;
const double pi = 3.14159265358979323846;
// double dp[100005];
// bool cmp
lli dp[200005];
lli back[200005];
lli ans[200005];
int main() {
IO;
OS;
cin >> k >> n;
lli a[n + 1];
lli mx = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
if (i == 1)
mx = max(mx, a[1] + k - a[n]);
else
mx = max(mx, a[i] - a[i - 1]);
}
cout << k - mx;
} | replace | 48 | 52 | 48 | 49 | 0 | |
p02725 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int k, n, a[200010], minn;
int main() {
cin >> k >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
for (int i = 0; i < n; i++) {
int ans = 0;
int j = i;
int f = (i == 0) ? (n - 1) : (i - 1);
while (1) {
ans = ans + (a[j + 1] - a[j] + k) % k;
j++;
j %= n;
if (j == f)
break;
}
if (i == 0)
minn = ans;
else
minn = min(minn, ans);
}
cout << minn;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int k, n, a[200010], minn;
int main() {
cin >> k >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
for (int i = 0; i < n; i++) {
int ans = 0;
int f = (i + n - 1) % n;
ans = (a[f] - a[i] + k) % k;
if (i == 0)
minn = ans;
else
minn = min(minn, ans);
}
cout << minn;
return 0;
} | replace | 11 | 20 | 11 | 13 | TLE | |
p02725 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define mod 1e9 + 7;
#define INF 1e9 + 9;
#define ps(x, y) fixed << setprecision(y) << x
#define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int k, n;
cin >> k >> n;
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
int maxi = -1;
for (int i = 0; i < n - 1; i++)
maxi = max(maxi, a[i + 1] - a[i]);
maxi = max(maxi, k - a[n - 1] + a[0]);
cout << k - maxi << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define mod 1e9 + 7;
#define INF 1e9 + 9;
#define ps(x, y) fixed << setprecision(y) << x
#define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
#endif
int k, n;
cin >> k >> n;
int a[n];
for (int i = 0; i < n; i++)
cin >> a[i];
int maxi = -1;
for (int i = 0; i < n - 1; i++)
maxi = max(maxi, a[i + 1] - a[i]);
maxi = max(maxi, k - a[n - 1] + a[0]);
cout << k - maxi << endl;
return 0;
} | replace | 14 | 16 | 14 | 16 | 0 | |
p02725 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
int a[100010];
int main() {
int n, k;
cin >> k >> n;
int mx = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (i != 0) {
mx = max(mx, a[i] - a[i - 1]);
}
}
mx = max(mx, a[0] + k - a[n - 1]);
cout << k - mx << endl;
return 0;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
int a[200010];
int main() {
int n, k;
cin >> k >> n;
int mx = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (i != 0) {
mx = max(mx, a[i] - a[i - 1]);
}
}
mx = max(mx, a[0] + k - a[n - 1]);
cout << k - mx << endl;
return 0;
} | replace | 24 | 25 | 24 | 25 | 0 | |
p02725 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 100;
ll a[maxn];
int main() {
int n, k;
cin >> k >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
a[n + 1] = k + a[1];
n++;
ll sum = 0, mx = 0;
for (int i = 2; i <= n; i++) {
sum += a[i] - a[i - 1];
mx = max(mx, a[i] - a[i - 1]);
}
sum -= mx;
cout << sum << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 3e5 + 100;
ll a[maxn];
int main() {
int n, k;
cin >> k >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
a[n + 1] = k + a[1];
n++;
ll sum = 0, mx = 0;
for (int i = 2; i <= n; i++) {
sum += a[i] - a[i - 1];
mx = max(mx, a[i] - a[i - 1]);
}
sum -= mx;
cout << sum << endl;
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02725 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
int a[100005];
void solve() {
int k, n;
cin >> k >> n;
int ans = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
ans = a[n - 1] - a[0];
for (int i = 1; i < n; i++) {
ans = min(ans, k - a[i] + a[i - 1]);
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin>> t;
while (t--)
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
int a[200005];
void solve() {
int k, n;
cin >> k >> n;
int ans = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
ans = a[n - 1] - a[0];
for (int i = 1; i < n; i++) {
ans = min(ans, k - a[i] + a[i - 1]);
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin>> t;
while (t--)
solve();
return 0;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p02725 | C++ | Runtime Error | // Best practice
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define pf emplace_front
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pii pair<int, int>
#define psi pair<string, int>
#define vi vector<int>
#define vpii vector<pii>
#define vvi vector<vi>
#define sz(x) (int)(x).size()
#define x first
#define y second
#define endl '\n'
#define tezz \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define MOD 1000000007
#define hell 998244353
#define output(x) cout << (x ? "YES" : "NO") << endl;
using namespace std;
// Code from Here
// -------------------------------------------------------------------------------
signed main() {
tezz
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int p, n;
cin >> p >> n;
int dis = 0;
vi a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
if (i != 0) {
dis = max(dis, a[i] - a[i - 1]);
}
}
dis = max(dis, a[0] + p - a[n - 1]);
cout << p - dis;
return 0;
}
| // Best practice
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define pf emplace_front
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pii pair<int, int>
#define psi pair<string, int>
#define vi vector<int>
#define vpii vector<pii>
#define vvi vector<vi>
#define sz(x) (int)(x).size()
#define x first
#define y second
#define endl '\n'
#define tezz \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define MOD 1000000007
#define hell 998244353
#define output(x) cout << (x ? "YES" : "NO") << endl;
using namespace std;
// Code from Here
// -------------------------------------------------------------------------------
signed main() {
tezz int p, n;
cin >> p >> n;
int dis = 0;
vi a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
if (i != 0) {
dis = max(dis, a[i] - a[i - 1]);
}
}
dis = max(dis, a[0] + p - a[n - 1]);
cout << p - dis;
return 0;
}
| replace | 31 | 39 | 31 | 32 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p02725 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int k, n;
cin >> k >> n;
int a[100001];
for (int i = 0; i < n; i++)
cin >> a[i];
int m, ans;
ans = a[n - 1] - a[0];
for (int i = 0; i < n - 1; i++) {
int s = (k - a[i + 1]) + a[i];
ans = min(ans, s);
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int k, n;
cin >> k >> n;
int a[200001];
for (int i = 0; i < n; i++)
cin >> a[i];
int m, ans;
ans = a[n - 1] - a[0];
for (int i = 0; i < n - 1; i++) {
int s = (k - a[i + 1]) + a[i];
ans = min(ans, s);
}
cout << ans << endl;
return 0;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p02725 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int K, N, maxv = 0;
int A[100000];
cin >> K >> N;
for (int i = 0; i < N; i++) {
cin >> A[i];
}
maxv = K - A[N - 1] + A[0];
for (int i = 0; i < N; i++) {
maxv = max(maxv, A[i + 1] - A[i]);
}
cout << K - maxv << endl;
}
| #include <iostream>
using namespace std;
int main() {
int K, N, maxv = 0;
int A[1000000];
cin >> K >> N;
for (int i = 0; i < N; i++) {
cin >> A[i];
}
maxv = K - A[N - 1] + A[0];
for (int i = 0; i < N; i++) {
maxv = max(maxv, A[i + 1] - A[i]);
}
cout << K - maxv << endl;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p02725 | C++ | Runtime Error | #include <algorithm>
#include <stdio.h>
int main(void) {
int k, n, a[100000000], b[10000000], i, p = 0, l;
scanf("%d%d", &k, &n);
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (i != 0) {
b[i] = a[i] - a[i - 1];
}
}
b[0] = k - a[n - 1] + a[0];
std::sort(b, b + n);
for (i = 0; i < n - 1; i++) {
p += b[i];
}
printf("%d\n", p);
return 0;
}
| #include <algorithm>
#include <stdio.h>
int main(void) {
int k, n, a[10000000], b[10000000], i, p = 0, l;
scanf("%d%d", &k, &n);
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (i != 0) {
b[i] = a[i] - a[i - 1];
}
}
b[0] = k - a[n - 1] + a[0];
std::sort(b, b + n);
for (i = 0; i < n - 1; i++) {
p += b[i];
}
printf("%d\n", p);
return 0;
}
| replace | 3 | 4 | 3 | 4 | -11 | |
p02725 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
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;
}
signed main() {
int k, n;
cin >> k >> n;
int a[100010];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
a[n] = k + a[0];
int ans = k;
for (int i = 0; i < n; i++) {
chmin(ans, k - (a[i + 1] - a[i]));
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
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;
}
signed main() {
int k, n;
cin >> k >> n;
int a[200010];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
a[n] = k + a[0];
int ans = k;
for (int i = 0; i < n; i++) {
chmin(ans, k - (a[i + 1] - a[i]));
}
cout << ans << endl;
return 0;
}
| replace | 22 | 23 | 22 | 23 | 0 | |
p02725 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, i;
long long sum = 0;
long long arr[100005];
scanf("%lld%lld", &n, &k);
for (i = 0; i < k; i++) {
scanf("%lld", &arr[i]);
}
sort(arr, arr + k);
for (i = 1; i < k; i++) {
sum = max(sum, arr[i] - arr[i - 1]);
}
sum = max(sum, n - arr[k - 1] + arr[0]);
printf("%lld", n - sum);
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, i;
long long sum = 0;
long long arr[200005];
scanf("%lld%lld", &n, &k);
for (i = 0; i < k; i++) {
scanf("%lld", &arr[i]);
}
sort(arr, arr + k);
for (i = 1; i < k; i++) {
sum = max(sum, arr[i] - arr[i - 1]);
}
sum = max(sum, n - arr[k - 1] + arr[0]);
printf("%lld", n - sum);
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02725 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << #x << " " << x << endl;
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n) for (int i = k; i < n; i++)
#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define ll long long
#define pb push_back
#define endl "\n"
#define mp map<int, int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
void c_p_c() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
int main() {
c_p_c();
int k, m;
cin >> k >> m;
int a[m];
fo(i, m) cin >> a[i];
int ans = a[m - 1] - a[0];
Fo(i, 1, m) { ans = min(a[i - 1] + k - a[i], ans); }
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << #x << " " << x << endl;
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n) for (int i = k; i < n; i++)
#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define ll long long
#define pb push_back
#define endl "\n"
#define mp map<int, int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
void c_p_c() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
}
int main() {
c_p_c();
int k, m;
cin >> k >> m;
int a[m];
fo(i, m) cin >> a[i];
int ans = a[m - 1] - a[0];
Fo(i, 1, m) { ans = min(a[i - 1] + k - a[i], ans); }
cout << ans << endl;
return 0;
} | replace | 22 | 26 | 22 | 26 | 0 | |
p02725 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int K, N, a;
cin >> K >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A.at(i);
}
a = K + A.at(0) - A.at(N - 1);
for (int i = 0; i < N; i++) {
if (A.at(i + 1) - A.at(i) > a) {
a = A.at(i + 1) - A.at(i);
}
}
cout << K - a << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int K, N, a;
cin >> K >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A.at(i);
}
a = K + A.at(0) - A.at(N - 1);
for (int i = 0; i < N - 1; i++) {
if (A.at(i + 1) - A.at(i) > a) {
a = A.at(i + 1) - A.at(i);
}
}
cout << K - a << endl;
} | replace | 10 | 11 | 10 | 11 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 3) >= this->size() (which is 3)
|
p02725 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 2 * 100 * 1000 + 20;
int n, k, a[N], ans;
int main() {
cin >> k >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 1; i < k; i++)
ans = max(ans, a[i] - a[i - 1]);
ans = max(ans, a[0] + k - a[n - 1]);
return cout << k - ans << "\n", 0;
} | #include <bits/stdc++.h>
using namespace std;
const int N = 2 * 100 * 1000 + 20;
int n, k, a[N], ans;
int main() {
cin >> k >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 1; i < n; i++)
ans = max(ans, a[i] - a[i - 1]);
ans = max(ans, a[0] + k - a[n - 1]);
return cout << k - ans << "\n", 0;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p02725 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
// #include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i <= (n); i++)
#define mp make_pair
#define all(x) x.begin(), x.end()
using namespace std;
int k, n, a[123456];
signed main() {
cin >> k >> n;
for1(i, n) cin >> a[i];
int ans = a[n] - a[1];
for1(i, n - 1) ans = min(ans, a[i] + k - a[i + 1]);
cout << ans << endl;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
// #include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i <= (n); i++)
#define mp make_pair
#define all(x) x.begin(), x.end()
using namespace std;
int k, n, a[234536];
signed main() {
cin >> k >> n;
for1(i, n) cin >> a[i];
int ans = a[n] - a[1];
for1(i, n - 1) ans = min(ans, a[i] + k - a[i + 1]);
cout << ans << endl;
} | replace | 13 | 14 | 13 | 14 | 0 | |
p02725 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[100005];
int main() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= k; i++) {
cin >> a[i];
}
int ans = 1e9;
for (int i = 1; i <= k; i++) {
if (i == 1)
ans = min(ans, n - (a[1] + n - a[k]));
else
ans = min(ans, n - (a[i] - a[i - 1]));
}
cout << ans;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[1000005];
int main() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= k; i++) {
cin >> a[i];
}
int ans = 1e9;
for (int i = 1; i <= k; i++) {
if (i == 1)
ans = min(ans, n - (a[1] + n - a[k]));
else
ans = min(ans, n - (a[i] - a[i - 1]));
}
cout << ans;
return 0;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p02726 | C++ | Runtime Error | #include <cstring>
#include <iostream>
#include <set>
using namespace std;
int n, x, y;
int ans[1001], viz[1001];
int modul(int x, int y) {
if (x > y)
return x - y;
else
return y - x;
}
int main() {
cin >> n >> x >> y;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++) {
int minim = min(modul(j, i), min(modul(x, i) + 1 + modul(j, y),
modul(y, i) + 1 + modul(j, x)));
ans[minim]++;
}
for (int i = 1; i < n; i++)
cout << ans[i] << '\n';
return 0;
}
| #include <cstring>
#include <iostream>
#include <set>
using namespace std;
int n, x, y;
int ans[3003], viz[2001];
int modul(int x, int y) {
if (x > y)
return x - y;
else
return y - x;
}
int main() {
cin >> n >> x >> y;
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++) {
int minim = min(modul(j, i), min(modul(x, i) + 1 + modul(j, y),
modul(y, i) + 1 + modul(j, x)));
ans[minim]++;
}
for (int i = 1; i < n; i++)
cout << ans[i] << '\n';
return 0;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p02726 | C++ | Runtime Error | #include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define fr(j, p) for (int i = j; i < p; i++)
#define fastScan \
ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define inp(x, n) fr(0, n) cin >> x[i];
#define out(x, n) fr(0, n) cout << x[i] << " ";
#define test \
int t; \
cin >> t; \
while (t--)
#define YESF \
if (flag == 0) \
cout << "YES" << endl; \
else \
cout << "NO" << endl;
#define yesf \
if (flag == 0) \
cout << "Yes" << endl; \
else \
cout << "No" << endl;
const long long md = 1e9 + 7;
using namespace std;
int main() {
int n, x, y;
cin >> n >> x >> y;
int dp[n][n];
x--, y--;
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; i++) {
dp[i][i] = 0;
}
for (int i = 0; i < n - 1; i++) {
dp[i][i + 1] = 1;
}
dp[x][y] = 1;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int temp1 = x - i;
int temp2 = j - y;
if (temp1 >= 0 && temp2 >= 0) {
dp[i][j] = 1 + temp1 + temp2;
} else if (temp1 < 0 && temp2 >= 0) {
dp[i][j] = min(i - x + 1 + temp2, j - i);
} else if (temp1 >= 0 && temp2 < 0)
dp[i][j] = (j - i, 1 + temp1 - temp2);
else
dp[i][j] = min(j - i, 1 - temp1 - temp2);
}
}
// for(int i=0; i<n ; i++){
// for(int j=0; j<n ; j++)
// {
// cout<<dp[i][j]<<" ";
// }
// cout<<endl;
// }
vector<int> ans(n, 0);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
ans[dp[i][j]]++;
}
}
for (int i = 1; i < n; i++)
cout << ans[i] << endl;
} | #include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define fr(j, p) for (int i = j; i < p; i++)
#define fastScan \
ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define inp(x, n) fr(0, n) cin >> x[i];
#define out(x, n) fr(0, n) cout << x[i] << " ";
#define test \
int t; \
cin >> t; \
while (t--)
#define YESF \
if (flag == 0) \
cout << "YES" << endl; \
else \
cout << "NO" << endl;
#define yesf \
if (flag == 0) \
cout << "Yes" << endl; \
else \
cout << "No" << endl;
const long long md = 1e9 + 7;
using namespace std;
int main() {
int n, x, y;
cin >> n >> x >> y;
int dp[n][n];
x--, y--;
memset(dp, 0, sizeof(dp));
for (int i = 0; i < n; i++) {
dp[i][i] = 0;
}
for (int i = 0; i < n - 1; i++) {
dp[i][i + 1] = 1;
}
dp[x][y] = 1;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int temp1 = x - i;
int temp2 = j - y;
if (temp1 >= 0 && temp2 >= 0) {
dp[i][j] = 1 + temp1 + temp2;
} else if (temp1 < 0 && temp2 >= 0) {
dp[i][j] = min(i - x + 1 + temp2, j - i);
} else if (temp1 >= 0 && temp2 < 0)
dp[i][j] = min(j - i, 1 + temp1 - temp2);
else
dp[i][j] = min(j - i, 1 - temp1 - temp2);
}
}
// for(int i=0; i<n ; i++){
// for(int j=0; j<n ; j++)
// {
// cout<<dp[i][j]<<" ";
// }
// cout<<endl;
// }
vector<int> ans(n, 0);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
ans[dp[i][j]]++;
}
}
for (int i = 1; i < n; i++)
cout << ans[i] << endl;
} | replace | 64 | 65 | 64 | 65 | 0 | |
p02726 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
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;
}
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define P pair<ll, ll>
#define sz(x) (ll) x.size()
#define ALL(x) (x).begin(), (x).end()
#define ALLR(x) (x).rbegin(), (x).rend()
#define VE vector<ll>
#define COUT(x) cout << (x) << endl
#define MA map<ll, ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll, VE, greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define EPS (1e-14)
#define pb push_back
long long MOD = 1000000007;
// const long long MOD = 998244353;
const long long INF = 1LL << 60;
const double PI = acos(-1.0);
using Graph = vector<VE>;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime MOD
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
struct combination {
vector<mint> fact, ifact;
combination(int n) : fact(n + 1), ifact(n + 1) {
assert(n < MOD);
fact[0] = 1;
for (int i = 1; i <= n; ++i)
fact[i] = fact[i - 1] * i;
ifact[n] = fact[n].inv();
for (int i = n; i >= 1; --i)
ifact[i - 1] = ifact[i] * i;
}
mint operator()(int n, int k) {
if (k < 0 || k > n)
return 0;
return fact[n] * ifact[k] * ifact[n - k];
}
} com(10);
struct Sieve {
int n;
vector<int> f, primes;
Sieve(int n = 1) : n(n), f(n + 1) {
f[0] = f[1] = -1;
for (ll i = 2; i <= n; ++i) {
if (f[i])
continue;
primes.push_back(i);
f[i] = i;
for (ll j = i * i; j <= n; j += i) {
if (!f[j])
f[j] = i;
}
}
}
bool isPrime(int x) { return f[x] == x; }
vector<int> factorList(int x) {
vector<int> res;
while (x != 1) {
res.push_back(f[x]);
x /= f[x];
}
return res;
}
vector<P> factor(int x) {
vector<int> fl = factorList(x);
if (fl.size() == 0)
return {};
vector<P> res(1, P(fl[0], 0));
for (int p : fl) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
};
class UnionFind {
public:
vector<ll> par;
vector<ll> siz;
// Constructor
UnionFind(ll sz_) : par(sz_), siz(sz_, 1) {
for (ll i = 0; i < sz_; ++i)
par[i] = i;
}
void init(ll sz_) {
par.resize(sz_);
siz.resize(sz_, 1);
for (ll i = 0; i < sz_; ++i)
par[i] = i;
}
// Member Function
// Find
ll root(ll x) {
while (par[x] != x) {
x = par[x] = par[par[x]];
}
return x;
}
// Union(Unite, Merge)
bool merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (siz[x] < siz[y])
swap(x, y);
siz[x] += siz[y];
par[y] = x;
return true;
}
bool issame(ll x, ll y) { return root(x) == root(y); }
ll size(ll x) { return siz[root(x)]; }
};
template <class t> t gcd(t a, t b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
return a / g * b;
}
bool prime(ll n) {
for (ll i = 2; i <= sqrt(n); i++) {
if (n % i == 0)
return false;
}
return n != 1;
}
map<ll, ll> prime_factor(ll n) {
map<ll, ll> ret;
for (ll i = 2; i * i <= n; i++) {
while (n % i == 0) {
ret[i]++;
n /= i;
}
}
if (n != 1)
ret[n] = 1;
return ret;
}
ll modinv(ll a, ll m) {
ll b = m, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
vector<pair<char, int>> RunLength(string s) {
if (s.size() == 0)
return {};
vector<pair<char, int>> res(1, pair<char, int>(s[0], 0));
for (char p : s) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
// Digit Count
int GetDigit(int num) { return log10(num) + 1; }
// bit calculation[how many "1"] (= __builtin_popcount())
int bit_count(int n) {
int cnt = 0;
while (n > 0) {
if (n % 2 == 1)
cnt++;
n /= 2;
}
return cnt;
}
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, 1, 0, -1};
struct edge {
ll to, cost;
};
typedef long double ld;
int V;
vector<edge> G[1010];
int d[1010];
void dijkstra(int s) {
priority_queue<P, vector<P>, greater<P>> que;
fill(d, d + V, INF);
d[s] = 0;
que.push(P(0, s));
while (!que.empty()) {
P p = que.top();
que.pop();
int v = p.second;
if (d[v] < p.first)
continue;
rep(i, G[v].size()) {
edge e = G[v][i];
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
que.push(P(d[e.to], e.to));
}
}
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// cout << fixed << setprecision(15);
int n, x, y;
cin >> n >> x >> y;
x--;
y--;
V = n;
rep(i, n - 1) {
G[i].push_back({i + 1, 1});
G[i + 1].push_back({i, 1});
}
G[x].push_back({y, 1});
G[y].push_back({x, 1});
map<int, int> mp;
rep(i, n) {
dijkstra(i);
rep(j, n) { mp[d[j]]++; }
}
rep(i, n - 1) { cout << mp[i + 1] / 2 << endl; }
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
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;
}
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define P pair<ll, ll>
#define sz(x) (ll) x.size()
#define ALL(x) (x).begin(), (x).end()
#define ALLR(x) (x).rbegin(), (x).rend()
#define VE vector<ll>
#define COUT(x) cout << (x) << endl
#define MA map<ll, ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll, VE, greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define EPS (1e-14)
#define pb push_back
long long MOD = 1000000007;
// const long long MOD = 998244353;
const long long INF = 1LL << 60;
const double PI = acos(-1.0);
using Graph = vector<VE>;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime MOD
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
struct combination {
vector<mint> fact, ifact;
combination(int n) : fact(n + 1), ifact(n + 1) {
assert(n < MOD);
fact[0] = 1;
for (int i = 1; i <= n; ++i)
fact[i] = fact[i - 1] * i;
ifact[n] = fact[n].inv();
for (int i = n; i >= 1; --i)
ifact[i - 1] = ifact[i] * i;
}
mint operator()(int n, int k) {
if (k < 0 || k > n)
return 0;
return fact[n] * ifact[k] * ifact[n - k];
}
} com(10);
struct Sieve {
int n;
vector<int> f, primes;
Sieve(int n = 1) : n(n), f(n + 1) {
f[0] = f[1] = -1;
for (ll i = 2; i <= n; ++i) {
if (f[i])
continue;
primes.push_back(i);
f[i] = i;
for (ll j = i * i; j <= n; j += i) {
if (!f[j])
f[j] = i;
}
}
}
bool isPrime(int x) { return f[x] == x; }
vector<int> factorList(int x) {
vector<int> res;
while (x != 1) {
res.push_back(f[x]);
x /= f[x];
}
return res;
}
vector<P> factor(int x) {
vector<int> fl = factorList(x);
if (fl.size() == 0)
return {};
vector<P> res(1, P(fl[0], 0));
for (int p : fl) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
};
class UnionFind {
public:
vector<ll> par;
vector<ll> siz;
// Constructor
UnionFind(ll sz_) : par(sz_), siz(sz_, 1) {
for (ll i = 0; i < sz_; ++i)
par[i] = i;
}
void init(ll sz_) {
par.resize(sz_);
siz.resize(sz_, 1);
for (ll i = 0; i < sz_; ++i)
par[i] = i;
}
// Member Function
// Find
ll root(ll x) {
while (par[x] != x) {
x = par[x] = par[par[x]];
}
return x;
}
// Union(Unite, Merge)
bool merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (siz[x] < siz[y])
swap(x, y);
siz[x] += siz[y];
par[y] = x;
return true;
}
bool issame(ll x, ll y) { return root(x) == root(y); }
ll size(ll x) { return siz[root(x)]; }
};
template <class t> t gcd(t a, t b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
return a / g * b;
}
bool prime(ll n) {
for (ll i = 2; i <= sqrt(n); i++) {
if (n % i == 0)
return false;
}
return n != 1;
}
map<ll, ll> prime_factor(ll n) {
map<ll, ll> ret;
for (ll i = 2; i * i <= n; i++) {
while (n % i == 0) {
ret[i]++;
n /= i;
}
}
if (n != 1)
ret[n] = 1;
return ret;
}
ll modinv(ll a, ll m) {
ll b = m, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
vector<pair<char, int>> RunLength(string s) {
if (s.size() == 0)
return {};
vector<pair<char, int>> res(1, pair<char, int>(s[0], 0));
for (char p : s) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
// Digit Count
int GetDigit(int num) { return log10(num) + 1; }
// bit calculation[how many "1"] (= __builtin_popcount())
int bit_count(int n) {
int cnt = 0;
while (n > 0) {
if (n % 2 == 1)
cnt++;
n /= 2;
}
return cnt;
}
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, 1, 0, -1};
struct edge {
ll to, cost;
};
typedef long double ld;
int V;
vector<edge> G[2010];
int d[2010];
void dijkstra(int s) {
priority_queue<P, vector<P>, greater<P>> que;
fill(d, d + V, INF);
d[s] = 0;
que.push(P(0, s));
while (!que.empty()) {
P p = que.top();
que.pop();
int v = p.second;
if (d[v] < p.first)
continue;
rep(i, G[v].size()) {
edge e = G[v][i];
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
que.push(P(d[e.to], e.to));
}
}
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// cout << fixed << setprecision(15);
int n, x, y;
cin >> n >> x >> y;
x--;
y--;
V = n;
rep(i, n - 1) {
G[i].push_back({i + 1, 1});
G[i + 1].push_back({i, 1});
}
G[x].push_back({y, 1});
G[y].push_back({x, 1});
map<int, int> mp;
rep(i, n) {
dijkstra(i);
rep(j, n) { mp[d[j]]++; }
}
rep(i, n - 1) { cout << mp[i + 1] / 2 << endl; }
return 0;
} | replace | 295 | 297 | 295 | 297 | 0 | |
p02726 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, f, e) for (int(i) = (f); (i) < (e); (i)++)
#define repr(i, e, f) for (int(i) = (e - 1); (i) >= (f); (i)--)
const ll MOD = 1e9 + 7;
const int INF = (int)1e9 + 7;
// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
// for( int i = 0; i < N; i++ ){
// cin >> v >> w;
// items.push_back( make_tuple(v, w) ); // item : (value, weight)
// }
deque<int> G[2010];
int K[2010];
int main() {
int N, X, Y;
cin >> N >> X >> Y;
rep(i, 1, N) {
G[i].push_back(i + 1);
G[i + 1].push_back(i);
}
G[X].push_back(Y);
G[Y].push_back(X);
// rep(i,1,N+1){
// cout << i << " : ";
// for(auto j : G[i]){
// cout << j << " ";
// }
// cout << endl;
// }
rep(i, 1, N + 1) {
vector<int> dist(N + 1, -1);
queue<int> que;
dist[i] = 0;
for (int j = i - 1; j = 0; j--) {
dist[j] = INF;
}
que.push(i);
while (!que.empty()) {
int v = que.front(); // キューから先頭頂点を取り出す
que.pop();
// v から辿れる頂点をすべて調べる
for (int nv : G[v]) {
if (dist[nv] != -1)
continue; // すでに発見済みの頂点は探索しない
// 新たな白色頂点 nv について距離情報を更新してキューに追加する
dist[nv] = dist[v] + 1;
que.push(nv);
}
}
rep(k, 1, N) {
rep(v, i, N + 1) {
if (k == dist[v])
K[k] += 1;
}
}
}
rep(k, 1, N) { cout << K[k] << endl; }
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, f, e) for (int(i) = (f); (i) < (e); (i)++)
#define repr(i, e, f) for (int(i) = (e - 1); (i) >= (f); (i)--)
const ll MOD = 1e9 + 7;
const int INF = (int)1e9 + 7;
// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
// for( int i = 0; i < N; i++ ){
// cin >> v >> w;
// items.push_back( make_tuple(v, w) ); // item : (value, weight)
// }
deque<int> G[2010];
int K[2010];
int main() {
int N, X, Y;
cin >> N >> X >> Y;
rep(i, 1, N) {
G[i].push_back(i + 1);
G[i + 1].push_back(i);
}
G[X].push_back(Y);
G[Y].push_back(X);
// rep(i,1,N+1){
// cout << i << " : ";
// for(auto j : G[i]){
// cout << j << " ";
// }
// cout << endl;
// }
rep(i, 1, N + 1) {
vector<int> dist(N + 1, -1);
queue<int> que;
dist[i] = 0;
for (int j = i - 1; j = 0; j--) {
dist[j] = INF;
}
que.push(i);
while (!que.empty()) {
int v = que.front(); // キューから先頭頂点を取り出す
que.pop();
// v から辿れる頂点をすべて調べる
for (int nv : G[v]) {
if (dist[nv] != -1)
continue; // すでに発見済みの頂点は探索しない
// 新たな白色頂点 nv について距離情報を更新してキューに追加する
dist[nv] = dist[v] + 1;
que.push(nv);
}
}
rep(v, i, N + 1) { K[dist[v]] += 1; }
}
rep(k, 1, N) { cout << K[k] << endl; }
return 0;
} | replace | 65 | 71 | 65 | 66 | TLE | |
p02726 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define inf 1e9
const int mod = (int)1e9 + 7;
vector<int> adj[1005];
vector<int> vis(1005), dist(1005), ans(1005);
void bfs(int v) {
queue<int> q;
q.push(v);
vis[v] = 1;
dist[v] = 0;
while (!q.empty()) {
auto x = q.front();
q.pop();
for (auto u : adj[x]) {
if (vis[u])
continue;
q.push(u);
dist[u] = dist[x] + 1;
vis[u] = 1;
}
}
}
void test_case() {
int n, x, y;
cin >> n >> x >> y;
--x, --y;
for (int i = 0; i < n - 1; i++) {
adj[i].push_back(i + 1);
adj[i + 1].push_back(i);
}
adj[x].push_back(y);
adj[y].push_back(x);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
vis[j] = 0, dist[j] = 0;
bfs(i);
for (int j = 0; j < n; j++)
ans[dist[j]]++;
}
for (int i = 1; i <= n - 1; i++)
cout << ans[i] / 2 << "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin>>t;
while (t--)
test_case();
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define inf 1e9
const int mod = (int)1e9 + 7;
vector<int> adj[2005];
vector<int> vis(2005), dist(2005), ans(2005);
void bfs(int v) {
queue<int> q;
q.push(v);
vis[v] = 1;
dist[v] = 0;
while (!q.empty()) {
auto x = q.front();
q.pop();
for (auto u : adj[x]) {
if (vis[u])
continue;
q.push(u);
dist[u] = dist[x] + 1;
vis[u] = 1;
}
}
}
void test_case() {
int n, x, y;
cin >> n >> x >> y;
--x, --y;
for (int i = 0; i < n - 1; i++) {
adj[i].push_back(i + 1);
adj[i + 1].push_back(i);
}
adj[x].push_back(y);
adj[y].push_back(x);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)
vis[j] = 0, dist[j] = 0;
bfs(i);
for (int j = 0; j < n; j++)
ans[dist[j]]++;
}
for (int i = 1; i <= n - 1; i++)
cout << ans[i] / 2 << "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
// cin>>t;
while (t--)
test_case();
}
| replace | 9 | 11 | 9 | 11 | 0 | |
p02726 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
int main() {
int n, x, y;
cin >> n >> x >> y;
vector<int> distances(n);
rep(i, n) distances[i] = 0;
for (int i = 1; i <= n - 1; i++) {
for (int j = 1; j <= n; j++) {
int d = min(j - i, abs(x - i) + 1 + abs(y - j));
distances[d]++;
}
}
for (int i = 1; i < n; i++) {
cout << distances[i] << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
int main() {
int n, x, y;
cin >> n >> x >> y;
vector<int> distances(n);
rep(i, n) distances[i] = 0;
for (int i = 1; i <= n - 1; i++) {
for (int j = i + 1; j <= n; j++) {
int d = min(j - i, abs(x - i) + 1 + abs(y - j));
distances[d]++;
}
}
for (int i = 1; i < n; i++) {
cout << distances[i] << endl;
}
return 0;
} | replace | 11 | 12 | 11 | 12 | -6 | munmap_chunk(): invalid pointer
|
p02726 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int N, X, Y, i, j, ans, dist, list[2001] = {0};
// stdinから入力受付
cin >> N >> X >> Y;
X--;
Y--; // 0からの値に変換
// メイン処理
for (i = 0; i < N - 1; i++) { // 始点
for (j = i + 1; j < N; j++) { // 目的地
// 道を必ず通る場合
if (abs(i - X) < abs(i - Y))
dist = abs(i - X) + 1 + abs(j - Y);
else
dist = abs(i - Y) + 1 + abs(j - X);
// 直接行く場合と比較、短いほうをdistに入れる
if (j - i < dist)
dist = j - i;
// list配列のdist番目を1増やす
list[dist]++;
cerr << i << ' ' << j << ' ' << dist << endl; // デバッグ出力(stderr)
}
}
// 答えをstdoutに出力
for (i = 1; i < N; i++)
cout << list[i] << endl;
} | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int N, X, Y, i, j, ans, dist, list[2001] = {0};
// stdinから入力受付
cin >> N >> X >> Y;
X--;
Y--; // 0からの値に変換
// メイン処理
for (i = 0; i < N - 1; i++) { // 始点
for (j = i + 1; j < N; j++) { // 目的地
// 道を必ず通る場合
if (abs(i - X) < abs(i - Y))
dist = abs(i - X) + 1 + abs(j - Y);
else
dist = abs(i - Y) + 1 + abs(j - X);
// 直接行く場合と比較、短いほうをdistに入れる
if (j - i < dist)
dist = j - i;
// list配列のdist番目を1増やす
list[dist]++;
}
}
// 答えをstdoutに出力
for (i = 1; i < N; i++)
cout << list[i] << endl;
} | delete | 25 | 26 | 25 | 25 | TLE | |
p02726 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mem(a, b) memset(a, b, sizeof(a))
#define all(x) (x).begin(), (x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
inline void normal(ll &a) {
a %= MOD;
(a < 0) && (a += MOD);
}
inline ll modMul(ll a, ll b) {
a %= MOD, b %= MOD;
normal(a), normal(b);
return (a * b) % MOD;
}
inline ll modAdd(ll a, ll b) {
a %= MOD, b %= MOD;
normal(a), normal(b);
return (a + b) % MOD;
}
inline ll modSub(ll a, ll b) {
a %= MOD, b %= MOD;
normal(a), normal(b);
a -= b;
normal(a);
return a;
}
inline ll modPow(ll b, ll p) {
ll r = 1;
while (p) {
if (p & 1)
r = modMul(r, b);
b = modMul(b, b);
p >>= 1;
}
return r;
}
inline ll modInverse(ll a) { return modPow(a, MOD - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int ctoi(char c) {
if (c >= '0' && c <= '9') {
return c - '0';
}
return 0;
}
int main() {
int n, x, y;
cin >> n >> x >> y;
x--;
y--;
vvi a(n, vi(n));
rep(i, n) {
rep(j, n) {
if (i < j) {
a[i][j] = abs(i - j);
if ((i >= x && i <= y) && (j >= x && j <= y)) {
a[i][j] = min(a[i][j], (i - x) + 1 + (y - j));
}
if (x >= i && (j >= x && j <= y)) {
a[i][j] = min(a[i][j], (x - i) + 1 + (y - j));
}
if (j >= y && (i >= x && i <= y)) {
a[i][j] = min(a[i][j], (j - y) + 1 + (i - x));
}
if (i <= x && y <= j) {
a[i][j] = min(a[i][j], (x - i) + 1 + (j - y));
}
} else
a[i][j] = 100000000;
}
}
int d = 0, cnt = 0;
while (d < n - 1) {
d++;
rep(i, n) {
rep(j, n) {
if (a[i][j] == d) {
cnt++;
}
}
}
cout << cnt << endl;
cnt = 0;
}
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mem(a, b) memset(a, b, sizeof(a))
#define all(x) (x).begin(), (x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
inline void normal(ll &a) {
a %= MOD;
(a < 0) && (a += MOD);
}
inline ll modMul(ll a, ll b) {
a %= MOD, b %= MOD;
normal(a), normal(b);
return (a * b) % MOD;
}
inline ll modAdd(ll a, ll b) {
a %= MOD, b %= MOD;
normal(a), normal(b);
return (a + b) % MOD;
}
inline ll modSub(ll a, ll b) {
a %= MOD, b %= MOD;
normal(a), normal(b);
a -= b;
normal(a);
return a;
}
inline ll modPow(ll b, ll p) {
ll r = 1;
while (p) {
if (p & 1)
r = modMul(r, b);
b = modMul(b, b);
p >>= 1;
}
return r;
}
inline ll modInverse(ll a) { return modPow(a, MOD - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int ctoi(char c) {
if (c >= '0' && c <= '9') {
return c - '0';
}
return 0;
}
int main() {
int n, x, y;
cin >> n >> x >> y;
x--;
y--;
vvi a(n, vi(n));
rep(i, n) {
rep(j, n) {
if (i < j) {
a[i][j] = abs(i - j);
if ((i >= x && i <= y) && (j >= x && j <= y)) {
a[i][j] = min(a[i][j], (i - x) + 1 + (y - j));
}
if (x >= i && (j >= x && j <= y)) {
a[i][j] = min(a[i][j], (x - i) + 1 + (y - j));
}
if (j >= y && (i >= x && i <= y)) {
a[i][j] = min(a[i][j], (j - y) + 1 + (i - x));
}
if (i <= x && y <= j) {
a[i][j] = min(a[i][j], (x - i) + 1 + (j - y));
}
} else
a[i][j] = 100000000;
}
}
map<int, int> d;
rep(i, n) {
rep(j, n) { d[a[i][j]]++; }
}
for (int i = 1; i < n; ++i) {
cout << d[i] << endl;
}
}
| replace | 97 | 109 | 97 | 103 | TLE | |
p02726 | C++ | Runtime Error | // BISMILLAHIR RAHMANIR RAHIM
#include <bits/stdc++.h>
#define mem(a, b) (memset(a, b, sizeof(a)))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define INF 2147483647
#define MOD 1000000007
#define MAX 1005
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
typedef vector<ii> vii;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
int Set(int mask, int pos) { return mask = mask | (1 << pos); }
bool check(int mask, int pos) { return (bool)(mask & (1 << pos)); }
int cnt[1005];
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n, x, y;
cin >> n >> x >> y;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
int dist = j - i;
dist = min(dist, abs(i - x) + 1 + abs(y - j));
cnt[dist]++;
}
}
for (int i = 1; i <= n - 1; i++) {
cout << cnt[i] << endl;
}
}
| // BISMILLAHIR RAHMANIR RAHIM
#include <bits/stdc++.h>
#define mem(a, b) (memset(a, b, sizeof(a)))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define INF 2147483647
#define MOD 1000000007
#define MAX 1005
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
typedef vector<ii> vii;
typedef priority_queue<int, vector<int>, greater<int>> PQ;
int Set(int mask, int pos) { return mask = mask | (1 << pos); }
bool check(int mask, int pos) { return (bool)(mask & (1 << pos)); }
int cnt[2005];
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n, x, y;
cin >> n >> x >> y;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
int dist = j - i;
dist = min(dist, abs(i - x) + 1 + abs(y - j));
cnt[dist]++;
}
}
for (int i = 1; i <= n - 1; i++) {
cout << cnt[i] << endl;
}
}
| replace | 23 | 24 | 23 | 24 | 0 | |
p02726 | C++ | Runtime Error | #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <random>
#define all(x) (x).begin(), (x).end()
using namespace std;
void dout() { cerr << endl; }
typedef long long ll;
template <typename Head, typename... Tail> void dout(Head H, Tail... T) {
cerr << H << ' ';
dout(T...);
}
#define debug(x) cout << #x " = " << (x) << endl
using ll = long long;
using pii = pair<ll, ll>;
using ld = long double;
using pll = pair<long long, long long>;
template <typename T> void do_uniq(vector<T> vec) {
sort(all(vec));
vec.resize(unique(all(vec)) - vec.begin());
}
// #define solvsh
// #define multi
#ifdef solvsh
void solve() {}
#else
const int MAXN = 1e3 + 9;
vector<int> g[MAXN];
int answr[MAXN];
int d[MAXN];
int usd[MAXN];
int n;
void f(int v) {
for (int i = 1; i <= n; ++i) {
d[i] = n + 2;
usd[i] = false;
}
queue<int> q;
q.push(v);
d[v] = 0;
usd[v] = true;
while (!q.empty()) {
auto h = q.front();
q.pop();
for (auto e : g[h]) {
d[e] = min(d[e], d[h] + 1);
if (!usd[e]) {
q.push(e);
usd[e] = true;
}
}
}
for (int i = 1; i <= n; ++i) {
answr[d[i]]++;
}
}
void solve() {
cin >> n;
int x, y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
for (int i = 1; i < n; ++i) {
g[i].push_back(i + 1);
g[i + 1].push_back(i);
}
for (int i = 1; i <= n; ++i) {
f(i);
}
for (int i = 1; i < n; ++i) {
cout << answr[i] / 2 << "\n";
}
}
#endif
void multisolve() {
int t;
cin >> t;
int i = 1;
while (t--) {
// cout << "Case #" << (i++) << ": ";
solve();
// cout << "\n";
}
}
#define int int
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
cout << fixed << setprecision(20);
#ifdef multi
multisolve();
#else
solve();
// gen();
#endif
#ifdef LOCAL
// cout << '\n' << (double)clock() / CLOCKS_PER_SEC << '\n';
#endif
} | #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <bitset>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <random>
#define all(x) (x).begin(), (x).end()
using namespace std;
void dout() { cerr << endl; }
typedef long long ll;
template <typename Head, typename... Tail> void dout(Head H, Tail... T) {
cerr << H << ' ';
dout(T...);
}
#define debug(x) cout << #x " = " << (x) << endl
using ll = long long;
using pii = pair<ll, ll>;
using ld = long double;
using pll = pair<long long, long long>;
template <typename T> void do_uniq(vector<T> vec) {
sort(all(vec));
vec.resize(unique(all(vec)) - vec.begin());
}
// #define solvsh
// #define multi
#ifdef solvsh
void solve() {}
#else
const int MAXN = 1e4 + 9;
vector<int> g[MAXN];
int answr[MAXN];
int d[MAXN];
int usd[MAXN];
int n;
void f(int v) {
for (int i = 1; i <= n; ++i) {
d[i] = n + 2;
usd[i] = false;
}
queue<int> q;
q.push(v);
d[v] = 0;
usd[v] = true;
while (!q.empty()) {
auto h = q.front();
q.pop();
for (auto e : g[h]) {
d[e] = min(d[e], d[h] + 1);
if (!usd[e]) {
q.push(e);
usd[e] = true;
}
}
}
for (int i = 1; i <= n; ++i) {
answr[d[i]]++;
}
}
void solve() {
cin >> n;
int x, y;
cin >> x >> y;
g[x].push_back(y);
g[y].push_back(x);
for (int i = 1; i < n; ++i) {
g[i].push_back(i + 1);
g[i + 1].push_back(i);
}
for (int i = 1; i <= n; ++i) {
f(i);
}
for (int i = 1; i < n; ++i) {
cout << answr[i] / 2 << "\n";
}
}
#endif
void multisolve() {
int t;
cin >> t;
int i = 1;
while (t--) {
// cout << "Case #" << (i++) << ": ";
solve();
// cout << "\n";
}
}
#define int int
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
cout << fixed << setprecision(20);
#ifdef multi
multisolve();
#else
solve();
// gen();
#endif
#ifdef LOCAL
// cout << '\n' << (double)clock() / CLOCKS_PER_SEC << '\n';
#endif
} | replace | 48 | 49 | 48 | 49 | 0 | |
p02726 | C++ | Runtime Error | // RAKSHIT KADAM
// ALWAYS USE &IT FOR ITERATING USING AUTO ...
// USE COUNT(STARTING ADDRESS, ENDING ADRESS ,VALUE) FOR FINDING THE COUNT IN
// THE RESPECTIVE DATA STRUCTURE NOTE THAT MEMSET CANNOT ASSIGN A VALUE OF 10^18
// IT WILL ASSIGN A LOWER VALUE THAN THAT!!! NOTE THAT MEMSET CANT FILL THE
// DOUBLE VALUES;
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int , null_type , less<int> , rb_tree_tag ,
// tree_order_statistics_node_update>
#warning !!!check the size of arrayss!!!
// NUMERIC DEFINITIONS :
#define INF 2000000000000000005
#define MOD 1000000007
#define newMOD 998244353
#define MAX 300006
#define pi 3.1415926535897932384626433832795
#define ld long double
#define ll long long
#define int long long
#define P(gg) \
for (auto rax : gg) { \
cout << rax << " "; \
} \
cout << endl;
#define Need_for_speed(activated) \
ios_base ::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL)
#define satisfy \
ll t; \
cin >> t; \
while (t--)
#define inp(n) \
int n; \
cin >> n
#define mp make_pair
#define pb push_back
#define endl "\n"
#define x first
#define y second
#define fore(i, a, b) for (ll i = a; i < b; i++)
#define forci(i, n) for (ll i = 0; i < n; i++)
#define vi vector<ll>
#define Endl endl
#define lb lower_bound
#define ub upper_bound
#define pii pair<ll, ll>
#define input \
freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define time \
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int power(int x, unsigned int y, unsigned int m) {
if (y == 0)
return 1;
int p = power(x, y / 2, m) % m;
p = (p * p) % m;
return (y % 2 == 0) ? p : (x * p) % m;
}
ll modInverse(int a, int m) {
int g = gcd(a, m);
{ return power(a, m - 2, m); }
}
ll n;
// DIJSTRAS ALGORITHM ,DECLARE PARENT,VIS, DISTANCE ARRAYS...
// pair of distance, the vertex
ll dis[10004];
vector<pii> v[2000];
ll ans[2003];
void dijikstra(ll source) {
ll parent[n + 3];
memset(parent, 0, sizeof parent);
ll vis[n + 3];
for (ll i = 0; i <= n; i++)
vis[i] = 0;
multiset<pair<ll, ll>> m;
m.insert(mp(0, source));
parent[source] = source;
for (ll i = 0; i < n + 2; i++)
dis[i] = 1e12;
dis[source] = 0;
while (m.size()) {
pair<ll, ll> p = *m.begin();
ll x = p.first, y = p.second;
m.erase(m.begin());
if (vis[y])
continue;
vis[y] = 1;
for (ll i = 0; i < v[y].size(); i++) {
ll ax = v[y][i].first;
ll ay = v[y][i].second;
if (dis[y] + ax < dis[ay]) {
dis[ay] = ax + dis[y];
m.insert(mp(dis[ay], ay));
parent[ay] = y;
}
}
}
for (ll i = 1; i <= n; i++)
ans[dis[i]]++;
}
void solve() {
cin >> n;
ll x, y;
cin >> x >> y;
for (ll i = 1; i <= n - 1; i++) {
v[i].pb(mp(1, i + 1));
v[i + 1].pb(mp(1, i));
}
v[x].pb(mp(1, y));
v[y].pb(mp(1, x));
for (ll i = 1; i <= n; i++) {
dijikstra(i);
memset(dis, 0, sizeof dis);
}
for (ll i = 1; i <= n - 1; i++)
cout << ans[i] / 2 << endl;
}
signed main() {
Need_for_speed(activated);
// satisfy
// {
// solve();
// }
solve();
return 0;
}
| // RAKSHIT KADAM
// ALWAYS USE &IT FOR ITERATING USING AUTO ...
// USE COUNT(STARTING ADDRESS, ENDING ADRESS ,VALUE) FOR FINDING THE COUNT IN
// THE RESPECTIVE DATA STRUCTURE NOTE THAT MEMSET CANNOT ASSIGN A VALUE OF 10^18
// IT WILL ASSIGN A LOWER VALUE THAN THAT!!! NOTE THAT MEMSET CANT FILL THE
// DOUBLE VALUES;
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int , null_type , less<int> , rb_tree_tag ,
// tree_order_statistics_node_update>
#warning !!!check the size of arrayss!!!
// NUMERIC DEFINITIONS :
#define INF 2000000000000000005
#define MOD 1000000007
#define newMOD 998244353
#define MAX 300006
#define pi 3.1415926535897932384626433832795
#define ld long double
#define ll long long
#define int long long
#define P(gg) \
for (auto rax : gg) { \
cout << rax << " "; \
} \
cout << endl;
#define Need_for_speed(activated) \
ios_base ::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL)
#define satisfy \
ll t; \
cin >> t; \
while (t--)
#define inp(n) \
int n; \
cin >> n
#define mp make_pair
#define pb push_back
#define endl "\n"
#define x first
#define y second
#define fore(i, a, b) for (ll i = a; i < b; i++)
#define forci(i, n) for (ll i = 0; i < n; i++)
#define vi vector<ll>
#define Endl endl
#define lb lower_bound
#define ub upper_bound
#define pii pair<ll, ll>
#define input \
freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define time \
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int power(int x, unsigned int y, unsigned int m) {
if (y == 0)
return 1;
int p = power(x, y / 2, m) % m;
p = (p * p) % m;
return (y % 2 == 0) ? p : (x * p) % m;
}
ll modInverse(int a, int m) {
int g = gcd(a, m);
{ return power(a, m - 2, m); }
}
ll n;
// DIJSTRAS ALGORITHM ,DECLARE PARENT,VIS, DISTANCE ARRAYS...
// pair of distance, the vertex
ll dis[10004];
vector<pii> v[2003];
ll ans[2003];
void dijikstra(ll source) {
ll parent[n + 3];
memset(parent, 0, sizeof parent);
ll vis[n + 3];
for (ll i = 0; i <= n; i++)
vis[i] = 0;
multiset<pair<ll, ll>> m;
m.insert(mp(0, source));
parent[source] = source;
for (ll i = 0; i < n + 2; i++)
dis[i] = 1e12;
dis[source] = 0;
while (m.size()) {
pair<ll, ll> p = *m.begin();
ll x = p.first, y = p.second;
m.erase(m.begin());
if (vis[y])
continue;
vis[y] = 1;
for (ll i = 0; i < v[y].size(); i++) {
ll ax = v[y][i].first;
ll ay = v[y][i].second;
if (dis[y] + ax < dis[ay]) {
dis[ay] = ax + dis[y];
m.insert(mp(dis[ay], ay));
parent[ay] = y;
}
}
}
for (ll i = 1; i <= n; i++)
ans[dis[i]]++;
}
void solve() {
cin >> n;
ll x, y;
cin >> x >> y;
for (ll i = 1; i <= n - 1; i++) {
v[i].pb(mp(1, i + 1));
v[i + 1].pb(mp(1, i));
}
v[x].pb(mp(1, y));
v[y].pb(mp(1, x));
for (ll i = 1; i <= n; i++) {
dijikstra(i);
memset(dis, 0, sizeof dis);
}
for (ll i = 1; i <= n - 1; i++)
cout << ans[i] / 2 << endl;
}
signed main() {
Need_for_speed(activated);
// satisfy
// {
// solve();
// }
solve();
return 0;
}
| replace | 81 | 82 | 81 | 82 | 0 | |
p02726 | C++ | Runtime Error | #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;
const int N = 1e3 + 5;
int cnt[N];
int n, x, y;
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
cin >> n >> x >> y;
rep(i, 1, n + 1) {
rep(j, i + 1, n + 1) {
int res = min(j - i, abs(i - x) + 1 + abs(y - j));
++cnt[res];
}
}
rep(i, 1, n) cout << cnt[i] << '\n';
}
| #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;
const int N = 2e3 + 5;
int cnt[N];
int n, x, y;
int main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
cin >> n >> x >> y;
rep(i, 1, n + 1) {
rep(j, i + 1, n + 1) {
int res = min(j - i, abs(i - x) + 1 + abs(y - j));
++cnt[res];
}
}
rep(i, 1, n) cout << cnt[i] << '\n';
}
| replace | 12 | 13 | 12 | 13 | 0 | |
p02726 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define IOS \
ios_base::sync_with_stdio(0); \
cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x, y) memset(x, y, sizeof(x))
using namespace std;
int dt[][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {0, 0}};
// typedef pair<int, int> P;
// priority_queue<int, vector<int>, greater<int> > q;
const int manx = 2e3 + 10; // 顶点个数的最大范围
const int mamx = 2e3 + 10; // 边数的最大范围(最多有几条路,可以看)
int cnt[manx];
struct node {
int v, next, w;
} a[mamx];
int d[manx][manx], head[manx];
bool vis[manx];
int n, m, s, e, k = 0;
void add(int u, int v, int w) {
a[++k].next = head[u];
head[u] = k;
a[k].v = v;
a[k].w = w;
}
void dij() {
for (int i = 1; i <= n; i++)
d[s][i] = 1e9;
memset(vis, 0, sizeof(vis));
priority_queue<pair<int, int>> q;
d[s][s] = 0;
q.push(make_pair(0, s));
while (q.size()) {
int u = q.top().second;
q.pop();
if (vis[u])
continue;
vis[u] = 1;
for (int i = head[u]; i; i = a[i].next) {
int v = a[i].v, w = a[i].w;
if (d[s][v] > d[s][u] + w)
d[s][v] = d[s][u] + w, q.push(make_pair(-d[s][v], v));
}
}
}
int main() {
int x, y;
cin >> n >> x >> y;
for (int i = 1; i <= n; i++) {
add(i, i + 1, 1);
add(i + 1, i, 1);
}
add(x, y, 1);
add(y, x, 1);
for (int i = 1; i <= n; i++)
s = i, dij();
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
cnt[d[i][j]]++;
}
}
for (int i = 1; i < n; i++)
cout << cnt[i] << endl;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define IOS \
ios_base::sync_with_stdio(0); \
cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x, y) memset(x, y, sizeof(x))
using namespace std;
int dt[][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {0, 0}};
// typedef pair<int, int> P;
// priority_queue<int, vector<int>, greater<int> > q;
const int manx = 2e3 + 10; // 顶点个数的最大范围
const int mamx = 2e4 + 10; // 边数的最大范围(最多有几条路,可以看)
int cnt[manx];
struct node {
int v, next, w;
} a[mamx];
int d[manx][manx], head[manx];
bool vis[manx];
int n, m, s, e, k = 0;
void add(int u, int v, int w) {
a[++k].next = head[u];
head[u] = k;
a[k].v = v;
a[k].w = w;
}
void dij() {
for (int i = 1; i <= n; i++)
d[s][i] = 1e9;
memset(vis, 0, sizeof(vis));
priority_queue<pair<int, int>> q;
d[s][s] = 0;
q.push(make_pair(0, s));
while (q.size()) {
int u = q.top().second;
q.pop();
if (vis[u])
continue;
vis[u] = 1;
for (int i = head[u]; i; i = a[i].next) {
int v = a[i].v, w = a[i].w;
if (d[s][v] > d[s][u] + w)
d[s][v] = d[s][u] + w, q.push(make_pair(-d[s][v], v));
}
}
}
int main() {
int x, y;
cin >> n >> x >> y;
for (int i = 1; i <= n; i++) {
add(i, i + 1, 1);
add(i + 1, i, 1);
}
add(x, y, 1);
add(y, x, 1);
for (int i = 1; i <= n; i++)
s = i, dij();
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
cnt[d[i][j]]++;
}
}
for (int i = 1; i < n; i++)
cout << cnt[i] << endl;
} | replace | 28 | 29 | 28 | 29 | 0 | |
p02726 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int Inf = 1e9 + 5;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int n, x, y;
cin >> n >> x >> y;
vector<vector<int>> dis(n, vector<int>(n));
vector<int> freq(n);
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
dis[i][j] = min(
{j - i, 1 + abs(x - i) + abs(y - j), 1 + abs(x - j) + abs(y - i)});
freq[dis[i][j]]++;
}
}
for (int i = 1; i < n; i++) {
cout << freq[i] << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int Inf = 1e9 + 5;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int n, x, y;
cin >> n >> x >> y;
vector<vector<int>> dis(n + 1, vector<int>(n + 1));
vector<int> freq(n);
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
dis[i][j] = min(
{j - i, 1 + abs(x - i) + abs(y - j), 1 + abs(x - j) + abs(y - i)});
freq[dis[i][j]]++;
}
}
for (int i = 1; i < n; i++) {
cout << freq[i] << endl;
}
return 0;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p02726 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll i, j, k, l, m, n, w, x, y, z, p, q, tmp, sum = 0;
ll a[1000];
string str;
cin >> n >> x >> y;
;
x--;
y--;
rep(i, n - 1) {
REP(j, i + 1, n) {
a[min(j - i, abs(j - y) + 1 + abs(x - i))]++;
// cout<<i<<" "<<j<<" "<<min(j-i,abs(j-y)+1+abs(x-i))<<endl;
}
}
rep(i, n) {
if (i == 0)
continue;
cout << a[i] << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll i, j, k, l, m, n, w, x, y, z, p, q, tmp, sum = 0;
ll a[100000];
string str;
cin >> n >> x >> y;
;
x--;
y--;
rep(i, n - 1) {
REP(j, i + 1, n) {
a[min(j - i, abs(j - y) + 1 + abs(x - i))]++;
// cout<<i<<" "<<j<<" "<<min(j-i,abs(j-y)+1+abs(x-i))<<endl;
}
}
rep(i, n) {
if (i == 0)
continue;
cout << a[i] << endl;
}
return 0;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p02726 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
const int INF = 1 << 29;
#define LNF __LONG_LONG_MAX__;
const ll MOD = 1000000007;
const int MAX = 200000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
// 最大公約数
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
// 最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n, long long k) {
com[0] = 1;
for (int i = 1; i <= k; i++) {
com[i] = (com[i - 1] * (n - i + 1) % MOD) * modinv(i, MOD) % MOD;
}
}
int main() {
int N, X, Y;
cin >> N >> X >> Y;
X--;
Y--;
int s = Y - X - 1;
vector<int> out(N, 0);
vector<int> lp(N, 0);
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
int a = j - i;
int b = abs(X - i) + abs(Y - j) + 1;
int tmp = min(a, b);
out[tmp]++;
cerr << i << " " << j << " " << tmp << endl;
}
}
for (int i = 1; i < N; i++) {
cout << out[i] << endl;
}
return 0;
}
| #include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
const int INF = 1 << 29;
#define LNF __LONG_LONG_MAX__;
const ll MOD = 1000000007;
const int MAX = 200000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
// 最大公約数
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
// 最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n, long long k) {
com[0] = 1;
for (int i = 1; i <= k; i++) {
com[i] = (com[i - 1] * (n - i + 1) % MOD) * modinv(i, MOD) % MOD;
}
}
int main() {
int N, X, Y;
cin >> N >> X >> Y;
X--;
Y--;
int s = Y - X - 1;
vector<int> out(N, 0);
vector<int> lp(N, 0);
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
int a = j - i;
int b = abs(X - i) + abs(Y - j) + 1;
int tmp = min(a, b);
out[tmp]++;
// cerr << i << " " << j << " " << tmp << endl;
}
}
for (int i = 1; i < N; i++) {
cout << out[i] << endl;
}
return 0;
}
| replace | 97 | 98 | 97 | 98 | TLE | |
p02726 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T>>
using namespace std;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using P = pair<int, int>;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int mod = 1000000007;
int dist[202][202];
int main() {
int n, x, y;
cin >> n >> x >> y;
--x;
--y;
rep(i, n) rep(j, n) {
if (j <= i)
continue;
dist[i][j] = j - i;
}
dist[x][y] = 1;
rep(i, n) {
rep(j, n) {
if (j <= i)
continue;
if (i == x && j == y)
continue;
if (i <= x && y <= j)
dist[i][j] = min(dist[i][x] + dist[y][j] + 1, dist[i][j]);
else if (i > x && y <= j)
dist[i][j] = min(dist[x][i] + dist[y][j] + 1, dist[i][j]);
else if (i <= x && y > j)
dist[i][j] = min(dist[i][x] + dist[j][y] + 1, dist[i][j]);
else if (i > x && y > j)
dist[i][j] = min(dist[x][i] + dist[j][y] + 1, dist[i][j]);
// if (i<=x && y<=j) dist[i][j] =
// min(dist[i][x]+dist[y][j]+1,dist[i][j-1]+1); else if (i>x && y<=j)
// dist[i][j] = min(dist[x][i]+dist[y][j]+1,dist[i][j-1]+1); else if (i<=x
// && y>j) dist[i][j] = min(dist[i][x]+dist[j][y]+1,dist[i][j-1]+1); else
// if (i>x && y>j) dist[i][j] =
// min(dist[x][i]+dist[j][y]+1,dist[i][j-1]+1);
}
}
map<int, int> mp;
rep(i, n) {
rep(j, n) {
if (j <= i)
continue;
// cout << "i: " << i << " j: " << j << " dist: " << dist[i][j] << endl;
mp[dist[i][j]]++;
}
}
for (int i = 1; i <= n - 1; ++i) {
cout << mp[i] << endl;
}
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T>>
using namespace std;
using ll = long long;
using uint = unsigned;
using ull = unsigned long long;
using P = pair<int, int>;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int mod = 1000000007;
int dist[2020][2020];
int main() {
int n, x, y;
cin >> n >> x >> y;
--x;
--y;
rep(i, n) rep(j, n) {
if (j <= i)
continue;
dist[i][j] = j - i;
}
dist[x][y] = 1;
rep(i, n) {
rep(j, n) {
if (j <= i)
continue;
if (i == x && j == y)
continue;
if (i <= x && y <= j)
dist[i][j] = min(dist[i][x] + dist[y][j] + 1, dist[i][j]);
else if (i > x && y <= j)
dist[i][j] = min(dist[x][i] + dist[y][j] + 1, dist[i][j]);
else if (i <= x && y > j)
dist[i][j] = min(dist[i][x] + dist[j][y] + 1, dist[i][j]);
else if (i > x && y > j)
dist[i][j] = min(dist[x][i] + dist[j][y] + 1, dist[i][j]);
// if (i<=x && y<=j) dist[i][j] =
// min(dist[i][x]+dist[y][j]+1,dist[i][j-1]+1); else if (i>x && y<=j)
// dist[i][j] = min(dist[x][i]+dist[y][j]+1,dist[i][j-1]+1); else if (i<=x
// && y>j) dist[i][j] = min(dist[i][x]+dist[j][y]+1,dist[i][j-1]+1); else
// if (i>x && y>j) dist[i][j] =
// min(dist[x][i]+dist[j][y]+1,dist[i][j-1]+1);
}
}
map<int, int> mp;
rep(i, n) {
rep(j, n) {
if (j <= i)
continue;
// cout << "i: " << i << " j: " << j << " dist: " << dist[i][j] << endl;
mp[dist[i][j]]++;
}
}
for (int i = 1; i <= n - 1; ++i) {
cout << mp[i] << endl;
}
return 0;
}
| replace | 33 | 34 | 33 | 34 | 0 | |
p02726 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
const int MAXN = 1e3 + 5;
int n, x, y;
int dist[MAXN][MAXN], ans[MAXN];
int main() {
scanf("%d%d%d", &n, &x, &y);
for (int i = 1; i <= n; ++i) {
for (int j = i; j <= n; ++j) {
dist[j][i] = dist[i][j] = j - i;
}
}
dist[x][y] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = i + 1; j <= n; ++j) {
dist[i][j] =
std::min(dist[i][j], std::min(dist[i][x] + dist[x][y] + dist[y][j],
dist[i][y] + dist[y][x] + dist[x][j]));
++ans[dist[i][j]];
}
}
for (int i = 1; i < n; ++i) {
printf("%d\n", ans[i]);
}
return 0;
} | #include <algorithm>
#include <cstdio>
const int MAXN = 2e3 + 5;
int n, x, y;
int dist[MAXN][MAXN], ans[MAXN];
int main() {
scanf("%d%d%d", &n, &x, &y);
for (int i = 1; i <= n; ++i) {
for (int j = i; j <= n; ++j) {
dist[j][i] = dist[i][j] = j - i;
}
}
dist[x][y] = 1;
for (int i = 1; i <= n; ++i) {
for (int j = i + 1; j <= n; ++j) {
dist[i][j] =
std::min(dist[i][j], std::min(dist[i][x] + dist[x][y] + dist[y][j],
dist[i][y] + dist[y][x] + dist[x][j]));
++ans[dist[i][j]];
}
}
for (int i = 1; i < n; ++i) {
printf("%d\n", ans[i]);
}
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02726 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define for0(i, N) for (long long i = 0; i < (N); ++i)
#define for1n(i, N) for (long long i = 1; i <= (N); ++i)
#define for1(i, N) for (long long i = 1; i < (N); ++i)
#define forn(i, N) for (long long i = 0; i <= (N); ++i)
#define forx(i, N, x) for (long long i = (x); i < (N); ++i)
#define forl(i, N, x, a) \
for (long long i = (x), a = 0; a < (N); i = (i + 1) % (N), ++a)
#define int long long
template <size_t i> std::bitset<i> operator++(std::bitset<i> b, signed) {
static_assert(i <= 64, "Cannot cast 64bit int.");
return b = (unsigned long long)b + 1;
}
template <size_t i> std::bitset<i> operator++(std::bitset<i> b) {
static_assert(i <= 64, "Cannot cast 64bit int.");
auto temp = b;
b++;
return temp;
}
template <size_t i> std::bitset<i> operator--(std::bitset<i> b, signed) {
static_assert(i <= 64, "Cannot cast 64bit int.");
return b = (unsigned long long)b - 1;
}
template <size_t i> std::bitset<i> operator--(std::bitset<i> b) {
static_assert(i <= 64, "Cannot cast 64bit int.");
auto temp = b;
b--;
return temp;
}
long long constexpr inf = std::numeric_limits<long long>::max();
using namespace std;
typedef long long ll;
typedef long double ld;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef set<ll> sll;
typedef unordered_set<ll> usll;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<vector<ll>> vvll;
struct arc {
int to;
int cost;
};
template <typename T> struct node {
T value;
vector<arc> arcs;
node(T v) : value(v) {}
node &operator=(T const &a) {
value = a;
return *this;
}
operator T() const { return value; }
};
template <typename T> class graph {
protected:
vector<node<T>> nodes;
T init;
int n;
public:
graph(int N, T value) : nodes(N, value), init(value), n(N){};
void addArc(int from, int to, int cost) {
assert(0 <= from && from <= n - 1 && 0 <= to && to <= n - 1);
nodes[from].arcs.push_back({to, cost});
}
void addEdge(int a, int b, int cost) {
addArc(a, b, cost);
addArc(b, a, cost);
}
node<T> &operator[](int index) { return nodes[index]; }
auto begin() { return nodes.begin(); }
auto end() { return nodes.end(); }
auto const &getInstance() { return nodes; }
void reset(T init) {
for (auto &x : nodes) {
x.value = init;
}
}
void reset(void) { reset(init); }
};
template <typename T> class tree : public graph<std::pair<T, bool>> {
std::map<pair<int, int>, std::list<int>> roads;
public:
tree(int n, T value) : graph<std::pair<T, bool>>(n, {value, false}) {}
std::list<int> road(int from, int to, std::list<int> l = std::list<int>()) {
l.push_back(from);
if (from == to) {
return l;
}
if (roads.find(make_pair(from, to)) != roads.end()) {
return roads[make_pair(from, to)];
}
this->nodes[from].value.second = true;
for (auto &n : this->nodes[from].arcs) {
if (this->nodes[n.to].value.second)
continue;
auto x = road(n.to, to, l);
if (!x.empty()) {
this->nodes[from].value.second = false;
roads[make_pair(from, to)] = x;
roads[make_pair(to, from)].assign(x.rbegin(), x.rend());
return x;
}
}
this->nodes[from].value.second = false;
return list<int>();
}
};
class bellmanford : public graph<int> {
int N;
int changed;
void r(unordered_set<int> froms, int termination) {
bool c = false;
unordered_set<int> f;
for (auto &from : froms) {
for (auto &i : nodes[from].arcs) {
if (nodes[i.to].value > i.cost + nodes[from].value) {
nodes[i.to].value = i.cost + nodes[from].value;
f.insert(i.to);
c = true;
}
}
}
// Terminated
if (!c)
return;
// Negative loop?
if (!termination) {
changed = c;
return;
}
// continue
r(move(f), termination - 1);
}
public:
bellmanford(int N)
: graph::graph(N, std::numeric_limits<int>::max()), N(N), changed(false) {
}
bool run(int start) {
nodes[start].value = 0;
r({start}, N - 1);
return changed;
}
int const &operator[](int index) { return nodes[index].value; }
};
struct warshallFloyd : public graph<ll> {
static constexpr auto INF = std::numeric_limits<ll>::max();
warshallFloyd(int n) : graph<ll>(n, 0) {}
auto run(void) {
std::vector<std::vector<ll>> K(n, std::vector<ll>(n, INF));
for (int i = 0; i < n; ++i) {
K[i][i] = 0;
auto const &arcs = getInstance()[i].arcs;
for (auto &x : arcs) {
K[i][x.to] = min<ll>(K[i][x.to], x.cost);
}
}
for (int k = 0; k < n; ++k) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (K[i][k] == INF || K[k][j] == INF)
continue;
K[i][j] = min(K[i][j], K[i][k] + K[k][j]);
}
}
}
return K;
}
auto runWithPath(void) {
std::vector<std::vector<std::pair<ll, std::list<ll>>>> K(
n, std::vector<std::pair<ll, std::list<ll>>>(
n, std::make_pair(INF, list<ll>())));
for (int i = 0; i < n; ++i) {
K[i][i].first = 0;
auto const &arcs = getInstance()[i].arcs;
for (auto &x : arcs) {
if (K[i][x.to].first > x.cost) {
K[i][x.to].first = x.cost;
K[i][x.to].second.push_back(x.to);
}
}
}
for (int k = 0; k < n; ++k) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (K[i][k].first == INF || K[k][j].first == INF)
continue;
if (K[i][j].first > K[i][k].first + K[k][j].first) {
K[i][j].first = K[i][k].first + K[k][j].first;
K[i][j].second.assign(K[i][k].second.begin(), K[i][k].second.end());
K[i][j].second.insert(K[i][j].second.end(), K[k][j].second.begin(),
K[k][j].second.end());
}
}
}
}
return K;
}
};
constexpr ll warshallFloyd::INF;
signed main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
ll n, x, y;
cin >> n >> x >> y;
bellmanford g(n);
for0(i, n - 1) { g.addEdge(i, i + 1, 1); }
g.addEdge(x - 1, y - 1, 1);
vll m(n, 0);
for0(i, n) {
g.run(i);
for (auto &t : g.getInstance()) {
++m[t.value];
}
}
for1(i, n) {
assert(m[i] % 2 == 0);
cout << m[i] / 2 << "\n";
}
return 0;
}
| #include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define for0(i, N) for (long long i = 0; i < (N); ++i)
#define for1n(i, N) for (long long i = 1; i <= (N); ++i)
#define for1(i, N) for (long long i = 1; i < (N); ++i)
#define forn(i, N) for (long long i = 0; i <= (N); ++i)
#define forx(i, N, x) for (long long i = (x); i < (N); ++i)
#define forl(i, N, x, a) \
for (long long i = (x), a = 0; a < (N); i = (i + 1) % (N), ++a)
#define int long long
template <size_t i> std::bitset<i> operator++(std::bitset<i> b, signed) {
static_assert(i <= 64, "Cannot cast 64bit int.");
return b = (unsigned long long)b + 1;
}
template <size_t i> std::bitset<i> operator++(std::bitset<i> b) {
static_assert(i <= 64, "Cannot cast 64bit int.");
auto temp = b;
b++;
return temp;
}
template <size_t i> std::bitset<i> operator--(std::bitset<i> b, signed) {
static_assert(i <= 64, "Cannot cast 64bit int.");
return b = (unsigned long long)b - 1;
}
template <size_t i> std::bitset<i> operator--(std::bitset<i> b) {
static_assert(i <= 64, "Cannot cast 64bit int.");
auto temp = b;
b--;
return temp;
}
long long constexpr inf = std::numeric_limits<long long>::max();
using namespace std;
typedef long long ll;
typedef long double ld;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef set<ll> sll;
typedef unordered_set<ll> usll;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<vector<ll>> vvll;
struct arc {
int to;
int cost;
};
template <typename T> struct node {
T value;
vector<arc> arcs;
node(T v) : value(v) {}
node &operator=(T const &a) {
value = a;
return *this;
}
operator T() const { return value; }
};
template <typename T> class graph {
protected:
vector<node<T>> nodes;
T init;
int n;
public:
graph(int N, T value) : nodes(N, value), init(value), n(N){};
void addArc(int from, int to, int cost) {
assert(0 <= from && from <= n - 1 && 0 <= to && to <= n - 1);
nodes[from].arcs.push_back({to, cost});
}
void addEdge(int a, int b, int cost) {
addArc(a, b, cost);
addArc(b, a, cost);
}
node<T> &operator[](int index) { return nodes[index]; }
auto begin() { return nodes.begin(); }
auto end() { return nodes.end(); }
auto const &getInstance() { return nodes; }
void reset(T init) {
for (auto &x : nodes) {
x.value = init;
}
}
void reset(void) { reset(init); }
};
template <typename T> class tree : public graph<std::pair<T, bool>> {
std::map<pair<int, int>, std::list<int>> roads;
public:
tree(int n, T value) : graph<std::pair<T, bool>>(n, {value, false}) {}
std::list<int> road(int from, int to, std::list<int> l = std::list<int>()) {
l.push_back(from);
if (from == to) {
return l;
}
if (roads.find(make_pair(from, to)) != roads.end()) {
return roads[make_pair(from, to)];
}
this->nodes[from].value.second = true;
for (auto &n : this->nodes[from].arcs) {
if (this->nodes[n.to].value.second)
continue;
auto x = road(n.to, to, l);
if (!x.empty()) {
this->nodes[from].value.second = false;
roads[make_pair(from, to)] = x;
roads[make_pair(to, from)].assign(x.rbegin(), x.rend());
return x;
}
}
this->nodes[from].value.second = false;
return list<int>();
}
};
class bellmanford : public graph<int> {
int N;
int changed;
void r(unordered_set<int> froms, int termination) {
bool c = false;
unordered_set<int> f;
for (auto &from : froms) {
for (auto &i : nodes[from].arcs) {
if (nodes[i.to].value > i.cost + nodes[from].value) {
nodes[i.to].value = i.cost + nodes[from].value;
f.insert(i.to);
c = true;
}
}
}
// Terminated
if (!c)
return;
// Negative loop?
if (!termination) {
changed = c;
return;
}
// continue
r(move(f), termination - 1);
}
public:
bellmanford(int N)
: graph::graph(N, std::numeric_limits<int>::max()), N(N), changed(false) {
}
bool run(int start) {
nodes[start].value = 0;
r({start}, N - 1);
return changed;
}
int const &operator[](int index) { return nodes[index].value; }
};
struct warshallFloyd : public graph<ll> {
static constexpr auto INF = std::numeric_limits<ll>::max();
warshallFloyd(int n) : graph<ll>(n, 0) {}
auto run(void) {
std::vector<std::vector<ll>> K(n, std::vector<ll>(n, INF));
for (int i = 0; i < n; ++i) {
K[i][i] = 0;
auto const &arcs = getInstance()[i].arcs;
for (auto &x : arcs) {
K[i][x.to] = min<ll>(K[i][x.to], x.cost);
}
}
for (int k = 0; k < n; ++k) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (K[i][k] == INF || K[k][j] == INF)
continue;
K[i][j] = min(K[i][j], K[i][k] + K[k][j]);
}
}
}
return K;
}
auto runWithPath(void) {
std::vector<std::vector<std::pair<ll, std::list<ll>>>> K(
n, std::vector<std::pair<ll, std::list<ll>>>(
n, std::make_pair(INF, list<ll>())));
for (int i = 0; i < n; ++i) {
K[i][i].first = 0;
auto const &arcs = getInstance()[i].arcs;
for (auto &x : arcs) {
if (K[i][x.to].first > x.cost) {
K[i][x.to].first = x.cost;
K[i][x.to].second.push_back(x.to);
}
}
}
for (int k = 0; k < n; ++k) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (K[i][k].first == INF || K[k][j].first == INF)
continue;
if (K[i][j].first > K[i][k].first + K[k][j].first) {
K[i][j].first = K[i][k].first + K[k][j].first;
K[i][j].second.assign(K[i][k].second.begin(), K[i][k].second.end());
K[i][j].second.insert(K[i][j].second.end(), K[k][j].second.begin(),
K[k][j].second.end());
}
}
}
}
return K;
}
};
constexpr ll warshallFloyd::INF;
signed main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
ll n, x, y;
cin >> n >> x >> y;
bellmanford g(n);
for0(i, n - 1) { g.addEdge(i, i + 1, 1); }
g.addEdge(x - 1, y - 1, 1);
vll m(n, 0);
for0(i, n) {
g.run(i);
for (auto &t : g.getInstance()) {
++m[t.value];
}
g.reset();
}
for1(i, n) {
assert(m[i] % 2 == 0);
cout << m[i] / 2 << "\n";
}
return 0;
}
| insert | 286 | 286 | 286 | 287 | -6 | 7fccfae5-c779-441e-8abb-51520c1c32b5.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02726/C++/s452697144.cpp:313: int main(): Assertion `m[i] % 2 == 0' failed.
|
p02726 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define IOS \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define MOD 1000000007
#define MOD2 998244353
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(x) (ll) x.size()
#define F first
#define S second
#define FOR(i, a, b) for (ll i = a; i <= b; ++i)
#define ROF(i, a, b) for (ll i = a; i >= b; --i)
#define trace(x) cerr << #x << ": " << x << '\n';
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;
#define TEMP int
#define ordered_set \
tree<TEMP, null_type, less<TEMP>, rb_tree_tag, \
tree_order_statistics_node_update>
auto clk = clock();
ll mexp(ll a, ll b, ll m) {
ll ans = 1;
a %= m;
while (b) {
if (b & 1)
ans = ans * a % m;
b >>= 1;
a = a * a % m;
}
return ans;
}
int d[2005];
int main() {
IOS srand(chrono::high_resolution_clock::now().time_since_epoch().count());
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n, x, y;
cin >> n >> x >> y;
FOR(i, 1, n) {
FOR(j, i + 1, n) {
d[min(abs(j - i),
min(abs(x - i) + 1 + abs(j - y), abs(y - i) + 1 + abs(j - x)))]++;
}
}
FOR(i, 1, n - 1) { cout << d[i] << endl; }
cerr << endl
<< endl
<< "Time: " << fixed << setprecision(12)
<< (long double)(clock() - clk) / CLOCKS_PER_SEC << " ms" << endl
<< endl;
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define IOS \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define MOD 1000000007
#define MOD2 998244353
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(x) (ll) x.size()
#define F first
#define S second
#define FOR(i, a, b) for (ll i = a; i <= b; ++i)
#define ROF(i, a, b) for (ll i = a; i >= b; --i)
#define trace(x) cerr << #x << ": " << x << '\n';
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;
#define TEMP int
#define ordered_set \
tree<TEMP, null_type, less<TEMP>, rb_tree_tag, \
tree_order_statistics_node_update>
auto clk = clock();
ll mexp(ll a, ll b, ll m) {
ll ans = 1;
a %= m;
while (b) {
if (b & 1)
ans = ans * a % m;
b >>= 1;
a = a * a % m;
}
return ans;
}
int d[2005];
int main() {
IOS srand(chrono::high_resolution_clock::now().time_since_epoch().count());
int n, x, y;
cin >> n >> x >> y;
FOR(i, 1, n) {
FOR(j, i + 1, n) {
d[min(abs(j - i),
min(abs(x - i) + 1 + abs(j - y), abs(y - i) + 1 + abs(j - x)))]++;
}
}
FOR(i, 1, n - 1) { cout << d[i] << endl; }
cerr << endl
<< endl
<< "Time: " << fixed << setprecision(12)
<< (long double)(clock() - clk) / CLOCKS_PER_SEC << " ms" << endl
<< endl;
return 0;
} | delete | 43 | 47 | 43 | 43 | -11 | |
p02726 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int a[1010];
int main() {
int n, x, y;
cin >> n >> x >> y;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (x <= i && y >= j) {
a[min(j - i, i - x + y - j + 1)]++;
} else {
if (x >= i && y <= j) {
a[j - i - (y - x) + 1]++;
} else {
if (j >= x && j <= y && i <= x) {
a[min(j - i, y - j + x - i + 1)]++;
} else {
if (j >= y && i <= y && i >= x) {
a[min(j - i, i - x + j - y + 1)]++;
} else {
a[j - i]++;
}
}
}
}
}
}
for (int i = 1; i <= n - 1; i++) {
cout << a[i] << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int a[2010];
int main() {
int n, x, y;
cin >> n >> x >> y;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (x <= i && y >= j) {
a[min(j - i, i - x + y - j + 1)]++;
} else {
if (x >= i && y <= j) {
a[j - i - (y - x) + 1]++;
} else {
if (j >= x && j <= y && i <= x) {
a[min(j - i, y - j + x - i + 1)]++;
} else {
if (j >= y && i <= y && i >= x) {
a[min(j - i, i - x + j - y + 1)]++;
} else {
a[j - i]++;
}
}
}
}
}
}
for (int i = 1; i <= n - 1; i++) {
cout << a[i] << endl;
}
} | replace | 2 | 3 | 2 | 3 | 0 | |
p02726 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
// 最大公約数
ll gcd(ll x, ll y) {
ll tmp = 0;
if (x < y) {
tmp = x;
x = y;
y = tmp;
}
while (y > 0) {
ll r = x % y;
x = y;
y = r;
}
return x;
}
// 最大公倍数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
const int MAX = 1e6 + 1;
const ll MOD = 1e9 + 7;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime MOD
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 階乗
ll kaijo(ll k) {
ll sum = 1;
for (ll i = 1; i <= k; ++i) {
sum *= i;
sum %= 1000000000 + 7;
}
return sum;
}
long long modpow(long long a, long long n, long long MOD) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % MOD;
a = a * a % MOD;
n >>= 1;
}
return res;
}
// //sieve(MAX);でベクトルIsPrimeに「MAXまでの数値の素数の真偽」を格納する。
// struct Sieve {
// int n;
// vector<int> f, primes;
// Sieve(int n=1):n(n), f(n+1) {
// f[0] = f[1] = -1;
// for (ll i = 2; i <= n; ++i) {
// if (f[i]) continue;
// primes.push_back(i);
// f[i] = i;
// for (ll j = i*i; j <= n; j += i) {
// if (!f[j]) f[j] = i;
// }
// }
// }
// bool isPrime(int x) { return f[x] == x;}
// vector<int> factorList(int x) {
// vector<int> res;
// while (x != 1) {
// res.push_back(f[x]);
// x /= f[x];
// }
// return res;
// }
// vector<P> factor(int x) {
// vector<int> fl = factorList(x);
// if (fl.size() == 0) return {};
// vector<P> res(1, P(fl[0], 0));
// for (int p : fl) {
// if (res.back().first == p) {
// res.back().second++;
// } else {
// res.emplace_back(p, 1);
// }
// }
// return res;
// }
// };
struct UnionFind {
vector<int> par;
UnionFind(int n) : par(n, -1) {}
int root(int x) {
if (par[x] < 0)
return x;
else
return par[x] = root(par[x]);
}
bool issame(int x, int y) { return root(x) == root(y); }
bool merge(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (par[x] > par[y])
swap(x, y); // merge technique
par[x] += par[y];
par[y] = x;
return true;
}
ll size(int x) { return -par[root(x)]; }
};
ll count(int n, int a) {
ll bunshi = 1;
for (int i = 0; i < a; i++) {
bunshi *= (n - i);
bunshi %= MOD;
}
ll bunbo = 1;
for (int i = 1; i < a + 1; i++) {
bunbo *= i;
bunbo %= MOD;
}
bunbo = modpow(bunbo, MOD - 2, MOD);
// cout<<(bunshi*bunbo)%MOD<<endl;
return (bunshi * bunbo) % MOD;
}
// 約数列挙。約数をvector<ll>で返す。計算量はsqrt(n)。
vector<ll> divisor(ll n) {
vector<ll> ret;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n)
ret.push_back(n / i);
}
}
sort(begin(ret), end(ret));
return (ret);
}
// ここから開始
const ll INF = 1e18;
const double PI = 3.14159265358979323846264338327950;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
int N;
cin >> N;
int x, y;
cin >> x >> y;
x--;
y--;
int dis[N][N];
rep(i, N) {
rep(j, N) {
if (i == j)
dis[i][j] = 0;
else if (abs(i - j) == 1)
dis[i][j] = 1;
else if ((i == x && j == y) || (i == y && j == x))
dis[i][j] = 1;
else
dis[i][j] = 1000000000;
}
}
rep(k, N) {
rep(i, N) {
rep(j, N) { dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]); }
}
}
vector<int> cnt(N, 0);
rep(i, N) {
for (int j = i + 1; j < N; j++) {
cnt[dis[i][j]]++;
}
}
for (int i = 1; i < N; i++) {
cout << cnt[i] << endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
// 最大公約数
ll gcd(ll x, ll y) {
ll tmp = 0;
if (x < y) {
tmp = x;
x = y;
y = tmp;
}
while (y > 0) {
ll r = x % y;
x = y;
y = r;
}
return x;
}
// 最大公倍数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
const int MAX = 1e6 + 1;
const ll MOD = 1e9 + 7;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime MOD
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 階乗
ll kaijo(ll k) {
ll sum = 1;
for (ll i = 1; i <= k; ++i) {
sum *= i;
sum %= 1000000000 + 7;
}
return sum;
}
long long modpow(long long a, long long n, long long MOD) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % MOD;
a = a * a % MOD;
n >>= 1;
}
return res;
}
// //sieve(MAX);でベクトルIsPrimeに「MAXまでの数値の素数の真偽」を格納する。
// struct Sieve {
// int n;
// vector<int> f, primes;
// Sieve(int n=1):n(n), f(n+1) {
// f[0] = f[1] = -1;
// for (ll i = 2; i <= n; ++i) {
// if (f[i]) continue;
// primes.push_back(i);
// f[i] = i;
// for (ll j = i*i; j <= n; j += i) {
// if (!f[j]) f[j] = i;
// }
// }
// }
// bool isPrime(int x) { return f[x] == x;}
// vector<int> factorList(int x) {
// vector<int> res;
// while (x != 1) {
// res.push_back(f[x]);
// x /= f[x];
// }
// return res;
// }
// vector<P> factor(int x) {
// vector<int> fl = factorList(x);
// if (fl.size() == 0) return {};
// vector<P> res(1, P(fl[0], 0));
// for (int p : fl) {
// if (res.back().first == p) {
// res.back().second++;
// } else {
// res.emplace_back(p, 1);
// }
// }
// return res;
// }
// };
struct UnionFind {
vector<int> par;
UnionFind(int n) : par(n, -1) {}
int root(int x) {
if (par[x] < 0)
return x;
else
return par[x] = root(par[x]);
}
bool issame(int x, int y) { return root(x) == root(y); }
bool merge(int x, int y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (par[x] > par[y])
swap(x, y); // merge technique
par[x] += par[y];
par[y] = x;
return true;
}
ll size(int x) { return -par[root(x)]; }
};
ll count(int n, int a) {
ll bunshi = 1;
for (int i = 0; i < a; i++) {
bunshi *= (n - i);
bunshi %= MOD;
}
ll bunbo = 1;
for (int i = 1; i < a + 1; i++) {
bunbo *= i;
bunbo %= MOD;
}
bunbo = modpow(bunbo, MOD - 2, MOD);
// cout<<(bunshi*bunbo)%MOD<<endl;
return (bunshi * bunbo) % MOD;
}
// 約数列挙。約数をvector<ll>で返す。計算量はsqrt(n)。
vector<ll> divisor(ll n) {
vector<ll> ret;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n)
ret.push_back(n / i);
}
}
sort(begin(ret), end(ret));
return (ret);
}
// ここから開始
const ll INF = 1e18;
const double PI = 3.14159265358979323846264338327950;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
int main() {
int N;
cin >> N;
int x, y;
cin >> x >> y;
x--;
y--;
int dis[N][N];
rep(i, N) {
rep(j, N) {
dis[i][j] = abs(i - j);
dis[j][i] = abs(i - j);
}
}
// dis[x][y] = 1;
// dis[y][x] = 1;
rep(i, N) {
rep(j, N) {
dis[i][j] = min(dis[i][j], dis[i][x] + dis[y][j] + 1);
dis[i][j] = min(dis[i][j], dis[i][y] + dis[x][j] + 1);
// cout<<dis[i][j]<<" ";
}
// cout<<endl;
}
vector<int> cnt(N, 0);
rep(i, N) {
for (int j = i + 1; j < N; j++) {
cnt[dis[i][j]]++;
}
}
for (int i = 1; i < N; i++) {
cout << cnt[i] << endl;
}
return 0;
}
| replace | 245 | 259 | 245 | 258 | TLE | |
p02726 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
struct edge {
int v, nxt;
} e[N];
int p[N], eid;
int ans[N], d[N];
void bfs(int s) {
memset(d, 0x3f, sizeof(d));
queue<int> q;
q.push(s);
d[s] = 0;
while (q.size()) {
int u = q.front();
q.pop();
for (int i = p[u]; ~i; i = e[i].nxt) {
int v = e[i].v;
if (d[u] + 1 < d[v]) {
d[v] = d[u] + 1;
q.push(v);
}
}
}
}
int main() {
int n, x, y;
cin >> n >> x >> y;
memset(p, -1, sizeof(p));
for (int i = 2; i <= n; ++i) {
e[eid] = edge{i, p[i - 1]};
p[i - 1] = eid++;
e[eid] = edge{i - 1, p[i]};
p[i] = eid++;
}
e[eid] = edge{y, p[x]};
p[x] = eid++;
e[eid] = edge{x, p[y]};
p[y] = eid++;
for (int i = 1; i <= n; ++i) {
bfs(i);
for (int i = 1; i <= n; ++i)
ans[d[i]]++;
}
for (int i = 1; i <= n - 1; ++i)
cout << ans[i] / 2 << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 5;
struct edge {
int v, nxt;
} e[N * 2];
int p[N], eid;
int ans[N], d[N];
void bfs(int s) {
memset(d, 0x3f, sizeof(d));
queue<int> q;
q.push(s);
d[s] = 0;
while (q.size()) {
int u = q.front();
q.pop();
for (int i = p[u]; ~i; i = e[i].nxt) {
int v = e[i].v;
if (d[u] + 1 < d[v]) {
d[v] = d[u] + 1;
q.push(v);
}
}
}
}
int main() {
int n, x, y;
cin >> n >> x >> y;
memset(p, -1, sizeof(p));
for (int i = 2; i <= n; ++i) {
e[eid] = edge{i, p[i - 1]};
p[i - 1] = eid++;
e[eid] = edge{i - 1, p[i]};
p[i] = eid++;
}
e[eid] = edge{y, p[x]};
p[x] = eid++;
e[eid] = edge{x, p[y]};
p[y] = eid++;
for (int i = 1; i <= n; ++i) {
bfs(i);
for (int i = 1; i <= n; ++i)
ans[d[i]]++;
}
for (int i = 1; i <= n - 1; ++i)
cout << ans[i] / 2 << endl;
return 0;
} | replace | 6 | 7 | 6 | 7 | 0 | |
p02726 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
#define ll long long
const int N = 1e3 + 5;
queue<int> q;
int n;
struct node {
int from, to, next;
} f[2 * N];
int head[N], tot;
int ans[N], vis[N], dis[N];
void add(int a, int b) {
f[++tot].from = a;
f[tot].to = b;
f[tot].next = head[a];
head[a] = tot;
}
void clean() {
memset(dis, 0x7f, sizeof(dis));
memset(vis, 0, sizeof(vis));
}
void spfa(int s) {
dis[s] = 0;
vis[s] = 1;
q.push(s);
while (!q.empty()) {
int now = q.front();
q.pop();
// cout << head[now];
for (int i = head[now]; i != -1; i = f[i].next) {
int v = f[i].to;
// cout << v;
if (dis[v] > dis[now] + 1) {
dis[v] = dis[now] + 1;
if (!vis[v]) {
vis[v] = 1;
q.push(v);
}
}
}
}
}
int main() {
int x, y;
memset(head, -1, sizeof(head));
cin >> n >> x >> y;
for (int i = 2; i <= n; i++)
add(i - 1, i), add(i, i - 1);
add(x, y), add(y, x);
for (int i = 1; i <= n; i++) {
clean();
spfa(i);
// cout << i << "GG ";
for (int j = i + 1; j <= n; j++)
ans[dis[j]]++; // cout<<dis[j] << " ";
// cout << endl;
}
for (int i = 1; i < n; i++)
cout << ans[i] << endl;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
using namespace std;
#define ll long long
const int N = 1e4 + 5;
queue<int> q;
int n;
struct node {
int from, to, next;
} f[2 * N];
int head[N], tot;
int ans[N], vis[N], dis[N];
void add(int a, int b) {
f[++tot].from = a;
f[tot].to = b;
f[tot].next = head[a];
head[a] = tot;
}
void clean() {
memset(dis, 0x7f, sizeof(dis));
memset(vis, 0, sizeof(vis));
}
void spfa(int s) {
dis[s] = 0;
vis[s] = 1;
q.push(s);
while (!q.empty()) {
int now = q.front();
q.pop();
// cout << head[now];
for (int i = head[now]; i != -1; i = f[i].next) {
int v = f[i].to;
// cout << v;
if (dis[v] > dis[now] + 1) {
dis[v] = dis[now] + 1;
if (!vis[v]) {
vis[v] = 1;
q.push(v);
}
}
}
}
}
int main() {
int x, y;
memset(head, -1, sizeof(head));
cin >> n >> x >> y;
for (int i = 2; i <= n; i++)
add(i - 1, i), add(i, i - 1);
add(x, y), add(y, x);
for (int i = 1; i <= n; i++) {
clean();
spfa(i);
// cout << i << "GG ";
for (int j = i + 1; j <= n; j++)
ans[dis[j]]++; // cout<<dis[j] << " ";
// cout << endl;
}
for (int i = 1; i < n; i++)
cout << ans[i] << endl;
} | replace | 9 | 10 | 9 | 10 | 0 | |
p02726 | C++ | Time Limit Exceeded | // Keep Working Hard
// I__Like__Food
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rep2(i, a, b) for (int i = a; i >= b; i--)
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
using namespace __gnu_pbds;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define endl "\n"
#define int long long
#define all(v) v.begin(), v.end()
#define PB push_back
#define MP make_pair
#define double long double
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) \
cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
#define trace4(a, b, c, d) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \
<< #f << ": " << f << endl
#define cases \
int testcases; \
cin >> testcases; \
while (testcases--)
const int mod = 1e9 + 7;
const int N = 200005;
const int INF = 1e16;
const double PI = acos(-1);
vector<int> adj[N];
int bvis[N];
int dist[N];
void bfs(int u) {
queue<int> q;
q.push(u);
dist[u] = 0;
while (q.size()) {
u = q.front(), q.pop();
for (int &v : adj[u]) {
if (!bvis[v]) {
dist[v] = dist[u] + 1;
bvis[v] = 1;
q.push(v);
}
}
}
}
int ans[N];
int32_t main() {
IOS
int n,
x, y;
cin >> n >> x >> y;
for (int i = 1; i <= n - 1; i++) {
adj[i].PB(i + 1);
adj[i + 1].PB(i);
}
adj[x].PB(y);
adj[y].PB(x);
set<pair<int, int>> s;
map<int, int> mp;
for (int i = 1; i <= n; i++) {
bfs(i);
dist[i] = 0;
for (int j = 1; j <= n; j++) {
int xx = i;
int yy = j;
if (xx > yy)
swap(xx, yy);
if (!s.count({xx, yy})) {
mp[dist[yy]]++;
s.insert({xx, yy});
}
}
for (int j = 1; j <= n; j++) {
bvis[j] = false;
dist[j] = 0;
}
}
for (auto i : mp) {
// trace2(i.first,i.second);
if (i.first >= 1 and i.first <= n - 1) {
ans[i.first] = i.second;
}
}
for (int i = 1; i <= n - 1; i++)
cout << ans[i] << endl;
// bfs(4);
// for(int i = 1; i <= n; i++)
// {
// cout << dist[i] << endl;
// }
return 0;
} | // Keep Working Hard
// I__Like__Food
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rep2(i, a, b) for (int i = a; i >= b; i--)
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
using namespace __gnu_pbds;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define endl "\n"
#define int long long
#define all(v) v.begin(), v.end()
#define PB push_back
#define MP make_pair
#define double long double
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) \
cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
#define trace4(a, b, c, d) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \
<< #f << ": " << f << endl
#define cases \
int testcases; \
cin >> testcases; \
while (testcases--)
const int mod = 1e9 + 7;
const int N = 200005;
const int INF = 1e16;
const double PI = acos(-1);
vector<int> adj[N];
int bvis[N];
int dist[N];
void bfs(int u) {
queue<int> q;
q.push(u);
dist[u] = 0;
while (q.size()) {
u = q.front(), q.pop();
for (int &v : adj[u]) {
if (!bvis[v]) {
dist[v] = dist[u] + 1;
bvis[v] = 1;
q.push(v);
}
}
}
}
int ans[N];
int32_t main() {
IOS
int n,
x, y;
cin >> n >> x >> y;
for (int i = 1; i <= n - 1; i++) {
adj[i].PB(i + 1);
adj[i + 1].PB(i);
}
adj[x].PB(y);
adj[y].PB(x);
set<pair<int, int>> s;
map<int, int> mp;
for (int i = 1; i <= n; i++) {
bfs(i);
dist[i] = 0;
for (int j = 1; j <= n; j++) {
int xx = i;
int yy = j;
if (xx > yy)
swap(xx, yy);
if (!s.count({xx, yy})) {
mp[dist[yy]]++;
s.insert({xx, yy});
}
bvis[j] = false;
dist[j] = 0;
}
}
for (auto i : mp) {
// trace2(i.first,i.second);
if (i.first >= 1 and i.first <= n - 1) {
ans[i.first] = i.second;
}
}
for (int i = 1; i <= n - 1; i++)
cout << ans[i] << endl;
// bfs(4);
// for(int i = 1; i <= n; i++)
// {
// cout << dist[i] << endl;
// }
return 0;
} | delete | 101 | 104 | 101 | 101 | TLE | |
p02726 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, x, y;
cin >> n >> x >> y;
--x, --y;
int t = y - x - 1;
for (int i = 1; i < n; ++i) {
int res = 0;
for (int j = 0; j < n; ++j) {
for (int k = j + 1; k < n; ++k) {
if (min(k - j, abs(k - y) + abs(j - x) + 1) == i)
++res;
}
}
cout << res << endl;
}
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, x, y;
cin >> n >> x >> y;
--x, --y;
vector<int> ans(n - 1);
for (int j = 0; j < n; ++j)
for (int k = j + 1; k < n; ++k)
++ans[min(k - j, abs(k - y) + abs(j - x) + 1) - 1];
for (auto a : ans)
cout << a << endl;
return 0;
} | replace | 10 | 21 | 10 | 16 | TLE | |
p02726 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define per(i, a, b) for (ll i = (a)-1; i >= (b); i--)
const ll maxn = 2e3;
ll q[maxn], d[maxn], u[maxn], s, e, c, ans[maxn], n, x, y;
vector<ll> ady[maxn];
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> n >> x >> y;
rep(i, 1, n) ady[i].push_back(i + 1), ady[i + 1].push_back(i);
ady[x].push_back(y), ady[y].push_back(x);
rep(i, 1, n + 1) {
s = e = 0;
q[e++] = i, d[i] = 0, u[i] = ++c;
while (s < e) {
ll j = q[s++];
for (ll to : ady[j])
if (u[to] != c)
q[e++] = to, d[to] = d[j] + 1, u[to] = c;
}
rep(j, 1, n + 1) ans[d[j]]++;
}
rep(i, 1, n) cout << ans[i] / 2 << "\n";
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define per(i, a, b) for (ll i = (a)-1; i >= (b); i--)
const ll maxn = 2e3 + 5;
ll q[maxn], d[maxn], u[maxn], s, e, c, ans[maxn], n, x, y;
vector<ll> ady[maxn];
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> n >> x >> y;
rep(i, 1, n) ady[i].push_back(i + 1), ady[i + 1].push_back(i);
ady[x].push_back(y), ady[y].push_back(x);
rep(i, 1, n + 1) {
s = e = 0;
q[e++] = i, d[i] = 0, u[i] = ++c;
while (s < e) {
ll j = q[s++];
for (ll to : ady[j])
if (u[to] != c)
q[e++] = to, d[to] = d[j] + 1, u[to] = c;
}
rep(j, 1, n + 1) ans[d[j]]++;
}
rep(i, 1, n) cout << ans[i] / 2 << "\n";
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02726 | Python | Time Limit Exceeded | from collections import deque
n, x, y = [int(x) for x in input().split()]
x -= 1
y -= 1
BIG = 65521
ans = {i: 0 for i in range(n)}
def bfs(start_v):
"""ある始点からほかの全点に行くまでの最短距離を求める。"""
qu = deque()
qu_append = qu.append
qu_popleft = qu.popleft
qu_append(start_v)
# 始点からvに移動するまでの最短距離: dist[v]
dist = [BIG] * n
def push(v, d):
"""始点からvまでの最短距離が算出されていないときに,その距離を保存し,
キューに頂点vを追加する。"""
if dist[v] != BIG:
# 既に訪問済みで距離が求められている。
return
dist[v] = d
qu_append(v)
push(start_v, 0)
while len(qu):
v = qu_popleft()
# 始点からvの次の頂点へ移動する距離。
d = dist[v] + 1
if v < n - 1:
push(v + 1, d)
if v > 0:
push(v - 1, d)
if v == x:
push(y, d)
if v == y:
push(x, d)
for i in range(n):
if dist[i] != 0:
ans[dist[i]] += 1
def main():
for i in range(n):
bfs(i)
for i in range(1, n):
print(ans[i] // 2)
if __name__ == "__main__":
main()
| from collections import deque
n, x, y = [int(x) for x in input().split()]
x -= 1
y -= 1
BIG = 65521
ans = {i: 0 for i in range(n)}
def bfs(start_v):
"""ある始点からほかの全点に行くまでの最短距離を求める。"""
qu = deque()
qu_append = qu.append
qu_popleft = qu.popleft
qu_append(start_v)
# 始点からvに移動するまでの最短距離: dist[v]
dist = [BIG] * n
def push(v, d):
"""始点からvまでの最短距離が算出されていないときに,その距離を保存し,
キューに頂点vを追加する。"""
if dist[v] != BIG:
# 既に訪問済みで距離が求められている。
return
dist[v] = d
qu_append(v)
push(start_v, 0)
while len(qu):
v = qu_popleft()
# 始点からvの次の頂点へ移動する距離。
d = dist[v] + 1
if v < n - 1:
push(v + 1, d)
if v > 0:
push(v - 1, d)
if v == x:
push(y, d)
if v == y:
push(x, d)
for i in range(n):
if dist[i] != 0:
ans[dist[i]] += 1
def main():
for i in range(n):
bfs(i)
for i in range(1, n):
print(ans[i] // 2)
if __name__ == "__main__":
main()
# TLE
| insert | 57 | 57 | 57 | 59 | TLE | |
p02726 | Python | Runtime Error | n, x, y = map(int, input().split())
cnt = [0] * n
# 漸化式が建てられそうでめんどくさい場合は、片方を固定する
# 端点を固定する 1..n-2 から順に大きい頂点に向かって伸びていく
for i in range(n - 1):
for j in range(i + 1, n):
if i <= x - 1:
if j <= x - 1: # 1 idx
cnt[j - i] += 1
elif j <= y - 1:
cnt[min(j - i, x + y - i - j - 1)] += 1
else:
cnt[x - y - i + j + 1] += 1
elif x - 1 < x <= y - 1:
if j <= y - 1:
cnt[min(j - i, 1 + (i - x + 1) + (y - 1 - j))] += 1
else:
cnt[min(j - i), 1 + (i - x + 1) + (j - y + 1)] += 1
else:
cnt[j - i] += 1
for i in range(1, n):
print(cnt[i])
| n, x, y = map(int, input().split())
cnt = [0] * n
# 漸化式が建てられそうでめんどくさい場合は、片方を固定する
# 端点を固定する 1..n-2 から順に大きい頂点に向かって伸びていく
for i in range(n - 1):
for j in range(i + 1, n):
if i <= x - 1:
if j <= x - 1: # 1 idx
cnt[j - i] += 1
elif j <= y - 1:
cnt[min(j - i, x + y - i - j - 1)] += 1
else:
cnt[x - y - i + j + 1] += 1
elif x - 1 < x <= y - 1:
if j <= y - 1:
cnt[min(j - i, 1 + (i - x + 1) + (y - 1 - j))] += 1
else:
cnt[min((j - i), 1 + (i - x + 1) + (j - y + 1))] += 1
else:
cnt[j - i] += 1
for i in range(1, n):
print(cnt[i])
| replace | 17 | 18 | 17 | 18 | TypeError: 'int' object is not iterable | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02726/Python/s903600229.py", line 18, in <module>
cnt[min(j - i), 1 + (i - x + 1) + (j - y + 1)] += 1
TypeError: 'int' object is not iterable
|
p02726 | Python | Time Limit Exceeded | #!/usr/bin/python3
(n, x, y) = map(int, input().split())
cs = [0 for i in range(n)]
for i in range(1, n + 1):
for j in range(i + 1, n + 1):
d = min(abs(j - i), abs(x - i) + 1 + abs(j - y), abs(y - i) + 1 + abs(j - x))
if d == (abs(y - i) + 1 + abs(j - x)):
print(i, j, d)
cs[d] += 1
for i in range(1, n):
print(cs[i])
| #!/usr/bin/python3
(n, x, y) = map(int, input().split())
cs = [0 for i in range(n)]
for i in range(1, n + 1):
for j in range(i + 1, n + 1):
d = min(abs(j - i), abs(x - i) + 1 + abs(j - y))
cs[d] += 1
for i in range(1, n):
print(cs[i])
| replace | 8 | 11 | 8 | 9 | TLE | |
p02726 | Python | Runtime Error | N, X, Y = map(int, input().split())
dic = {}
X = X - 1
Y = Y - 1
for i in range(N):
for j in range(i + 1, N):
if i <= X and Y <= j:
v = X - i + 1 + j - Y
elif (i <= X) and (X <= j and j <= Y):
v = min(j - i, X - i + 1 + Y - j)
elif (X <= i and i <= Y) and Y <= j:
v = min(j - i, i - X + 1 + j - Y)
elif (X <= i and i <= Y) and (X <= j and j <= Y):
v = min(j - i, i - X + 1 + Y - j)
else:
v = j - i
if v in dic:
dic[v] += 1
else:
dic[v] = 1
for i in range(1, N):
print(dic[i])
| N, X, Y = map(int, input().split())
dic = {}
X = X - 1
Y = Y - 1
for i in range(N):
for j in range(i + 1, N):
if i <= X and Y <= j:
v = X - i + 1 + j - Y
elif (i <= X) and (X <= j and j <= Y):
v = min(j - i, X - i + 1 + Y - j)
elif (X <= i and i <= Y) and Y <= j:
v = min(j - i, i - X + 1 + j - Y)
elif (X <= i and i <= Y) and (X <= j and j <= Y):
v = min(j - i, i - X + 1 + Y - j)
else:
v = j - i
if v in dic:
dic[v] += 1
else:
dic[v] = 1
for i in range(1, N):
if i in dic:
print(dic[i])
else:
print(0)
| replace | 28 | 29 | 28 | 32 | KeyError: 4 | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02726/Python/s708368036.py", line 29, in <module>
print(dic[i])
KeyError: 4
|
p02726 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define INF (INT32_MAX / 4)
int main() {
int N, X, Y;
cin >> N >> X >> Y;
X--;
Y--;
vector<vector<int>> m(N, vector<int>(N, INF));
for (int i = 0; i < N; i++)
m[i][i] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i == j)
continue;
m[i][j] = abs(i - j);
}
}
m[X][Y] = 1;
m[Y][X] = 1;
for (int k = 0; k < N; k++) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
m[i][j] = min(m[i][j], m[i][k] + m[k][j]);
}
}
}
vector<int> ans(N - 1);
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
if (m[i][j] < 1)
continue;
ans[m[i][j] - 1]++;
}
}
for (int i = 0; i < N - 1; i++) {
cout << ans[i] << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
#define INF (INT32_MAX / 4)
int main() {
int N, X, Y;
cin >> N >> X >> Y;
X--;
Y--;
vector<vector<int>> m(N, vector<int>(N, INF));
for (int i = 0; i < N; i++)
m[i][i] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (i == j)
continue;
m[i][j] = abs(i - j);
}
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
m[i][j] = min(m[i][j], min(m[i][X] + m[Y][j] + 1, m[i][Y] + m[X][j] + 1));
}
}
vector<int> ans(N - 1);
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
if (m[i][j] < 1)
continue;
ans[m[i][j] - 1]++;
}
}
for (int i = 0; i < N - 1; i++) {
cout << ans[i] << endl;
}
}
| replace | 21 | 28 | 21 | 24 | TLE | |
p02726 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int N, x, y, ans[2010];
int main() {
cin >> N >> x >> y;
for (int i = 1; i <= x; i++)
for (int j = i + 1; j <= x; j++)
ans[j - i]++;
for (int i = y; i <= N; i++)
for (int j = y + 1; j <= N; j++)
ans[j - i]++;
for (int i = x + 1; i < y; i++)
for (int j = i + 1; j < y; j++)
ans[min(j - i, i - x + y - j + 1)]++;
for (int i = 1; i <= x; i++)
for (int j = x + 1; j < y; j++)
ans[min(j - i, y - j + 1 + x - i)]++;
for (int i = y; i <= N; i++)
for (int j = x + 1; j < y; j++)
ans[min(i - j, j - x + 1 + i - y)]++;
for (int i = 1; i <= x; i++)
for (int j = y; j <= N; j++)
ans[j - y + x - i + 1]++;
for (int i = 1; i < N; i++)
cout << ans[i] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int N, x, y, ans[2010];
int main() {
cin >> N >> x >> y;
for (int i = 1; i <= x; i++)
for (int j = i + 1; j <= x; j++)
ans[j - i]++;
for (int i = y; i <= N; i++)
for (int j = i + 1; j <= N; j++)
ans[j - i]++;
for (int i = x + 1; i < y; i++)
for (int j = i + 1; j < y; j++)
ans[min(j - i, i - x + y - j + 1)]++;
for (int i = 1; i <= x; i++)
for (int j = x + 1; j < y; j++)
ans[min(j - i, y - j + 1 + x - i)]++;
for (int i = y; i <= N; i++)
for (int j = x + 1; j < y; j++)
ans[min(i - j, j - x + 1 + i - y)]++;
for (int i = 1; i <= x; i++)
for (int j = y; j <= N; j++)
ans[j - y + x - i + 1]++;
for (int i = 1; i < N; i++)
cout << ans[i] << endl;
return 0;
} | replace | 12 | 13 | 12 | 13 | 0 | |
p02726 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll MOD = (1e9 + 7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
ll factorial(ll n, ll m = 2) {
// calculate n!
m = max(2LL, m);
ll rtn = 1;
for (ll i = m; i <= n; i++) {
rtn = (rtn * i) % MOD;
}
return rtn;
}
ll modinv(ll a, ll m) {
ll b = m, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
ll modpow(ll a, ll n) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % MOD;
a = a * a % MOD;
n >>= 1;
}
return res;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, x, y;
cin >> n >> x >> y;
x--;
y--;
vector<vector<int>> dist(n, vector<int>(n, 0));
rep(i, n) rep(j, n) {
if (i == j)
dist[i][j] = 0;
dist[i][j] = min(
{abs(j - i), abs(j - y) + abs(x - i) + 1, abs(j - x) + abs(y - i) + 1});
}
rep1(i, n - 1) {
int ans = 0;
rep(j, n) for (int k = j + 1; k < n; ++k) {
if (dist[j][k] == i) {
ans++;
// cout << j << " " << k << endl;
}
}
cout << ans << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
constexpr ll MOD = (1e9 + 7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
ll factorial(ll n, ll m = 2) {
// calculate n!
m = max(2LL, m);
ll rtn = 1;
for (ll i = m; i <= n; i++) {
rtn = (rtn * i) % MOD;
}
return rtn;
}
ll modinv(ll a, ll m) {
ll b = m, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
ll modpow(ll a, ll n) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % MOD;
a = a * a % MOD;
n >>= 1;
}
return res;
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, x, y;
cin >> n >> x >> y;
x--;
y--;
vector<vector<int>> dist(n, vector<int>(n, 0));
rep(i, n) rep(j, n) {
if (i == j)
dist[i][j] = 0;
dist[i][j] = min(
{abs(j - i), abs(j - y) + abs(x - i) + 1, abs(j - x) + abs(y - i) + 1});
}
// rep1(i, n-1) {
// int ans = 0;
// rep(j, n) for(int k=j+1; k<n; ++k) {
// if (dist[j][k] == i) {
// ans++;
// // cout << j << " " << k << endl;
// }
// }
// cout << ans << endl;
// }
vector<int> ans(n);
rep(i, n) for (int j = i + 1; j < n; ++j) { ans[dist[i][j]]++; }
rep1(i, n - 1) cout << ans[i] << endl;
return 0;
} | replace | 77 | 87 | 77 | 90 | TLE | |
p02726 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif
void init() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const int N = 2e3 + 34;
int s[N];
void solve() {
int n, x, y;
scanf("%d%d%d", &n, &x, &y);
--x;
--y;
for (int i = 0; i < n - 1; ++i) {
for (int j = i + 1; j < n; ++j) {
int d = j - i; // 3
if (j >= y && i <= x) {
d -= y - x - 1;
} else if (i <= x && j <= y && j > x) {
d = min(d, x - i + y - j + 1); // 3, 1-0+3-3+1
} else if (i >= x && i < y && j >= y) {
d = min(d, i - x + j - y + 1); // 2, 2-1+4-3+1
} else {
d = min(d, i - x + y - j + 1);
}
++s[d];
// printf("(%d, %d) -> %d\n", i+1, j+1, d);
}
}
for (int i = 1; i < n; ++i) {
printf("%d\n", s[i]);
}
}
int main() {
init();
int t = 1; // scanf("%d", &t);
while (t--) {
solve();
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif
void init() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const int N = 2e3 + 34;
int s[N];
void solve() {
int n, x, y;
scanf("%d%d%d", &n, &x, &y);
--x;
--y;
for (int i = 0; i < n - 1; ++i) {
for (int j = i + 1; j < n; ++j) {
int d = j - i; // 3
if (j >= y && i <= x) {
d -= y - x - 1;
} else if (i <= x && j <= y && j > x) {
d = min(d, x - i + y - j + 1); // 3, 1-0+3-3+1
} else if (i >= x && i < y && j >= y) {
d = min(d, i - x + j - y + 1); // 2, 2-1+4-3+1
} else if (i >= x && j <= y) {
d = min(d, i - x + y - j + 1);
}
++s[d];
// printf("(%d, %d) -> %d\n", i+1, j+1, d);
}
}
for (int i = 1; i < n; ++i) {
printf("%d\n", s[i]);
}
}
int main() {
init();
int t = 1; // scanf("%d", &t);
while (t--) {
solve();
}
return 0;
}
| replace | 33 | 34 | 33 | 34 | 0 | |
p02726 | C++ | Runtime Error | #define ll long long
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mp make_pair
#define fo(i, n) for (ll i = 0; i < n; i++)
// #include<bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
ll pi = acos(-1);
ll z = 1000000007;
ll inf = 100000000000000000;
ll p1 = 37;
ll p2 = 53;
ll mod1 = 202976689;
ll mod2 = 203034253;
ll gcd(ll a, ll b) {
if (b > a)
return gcd(b, a);
if (b == 0)
return a;
return gcd(b, a % b);
}
ll power(ll a, ll b, ll p) {
if (b == 0)
return 1;
ll c = power(a, b / 2, p);
if (b % 2 == 0)
return ((c * c) % p);
else
return ((((c * c) % p) * a) % p);
}
ll inverse(ll a, ll n) { return power(a, n - 2, n); }
ll max(ll a, ll b) {
if (a > b)
return a;
return b;
}
ll left(ll i) { return ((2 * i) + 1); }
ll right(ll i) { return (2 * (i + 1)); }
// ios_base::sync_with_stdio(0);
// cin.tie(0); cout.tie(0);
using namespace std;
void solve() {
ll n, x, y;
cin >> n >> x >> y;
// x-- ; y-- ;
ll dist[n + 1];
fo(i, n + 1) dist[i] = 0;
ll a = min(x, y);
ll b = max(x, y);
for (ll i = 1; i <= n; i++) {
for (ll j = i + 1; j <= n; j++) {
ll d = min(j - i, abs(a - i) + 1 + abs(b - j));
dist[d]++;
}
}
for (ll i = 1; i < n; i++) {
cout << dist[i] << '\n';
}
return;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("inputf.txt", "r", stdin);
freopen("outputf.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
ll t;
// cin >> t ;
t = 1;
while (t--) {
solve();
}
return 0;
} | #define ll long long
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mp make_pair
#define fo(i, n) for (ll i = 0; i < n; i++)
// #include<bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
ll pi = acos(-1);
ll z = 1000000007;
ll inf = 100000000000000000;
ll p1 = 37;
ll p2 = 53;
ll mod1 = 202976689;
ll mod2 = 203034253;
ll gcd(ll a, ll b) {
if (b > a)
return gcd(b, a);
if (b == 0)
return a;
return gcd(b, a % b);
}
ll power(ll a, ll b, ll p) {
if (b == 0)
return 1;
ll c = power(a, b / 2, p);
if (b % 2 == 0)
return ((c * c) % p);
else
return ((((c * c) % p) * a) % p);
}
ll inverse(ll a, ll n) { return power(a, n - 2, n); }
ll max(ll a, ll b) {
if (a > b)
return a;
return b;
}
ll left(ll i) { return ((2 * i) + 1); }
ll right(ll i) { return (2 * (i + 1)); }
// ios_base::sync_with_stdio(0);
// cin.tie(0); cout.tie(0);
using namespace std;
void solve() {
ll n, x, y;
cin >> n >> x >> y;
// x-- ; y-- ;
ll dist[n + 1];
fo(i, n + 1) dist[i] = 0;
ll a = min(x, y);
ll b = max(x, y);
for (ll i = 1; i <= n; i++) {
for (ll j = i + 1; j <= n; j++) {
ll d = min(j - i, abs(a - i) + 1 + abs(b - j));
dist[d]++;
}
}
for (ll i = 1; i < n; i++) {
cout << dist[i] << '\n';
}
return;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
/*#ifndef ONLINE_JUDGE
freopen("inputf.txt" , "r" , stdin) ;
freopen("outputf.txt" , "w" , stdout) ;
freopen("error.txt" , "w" , stderr) ;
#endif*/
ll t;
// cin >> t ;
t = 1;
while (t--) {
solve();
}
return 0;
} | replace | 79 | 84 | 79 | 84 | -11 | |
p02726 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF = (ll)1e9;
const ll MOD = (ll)1e9 + 7;
const ll MAX = 100100;
vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main() {
ll N, X, Y;
cin >> N >> X >> Y;
vector<vector<ll>> v(N, vector<ll>(N));
vector<ll> ans(N, 0);
for (ll i = 0; i < N; i++) {
for (ll j = 0; j < N; j++)
v[i][j] = abs(i - j);
}
v[X - 1][Y - 1] = 1;
v[Y - 1][X - 1] = 1;
for (ll k = 0; k < N; k++) {
for (ll i = 0; i < N; i++) {
for (ll j = i + 1; j < N; j++) {
v[i][j] = min(v[i][k] + v[k][j], v[i][j]);
}
}
}
for (ll i = 0; i < N; i++) {
for (ll j = i + 1; j < N; j++) {
ans[v[i][j]]++;
}
}
for (ll i = 1; i < N; i++)
cout << ans[i] << endl;
}
| #include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF = (ll)1e9;
const ll MOD = (ll)1e9 + 7;
const ll MAX = 100100;
vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main() {
ll N, X, Y;
cin >> N >> X >> Y;
vector<vector<ll>> v(N, vector<ll>(N));
vector<ll> ans(N, 0);
for (ll i = 0; i < N; i++) {
for (ll j = 0; j < N; j++)
v[i][j] = abs(i - j);
}
v[X - 1][Y - 1] = 1;
v[Y - 1][X - 1] = 1;
for (ll i = 0; i < N; i++) {
for (ll j = 0; j < N; j++) {
v[i][j] = min(v[i][j], abs(X - i - 1) + abs(Y - j - 1) + 1);
}
}
for (ll i = 0; i < N; i++) {
for (ll j = i + 1; j < N; j++) {
ans[v[i][j]]++;
}
}
for (ll i = 1; i < N; i++)
cout << ans[i] << endl;
}
| replace | 36 | 41 | 36 | 39 | TLE | |
p02726 | C++ | Runtime Error | #include <bits/stdc++.h>
#define fs first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef double db;
const int maxn = 1e3 + 5;
const ll inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
ll num[maxn];
int main() {
int n, x, y;
scanf("%d%d%d", &n, &x, &y);
for (int i = 1; i < n; i++) {
for (int j = i + 1; j <= n; j++) {
int dis = j - i;
dis = min(dis, abs(x - i) + abs(j - y) + 1);
num[dis]++;
}
}
for (int i = 1; i < n; i++) {
printf("%lld\n", num[i]);
}
return 0;
} | #include <bits/stdc++.h>
#define fs first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef double db;
const int maxn = 2e3 + 5;
const ll inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
ll num[maxn];
int main() {
int n, x, y;
scanf("%d%d%d", &n, &x, &y);
for (int i = 1; i < n; i++) {
for (int j = i + 1; j <= n; j++) {
int dis = j - i;
dis = min(dis, abs(x - i) + abs(j - y) + 1);
num[dis]++;
}
}
for (int i = 1; i < n; i++) {
printf("%lld\n", num[i]);
}
return 0;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p02726 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main() {
int n, x, y;
cin >> n >> x >> y;
x--;
y--;
vector<int> adj[1000];
rep(i, n - 1) {
adj[i].push_back(i + 1);
adj[i + 1].push_back(i);
}
adj[x].push_back(y);
adj[y].push_back(x);
vector<int> counter(n, 0);
for (int start = 0; start < n; start++) {
queue<int> q;
q.push(start);
vector<int> dist(n, 1e9);
dist[start] = 1;
while (!q.empty()) {
int now = q.front();
q.pop();
for (int to : adj[now]) {
if (dist[to] != 1e9)
continue;
if (dist[to] > dist[now] + 1) {
dist[to] = dist[now] + 1;
q.push(to);
}
}
}
for (int i = start + 1; i < n; i++) {
counter[dist[i] - 1]++;
}
// cout << "start: " << start << ", counter: ";
// for (int i = 0; i < n; i++) {
// cout << counter[i] << " ";
// }
// cout << endl;
}
for (int i = 1; i < n; i++) {
cout << counter[i] << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
int main() {
int n, x, y;
cin >> n >> x >> y;
x--;
y--;
vector<int> adj[10000];
rep(i, n - 1) {
adj[i].push_back(i + 1);
adj[i + 1].push_back(i);
}
adj[x].push_back(y);
adj[y].push_back(x);
vector<int> counter(n, 0);
for (int start = 0; start < n; start++) {
queue<int> q;
q.push(start);
vector<int> dist(n, 1e9);
dist[start] = 1;
while (!q.empty()) {
int now = q.front();
q.pop();
for (int to : adj[now]) {
if (dist[to] != 1e9)
continue;
if (dist[to] > dist[now] + 1) {
dist[to] = dist[now] + 1;
q.push(to);
}
}
}
for (int i = start + 1; i < n; i++) {
counter[dist[i] - 1]++;
}
// cout << "start: " << start << ", counter: ";
// for (int i = 0; i < n; i++) {
// cout << counter[i] << " ";
// }
// cout << endl;
}
for (int i = 1; i < n; i++) {
cout << counter[i] << endl;
}
} | replace | 10 | 11 | 10 | 11 | 0 | |
p02726 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
ll memo[2001][2001]; // 各点の最短距離を記録したもの
int main() {
ll n;
ll x;
ll y;
cin >> n >> x >> y;
x--;
y--;
rep(i, n) {
rep(j, n) { memo[i][j] = -1; }
}
rep(i, n - 1) {
memo[i][i] = 0;
memo[i][i + 1] = 1;
memo[i + 1][i] = 1;
}
memo[n - 1][n - 1] = 0;
memo[x][y] = 1;
memo[y][x] = 1;
for (ll k = 2; k < n; k++) {
for (ll i = 0; i < n - 2; i++) {
if (memo[i][i + k] != -1) {
continue;
}
ll p = min(memo[i][i + k - 1], memo[i + 1][i + k]);
ll j = labs(i - x) + labs(i + k - y);
ll h = labs(i - y) + labs(i + k - x);
ll g = min(p + 1, j + 1);
memo[i][i + k] = min(g, h + 1);
memo[i + k][i] = min(g, h + 1);
}
}
map<ll, ll> score;
rep(i, n) {
rep(j, n) { score[memo[i][j]] += 1; }
}
rep(i, n - 1) { cout << score[i + 1] / 2 << endl; }
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)
ll memo[20001][20001]; // 各点の最短距離を記録したもの
int main() {
ll n;
ll x;
ll y;
cin >> n >> x >> y;
x--;
y--;
rep(i, n) {
rep(j, n) { memo[i][j] = -1; }
}
rep(i, n - 1) {
memo[i][i] = 0;
memo[i][i + 1] = 1;
memo[i + 1][i] = 1;
}
memo[n - 1][n - 1] = 0;
memo[x][y] = 1;
memo[y][x] = 1;
for (ll k = 2; k < n; k++) {
for (ll i = 0; i < n - 2; i++) {
if (memo[i][i + k] != -1) {
continue;
}
ll p = min(memo[i][i + k - 1], memo[i + 1][i + k]);
ll j = labs(i - x) + labs(i + k - y);
ll h = labs(i - y) + labs(i + k - x);
ll g = min(p + 1, j + 1);
memo[i][i + k] = min(g, h + 1);
memo[i + k][i] = min(g, h + 1);
}
}
map<ll, ll> score;
rep(i, n) {
rep(j, n) { score[memo[i][j]] += 1; }
}
rep(i, n - 1) { cout << score[i + 1] / 2 << endl; }
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02726 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int inf = 0x3f3f3f3f;
const int maxn = 4e3 + 10;
int cnt = 0, head[maxn];
int dst[maxn], vis[maxn] = {0};
int n;
struct Edge {
int val, to, next;
} edge[maxn];
struct node {
int dst, to;
bool operator<(const node &b) const { return dst > b.dst; }
} p[maxn];
void add_edge(int from, int to, int val) {
cnt++;
edge[cnt].to = to;
edge[cnt].val = val;
edge[cnt].next = head[from];
head[from] = cnt;
}
void dijkstra(int s) {
// memset(dst,inf,sizeof dst);
// memset(vis,0,sizeof vis);
for (int i = 0; i <= n; i++) {
vis[i] = 0;
dst[i] = inf;
}
priority_queue<node> q;
q.push((node){0, s});
while (!q.empty()) {
node on = q.top();
q.pop();
if (vis[on.to])
continue;
dst[on.to] = on.dst;
vis[on.to] = 1;
for (int i = head[on.to]; i; i = edge[i].next) {
if (dst[edge[i].to] > dst[on.to] + edge[i].val) {
dst[edge[i].to] = dst[on.to] + edge[i].val;
if (vis[edge[i].to] == 0)
q.push((node){dst[edge[i].to], edge[i].to});
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int m, s, x, y;
memset(head, -1, sizeof head);
cin >> n >> x >> y;
for (int i = 1; i < n; i++) {
add_edge(i, i + 1, 1);
add_edge(i + 1, i, 1);
}
add_edge(x, y, 1);
add_edge(y, x, 1);
int len[2000][20000];
for (int i = 1; i <= n; i++) {
dijkstra(i);
for (int j = 1; j <= n; j++) {
// cout<<dst[j]<<' ';
if (len[i][j] == 0)
len[i][j] = dst[j];
else
len[i][j] = min(len[i][j], dst[j]);
}
}
int ans[maxn];
for (int i = 1; i < n; i++) {
for (int j = i + 1; j <= n; j++) {
ans[len[i][j]]++;
}
}
for (int i = 1; i < n; i++)
cout << ans[i] << ' ';
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int inf = 0x3f3f3f3f;
const int maxn = 4e3 + 10;
int cnt = 0, head[maxn];
int dst[maxn], vis[maxn] = {0};
int n;
struct Edge {
int val, to, next;
} edge[maxn];
struct node {
int dst, to;
bool operator<(const node &b) const { return dst > b.dst; }
} p[maxn];
void add_edge(int from, int to, int val) {
cnt++;
edge[cnt].to = to;
edge[cnt].val = val;
edge[cnt].next = head[from];
head[from] = cnt;
}
void dijkstra(int s) {
// memset(dst,inf,sizeof dst);
// memset(vis,0,sizeof vis);
for (int i = 0; i <= n; i++) {
vis[i] = 0;
dst[i] = inf;
}
priority_queue<node> q;
q.push((node){0, s});
while (!q.empty()) {
node on = q.top();
q.pop();
if (vis[on.to])
continue;
dst[on.to] = on.dst;
vis[on.to] = 1;
for (int i = head[on.to]; i; i = edge[i].next) {
if (dst[edge[i].to] > dst[on.to] + edge[i].val) {
dst[edge[i].to] = dst[on.to] + edge[i].val;
if (vis[edge[i].to] == 0)
q.push((node){dst[edge[i].to], edge[i].to});
}
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int m, s, x, y;
memset(head, -1, sizeof head);
cin >> n >> x >> y;
for (int i = 1; i < n; i++) {
add_edge(i, i + 1, 1);
add_edge(i + 1, i, 1);
}
add_edge(x, y, 1);
add_edge(y, x, 1);
int len[2020][2020];
for (int i = 1; i <= n; i++) {
dijkstra(i);
for (int j = 1; j <= n; j++) {
// cout<<dst[j]<<' ';
if (len[i][j] == 0)
len[i][j] = dst[j];
else
len[i][j] = min(len[i][j], dst[j]);
}
}
int ans[maxn];
for (int i = 1; i < n; i++) {
for (int j = i + 1; j <= n; j++) {
ans[len[i][j]]++;
}
}
for (int i = 1; i < n; i++)
cout << ans[i] << ' ';
} | replace | 61 | 62 | 61 | 62 | -11 | |
p02726 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
using namespace std;
int n, x, y;
int all[1005];
int main() {
cin >> n >> x >> y;
for (int i = 1; i <= n; i++)
all[i] = 0;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
int dist1 = abs(j - i);
int dist2 = abs(x - i) + 1 + abs(j - y);
int min_dist = min(dist1, dist2);
all[min_dist]++;
}
}
for (int i = 1; i < n; i++) {
cout << all[i] << '\n';
}
return 0;
}
| #include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
using namespace std;
int n, x, y;
int all[20005];
int main() {
cin >> n >> x >> y;
for (int i = 1; i <= n; i++)
all[i] = 0;
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
int dist1 = abs(j - i);
int dist2 = abs(x - i) + 1 + abs(j - y);
int min_dist = min(dist1, dist2);
all[min_dist]++;
}
}
for (int i = 1; i < n; i++) {
cout << all[i] << '\n';
}
return 0;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p02726 | C++ | Time Limit Exceeded | // *
// *
// * Created By :hozaifa wahid
// * "mai maut ko takia aur kafan ko chadar banakar sota hu"
// *------------------------------------
// * OS : Ubuntu 16.04
// * Language : CPP14
// * Editor : Sublime Text 3
// * C++ compiler : g++
// *https://www.geeksforgeeks.org/space-and-time-efficient-binomial-coefficient/
// *https://www.geeksforgeeks.org/binomial-coefficient-dp-9/
// https://www.geeksforgeeks.org/compute-ncr-p-set-2-lucas-theorem/
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define inf 1000000007
#define fr first
#define sc second
#define eps 1e-9
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define sni(x) scanf("%d", &x)
#define snl(x) scanf("%lld", &x)
#define snc(x) scanf("%c", &c);
#define rep(n) for (int i = 0; i < n; i++)
#define repc(i, n) for (int i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
ll MOD = 1000000007;
ll C[2005][2005];
ll min(ll a, ll b) { return a < b ? a : b; }
ll pw(ll a, ll b) {
if (b == 0)
return 1;
ll x = pw(a, b / 2);
x = (x * x);
if (b % 2)
x = (x * a);
return x;
}
ll comb2(ll n, ll k, ll x) {
ll res = 1LL;
if (k > n - k)
k = n - k;
for (int i = 0; i < k; ++i) {
res = (res % MOD * (n - i) % MOD) % MOD;
res = (res % MOD * pw((i + 1), MOD - 2) % MOD) % MOD;
}
// return res;
return res % MOD;
}
void comb(ll n, ll k) {
// int C[n+1][k+1];
ll i, j;
// Caculate value of Binomial Coefficient in bottom up manner
for (i = 0; i <= n; i++) {
for (j = 0; j <= min(i, k); j++) {
// Base Cases
if (j == 0 || j == i)
C[i][j] = 1LL;
// Calculate value using previosly stored values
else
C[i][j] = (C[i - 1][j - 1] % MOD + C[i - 1][j] % MOD) % MOD;
}
}
// return C[n][k];
}
ll phi(ll n) {
ll result = n; // Initialize result as n
// Consider all prime factors of n and subtract their
// multiples from result
for (ll p = 2; p * p <= n; ++p) {
// Check if p is a prime factor.
if (n % p == 0) {
// If yes, then update n and result
while (n % p == 0)
n /= p;
result -= result / p;
}
}
// If n has a prime factor greater than sqrt(n)
// (There can be at-most one such prime factor)
if (n > 1)
result -= result / n;
return result;
}
ll cc(ll n) {
// Modulus operator are expensive
// on most of the computers.
// n & 3 will be equivalent to n % 4
// n % 4
switch (n & 3) {
// If n is a multiple of 4
case 0:
return n;
// If n % 4 gives remainder 1
case 1:
return 1;
// If n % 4 gives remainder 2
case 2:
return n + 1;
// If n % 4 gives remainder 3
case 3:
return 0;
}
}
void solve() {
// comb(2001,2001);
std::ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
ll t;
t = 1;
// cin>>t;
while (t--) {
ll n, x, y;
cin >> n >> x >> y;
map<ll, map<ll, ll>> mp;
FOR(i, 1, n + 1) {
FOR(j, 1, n + 1) { mp[i][j] = abs(i - j); }
}
FOR(i, 1, n + 1) {
FOR(j, 1, n + 1) {
mp[i][j] = min(mp[i][j], mp[i][x] + 1 + mp[y][j]);
mp[i][j] = min(mp[i][j], mp[i][y] + 1 + mp[x][j]);
}
}
map<ll, ll> mp1;
FOR(i, 0, n + 1) {
FOR(j, 1, i) { mp1[mp[i][j]]++; }
}
FOR(i, 1, n) { cout << mp1[i] << "\n"; }
}
}
int main() {
std::ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
solve();
}
| // *
// *
// * Created By :hozaifa wahid
// * "mai maut ko takia aur kafan ko chadar banakar sota hu"
// *------------------------------------
// * OS : Ubuntu 16.04
// * Language : CPP14
// * Editor : Sublime Text 3
// * C++ compiler : g++
// *https://www.geeksforgeeks.org/space-and-time-efficient-binomial-coefficient/
// *https://www.geeksforgeeks.org/binomial-coefficient-dp-9/
// https://www.geeksforgeeks.org/compute-ncr-p-set-2-lucas-theorem/
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define inf 1000000007
#define fr first
#define sc second
#define eps 1e-9
#define clr(a) memset(a, 0, sizeof(a))
#define sz(x) x.size()
#define sni(x) scanf("%d", &x)
#define snl(x) scanf("%lld", &x)
#define snc(x) scanf("%c", &c);
#define rep(n) for (int i = 0; i < n; i++)
#define repc(i, n) for (int i = 0; i < n; i++)
#define FOR(i, x, y) for (int i = x; i < y; i++)
#define DEC(i, x, y) for (int i = x; i >= y; i--)
#define all(v) v.begin(), v.end()
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define alla(a, n) a, a + n
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
ll MOD = 1000000007;
ll C[2005][2005];
ll min(ll a, ll b) { return a < b ? a : b; }
ll pw(ll a, ll b) {
if (b == 0)
return 1;
ll x = pw(a, b / 2);
x = (x * x);
if (b % 2)
x = (x * a);
return x;
}
ll comb2(ll n, ll k, ll x) {
ll res = 1LL;
if (k > n - k)
k = n - k;
for (int i = 0; i < k; ++i) {
res = (res % MOD * (n - i) % MOD) % MOD;
res = (res % MOD * pw((i + 1), MOD - 2) % MOD) % MOD;
}
// return res;
return res % MOD;
}
void comb(ll n, ll k) {
// int C[n+1][k+1];
ll i, j;
// Caculate value of Binomial Coefficient in bottom up manner
for (i = 0; i <= n; i++) {
for (j = 0; j <= min(i, k); j++) {
// Base Cases
if (j == 0 || j == i)
C[i][j] = 1LL;
// Calculate value using previosly stored values
else
C[i][j] = (C[i - 1][j - 1] % MOD + C[i - 1][j] % MOD) % MOD;
}
}
// return C[n][k];
}
ll phi(ll n) {
ll result = n; // Initialize result as n
// Consider all prime factors of n and subtract their
// multiples from result
for (ll p = 2; p * p <= n; ++p) {
// Check if p is a prime factor.
if (n % p == 0) {
// If yes, then update n and result
while (n % p == 0)
n /= p;
result -= result / p;
}
}
// If n has a prime factor greater than sqrt(n)
// (There can be at-most one such prime factor)
if (n > 1)
result -= result / n;
return result;
}
ll cc(ll n) {
// Modulus operator are expensive
// on most of the computers.
// n & 3 will be equivalent to n % 4
// n % 4
switch (n & 3) {
// If n is a multiple of 4
case 0:
return n;
// If n % 4 gives remainder 1
case 1:
return 1;
// If n % 4 gives remainder 2
case 2:
return n + 1;
// If n % 4 gives remainder 3
case 3:
return 0;
}
}
void solve() {
// comb(2001,2001);
std::ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
ll t;
t = 1;
// cin>>t;
while (t--) {
ll n, x, y;
cin >> n >> x >> y;
ll mp[n + 1][n + 1];
FOR(i, 1, n + 1) {
FOR(j, 1, n + 1) { mp[i][j] = abs(i - j); }
}
FOR(i, 1, n + 1) {
FOR(j, 1, n + 1) {
mp[i][j] = min(mp[i][j], mp[i][x] + 1 + mp[y][j]);
mp[i][j] = min(mp[i][j], mp[i][y] + 1 + mp[x][j]);
}
}
map<ll, ll> mp1;
FOR(i, 0, n + 1) {
FOR(j, 1, i) { mp1[mp[i][j]]++; }
}
FOR(i, 1, n) { cout << mp1[i] << "\n"; }
}
}
int main() {
std::ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
solve();
}
| replace | 145 | 146 | 145 | 146 | TLE | |
p02726 | C++ | Runtime Error | #include <iostream>
#include <queue>
#include <vector>
using namespace std;
int N, X, Y, a[1004][1004], ans[10005];
vector<int> graph[3004];
queue<int> q;
int main() {
cin >> N >> X >> Y;
for (int i = 2; i < N; i++) {
graph[i].push_back(i - 1);
graph[i].push_back(i + 1);
}
graph[1].push_back(2);
graph[N].push_back(N - 1);
graph[X].push_back(Y);
graph[Y].push_back(X);
for (int i = 1; i <= N; i++) {
a[i][i] = 0;
q.push(i);
while (!q.empty()) {
int f = q.front();
q.pop();
for (int j = 0; j < graph[f].size(); j++) {
if (a[i][graph[f][j]] == 0 && graph[f][j] != i) {
a[i][graph[f][j]] = a[i][f] + 1;
q.push(graph[f][j]);
}
}
}
}
for (int i = 1; i < N; i++) {
for (int j = i + 1; j <= N; j++) {
ans[a[i][j]]++;
}
}
for (int i = 1; i <= N - 1; i++) {
cout << ans[i] << endl;
}
return 0;
} | #include <iostream>
#include <queue>
#include <vector>
using namespace std;
int N, X, Y, a[3004][3004], ans[10005];
vector<int> graph[3004];
queue<int> q;
int main() {
cin >> N >> X >> Y;
for (int i = 2; i < N; i++) {
graph[i].push_back(i - 1);
graph[i].push_back(i + 1);
}
graph[1].push_back(2);
graph[N].push_back(N - 1);
graph[X].push_back(Y);
graph[Y].push_back(X);
for (int i = 1; i <= N; i++) {
a[i][i] = 0;
q.push(i);
while (!q.empty()) {
int f = q.front();
q.pop();
for (int j = 0; j < graph[f].size(); j++) {
if (a[i][graph[f][j]] == 0 && graph[f][j] != i) {
a[i][graph[f][j]] = a[i][f] + 1;
q.push(graph[f][j]);
}
}
}
}
for (int i = 1; i < N; i++) {
for (int j = i + 1; j <= N; j++) {
ans[a[i][j]]++;
}
}
for (int i = 1; i <= N - 1; i++) {
cout << ans[i] << endl;
}
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02726 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef double dbl;
typedef long long int lld;
#define MAX std::numeric_limits<lld>::max();
#define MIN std::numeric_limits<lld>::min();
#define FastIO \
ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
lld lvl[2001][2001];
void dfs(vector<lld> V[], lld s, lld i) {
set<lld> visit;
queue<lld> que;
lld y, j;
lvl[s][i] = 0;
visit.insert(i);
que.push(i);
while (!que.empty()) {
y = que.front();
que.pop();
for (j = 0; j < V[y].size(); j++) {
if (!visit.count(V[y][j])) {
visit.insert(V[y][j]);
que.push(V[y][j]);
lvl[s][V[y][j]] = lvl[s][y] + 1;
}
}
}
}
int main() {
#ifndef ONLINE_JUDGE
freopen("inputf.in", "r", stdin);
freopen("outputf.in", "w", stdout);
#endif
FastIO lld n, x;
lld y, i;
cin >> n;
cin >> x;
cin >> y;
lld j;
vector<lld> V[n + 1];
for (i = 2; i <= n; i++) {
lld j = i - 1;
V[i].push_back(j);
V[j].push_back(i);
}
V[x].push_back(y);
V[y].push_back(x);
for (i = 1; i <= n; i++) {
dfs(V, i, i);
}
set<lld> dist[n];
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
dist[lvl[i][j]].insert(((i + j) * (i + j + 1)) / 2 + j);
}
}
for (i = 1; i < n; i++) {
cout << dist[i].size() / 2;
cout << "\n";
}
return 0;
} | #include <bits/stdc++.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef double dbl;
typedef long long int lld;
#define MAX std::numeric_limits<lld>::max();
#define MIN std::numeric_limits<lld>::min();
#define FastIO \
ios::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
lld lvl[2001][2001];
void dfs(vector<lld> V[], lld s, lld i) {
set<lld> visit;
queue<lld> que;
lld y, j;
lvl[s][i] = 0;
visit.insert(i);
que.push(i);
while (!que.empty()) {
y = que.front();
que.pop();
for (j = 0; j < V[y].size(); j++) {
if (!visit.count(V[y][j])) {
visit.insert(V[y][j]);
que.push(V[y][j]);
lvl[s][V[y][j]] = lvl[s][y] + 1;
}
}
}
}
int main() {
FastIO lld n, x;
lld y, i;
cin >> n;
cin >> x;
cin >> y;
lld j;
vector<lld> V[n + 1];
for (i = 2; i <= n; i++) {
lld j = i - 1;
V[i].push_back(j);
V[j].push_back(i);
}
V[x].push_back(y);
V[y].push_back(x);
for (i = 1; i <= n; i++) {
dfs(V, i, i);
}
set<lld> dist[n];
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
dist[lvl[i][j]].insert(((i + j) * (i + j + 1)) / 2 + j);
}
}
for (i = 1; i < n; i++) {
cout << dist[i].size() / 2;
cout << "\n";
}
return 0;
} | delete | 37 | 41 | 37 | 37 | -11 | |
p02726 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define pb push_back
#define POP pop_back()
#define ll long long
#define db double
#define POP pop_back()
#define endl '\n'
#define PII pair<int, int>
#define FI first
#define SE second
#define VI vector<int>
#define QI queue<int>
#define SI stack<int>
#define debug cout << "debug" << endl;
#define PLL pair<ll, ll>
#define PDD pair<double, double>
#define ULL unsigned long long
#define fo(i, a, b) for (int i = a; i <= b; ++i)
#define fd(i, a, b) for (int i = a; i >= b; --i)
#define mem(x, a) memset(x, a, sizeof(x))
const int maxn = 1e3 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int a[maxn][maxn], ans[maxn];
int main() {
int n, k, x, y;
cin >> n >> x >> y;
fo(i, 1, n - 1) {
fo(j, i + 1, n) {
if (i <= x && j >= y)
a[i][j] = j - i - (y - x - 1), a[j][i] = j - i - (y - x - 1);
else
a[i][j] = a[j][j] = min(j - i, abs(x - i) + abs(y - j) + 1);
}
}
fo(i, 1, n) {
fo(j, i + 1, n) { ans[a[i][j]]++; }
}
fo(i, 1, n - 1) { cout << ans[i] << endl; }
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
#define pb push_back
#define POP pop_back()
#define ll long long
#define db double
#define POP pop_back()
#define endl '\n'
#define PII pair<int, int>
#define FI first
#define SE second
#define VI vector<int>
#define QI queue<int>
#define SI stack<int>
#define debug cout << "debug" << endl;
#define PLL pair<ll, ll>
#define PDD pair<double, double>
#define ULL unsigned long long
#define fo(i, a, b) for (int i = a; i <= b; ++i)
#define fd(i, a, b) for (int i = a; i >= b; --i)
#define mem(x, a) memset(x, a, sizeof(x))
const int maxn = 2e3 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int a[maxn][maxn], ans[maxn];
int main() {
int n, k, x, y;
cin >> n >> x >> y;
fo(i, 1, n - 1) {
fo(j, i + 1, n) {
if (i <= x && j >= y)
a[i][j] = j - i - (y - x - 1), a[j][i] = j - i - (y - x - 1);
else
a[i][j] = a[j][j] = min(j - i, abs(x - i) + abs(y - j) + 1);
}
}
fo(i, 1, n) {
fo(j, i + 1, n) { ans[a[i][j]]++; }
}
fo(i, 1, n - 1) { cout << ans[i] << endl; }
return 0;
} | replace | 31 | 32 | 31 | 32 | 0 | |
p02726 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
int main() {
int N, X, Y;
cin >> N >> X >> Y;
vector<int> ans(N - 1);
for (int k = 1; k <= N - 1; k++) {
int dist_min;
ans[k - 1] = 0;
for (int i = 1; i <= N - 1; i++) {
for (int j = i + 1; j <= N; j++) {
dist_min = min(abs(j - i), min(abs(X - i) + 1 + abs(j - Y),
abs(Y - i) + 1 + abs(j - X)));
if (dist_min == k)
ans[k - 1]++;
}
}
}
for (int i = 0; i < N - 1; i++)
cout << ans[i] << endl;
} | #include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
int main() {
int N, X, Y;
cin >> N >> X >> Y;
vector<int> ans(N - 1, 0);
int dist_min;
for (int i = 1; i <= N - 1; i++) {
for (int j = i + 1; j <= N; j++) {
dist_min = min(abs(j - i), min(abs(X - i) + 1 + abs(j - Y),
abs(Y - i) + 1 + abs(j - X)));
ans[dist_min - 1]++;
}
}
for (int i = 0; i < N - 1; i++)
cout << ans[i] << endl;
} | replace | 10 | 21 | 10 | 17 | TLE | |
p02726 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define oo 0x3f3f3f3fLL
#define sz(s) (int)(s.size())
#define RT(s) return cout << s, 0
#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
}
const int N = 1e3 + 9;
vector<int> adj[N];
vector<int> dis[N];
int n;
void bfs(int node) {
vector<int> &len = dis[node];
len = vector<int>(n + 1, oo);
len[node] = 0;
queue<int> q;
q.push(node);
while (sz(q)) {
node = q.front();
q.pop();
for (int ch : adj[node]) {
if (len[ch] > len[node] + 1) {
len[ch] = len[node] + 1;
q.push(ch);
}
}
}
}
int main() {
run();
int x, y;
cin >> n >> x >> y;
for (int i = 1; i < n; i++)
adj[i].push_back(i + 1), adj[i + 1].push_back(i);
adj[x].push_back(y);
adj[y].push_back(x);
map<int, int> mp;
for (int i = 1; i <= n; i++)
bfs(i);
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
mp[dis[i][j]]++;
for (int k = 1; k < n; k++)
cout << mp[k] << endl;
}
| #include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define oo 0x3f3f3f3fLL
#define sz(s) (int)(s.size())
#define RT(s) return cout << s, 0
#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
}
const int N = 2e3 + 9;
vector<int> adj[N];
vector<int> dis[N];
int n;
void bfs(int node) {
vector<int> &len = dis[node];
len = vector<int>(n + 1, oo);
len[node] = 0;
queue<int> q;
q.push(node);
while (sz(q)) {
node = q.front();
q.pop();
for (int ch : adj[node]) {
if (len[ch] > len[node] + 1) {
len[ch] = len[node] + 1;
q.push(ch);
}
}
}
}
int main() {
run();
int x, y;
cin >> n >> x >> y;
for (int i = 1; i < n; i++)
adj[i].push_back(i + 1), adj[i + 1].push_back(i);
adj[x].push_back(y);
adj[y].push_back(x);
map<int, int> mp;
for (int i = 1; i <= n; i++)
bfs(i);
for (int i = 1; i <= n; i++)
for (int j = i + 1; j <= n; j++)
mp[dis[i][j]]++;
for (int k = 1; k < n; k++)
cout << mp[k] << endl;
}
| replace | 31 | 32 | 31 | 32 | 0 | |
p02726 | C++ | Runtime Error | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <random>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
template <class T> using V = vector<T>;
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;
}
const long long INF = 1LL << 60;
using ll = long long;
using db = long double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll = V<pair<ll, ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using graph = V<V<int>>;
using pq = priority_queue<ll>;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn, (a).en)
#define REV(a) reverse((a).bgn, (a).en)
#define fi first
#define se second
#define sz size()
#define gcd(a, b) __gcd(a, b)
#define pb(a) push_back(a);
#define ALL(a) (a).begin(), (a).end()
ll Sum(ll n) {
ll m = 0;
while (n) {
m += n % 10;
n /= 10;
}
return m;
}
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void Comuse() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
#define comuse Comuse()
ll combi(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll perm(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] % MOD) % MOD;
}
ll modpow(ll a, ll n, ll mod) {
ll ans = 1;
while (n > 0) {
if (n & 1) {
ans = ans * a % mod;
}
a = a * a % mod;
n >>= 1;
}
return ans;
}
ll modinv(ll a, ll mod) { return modpow(a, mod - 2, mod); }
ll modcombi(int n, int k, int mod) {
ll ans = 1;
for (ll i = n; i > n - k; i--) {
ans *= i;
ans %= mod;
}
for (ll i = 1; i <= k; i++) {
ans *= modinv(i, mod);
ans %= mod;
}
return ans;
}
ll lcm(ll a, ll b) {
ll n;
n = a / gcd(a, b) * b;
return n;
}
vll div(ll n) {
vll ret;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n) {
ret.push_back(n / i);
}
}
}
SORT(ret);
return (ret);
}
vector<bool> isprime(MAX + 100, true);
void primeuse() {
isprime[0] = false;
isprime[1] = false;
for (int i = 2; i < MAX + 50; i++) {
int up = sqrt(i) + 1;
for (int j = 2; j < up; j++) {
if (i % j == 0) {
isprime[i] = false;
}
}
}
}
void Solve();
const int MAX_N = 131072;
// segment tree
int NN;
int seg[MAX_N * 2 - 1];
void seguse() {
for (int i = 0; i < 2 * NN - 1; i++) {
seg[i] = INT_MAX;
}
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(20) << fixed;
Solve();
}
/****************************************\
| Thank you for viewing my code:) |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka |
\****************************************/
// segtreeの葉の先頭の添え字はN-1
void Solve() {
// ll N=262144;
// vll segtree(2*N-1);
ll x, y, a, b, c;
cin >> x >> y >> a >> b >> c;
vll A(a);
vll B(b);
vll C(c);
FOR(i, 0, a) { cin >> A[i]; }
SORT(A);
REV(A);
FOR(i, 0, b) { cin >> B[i]; }
SORT(B);
REV(B);
FOR(i, 0, c) { cin >> C[i]; }
SORT(C);
REV(C);
C.push_back(0);
vll ans(0);
FOR(i, 0, x) {
ll now = A[i];
ans.push_back(now);
}
FOR(i, 0, y) {
ll now = B[i];
ans.push_back(now);
}
SORT(ans);
ll anow = 0;
FOR(i, 0, x + y) {
if (C[anow] > ans[i]) {
ans[i] = C[anow];
anow++;
}
}
ll s = 0;
FOR(i, 0, x + y) { s += ans[i]; }
cout << s << "\n";
} | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <random>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
template <class T> using V = vector<T>;
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;
}
const long long INF = 1LL << 60;
using ll = long long;
using db = long double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll = V<pair<ll, ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using graph = V<V<int>>;
using pq = priority_queue<ll>;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn, (a).en)
#define REV(a) reverse((a).bgn, (a).en)
#define fi first
#define se second
#define sz size()
#define gcd(a, b) __gcd(a, b)
#define pb(a) push_back(a);
#define ALL(a) (a).begin(), (a).end()
ll Sum(ll n) {
ll m = 0;
while (n) {
m += n % 10;
n /= 10;
}
return m;
}
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void Comuse() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
#define comuse Comuse()
ll combi(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll perm(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] % MOD) % MOD;
}
ll modpow(ll a, ll n, ll mod) {
ll ans = 1;
while (n > 0) {
if (n & 1) {
ans = ans * a % mod;
}
a = a * a % mod;
n >>= 1;
}
return ans;
}
ll modinv(ll a, ll mod) { return modpow(a, mod - 2, mod); }
ll modcombi(int n, int k, int mod) {
ll ans = 1;
for (ll i = n; i > n - k; i--) {
ans *= i;
ans %= mod;
}
for (ll i = 1; i <= k; i++) {
ans *= modinv(i, mod);
ans %= mod;
}
return ans;
}
ll lcm(ll a, ll b) {
ll n;
n = a / gcd(a, b) * b;
return n;
}
vll div(ll n) {
vll ret;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n) {
ret.push_back(n / i);
}
}
}
SORT(ret);
return (ret);
}
vector<bool> isprime(MAX + 100, true);
void primeuse() {
isprime[0] = false;
isprime[1] = false;
for (int i = 2; i < MAX + 50; i++) {
int up = sqrt(i) + 1;
for (int j = 2; j < up; j++) {
if (i % j == 0) {
isprime[i] = false;
}
}
}
}
void Solve();
const int MAX_N = 131072;
// segment tree
int NN;
int seg[MAX_N * 2 - 1];
void seguse() {
for (int i = 0; i < 2 * NN - 1; i++) {
seg[i] = INT_MAX;
}
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(20) << fixed;
Solve();
}
/****************************************\
| Thank you for viewing my code:) |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka |
\****************************************/
// segtreeの葉の先頭の添え字はN-1
void Solve() {
// ll N=262144;
// vll segtree(2*N-1);
ll n, x, y;
cin >> n >> x >> y;
vll A(n);
for (int i = 1; i < n; i++) {
for (int j = i + 1; j <= n; j++) {
ll sonomama = j - i;
ll hen = abs(x - i) + abs(y - j) + 1;
ll now = 0;
now = min(hen, sonomama);
A[now]++;
}
}
FOR(i, 1, n) { cout << A[i] << "\n"; }
} | replace | 196 | 232 | 196 | 211 | -6 | terminate called after throwing an instance of 'std::length_error'
what(): cannot create std::vector larger than max_size()
|
p02726 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
using namespace std;
const int MAXN = 1e3 + 10;
int n, x, y;
int sol[MAXN];
int main(void) {
scanf("%d%d%d", &n, &x, &y);
--x;
--y;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
int d = min(abs(i - j), min(1 + abs(i - x) + abs(j - y),
1 + abs(i - y) + abs(j - x)));
sol[d]++;
}
}
for (int i = 1; i < n; ++i)
printf("%d\n", sol[i]);
return 0;
}
| #include <algorithm>
#include <cstdio>
using namespace std;
const int MAXN = 2e3 + 10;
int n, x, y;
int sol[MAXN];
int main(void) {
scanf("%d%d%d", &n, &x, &y);
--x;
--y;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
int d = min(abs(i - j), min(1 + abs(i - x) + abs(j - y),
1 + abs(i - y) + abs(j - x)));
sol[d]++;
}
}
for (int i = 1; i < n; ++i)
printf("%d\n", sol[i]);
return 0;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p02726 | C++ | Runtime Error | #include <bits/stdc++.h>
//{ SFT
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
// 降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1 << (n))
#define pcnt(x) __builitin_popcountll(x)
// 配列内等要素削除
#define unique(x) (x).erase(unique(x).begin(),(x).end()),(x).end());
#define Fixed(n) fixed << setprecision(n)
// 総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
#define eb(x, a) (x).emplaes_back(a)
#define F first
#define S second
#define cauto (const auto &)
template <class A, class B> using pii = vector<pair<A, B>>;
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>;
template <class A> using uset = unordered_set<A>;
template <class T>
bool chmax(T &a, const T &b) // 最大値更新 返り値はbool
{
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b) // 最小値更新 返り値はbool
{
if (b < a) {
a = b;
return 1;
}
return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr long long mod1 = 1e9 + 7;
constexpr long long mod2 = 998244353;
//} END
constexpr int MAX_N = 2 * 1e3;
using P = pair<int, int>; // firstは最短距離,secondは頂点の番号
int n, x, y;
vector<vector<P>> graph;
int min_cost[MAX_N];
void Dijkstra(int s) {
// 昇順でfirstを小さい方から取る
min_heap<P> que;
fill(min_cost, min_cost + n + 2, INF);
min_cost[s] = 0;
que.emplace(0, s);
while (!que.empty()) {
int now_cost, now_node;
tie(now_cost, now_node) = que.top();
que.pop();
if (min_cost[now_node] <
now_cost) // queの値より新しいcostの方が小さいとき見ない
{
continue;
}
rep(i, 0, graph[now_node].size()) {
int next_node, next_cost;
tie(next_node, next_cost) = graph[now_node][i];
if (chmin(min_cost[next_node],
min_cost[now_node] + next_cost)) // 最短経路の更新
{ // 最短経路更新
que.emplace(min_cost[next_node], next_node);
}
}
}
}
signed main(void) {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cin >> n >> x >> y;
graph.resize(n + 1);
rep(i, 1, n) {
graph[i].emplace_back(i + 1, 1); // グラフの構築
graph[i + 1].emplace_back(i, 1);
}
graph[x].emplace_back(y, 1);
graph[y].emplace_back(x, 1);
vector<int> cnt(n + 1);
rep(i, 1, n) {
Dijkstra(i);
// cout << i << '\n';
rep(j, i + 1, n + 1) {
++cnt[min_cost[j]];
// cout << j << ' ' << min_cost[j] << '\n';
}
// cout << '\n';
}
rep(i, 1, n) { cout << cnt[i] << '\n'; }
return 0;
} | #include <bits/stdc++.h>
//{ SFT
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
// 降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1 << (n))
#define pcnt(x) __builitin_popcountll(x)
// 配列内等要素削除
#define unique(x) (x).erase(unique(x).begin(),(x).end()),(x).end());
#define Fixed(n) fixed << setprecision(n)
// 総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).flont_back(a)
#define eb(x, a) (x).emplaes_back(a)
#define F first
#define S second
#define cauto (const auto &)
template <class A, class B> using pii = vector<pair<A, B>>;
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>;
template <class A> using uset = unordered_set<A>;
template <class T>
bool chmax(T &a, const T &b) // 最大値更新 返り値はbool
{
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b) // 最小値更新 返り値はbool
{
if (b < a) {
a = b;
return 1;
}
return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr long long mod1 = 1e9 + 7;
constexpr long long mod2 = 998244353;
//} END
constexpr int MAX_N = 2 * 10e3;
using P = pair<int, int>; // firstは最短距離,secondは頂点の番号
int n, x, y;
vector<vector<P>> graph;
int min_cost[MAX_N];
void Dijkstra(int s) {
// 昇順でfirstを小さい方から取る
min_heap<P> que;
fill(min_cost, min_cost + n + 2, INF);
min_cost[s] = 0;
que.emplace(0, s);
while (!que.empty()) {
int now_cost, now_node;
tie(now_cost, now_node) = que.top();
que.pop();
if (min_cost[now_node] <
now_cost) // queの値より新しいcostの方が小さいとき見ない
{
continue;
}
rep(i, 0, graph[now_node].size()) {
int next_node, next_cost;
tie(next_node, next_cost) = graph[now_node][i];
if (chmin(min_cost[next_node],
min_cost[now_node] + next_cost)) // 最短経路の更新
{ // 最短経路更新
que.emplace(min_cost[next_node], next_node);
}
}
}
}
signed main(void) {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cin >> n >> x >> y;
graph.resize(n + 1);
rep(i, 1, n) {
graph[i].emplace_back(i + 1, 1); // グラフの構築
graph[i + 1].emplace_back(i, 1);
}
graph[x].emplace_back(y, 1);
graph[y].emplace_back(x, 1);
vector<int> cnt(n + 1);
rep(i, 1, n) {
Dijkstra(i);
// cout << i << '\n';
rep(j, i + 1, n + 1) {
++cnt[min_cost[j]];
// cout << j << ' ' << min_cost[j] << '\n';
}
// cout << '\n';
}
rep(i, 1, n) { cout << cnt[i] << '\n'; }
return 0;
} | replace | 59 | 60 | 59 | 60 | 0 | |
p02726 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
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;
}
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define P pair<ll, ll>
#define sz(x) (ll) x.size()
#define ALL(x) (x).begin(), (x).end()
#define ALLR(x) (x).rbegin(), (x).rend()
#define VE vector<ll>
#define COUT(x) cout << (x) << endl
#define MA map<ll, ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll, VE, greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define EPS (1e-14)
#define pb push_back
long long MOD = 1000000007;
// const long long MOD = 998244353;
const long long INF = 1LL << 60;
const double PI = acos(-1.0);
using Graph = vector<VE>;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime MOD
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
friend ostream &operator<<(ostream &os, const mint &m) {
os << m.x;
return os;
}
};
struct combination {
vector<mint> fact, ifact;
combination(int n) : fact(n + 1), ifact(n + 1) {
// assert(n < MOD);
fact[0] = 1;
for (int i = 1; i <= n; ++i)
fact[i] = fact[i - 1] * i;
ifact[n] = fact[n].inv();
for (int i = n; i >= 1; --i)
ifact[i - 1] = ifact[i] * i;
}
mint operator()(int n, int k) {
if (k < 0 || k > n)
return 0;
return fact[n] * ifact[k] * ifact[n - k];
}
} com(10);
struct Sieve {
int n;
vector<int> f, primes;
Sieve(int n = 1) : n(n), f(n + 1) {
f[0] = f[1] = -1;
for (ll i = 2; i <= n; ++i) {
if (f[i])
continue;
primes.push_back(i);
f[i] = i;
for (ll j = i * i; j <= n; j += i) {
if (!f[j])
f[j] = i;
}
}
}
bool isPrime(int x) { return f[x] == x; }
vector<int> factorList(int x) {
vector<int> res;
while (x != 1) {
res.push_back(f[x]);
x /= f[x];
}
return res;
}
vector<P> factor(int x) {
vector<int> fl = factorList(x);
if (fl.size() == 0)
return {};
vector<P> res(1, P(fl[0], 0));
for (int p : fl) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
};
class UnionFind {
public:
vector<ll> par;
vector<ll> siz;
// Constructor
UnionFind(ll sz_) : par(sz_), siz(sz_, 1) {
for (ll i = 0; i < sz_; ++i)
par[i] = i;
}
void init(ll sz_) {
par.resize(sz_);
siz.resize(sz_, 1);
for (ll i = 0; i < sz_; ++i)
par[i] = i;
}
// Member Function
// Find
ll root(ll x) {
while (par[x] != x) {
x = par[x] = par[par[x]];
}
return x;
}
// Union(Unite, Merge)
bool merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (siz[x] < siz[y])
swap(x, y);
siz[x] += siz[y];
par[y] = x;
return true;
}
bool issame(ll x, ll y) { return root(x) == root(y); }
ll size(ll x) { return siz[root(x)]; }
};
template <class t> t gcd(t a, t b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
return a * b / g;
}
bool prime(ll n) {
for (ll i = 2; i <= sqrt(n); i++) {
if (n % i == 0)
return false;
}
return n != 1;
}
map<ll, ll> prime_factor(ll n) {
map<ll, ll> ret;
for (ll i = 2; i * i <= n; i++) {
while (n % i == 0) {
ret[i]++;
n /= i;
}
}
if (n != 1)
ret[n] = 1;
return ret;
}
ll modinv(ll a, ll m) {
ll b = m, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
vector<pair<char, int>> RunLength(string s) {
if (s.size() == 0)
return {};
vector<pair<char, int>> res(1, pair<char, int>(s[0], 0));
for (char p : s) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
// Digit Count
int GetDigit(int num) { return log10(num) + 1; }
// bit calculation[how many "1"] (= __builtin_popcount())
int bit_count(int n) {
int cnt = 0;
while (n > 0) {
if (n % 2 == 1)
cnt++;
n /= 2;
}
return cnt;
}
mint POW(mint n, int p) {
if (p == 0)
return 1;
if (p % 2 == 0) {
mint t = POW(n, p / 2);
return t * t;
}
return n * POW(n, p - 1);
}
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, 1, 0, -1};
struct edge {
ll to, cost;
};
typedef long double ld;
int V;
vector<edge> G[1010];
int d[1010];
void dijkstra(int s) {
priority_queue<P, vector<P>, greater<P>> que;
fill(d, d + V, INF);
d[s] = 0;
que.push(P(0, s));
while (!que.empty()) {
P p = que.top();
que.pop();
int v = p.second;
if (d[v] < p.first)
continue;
rep(i, G[v].size()) {
edge e = G[v][i];
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
que.push(P(d[e.to], e.to));
}
}
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// cout << fixed << setprecision(15);
int n, x, y;
cin >> n >> x >> y;
V = n;
x--;
y--;
G[x].push_back({y, 1});
G[y].push_back({x, 1});
rep(i, n - 1) {
G[i].push_back({i + 1, 1});
G[i + 1].push_back({i, 1});
}
map<int, int> mp;
rep(i, n) {
dijkstra(i);
rep(j, n) { mp[d[j]]++; }
}
rep(i, n - 1) { cout << mp[i + 1] / 2 << endl; }
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
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;
}
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define P pair<ll, ll>
#define sz(x) (ll) x.size()
#define ALL(x) (x).begin(), (x).end()
#define ALLR(x) (x).rbegin(), (x).rend()
#define VE vector<ll>
#define COUT(x) cout << (x) << endl
#define MA map<ll, ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll, VE, greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define EPS (1e-14)
#define pb push_back
long long MOD = 1000000007;
// const long long MOD = 998244353;
const long long INF = 1LL << 60;
const double PI = acos(-1.0);
using Graph = vector<VE>;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime MOD
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
friend ostream &operator<<(ostream &os, const mint &m) {
os << m.x;
return os;
}
};
struct combination {
vector<mint> fact, ifact;
combination(int n) : fact(n + 1), ifact(n + 1) {
// assert(n < MOD);
fact[0] = 1;
for (int i = 1; i <= n; ++i)
fact[i] = fact[i - 1] * i;
ifact[n] = fact[n].inv();
for (int i = n; i >= 1; --i)
ifact[i - 1] = ifact[i] * i;
}
mint operator()(int n, int k) {
if (k < 0 || k > n)
return 0;
return fact[n] * ifact[k] * ifact[n - k];
}
} com(10);
struct Sieve {
int n;
vector<int> f, primes;
Sieve(int n = 1) : n(n), f(n + 1) {
f[0] = f[1] = -1;
for (ll i = 2; i <= n; ++i) {
if (f[i])
continue;
primes.push_back(i);
f[i] = i;
for (ll j = i * i; j <= n; j += i) {
if (!f[j])
f[j] = i;
}
}
}
bool isPrime(int x) { return f[x] == x; }
vector<int> factorList(int x) {
vector<int> res;
while (x != 1) {
res.push_back(f[x]);
x /= f[x];
}
return res;
}
vector<P> factor(int x) {
vector<int> fl = factorList(x);
if (fl.size() == 0)
return {};
vector<P> res(1, P(fl[0], 0));
for (int p : fl) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
};
class UnionFind {
public:
vector<ll> par;
vector<ll> siz;
// Constructor
UnionFind(ll sz_) : par(sz_), siz(sz_, 1) {
for (ll i = 0; i < sz_; ++i)
par[i] = i;
}
void init(ll sz_) {
par.resize(sz_);
siz.resize(sz_, 1);
for (ll i = 0; i < sz_; ++i)
par[i] = i;
}
// Member Function
// Find
ll root(ll x) {
while (par[x] != x) {
x = par[x] = par[par[x]];
}
return x;
}
// Union(Unite, Merge)
bool merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y)
return false;
if (siz[x] < siz[y])
swap(x, y);
siz[x] += siz[y];
par[y] = x;
return true;
}
bool issame(ll x, ll y) { return root(x) == root(y); }
ll size(ll x) { return siz[root(x)]; }
};
template <class t> t gcd(t a, t b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) {
ll g = gcd(a, b);
return a * b / g;
}
bool prime(ll n) {
for (ll i = 2; i <= sqrt(n); i++) {
if (n % i == 0)
return false;
}
return n != 1;
}
map<ll, ll> prime_factor(ll n) {
map<ll, ll> ret;
for (ll i = 2; i * i <= n; i++) {
while (n % i == 0) {
ret[i]++;
n /= i;
}
}
if (n != 1)
ret[n] = 1;
return ret;
}
ll modinv(ll a, ll m) {
ll b = m, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
vector<pair<char, int>> RunLength(string s) {
if (s.size() == 0)
return {};
vector<pair<char, int>> res(1, pair<char, int>(s[0], 0));
for (char p : s) {
if (res.back().first == p) {
res.back().second++;
} else {
res.emplace_back(p, 1);
}
}
return res;
}
// Digit Count
int GetDigit(int num) { return log10(num) + 1; }
// bit calculation[how many "1"] (= __builtin_popcount())
int bit_count(int n) {
int cnt = 0;
while (n > 0) {
if (n % 2 == 1)
cnt++;
n /= 2;
}
return cnt;
}
mint POW(mint n, int p) {
if (p == 0)
return 1;
if (p % 2 == 0) {
mint t = POW(n, p / 2);
return t * t;
}
return n * POW(n, p - 1);
}
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, 1, 0, -1};
struct edge {
ll to, cost;
};
typedef long double ld;
int V;
vector<edge> G[2010];
int d[2010];
void dijkstra(int s) {
priority_queue<P, vector<P>, greater<P>> que;
fill(d, d + V, INF);
d[s] = 0;
que.push(P(0, s));
while (!que.empty()) {
P p = que.top();
que.pop();
int v = p.second;
if (d[v] < p.first)
continue;
rep(i, G[v].size()) {
edge e = G[v][i];
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
que.push(P(d[e.to], e.to));
}
}
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// cout << fixed << setprecision(15);
int n, x, y;
cin >> n >> x >> y;
V = n;
x--;
y--;
G[x].push_back({y, 1});
G[y].push_back({x, 1});
rep(i, n - 1) {
G[i].push_back({i + 1, 1});
G[i + 1].push_back({i, 1});
}
map<int, int> mp;
rep(i, n) {
dijkstra(i);
rep(j, n) { mp[d[j]]++; }
}
rep(i, n - 1) { cout << mp[i + 1] / 2 << endl; }
return 0;
} | replace | 305 | 307 | 305 | 307 | 0 | |
p02726 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define sqr(x) ((x) * (x))
#define mp make_pair
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RE(i, n) FOR(i, 1, n)
#define REP(i, n) FOR(i, 0, (int)(n)-1)
#define fst first
#define snd second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef tuple<int, int, int> iii;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A> string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
void fastIO() {
cin.sync_with_stdio(false);
cin.tie(0);
}
int XMOV[4] = {0, 0, 1, -1};
int YMOV[4] = {1, -1, 0, 0};
// #############################
const int MAXN = 1000005;
int main() {
vector<int> g[1005];
int n, x, y;
cin >> n >> x >> y;
for (int i = 1; i < n; i++) {
g[i].pb(i + 1);
g[i + 1].pb(i);
}
g[x].pb(y);
g[y].pb(x);
ll ans[2005];
memset(ans, 0, sizeof(ans));
bool mark[2005];
queue<pii> q;
for (int node = 1; node <= n; node++) {
q.push(pii(node, 0));
// cout << "node: " << node << endl;
memset(mark, 0, sizeof(mark));
mark[node] = true;
while (!q.empty()) {
int j = q.front().snd;
// for(int i = 0; i < q.size(); i++){
// cout << q.front().fst << " ";
// q.push(q.front());
// q.pop();
// }
// cout << endl;
int src = q.front().fst;
q.pop();
for (auto w : g[src]) {
if (!mark[w]) {
mark[w] = true;
ans[j + 1]++;
q.push(pii(w, j + 1));
}
}
}
}
int i = 1;
// cout << "---" << endl;
while (i < n) {
cout << ans[i] / 2 << endl;
i++;
}
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define sqr(x) ((x) * (x))
#define mp make_pair
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RE(i, n) FOR(i, 1, n)
#define REP(i, n) FOR(i, 0, (int)(n)-1)
#define fst first
#define snd second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef tuple<int, int, int> iii;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A> string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
void fastIO() {
cin.sync_with_stdio(false);
cin.tie(0);
}
int XMOV[4] = {0, 0, 1, -1};
int YMOV[4] = {1, -1, 0, 0};
// #############################
const int MAXN = 1000005;
int main() {
vector<int> g[2005];
int n, x, y;
cin >> n >> x >> y;
for (int i = 1; i < n; i++) {
g[i].pb(i + 1);
g[i + 1].pb(i);
}
g[x].pb(y);
g[y].pb(x);
ll ans[2005];
memset(ans, 0, sizeof(ans));
bool mark[2005];
queue<pii> q;
for (int node = 1; node <= n; node++) {
q.push(pii(node, 0));
// cout << "node: " << node << endl;
memset(mark, 0, sizeof(mark));
mark[node] = true;
while (!q.empty()) {
int j = q.front().snd;
// for(int i = 0; i < q.size(); i++){
// cout << q.front().fst << " ";
// q.push(q.front());
// q.pop();
// }
// cout << endl;
int src = q.front().fst;
q.pop();
for (auto w : g[src]) {
if (!mark[w]) {
mark[w] = true;
ans[j + 1]++;
q.push(pii(w, j + 1));
}
}
}
}
int i = 1;
// cout << "---" << endl;
while (i < n) {
cout << ans[i] / 2 << endl;
i++;
}
return 0;
} | replace | 82 | 83 | 82 | 83 | 0 | |
p02726 | 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>;
/*
O(|E|log|V|)
P.first = shortest path, P.second = vertex index
G[v] = vector of edge (from v)
d[v] = shortest path from s to v
*/
struct edge {
int to, cost;
};
void dijkstra(vector<vector<edge>> &G, vector<int> &d, int s) {
int V = G.size();
const int INF = 10e8;
priority_queue<P, vector<P>, greater<P>> que;
rep(i, V) d[i] = INF;
d[s] = 0;
que.push(P(0, s));
while (!que.empty()) {
P p = que.top();
que.pop();
int v = p.second;
if (d[v] < p.first)
continue;
rep(i, G[v].size()) {
edge e = G[v][i];
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
que.push(P(d[e.to], e.to));
}
}
}
}
int main() {
int N, X, Y;
cin >> N >> X >> Y;
vector<vector<edge>> G(N);
rep(i, N - 1) {
G[i].push_back((edge){i + 1, 1});
G[i + 1].push_back((edge){i, 1});
}
--X;
--Y;
G[X].push_back((edge){Y, 1});
G[Y].push_back((edge){X, 1});
vector<int> ans(N);
rep(i, N) {
vector<int> d(N);
dijkstra(G, d, i);
rep(j, N) {
if (1 <= d[j] <= N - 1) {
++ans[d[j] - 1];
}
}
}
rep(k, N - 1) { cout << ans[k] / 2 << endl; }
} | #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>;
/*
O(|E|log|V|)
P.first = shortest path, P.second = vertex index
G[v] = vector of edge (from v)
d[v] = shortest path from s to v
*/
struct edge {
int to, cost;
};
void dijkstra(vector<vector<edge>> &G, vector<int> &d, int s) {
int V = G.size();
const int INF = 10e8;
priority_queue<P, vector<P>, greater<P>> que;
rep(i, V) d[i] = INF;
d[s] = 0;
que.push(P(0, s));
while (!que.empty()) {
P p = que.top();
que.pop();
int v = p.second;
if (d[v] < p.first)
continue;
rep(i, G[v].size()) {
edge e = G[v][i];
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
que.push(P(d[e.to], e.to));
}
}
}
}
int main() {
int N, X, Y;
cin >> N >> X >> Y;
vector<vector<edge>> G(N);
rep(i, N - 1) {
G[i].push_back((edge){i + 1, 1});
G[i + 1].push_back((edge){i, 1});
}
--X;
--Y;
G[X].push_back((edge){Y, 1});
G[Y].push_back((edge){X, 1});
vector<int> ans(N);
rep(i, N) {
vector<int> d(N);
dijkstra(G, d, i);
rep(j, N) {
if (1 <= d[j] && d[j] <= N - 1) {
++ans[d[j] - 1];
}
}
}
rep(k, N - 1) { cout << ans[k] / 2 << endl; }
} | replace | 61 | 62 | 61 | 62 | -6 | double free or corruption (out)
|
p02726 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, X, Y;
cin >> N >> X >> Y;
vector<vector<int>> dist_mat(N, vector<int>(N, 0));
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++)
dist_mat[i][j] = j - i;
;
}
// bypass
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
int i_dist = abs(X - 1 - i);
int j_dist = abs(Y - 1 - j);
dist_mat[i][j] = min(dist_mat[i][j], 1 + i_dist + j_dist);
}
}
for (int k = 1; k < N; k++) {
int count = 0;
for (const auto &row : dist_mat)
for (const auto &col : row)
if (col == k)
count++;
cout << count << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, X, Y;
cin >> N >> X >> Y;
vector<vector<int>> dist_mat(N, vector<int>(N, 0));
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++)
dist_mat[i][j] = j - i;
;
}
// bypass
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
int i_dist = abs(X - 1 - i);
int j_dist = abs(Y - 1 - j);
dist_mat[i][j] = min(dist_mat[i][j], 1 + i_dist + j_dist);
}
}
vector<int> counts(N, 0);
for (const auto &row : dist_mat)
for (const auto &col : row)
counts[col] += 1;
for (int k = 1; k < N; k++)
cout << counts[k] << endl;
}
| replace | 21 | 30 | 21 | 27 | TLE | |
p02726 | C++ | Runtime Error | /*Function Template*/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define Rep(i, n) for (ll i = 1; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define PI 3.14159265358979323846
ll fac[MAX], finv[MAX], inv[MAX];
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;
}
bool palindrome(string s) {
bool flag = true;
rep(i, s.size()) if (s[i] != s[s.size() - 1 - i]) flag = false;
return flag;
}
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (ll i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
ll Len(ll n) {
ll s = 0;
while (n != 0)
s++, n /= 10;
return s;
}
ll Sint(ll n) {
ll m = 0, s = 0, a = n;
while (a != 0)
s++, a /= 10;
for (ll i = s - 1; i >= 0; i--)
m += n / ((ll)pow(10, i)) - (n / ((ll)pow(10, i + 1))) * 10;
return m;
}
ll Svec(vector<ll> v) {
ll n = 0;
for (ll i = 0; i < v.size(); i++)
n += v[i];
return n;
}
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 Factorial(ll n) {
ll m = 1;
while (n >= 1)
m *= n, n--;
return m;
}
void runlength(string s, vector<pair<char, ll>> &p) {
ll x = 1;
if (s.size() == 1) {
p.push_back(pair<char, ll>(s[0], 1));
}
for (ll i = 0; i < s.size() - 1; i++) {
if (s[i] == s[i + 1]) {
x++;
if (i == s.size() - 2) {
p.push_back(pair<char, ll>(s[i], x));
}
} else {
p.push_back(pair<char, ll>(s[i], x));
x = 1;
if (i == s.size() - 2) {
p.push_back(pair<char, ll>(s[s.size() - 1], x));
}
}
}
}
ll COM(ll n, ll k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll modpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
string Toupper(string s) {
string ans = "";
rep(i, s.size()) {
if ('a' <= s[i] && s[i] <= 'z')
ans += (char)s[i] - 32;
else
ans += s[i];
}
return ans;
}
string Tolower(string s) {
string ans = "";
rep(i, s.size()) {
if ('A' <= s[i] && s[i] <= 'Z')
ans += (char)s[i] + 32;
else
ans += s[i];
}
return ans;
}
const int MAX_N = 100010;
vector<bool> sieve_of_eratosthenes() {
vector<bool> isPrime(MAX_N + 1, true);
for (int i = 2; i <= MAX_N; i++) {
if (isPrime[i]) {
for (int j = 2 * i; j <= MAX_N; j += i) {
isPrime[j] = false;
}
}
}
return isPrime;
}
vector<pint> prime_factorize(ll n) {
vector<pint> ans;
for (ll p = 2; p <= sqrt(n); p++) {
if (n % p != 0)
continue;
ll cnt = 0;
while (n % p == 0) {
n /= p;
cnt++;
}
ans.push_back(make_pair(p, cnt));
}
if (n != 1)
ans.push_back(make_pair(n, 1));
return ans;
}
/*bool cmp(pint a, pint b) { return a.second < b.second; }*/
/* ダイクストラ法 */
const int MAX_V = 1010;
struct edge {
ll to, cost;
};
typedef pair<ll, ll> pint;
ll n, a, b;
ll INF = 1e12;
vector<edge> graph[MAX_V];
ll dist[MAX_V];
void dijkstra(ll s) {
priority_queue<pint, vector<pint>, greater<pint>> que;
fill(dist, dist + n, INF);
dist[s] = 0;
que.push(pint(0, s));
while (!que.empty()) {
auto p = que.top();
que.pop();
ll v = p.second;
if (dist[v] < p.first)
continue;
for (auto e : graph[v]) {
if (dist[e.to] > dist[v] + e.cost) {
dist[e.to] = dist[v] + e.cost;
que.push(pint(dist[e.to], e.to));
}
}
}
}
/*nがmain関数に定義されていると動かない*/
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
IOS;
cin >> n >> a >> b;
a--;
b--;
vector<ll> v(n - 1, 0);
rep(i, n) {
graph[i].push_back(edge{i + 1, 1});
graph[i + 1].push_back(edge{i, 1});
}
graph[a].push_back(edge{b, 1});
graph[b].push_back(edge{a, 1});
rep(i, n - 1) {
dijkstra(i);
for (ll j = i + 1; j < n; j++) {
if (dist[j] == 0)
continue;
v[dist[j] - 1]++;
}
}
rep(i, n - 1) cout << v[i] << endl;
} | /*Function Template*/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define Rep(i, n) for (ll i = 1; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define PI 3.14159265358979323846
ll fac[MAX], finv[MAX], inv[MAX];
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;
}
bool palindrome(string s) {
bool flag = true;
rep(i, s.size()) if (s[i] != s[s.size() - 1 - i]) flag = false;
return flag;
}
// テーブルを作る前処理
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (ll i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
ll Len(ll n) {
ll s = 0;
while (n != 0)
s++, n /= 10;
return s;
}
ll Sint(ll n) {
ll m = 0, s = 0, a = n;
while (a != 0)
s++, a /= 10;
for (ll i = s - 1; i >= 0; i--)
m += n / ((ll)pow(10, i)) - (n / ((ll)pow(10, i + 1))) * 10;
return m;
}
ll Svec(vector<ll> v) {
ll n = 0;
for (ll i = 0; i < v.size(); i++)
n += v[i];
return n;
}
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 Factorial(ll n) {
ll m = 1;
while (n >= 1)
m *= n, n--;
return m;
}
void runlength(string s, vector<pair<char, ll>> &p) {
ll x = 1;
if (s.size() == 1) {
p.push_back(pair<char, ll>(s[0], 1));
}
for (ll i = 0; i < s.size() - 1; i++) {
if (s[i] == s[i + 1]) {
x++;
if (i == s.size() - 2) {
p.push_back(pair<char, ll>(s[i], x));
}
} else {
p.push_back(pair<char, ll>(s[i], x));
x = 1;
if (i == s.size() - 2) {
p.push_back(pair<char, ll>(s[s.size() - 1], x));
}
}
}
}
ll COM(ll n, ll k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll modpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
string Toupper(string s) {
string ans = "";
rep(i, s.size()) {
if ('a' <= s[i] && s[i] <= 'z')
ans += (char)s[i] - 32;
else
ans += s[i];
}
return ans;
}
string Tolower(string s) {
string ans = "";
rep(i, s.size()) {
if ('A' <= s[i] && s[i] <= 'Z')
ans += (char)s[i] + 32;
else
ans += s[i];
}
return ans;
}
const int MAX_N = 100010;
vector<bool> sieve_of_eratosthenes() {
vector<bool> isPrime(MAX_N + 1, true);
for (int i = 2; i <= MAX_N; i++) {
if (isPrime[i]) {
for (int j = 2 * i; j <= MAX_N; j += i) {
isPrime[j] = false;
}
}
}
return isPrime;
}
vector<pint> prime_factorize(ll n) {
vector<pint> ans;
for (ll p = 2; p <= sqrt(n); p++) {
if (n % p != 0)
continue;
ll cnt = 0;
while (n % p == 0) {
n /= p;
cnt++;
}
ans.push_back(make_pair(p, cnt));
}
if (n != 1)
ans.push_back(make_pair(n, 1));
return ans;
}
/*bool cmp(pint a, pint b) { return a.second < b.second; }*/
/* ダイクストラ法 */
const int MAX_V = 2010;
struct edge {
ll to, cost;
};
typedef pair<ll, ll> pint;
ll n, a, b;
ll INF = 1e12;
vector<edge> graph[MAX_V];
ll dist[MAX_V];
void dijkstra(ll s) {
priority_queue<pint, vector<pint>, greater<pint>> que;
fill(dist, dist + n, INF);
dist[s] = 0;
que.push(pint(0, s));
while (!que.empty()) {
auto p = que.top();
que.pop();
ll v = p.second;
if (dist[v] < p.first)
continue;
for (auto e : graph[v]) {
if (dist[e.to] > dist[v] + e.cost) {
dist[e.to] = dist[v] + e.cost;
que.push(pint(dist[e.to], e.to));
}
}
}
}
/*nがmain関数に定義されていると動かない*/
/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
IOS;
cin >> n >> a >> b;
a--;
b--;
vector<ll> v(n - 1, 0);
rep(i, n) {
graph[i].push_back(edge{i + 1, 1});
graph[i + 1].push_back(edge{i, 1});
}
graph[a].push_back(edge{b, 1});
graph[b].push_back(edge{a, 1});
rep(i, n - 1) {
dijkstra(i);
for (ll j = i + 1; j < n; j++) {
if (dist[j] == 0)
continue;
v[dist[j] - 1]++;
}
}
rep(i, n - 1) cout << v[i] << endl;
} | replace | 178 | 179 | 178 | 179 | 0 | |
p02726 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define getbit(n, i) (((n) & (1LL << (i))) != 0)
#define setbit0(n, i) ((n) & (~(1LL << (i))))
#define setbit1(n, i) ((n) | (1LL << (i)))
#define togglebit(n, i) ((n) ^ (1LL << (i)))
#define lastone(n) ((n) & (-(n)))
#define read freopen("debug\\in.txt", "r", stdin)
#define write freopen("debug\\out.txt", "w", stdout)
#define fi first
#define se second
#define getI(a) scanf("%d", &a)
#define getII(a, b) scanf("%d%d", &a, &b)
#define PI (acos(-1))
#define fastread \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define MOD (1000000007)
#define asz 500005
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define pf push_front
vector<ll> v[200005];
ll dis[2005][2005];
ll vis[2005];
ll cnt[5000005];
queue<ll> q;
int main() {
fastread;
ll n, i, j, k, l, m;
cin >> n >> k >> l;
for (i = 1; i < n; i++) {
v[i].pb(i + 1);
v[i + 1].pb(i);
}
v[k].pb(l);
v[l].pb(k);
for (i = 1; i <= n; i++) {
memset(vis, 0, (n + 10) * sizeof(ll));
q.push(i);
vis[i] = 1;
dis[i][i] = 0;
while (!q.empty()) {
ll temp = q.front();
q.pop();
for (auto x : v[temp]) {
if (vis[x] == 0) {
vis[x] = 1;
dis[i][x] = dis[i][temp] + 1;
q.push(x);
}
}
}
}
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
cnt[dis[i][j]]++;
}
}
for (i = 1; i < n; i++)
cout << cnt[i] / 2 << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
#define getbit(n, i) (((n) & (1LL << (i))) != 0)
#define setbit0(n, i) ((n) & (~(1LL << (i))))
#define setbit1(n, i) ((n) | (1LL << (i)))
#define togglebit(n, i) ((n) ^ (1LL << (i)))
#define lastone(n) ((n) & (-(n)))
#define read freopen("debug\\in.txt", "r", stdin)
#define write freopen("debug\\out.txt", "w", stdout)
#define fi first
#define se second
#define getI(a) scanf("%d", &a)
#define getII(a, b) scanf("%d%d", &a, &b)
#define PI (acos(-1))
#define fastread \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define MOD (1000000007)
#define asz 500005
#define pb push_back
#define ppf pop_front
#define ppb pop_back
#define pf push_front
vector<ll> v[200005];
ll dis[2005][2005];
ll vis[2005];
ll cnt[5000005];
queue<ll> q;
int main() {
fastread;
ll n, i, j, k, l, m;
cin >> n >> k >> l;
for (i = 1; i < n; i++) {
v[i].pb(i + 1);
v[i + 1].pb(i);
}
v[k].pb(l);
v[l].pb(k);
for (i = 1; i <= n; i++) {
memset(vis, 0, (n + 1) * sizeof(ll));
q.push(i);
vis[i] = 1;
dis[i][i] = 0;
while (!q.empty()) {
ll temp = q.front();
q.pop();
for (auto x : v[temp]) {
if (vis[x] == 0) {
vis[x] = 1;
dis[i][x] = dis[i][temp] + 1;
q.push(x);
}
}
}
}
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
cnt[dis[i][j]]++;
}
}
for (i = 1; i < n; i++)
cout << cnt[i] / 2 << "\n";
return 0;
} | replace | 45 | 46 | 45 | 46 | 0 | |
p02726 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 2020;
vector<int> g[N];
int d[1024][1024];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
memset(d, 255, sizeof(d));
int n, x, y;
cin >> n >> x >> y;
x--;
y--;
for (int i = 1; i < n; i++) {
g[i].push_back(i - 1);
g[i - 1].push_back(i);
}
g[x].push_back(y);
g[x].push_back(x);
for (int i = 0; i < n; i++) {
vector<int> q;
q.push_back(i);
d[i][i] = 0;
int qj = 0;
while (qj < q.size()) {
int curr = q[qj];
qj++;
int cd = d[i][curr];
for (int nxt : g[curr]) {
if (d[i][nxt] == -1) {
d[i][nxt] = cd + 1;
q.push_back(nxt);
}
}
}
}
map<int, int> res;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
res[d[i][j]]++;
}
}
for (int i = 1; i < n; i++) {
cout << res[i] << "\n";
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 2020;
vector<int> g[N];
int d[N][N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
memset(d, 255, sizeof(d));
int n, x, y;
cin >> n >> x >> y;
x--;
y--;
for (int i = 1; i < n; i++) {
g[i].push_back(i - 1);
g[i - 1].push_back(i);
}
g[x].push_back(y);
g[x].push_back(x);
for (int i = 0; i < n; i++) {
vector<int> q;
q.push_back(i);
d[i][i] = 0;
int qj = 0;
while (qj < q.size()) {
int curr = q[qj];
qj++;
int cd = d[i][curr];
for (int nxt : g[curr]) {
if (d[i][nxt] == -1) {
d[i][nxt] = cd + 1;
q.push_back(nxt);
}
}
}
}
map<int, int> res;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
res[d[i][j]]++;
}
}
for (int i = 1; i < n; i++) {
cout << res[i] << "\n";
}
return 0;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p02726 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
int n, x, y, dist[N], ans[N];
vector<int> gg[N];
bool used[N];
queue<int> q;
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> x >> y;
for (int i = 1; i <= n - 1; i++) {
gg[i].push_back(i + 1);
gg[i + 1].push_back(i);
}
gg[x].push_back(y);
gg[y].push_back(x);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
used[j] = false;
dist[j] = 0;
}
q.push(i);
used[i] = true;
dist[i] = 0;
while (!q.empty()) {
int cur = q.front();
q.pop();
for (int j = 0; j < gg[cur].size(); j++) {
int child = gg[cur][j];
if (used[child] == false) {
q.push(child);
used[child] = true;
dist[child] = dist[cur] + 1;
}
}
}
for (int j = 1; j <= n; j++) {
ans[dist[j]]++;
}
}
for (int i = 1; i <= n - 1; i++) {
ans[i] = ans[i] / 2;
cout << ans[i] << '\n';
}
} | #include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 10;
int n, x, y, dist[N], ans[N];
vector<int> gg[N];
bool used[N];
queue<int> q;
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> x >> y;
for (int i = 1; i <= n - 1; i++) {
gg[i].push_back(i + 1);
gg[i + 1].push_back(i);
}
gg[x].push_back(y);
gg[y].push_back(x);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
used[j] = false;
dist[j] = 0;
}
q.push(i);
used[i] = true;
dist[i] = 0;
while (!q.empty()) {
int cur = q.front();
q.pop();
for (int j = 0; j < gg[cur].size(); j++) {
int child = gg[cur][j];
if (used[child] == false) {
q.push(child);
used[child] = true;
dist[child] = dist[cur] + 1;
}
}
}
for (int j = 1; j <= n; j++) {
ans[dist[j]]++;
}
}
for (int i = 1; i <= n - 1; i++) {
ans[i] = ans[i] / 2;
cout << ans[i] << '\n';
}
} | replace | 2 | 3 | 2 | 3 | 0 | |
p02726 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll MAX = 100000;
int cnt[1005];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, x, y;
cin >> n >> x >> y;
// if (x != 1 || y != n) {
for (int i = 1; i <= n; ++i)
for (int j = i + 1; j <= n; ++j)
if (i < x) {
if (j <= x)
cnt[j - i]++;
else if (j > x && j <= y)
cnt[min(j - i, x - i + 1 + y - j)]++;
else
cnt[x - i + 1 + j - y]++;
} else if (i >= x && i <= y) {
if (j <= y)
cnt[min(j - i, i - x + 1 + y - j)]++;
else
cnt[min(j - i, i - x + 1 + j - y)]++;
} else
cnt[j - i]++;
for (int i = 1; i <= n - 1; ++i)
cout << cnt[i] << endl;
//}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll MAX = 100000;
int cnt[2005];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, x, y;
cin >> n >> x >> y;
// if (x != 1 || y != n) {
for (int i = 1; i <= n; ++i)
for (int j = i + 1; j <= n; ++j)
if (i < x) {
if (j <= x)
cnt[j - i]++;
else if (j > x && j <= y)
cnt[min(j - i, x - i + 1 + y - j)]++;
else
cnt[x - i + 1 + j - y]++;
} else if (i >= x && i <= y) {
if (j <= y)
cnt[min(j - i, i - x + 1 + y - j)]++;
else
cnt[min(j - i, i - x + 1 + j - y)]++;
} else
cnt[j - i]++;
for (int i = 1; i <= n - 1; ++i)
cout << cnt[i] << endl;
//}
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02726 | C++ | Time Limit Exceeded | /* include */
#include "bits/stdc++.h"
/* namespace */
using namespace std;
/* typedef */
/* long系 */
typedef long long ll; // long long
typedef long double ld; // long double
/* vector系 */
typedef vector<int> vint; // intのvector
typedef vector<double> vdouble; // doubleのvector
typedef vector<ll> vll; // llのvector
typedef vector<ld> vld; // ldのvector
typedef vector<pair<int, int>> vi_i; // i_iのvector
typedef vector<pair<double, double>> vd_d; // d_dのvector
typedef vector<pair<ll, ll>> vl_l; // l_lのvector
typedef vector<pair<ld, ld>> vld_ld; // ld_ldのvector
typedef vector<string> vstring; // stringのvector
/* pair系 */
typedef pair<int, int> i_i; // int同士のpair
typedef pair<double, double> d_d; // double同士のpair
typedef pair<ll, ll> l_l; // ll同士のpair
typedef pair<ld, ld> ld_ld; // ld同士のpair
/* define */
#define pb push_back // push_back
#define all(v) v.begin(), v.end() // コンテナ全体
#define PI (acos(-1)) // 円周率pi
/* 変数入出力 read, write */
template <typename T> // 1変数
void read(T &x) {
cin >> x;
}
template <typename T, typename T0> // 2変数
void read(T &x, T0 &y) {
cin >> x >> y;
}
template <typename T, typename T0, typename T1> // 3変数
void read(T &x, T0 &y, T1 &z) {
cin >> x >> y >> z;
}
template <typename T, typename T0, typename T1, typename T2> // 4変数
void read(T &x, T0 &y, T1 &z, T2 &w) {
cin >> x >> y >> z >> w;
}
template <typename T> // 1変数
void write(T &x) {
cout << x << endl;
}
template <typename T, typename T0> // 2変数
void write(T &x, T0 &y) {
cout << x << " " << y << endl;
}
template <typename T, typename T0, typename T1> // 3変数
void write(T &x, T0 &y, T1 &z) {
cout << x << " " << y << " " << z << endl;
}
template <typename T, typename T0, typename T1, typename T2> // 4変数
void write(T &x, T0 &y, T1 &z, T2 &w) {
cout << x << " " << y << " " << z << " " << w << endl;
}
// vectorの出力
template <typename T> void printvec(const vector<T> &data) {
for (const auto elm : data) {
cout << elm << " ";
}
cout << endl;
}
using Graph = vector<vector<int>>;
int main(void) {
// 頂点数と辺数
int n, x, y;
read(n, x, y);
x--;
y--;
// グラフ入力受取 (ここでは無向グラフを想定)
Graph G(n);
for (int i = 0; i < n - 1; ++i) {
G[i].push_back(i + 1);
G[i + 1].push_back(i);
}
G[x].pb(y);
G[y].pb(x);
vint lt;
lt.resize(n);
fill(all(lt), 0);
for (int j = 0; j < n; j++) {
// BFS のためのデータ構造
vector<int> dist(n, -1); // 全頂点を「未訪問」に初期化
queue<int> que; // 訪問保留中の頂点集合
// 初期条件 (頂点 0 を初期ノードとする)
dist[j] = 0;
que.push(j); // 0 を保留にする
// BFS 開始 (キューが空になるまで探索を行う)
while (!que.empty()) {
int v = que.front(); // キューから先頭頂点を取り出す
que.pop(); // 保留にする
// v から辿れる頂点をすべて調べる
for (int nv : G[v]) {
if (dist[nv] != -1)
continue; // すでに発見済みの頂点は探索しない
// 新たな探索していない頂点 nv
// について距離情報を更新してキューに追加する
dist[nv] = dist[v] + 1;
que.push(nv);
}
}
for (int i = 1; i <= n - 1; i++) {
// 結果出力 (各頂点の頂点 0 からの距離を見る)
for (int v = 0; v < n; ++v) {
if (dist[v] == i)
lt[i - 1]++;
}
}
}
for (int i = 0; i < n - 1; i++) {
lt[i] /= 2;
write(lt[i]);
}
return 0;
}
| /* include */
#include "bits/stdc++.h"
/* namespace */
using namespace std;
/* typedef */
/* long系 */
typedef long long ll; // long long
typedef long double ld; // long double
/* vector系 */
typedef vector<int> vint; // intのvector
typedef vector<double> vdouble; // doubleのvector
typedef vector<ll> vll; // llのvector
typedef vector<ld> vld; // ldのvector
typedef vector<pair<int, int>> vi_i; // i_iのvector
typedef vector<pair<double, double>> vd_d; // d_dのvector
typedef vector<pair<ll, ll>> vl_l; // l_lのvector
typedef vector<pair<ld, ld>> vld_ld; // ld_ldのvector
typedef vector<string> vstring; // stringのvector
/* pair系 */
typedef pair<int, int> i_i; // int同士のpair
typedef pair<double, double> d_d; // double同士のpair
typedef pair<ll, ll> l_l; // ll同士のpair
typedef pair<ld, ld> ld_ld; // ld同士のpair
/* define */
#define pb push_back // push_back
#define all(v) v.begin(), v.end() // コンテナ全体
#define PI (acos(-1)) // 円周率pi
/* 変数入出力 read, write */
template <typename T> // 1変数
void read(T &x) {
cin >> x;
}
template <typename T, typename T0> // 2変数
void read(T &x, T0 &y) {
cin >> x >> y;
}
template <typename T, typename T0, typename T1> // 3変数
void read(T &x, T0 &y, T1 &z) {
cin >> x >> y >> z;
}
template <typename T, typename T0, typename T1, typename T2> // 4変数
void read(T &x, T0 &y, T1 &z, T2 &w) {
cin >> x >> y >> z >> w;
}
template <typename T> // 1変数
void write(T &x) {
cout << x << endl;
}
template <typename T, typename T0> // 2変数
void write(T &x, T0 &y) {
cout << x << " " << y << endl;
}
template <typename T, typename T0, typename T1> // 3変数
void write(T &x, T0 &y, T1 &z) {
cout << x << " " << y << " " << z << endl;
}
template <typename T, typename T0, typename T1, typename T2> // 4変数
void write(T &x, T0 &y, T1 &z, T2 &w) {
cout << x << " " << y << " " << z << " " << w << endl;
}
// vectorの出力
template <typename T> void printvec(const vector<T> &data) {
for (const auto elm : data) {
cout << elm << " ";
}
cout << endl;
}
using Graph = vector<vector<int>>;
int main(void) {
// 頂点数と辺数
int n, x, y;
read(n, x, y);
x--;
y--;
// グラフ入力受取 (ここでは無向グラフを想定)
Graph G(n);
for (int i = 0; i < n - 1; ++i) {
G[i].push_back(i + 1);
G[i + 1].push_back(i);
}
G[x].pb(y);
G[y].pb(x);
vint lt;
lt.resize(n);
fill(all(lt), 0);
for (int j = 0; j < n; j++) {
// BFS のためのデータ構造
vector<int> dist(n, -1); // 全頂点を「未訪問」に初期化
queue<int> que; // 訪問保留中の頂点集合
// 初期条件 (頂点 0 を初期ノードとする)
dist[j] = 0;
que.push(j); // 0 を保留にする
// BFS 開始 (キューが空になるまで探索を行う)
while (!que.empty()) {
int v = que.front(); // キューから先頭頂点を取り出す
que.pop(); // 保留にする
// v から辿れる頂点をすべて調べる
for (int nv : G[v]) {
if (dist[nv] != -1)
continue; // すでに発見済みの頂点は探索しない
// 新たな探索していない頂点 nv
// について距離情報を更新してキューに追加する
dist[nv] = dist[v] + 1;
que.push(nv);
}
}
// 結果出力 (各頂点の頂点 0 からの距離を見る)
for (int v = 0; v < n; ++v) {
if (dist[v] == 0)
continue;
else
lt[dist[v] - 1]++;
}
}
for (int i = 0; i < n - 1; i++) {
lt[i] /= 2;
write(lt[i]);
}
return 0;
}
| replace | 115 | 121 | 115 | 121 | TLE | |
p02726 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
const int MAX_N = 1e3 + 5;
int n, x, y, dis[MAX_N], ans[MAX_N];
std::vector<int> adj[MAX_N];
bool vis[MAX_N];
int main() {
scanf("%d%d%d", &n, &x, &y);
adj[x].push_back(y);
adj[y].push_back(x);
for (int i = 2; i < n; ++i) {
adj[i].push_back(i + 1);
adj[i].push_back(i - 1);
}
if (n > 1)
adj[1].push_back(2);
if (n > 1)
adj[n].push_back(n - 1);
for (int i = 1; i < n; ++i) {
memset(vis, 0x00, sizeof(vis));
std::queue<int> q;
vis[i] = true;
dis[i] = 0;
for (q.push(i); !q.empty(); q.pop()) {
for (int j : adj[q.front()])
if (!vis[j]) {
dis[j] = dis[q.front()] + 1;
vis[j] = true;
q.push(j);
}
}
for (int j = i + 1; j <= n; ++j)
++ans[dis[j]];
}
for (int i = 1; i < n; ++i)
printf("%d\n", ans[i]);
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
const int MAX_N = 2e3 + 5;
int n, x, y, dis[MAX_N], ans[MAX_N];
std::vector<int> adj[MAX_N];
bool vis[MAX_N];
int main() {
scanf("%d%d%d", &n, &x, &y);
adj[x].push_back(y);
adj[y].push_back(x);
for (int i = 2; i < n; ++i) {
adj[i].push_back(i + 1);
adj[i].push_back(i - 1);
}
if (n > 1)
adj[1].push_back(2);
if (n > 1)
adj[n].push_back(n - 1);
for (int i = 1; i < n; ++i) {
memset(vis, 0x00, sizeof(vis));
std::queue<int> q;
vis[i] = true;
dis[i] = 0;
for (q.push(i); !q.empty(); q.pop()) {
for (int j : adj[q.front()])
if (!vis[j]) {
dis[j] = dis[q.front()] + 1;
vis[j] = true;
q.push(j);
}
}
for (int j = i + 1; j <= n; ++j)
++ans[dis[j]];
}
for (int i = 1; i < n; ++i)
printf("%d\n", ans[i]);
} | replace | 6 | 7 | 6 | 7 | 0 | |
p02726 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
const ll maxs = 305;
ll inf = 1e18;
ll cost[maxs][maxs];
ll dp[maxs][maxs];
ll n;
void warshall() {
for (ll k = 1; k <= n; k++)
for (ll i = 1; i <= n; i++)
for (ll j = 1; j <= n; j++)
if (dp[i][j] > dp[i][k] + dp[k][j])
dp[i][j] = dp[i][k] + dp[k][j];
}
// Use when new roads to be build
void update(ll s, ll d, ll w) {
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= n; j++) {
if (dp[i][j] > dp[i][s] + w + dp[d][j])
dp[i][j] = dp[i][s] + w + dp[d][j];
if (dp[i][j] > dp[i][d] + w + dp[s][j])
dp[i][j] = dp[i][d] + w + dp[s][j];
}
}
}
int main() {
ll x, y;
cin >> n >> x >> y;
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= n; j++) {
cost[i][j] = abs(i - j);
dp[i][j] = cost[i][j];
}
}
/* for(ll i=1;i<=n;i++)
{
for(ll j=1;j<=n;j++)
cout<<dp[i][j]<<" ";
cout<<endl;
} */
update(x, y, 1);
ll res[n + 1];
memset(res, 0, sizeof res);
for (ll i = 1; i < n + 1; i++) {
for (ll j = i + 1; j <= n; j++) {
res[dp[i][j]]++;
}
}
for (ll i = 1; i < n; i++)
cout << res[i] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
const ll maxs = 3005;
ll inf = 1e18;
ll cost[maxs][maxs];
ll dp[maxs][maxs];
ll n;
void warshall() {
for (ll k = 1; k <= n; k++)
for (ll i = 1; i <= n; i++)
for (ll j = 1; j <= n; j++)
if (dp[i][j] > dp[i][k] + dp[k][j])
dp[i][j] = dp[i][k] + dp[k][j];
}
// Use when new roads to be build
void update(ll s, ll d, ll w) {
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= n; j++) {
if (dp[i][j] > dp[i][s] + w + dp[d][j])
dp[i][j] = dp[i][s] + w + dp[d][j];
if (dp[i][j] > dp[i][d] + w + dp[s][j])
dp[i][j] = dp[i][d] + w + dp[s][j];
}
}
}
int main() {
ll x, y;
cin >> n >> x >> y;
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= n; j++) {
cost[i][j] = abs(i - j);
dp[i][j] = cost[i][j];
}
}
/* for(ll i=1;i<=n;i++)
{
for(ll j=1;j<=n;j++)
cout<<dp[i][j]<<" ";
cout<<endl;
} */
update(x, y, 1);
ll res[n + 1];
memset(res, 0, sizeof res);
for (ll i = 1; i < n + 1; i++) {
for (ll j = i + 1; j <= n; j++) {
res[dp[i][j]]++;
}
}
for (ll i = 1; i < n; i++)
cout << res[i] << endl;
return 0;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p02726 | C++ | Runtime Error | // file creato da gio il 2020-03-31 21:23:51.244903
#include <iostream>
#define FAST
#ifdef FAST
#pragma GCC optimize("Ofast")
#pragma GCC target( \
"fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#endif
#define S second
#define F first
#define PB push_back
using namespace std;
int arr[2000];
//[2000]
int main() {
// freopen("output","w",stdout);
// freopen("input","r",stdin);
#ifdef FAST
ios::sync_with_stdio(0);
cin.tie(0);
#endif
int N, X, Y;
cin >> N >> X >> Y;
X -= 1;
Y -= 1;
for (int i = 1; i < N; i++) {
arr[i] = N - i;
}
for (int i = 0; i <= X; i++) {
for (int j = Y; j < N; j++) {
arr[j - i]--;
arr[j - i - (Y - X) + 1]++;
}
}
for (int i = 1; i < N; i++) {
cout << arr[i] << endl;
}
} | // file creato da gio il 2020-03-31 21:23:51.244903
#include <iostream>
#define FAST
#ifdef FAST
#pragma GCC optimize("Ofast")
#pragma GCC target( \
"fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#endif
#define S second
#define F first
#define PB push_back
using namespace std;
int arr[2000];
//[2000]
int main() {
// freopen("output","w",stdout);
// freopen("input","r",stdin);
#ifdef FAST
ios::sync_with_stdio(0);
cin.tie(0);
#endif
int N, X, Y;
cin >> N >> X >> Y;
X -= 1;
Y -= 1;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
int d = j - i;
arr[min(d, abs(X - i) + abs(Y - j) + 1)]++;
}
}
for (int i = 1; i < N; i++) {
cout << arr[i] << endl;
}
} | replace | 30 | 37 | 30 | 34 | 0 | |
p02726 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, X, Y;
cin >> N >> X >> Y;
X--;
Y--;
map<int, long> m;
for (int i = 1; i < N; i++) {
m[i] = 0;
}
int a[N - 1][N - 1];
for (int i = 0; i < N - 1; i++) {
for (int j = i + 1; j < N; j++) {
a[i][j] = j - i;
}
}
for (int i = 0; i < N - 1; i++) {
for (int j = i + 1; j < N; j++) {
a[i][j] = min(a[i][j], a[i][X] + 1 + a[Y][j]);
m[a[i][j]]++;
}
}
for (auto x : m) {
cout << x.second << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, X, Y;
cin >> N >> X >> Y;
X--;
Y--;
map<int, long> m;
for (int i = 1; i < N; i++) {
m[i] = 0;
}
int a[N][N];
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
a[i][j] = abs(j - i);
}
}
for (int i = 0; i < N - 1; i++) {
for (int j = i + 1; j < N; j++) {
a[i][j] = min(a[i][j], a[i][X] + 1 + a[Y][j]);
m[a[i][j]]++;
}
}
for (auto x : m) {
cout << x.second << endl;
}
}
| replace | 13 | 17 | 13 | 18 | 0 | |
p02726 | C++ | Runtime Error | #include <iostream>
using namespace std;
#define MAX 200
int main() {
int N, x, y, D[MAX], i, j, d, d1, d2;
cin >> N >> x >> y;
for (i = 1; i <= N; i++)
D[i] = 0;
for (i = 1; i < N; i++) {
for (j = i + 1; j <= N; j++) {
d1 = j - i;
d2 = abs(y - j) + abs(x - i) + 1;
d = min(d1, d2);
D[d]++;
}
}
for (i = 1; i < N; i++)
cout << D[i] << endl;
}
| #include <iostream>
using namespace std;
#define MAX 2000
int main() {
int N, x, y, D[MAX], i, j, d, d1, d2;
cin >> N >> x >> y;
for (i = 1; i <= N; i++)
D[i] = 0;
for (i = 1; i < N; i++) {
for (j = i + 1; j <= N; j++) {
d1 = j - i;
d2 = abs(y - j) + abs(x - i) + 1;
d = min(d1, d2);
D[d]++;
}
}
for (i = 1; i < N; i++)
cout << D[i] << endl;
}
| replace | 2 | 3 | 2 | 3 | 0 | |
p02726 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 100;
#define ll long long
vector<int> s[N];
void add(int x, int y) {
s[x].push_back(y);
s[y].push_back(x);
}
int a[N];
vector<int> v;
void solve() {
int n, x, y;
scanf("%d%d%d", &n, &x, &y);
for (int i = 1; i < n; ++i) {
add(i, i + 1);
}
add(x, y);
for (int i = 1; i <= n; ++i) {
priority_queue<pair<int, int>> Q;
Q.push(make_pair(0, i));
int vis[N] = {0};
vis[i] = 1;
while (!Q.empty()) {
pair<int, int> p = Q.top();
Q.pop();
a[-p.first]++;
for (int j = 0, st = s[p.second].size(); j < st; ++j) {
int m = s[p.second][j];
if (!vis[m]) {
vis[m] = 1;
Q.push(make_pair(p.first - 1, m));
}
}
}
}
for (int i = 1; i < n; ++i) {
printf("%d\n", a[i] / 2);
}
}
int main() { solve(); }
| #include <bits/stdc++.h>
using namespace std;
const int N = 2e3 + 100;
#define ll long long
vector<int> s[N];
void add(int x, int y) {
s[x].push_back(y);
s[y].push_back(x);
}
int a[N];
vector<int> v;
void solve() {
int n, x, y;
scanf("%d%d%d", &n, &x, &y);
for (int i = 1; i < n; ++i) {
add(i, i + 1);
}
add(x, y);
for (int i = 1; i <= n; ++i) {
priority_queue<pair<int, int>> Q;
Q.push(make_pair(0, i));
int vis[N] = {0};
vis[i] = 1;
while (!Q.empty()) {
pair<int, int> p = Q.top();
Q.pop();
a[-p.first]++;
for (int j = 0, st = s[p.second].size(); j < st; ++j) {
int m = s[p.second][j];
if (!vis[m]) {
vis[m] = 1;
Q.push(make_pair(p.first - 1, m));
}
}
}
}
for (int i = 1; i < n; ++i) {
printf("%d\n", a[i] / 2);
}
}
int main() { solve(); }
| replace | 2 | 3 | 2 | 3 | 0 | |
p02726 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, X, Y;
cin >> N >> X >> Y;
vector<vector<int>> v(N - 1, vector<int>(N - 1));
vector<int> ans(N - 1);
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
v[i][j] = min(j - i, abs(Y - j - 1) + 1 + abs(X - i - 1));
}
}
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
if (v[i][j] > 0) {
int ind = v[i][j] - 1;
ans[ind] += 1;
}
}
}
for (int x : ans) {
cout << x << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, X, Y;
cin >> N >> X >> Y;
vector<vector<int>> v(N, vector<int>(N));
vector<int> ans(N - 1);
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
v[i][j] = min(j - i, abs(Y - j - 1) + 1 + abs(X - i - 1));
}
}
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
if (v[i][j] > 0) {
int ind = v[i][j] - 1;
ans[ind] += 1;
}
}
}
for (int x : ans) {
cout << x << endl;
}
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p02726 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long LL;
int main() {
int N, X, Y;
cin >> N >> X >> Y;
--X;
--Y;
vector<vector<int>> dist(N, vector<int>(N, 99999));
REP(i, N) {
queue<pair<int, int>> q;
q.push(make_pair(i, 0));
while (!q.empty()) {
auto t = q.front();
q.pop();
int pos = t.first, d = t.second;
if (dist[i][pos] <= d)
continue;
dist[i][pos] = d;
if (pos - 1 >= 0)
q.push(make_pair(pos - 1, d + 1));
if (pos + 1 < N)
q.push(make_pair(pos + 1, d + 1));
if (pos == X)
q.push(make_pair(Y, d + 1));
if (pos == Y)
q.push(make_pair(X, d + 1));
}
}
vector<int> ret(N, 0);
REP(i, N) {
for (int j = i + 1; j < N; ++j) {
int td = dist[i][j];
ret[td] += 1;
cerr << "(" << i << "," << j << ") " << td << endl;
}
}
for (int i = 1; i < N; ++i) {
cout << ret[i] << endl;
}
} | #include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long LL;
int main() {
int N, X, Y;
cin >> N >> X >> Y;
--X;
--Y;
vector<vector<int>> dist(N, vector<int>(N, 99999));
REP(i, N) {
queue<pair<int, int>> q;
q.push(make_pair(i, 0));
while (!q.empty()) {
auto t = q.front();
q.pop();
int pos = t.first, d = t.second;
if (dist[i][pos] <= d)
continue;
dist[i][pos] = d;
if (pos - 1 >= 0)
q.push(make_pair(pos - 1, d + 1));
if (pos + 1 < N)
q.push(make_pair(pos + 1, d + 1));
if (pos == X)
q.push(make_pair(Y, d + 1));
if (pos == Y)
q.push(make_pair(X, d + 1));
}
}
vector<int> ret(N, 0);
REP(i, N) {
for (int j = i + 1; j < N; ++j) {
ret[dist[i][j]]++;
}
}
for (int i = 1; i < N; ++i) {
cout << ret[i] << endl;
}
} | replace | 38 | 41 | 38 | 39 | TLE | |
p02726 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
#define int long long
int N, X, Y;
cin >> N >> X >> Y;
int l;
vector<int> box(N - 1);
for (int i = 1; i <= X; i++) {
for (int j = i + 1; j <= X; j++) {
l = j - i;
box.at(l - 1)++;
}
for (int j = X + 1; j < Y; j++) {
l = X - i + min(j - X, Y - j + 1);
box.at(l - 1)++;
}
for (int j = Y; j <= N; j++) {
l = j - i - Y + X + 1;
box.at(l - 1)++;
}
}
for (int i = X + 1; i < Y; i++) {
for (int j = i + 1; j < Y; j++) {
l = min(j - i, i - X + Y - j + 1);
box.at(l - 1)++;
}
for (int j = Y; j <= N; j++) {
l = j - Y + min(Y - i, i - X + 1);
box.at(l - 1)++;
}
}
for (int i = Y; i < N; i++) {
for (int j = i + 1; j <= N; j++) {
l = j - i;
box.at(l - 1)++;
}
}
for (int i = 0; i < N; i++) {
cout << box.at(i) << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
#define int long long
int N, X, Y;
cin >> N >> X >> Y;
int l;
vector<int> box(N - 1);
for (int i = 1; i <= X; i++) {
for (int j = i + 1; j <= X; j++) {
l = j - i;
box.at(l - 1)++;
}
for (int j = X + 1; j < Y; j++) {
l = X - i + min(j - X, Y - j + 1);
box.at(l - 1)++;
}
for (int j = Y; j <= N; j++) {
l = j - i - Y + X + 1;
box.at(l - 1)++;
}
}
for (int i = X + 1; i < Y; i++) {
for (int j = i + 1; j < Y; j++) {
l = min(j - i, i - X + Y - j + 1);
box.at(l - 1)++;
}
for (int j = Y; j <= N; j++) {
l = j - Y + min(Y - i, i - X + 1);
box.at(l - 1)++;
}
}
for (int i = Y; i < N; i++) {
for (int j = i + 1; j <= N; j++) {
l = j - i;
box.at(l - 1)++;
}
}
for (int i = 0; i < (N - 1); i++) {
cout << box.at(i) << endl;
}
}
| replace | 40 | 41 | 40 | 41 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 4) >= this->size() (which is 4)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.