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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02991 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i, a, b) for (ll i = (a); i < (b); ++i)
#define rep(i, a) repi(i, 0, a)
#define repdi(i, a, b) for (ll i = (a)-1; i >= (b); --i)
#define repd(i, a) repdi(i, a, 0)
#define itr(it, a) for (auto it = (a).begin(); it != (a).end(); ++it)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;
using ll = long long;
using P = std::pair<ll, ll>;
constexpr ll INF = 1ll << 60;
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;
}
template <class S, class T>
std::ostream &operator<<(std::ostream &out, const std::pair<S, T> &a) {
std::cout << '(' << a.first << ", " << a.second << ')';
return out;
}
template <class T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &a) {
std::cout << '[';
rep(i, a.size()) {
std::cout << a[i];
if (i != a.size() - 1)
std::cout << ", ";
}
std::cout << ']';
return out;
}
ll N, M;
ll S, T;
std::vector<std::vector<P>> G;
std::vector<ll> dist;
ll id(ll v, ll m) { return v * 3 + m; }
void dijkstra(ll s, std::vector<std::vector<P>> &G, std::vector<ll> &dist) {
std::priority_queue<P, std::vector<P>, std::greater<P>> pque;
dist.assign(N + 10, INF);
dist[s] = 0;
pque.emplace(dist[s], s);
while (!pque.empty()) {
P p = pque.top();
pque.pop();
ll d = p.first, v = p.second;
if (dist[v] < d)
continue;
for (auto u : G[v]) {
if (chmin(dist[u.first], dist[v] + u.second))
pque.emplace(dist[u.first], u.first);
}
}
return;
}
void add_edge(ll u, ll v) {
rep(j, 3) { G[id(u, j)].emplace_back(id(v, (j + 1) % 3), 1); }
return;
}
int main() {
std::cin >> N >> M;
G.resize(N * 3 + 10);
rep(i, M) {
ll u, v;
std::cin >> u >> v;
--u;
--v;
add_edge(u, v);
}
std::cin >> S >> T;
--S;
--T;
dijkstra(id(S, 0), G, dist);
std::cout << (dist[id(T, 0)] == INF ? -1 : dist[id(T, 0)] / 3) << endl;
return 0;
} | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i, a, b) for (ll i = (a); i < (b); ++i)
#define rep(i, a) repi(i, 0, a)
#define repdi(i, a, b) for (ll i = (a)-1; i >= (b); --i)
#define repd(i, a) repdi(i, a, 0)
#define itr(it, a) for (auto it = (a).begin(); it != (a).end(); ++it)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;
using ll = long long;
using P = std::pair<ll, ll>;
constexpr ll INF = 1ll << 60;
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;
}
template <class S, class T>
std::ostream &operator<<(std::ostream &out, const std::pair<S, T> &a) {
std::cout << '(' << a.first << ", " << a.second << ')';
return out;
}
template <class T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &a) {
std::cout << '[';
rep(i, a.size()) {
std::cout << a[i];
if (i != a.size() - 1)
std::cout << ", ";
}
std::cout << ']';
return out;
}
ll N, M;
ll S, T;
std::vector<std::vector<P>> G;
std::vector<ll> dist;
ll id(ll v, ll m) { return v * 3 + m; }
void dijkstra(ll s, std::vector<std::vector<P>> &G, std::vector<ll> &dist) {
std::priority_queue<P, std::vector<P>, std::greater<P>> pque;
dist.assign(N * 3 + 10, INF);
dist[s] = 0;
pque.emplace(dist[s], s);
while (!pque.empty()) {
P p = pque.top();
pque.pop();
ll d = p.first, v = p.second;
if (dist[v] < d)
continue;
for (auto u : G[v]) {
if (chmin(dist[u.first], dist[v] + u.second))
pque.emplace(dist[u.first], u.first);
}
}
return;
}
void add_edge(ll u, ll v) {
rep(j, 3) { G[id(u, j)].emplace_back(id(v, (j + 1) % 3), 1); }
return;
}
int main() {
std::cin >> N >> M;
G.resize(N * 3 + 10);
rep(i, M) {
ll u, v;
std::cin >> u >> v;
--u;
--v;
add_edge(u, v);
}
std::cin >> S >> T;
--S;
--T;
dijkstra(id(S, 0), G, dist);
std::cout << (dist[id(T, 0)] == INF ? -1 : dist[id(T, 0)] / 3) << endl;
return 0;
} | replace | 73 | 74 | 73 | 74 | 0 | |
p02991 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i, a) for (auto &i : a)
#define REP(i, n) for (int i = 0; i < n; i++)
#define eREP(i, n) for (int i = 0; i <= n; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define eFOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define SORT(c) sort((c).begin(), (c).end())
#define rSORT(c) sort((c).rbegin(), (c).rend())
#define LB(x, a) lower_bound((x).begin(), (x).end(), (a))
#define UB(x, a) upper_bound((x).begin(), (x).end(), (a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
// vector<vector<int> > dp;
// vector<vector<vector<int> > > vvvi;
// dp=vector<vector<int> >(N, vector<int>(M,0));
// vector<pair<int,int> > v;
// v.push_back(make_pair(x,y));
// priority_queue<int,vector<int>, greater<int> > q2;
int dist[100005][3];
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vector<VI> to(N);
REP(i, M) {
int a, b;
a--;
b--;
to[a].push_back(b);
}
int sv, tv;
cin >> sv >> tv;
sv--;
tv--;
REP(i, N) {
REP(j, 3) { dist[i][j] = LLINF; }
}
queue<pii> q;
q.push(pii(sv, 0));
dist[sv][0] = 0;
while (!q.empty()) {
int v = q.front().first;
int l = q.front().second;
q.pop();
for (int u : to[v]) {
int nl = (l + 1) % 3;
if (dist[u][nl] != LLINF)
continue;
dist[u][nl] = dist[v][l] + 1;
q.push(pii(u, nl));
}
}
int ans = dist[tv][0];
if (ans == LLINF)
ans = -1;
else
ans /= 3;
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i, a) for (auto &i : a)
#define REP(i, n) for (int i = 0; i < n; i++)
#define eREP(i, n) for (int i = 0; i <= n; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define eFOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define SORT(c) sort((c).begin(), (c).end())
#define rSORT(c) sort((c).rbegin(), (c).rend())
#define LB(x, a) lower_bound((x).begin(), (x).end(), (a))
#define UB(x, a) upper_bound((x).begin(), (x).end(), (a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
// vector<vector<int> > dp;
// vector<vector<vector<int> > > vvvi;
// dp=vector<vector<int> >(N, vector<int>(M,0));
// vector<pair<int,int> > v;
// v.push_back(make_pair(x,y));
// priority_queue<int,vector<int>, greater<int> > q2;
int dist[100005][3];
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
vector<VI> to(N);
REP(i, M) {
int a, b;
cin >> a >> b;
a--;
b--;
to[a].push_back(b);
}
int sv, tv;
cin >> sv >> tv;
sv--;
tv--;
REP(i, N) {
REP(j, 3) { dist[i][j] = LLINF; }
}
queue<pii> q;
q.push(pii(sv, 0));
dist[sv][0] = 0;
while (!q.empty()) {
int v = q.front().first;
int l = q.front().second;
q.pop();
for (int u : to[v]) {
int nl = (l + 1) % 3;
if (dist[u][nl] != LLINF)
continue;
dist[u][nl] = dist[v][l] + 1;
q.push(pii(u, nl));
}
}
int ans = dist[tv][0];
if (ans == LLINF)
ans = -1;
else
ans /= 3;
cout << ans << endl;
return 0;
}
| insert | 45 | 45 | 45 | 46 | -11 | |
p02991 | C++ | Runtime Error | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<int, int>;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<vector<int>> G(n);
REP(i, n) {
int u, v;
cin >> u >> v;
u--, v--;
G[u].push_back(v);
}
int s, t;
cin >> s >> t;
s--, t--;
vector<vector<ll>> dist(n, vector<ll>(3, -1));
dist[s][0] = 0;
queue<P> que;
que.emplace(s, 0);
while (!que.empty()) {
P cur = que.front();
que.pop();
int v = cur.first;
int step = cur.second;
for (auto nv : G[v]) {
int np = (step + 1) % 3;
if (dist[nv][np] == -1) {
dist[nv][np] = dist[v][step] + 1;
que.emplace(nv, np);
}
}
}
cout << (dist[t][0] == -1 ? -1 : dist[t][0] / 3) << endl;
return 0;
}
| #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
using P = pair<int, int>;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<vector<int>> G(n);
REP(i, m) {
int u, v;
cin >> u >> v;
u--, v--;
G[u].push_back(v);
}
int s, t;
cin >> s >> t;
s--, t--;
vector<vector<ll>> dist(n, vector<ll>(3, -1));
dist[s][0] = 0;
queue<P> que;
que.emplace(s, 0);
while (!que.empty()) {
P cur = que.front();
que.pop();
int v = cur.first;
int step = cur.second;
for (auto nv : G[v]) {
int np = (step + 1) % 3;
if (dist[nv][np] == -1) {
dist[nv][np] = dist[v][step] + 1;
que.emplace(nv, np);
}
}
}
cout << (dist[t][0] == -1 ? -1 : dist[t][0] / 3) << endl;
return 0;
}
| replace | 16 | 17 | 16 | 17 | 0 | |
p02991 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin()) // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(x, max(y, z))
#define MIN(x, y, z) min(x, min(y, z))
#define ANS cout << ans << "\n"
#define RETURN(x) \
cout << x << "\n"; \
return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
cin.tie(0); \
ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v) \
cerr << "[debugV] " << #v << ":"; \
rep(i, v.size()) cerr << " " << v[i]; \
cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) { return to_string(x).size(); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
vector<P> factorize(ll n) {
vector<P> result;
for (ll i = 2; i * i <= n; ++i) {
if (n % i == 0) {
result.pb({i, 0});
while (n % i == 0) {
n /= i;
result.back().second++;
}
}
}
if (n != 1) {
result.pb({n, 1});
}
return result;
}
vll divisor(ll n) {
vll ret;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n)
ret.push_back(n / i);
}
}
SORT(ret);
return (ret);
}
// ll dist[100005][3];
signed main() {
init();
ll N, M;
cin >> N >> M;
if (M == 0) {
COUT(-1);
return 0;
}
vvll to(M);
rep(i, M) {
ll u, v;
cin >> u >> v;
u--;
v--;
to[u].pb(v);
}
ll S, T;
cin >> S >> T;
S--;
T--;
// rep(i, N) rep(j, 3) dist[i][j] = INF;
queue<P> q;
q.push({S, 0});
vector<vector<bool>> done(N, vector<bool>(3, false));
done[S][0] = true;
while (!q.empty()) {
ll i = q.front().first;
ll d = q.front().second + 1;
q.pop();
rep(j, to[i].size()) {
ll next = to[i][j];
if (next == T && d % 3 == 0) {
COUT(d / 3);
return 0;
}
if (done[next][d % 3])
continue;
q.push({next, d});
}
}
COUT(-1);
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin()) // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(x, max(y, z))
#define MIN(x, y, z) min(x, min(y, z))
#define ANS cout << ans << "\n"
#define RETURN(x) \
cout << x << "\n"; \
return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
cin.tie(0); \
ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v) \
cerr << "[debugV] " << #v << ":"; \
rep(i, v.size()) cerr << " " << v[i]; \
cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) { return to_string(x).size(); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
vector<P> factorize(ll n) {
vector<P> result;
for (ll i = 2; i * i <= n; ++i) {
if (n % i == 0) {
result.pb({i, 0});
while (n % i == 0) {
n /= i;
result.back().second++;
}
}
}
if (n != 1) {
result.pb({n, 1});
}
return result;
}
vll divisor(ll n) {
vll ret;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n)
ret.push_back(n / i);
}
}
SORT(ret);
return (ret);
}
// ll dist[100005][3];
signed main() {
init();
ll N, M;
cin >> N >> M;
if (M == 0) {
COUT(-1);
return 0;
}
vvll to(M);
rep(i, M) {
ll u, v;
cin >> u >> v;
u--;
v--;
to[u].pb(v);
}
ll S, T;
cin >> S >> T;
S--;
T--;
// rep(i, N) rep(j, 3) dist[i][j] = INF;
queue<P> q;
q.push({S, 0});
vector<vector<bool>> done(N, vector<bool>(3, false));
done[S][0] = true;
while (!q.empty()) {
ll i = q.front().first;
ll d = q.front().second + 1;
q.pop();
rep(j, to[i].size()) {
ll next = to[i][j];
if (next == T && d % 3 == 0) {
COUT(d / 3);
return 0;
}
if (done[next][d % 3])
continue;
done[next][d % 3] = true;
q.push({next, d});
}
}
COUT(-1);
return 0;
} | insert | 124 | 124 | 124 | 125 | TLE | |
p02991 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using P = pair<int, int>;
const int mx = 100005;
int n, m, u, v, s, t, dis[mx * 3];
queue<int> qu;
vector<int> node[mx];
int main() {
scanf("%d%d", &n, &m);
rep(i, m) {
scanf("%d%d", &u, &v);
u--;
v--;
node[u].push_back(v + mx);
node[u + mx].push_back(v + mx * 2);
node[u + mx * 2].push_back(v);
}
scanf("%d%d", &s, &t);
s--;
t--;
qu.push(s);
dis[s] = 1;
while (!qu.empty()) {
int pos = qu.front();
qu.pop();
for (int it : node[pos]) {
if (dis[it] == 0) {
qu.push(it);
dis[it] = dis[pos] + 1;
}
}
}
printf("%d\n", dis[t] ? dis[t] / 3 : -1);
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
using P = pair<int, int>;
const int mx = 100005;
int n, m, u, v, s, t, dis[mx * 3];
queue<int> qu;
vector<int> node[mx * 3];
int main() {
scanf("%d%d", &n, &m);
rep(i, m) {
scanf("%d%d", &u, &v);
u--;
v--;
node[u].push_back(v + mx);
node[u + mx].push_back(v + mx * 2);
node[u + mx * 2].push_back(v);
}
scanf("%d%d", &s, &t);
s--;
t--;
qu.push(s);
dis[s] = 1;
while (!qu.empty()) {
int pos = qu.front();
qu.pop();
for (int it : node[pos]) {
if (dis[it] == 0) {
qu.push(it);
dis[it] = dis[pos] + 1;
}
}
}
printf("%d\n", dis[t] ? dis[t] / 3 : -1);
} | replace | 7 | 8 | 7 | 8 | -11 | |
p02991 | C++ | Runtime Error | #include <iostream>
#include <queue>
#include <vector>
#define MAX_N 100000
#define INF (1 << 29)
using namespace std;
typedef pair<int, int> P;
int N, M;
vector<int> G[3 * MAX_N + 1];
int d[MAX_N + 1];
int dijkstra(int s, int t, int N) {
priority_queue<P> que;
for (int v = 1; v <= N; v++) {
d[v] = (v == s) ? 0 : INF;
que.push(P(-d[v], v));
}
while (!que.empty()) {
int u = que.top().second;
que.pop();
for (auto v : G[u]) {
int alt = d[u] + 1;
if (d[v] > alt) {
d[v] = alt;
que.push(P(-d[v], v));
}
}
}
return d[t] >= INF ? -1 : d[t];
}
int main(int argc, char **argv) {
cin >> N >> M;
for (int i = 0; i < M; i++) {
int u, v;
cin >> u >> v;
int us[] = {u, u + N, u + 2 * N};
int vs[] = {v, v + N, v + 2 * N};
// u0->v1; u1->v2; u2->v0;
for (int i = 0; i < 3; i++)
G[us[i]].push_back(vs[(i + 1) % 3]);
}
int S, T;
cin >> S >> T;
int ans = dijkstra(S, T, 3 * N);
cout << (ans < 0 ? ans : ans / 3) << endl;
return 0;
}
| #include <iostream>
#include <queue>
#include <vector>
#define MAX_N 100000
#define INF (1 << 29)
using namespace std;
typedef pair<int, int> P;
int N, M;
vector<int> G[3 * MAX_N + 1];
int d[3 * MAX_N + 1];
int dijkstra(int s, int t, int N) {
priority_queue<P> que;
for (int v = 1; v <= N; v++) {
d[v] = (v == s) ? 0 : INF;
que.push(P(-d[v], v));
}
while (!que.empty()) {
int u = que.top().second;
que.pop();
for (auto v : G[u]) {
int alt = d[u] + 1;
if (d[v] > alt) {
d[v] = alt;
que.push(P(-d[v], v));
}
}
}
return d[t] >= INF ? -1 : d[t];
}
int main(int argc, char **argv) {
cin >> N >> M;
for (int i = 0; i < M; i++) {
int u, v;
cin >> u >> v;
int us[] = {u, u + N, u + 2 * N};
int vs[] = {v, v + N, v + 2 * N};
// u0->v1; u1->v2; u2->v0;
for (int i = 0; i < 3; i++)
G[us[i]].push_back(vs[(i + 1) % 3]);
}
int S, T;
cin >> S >> T;
int ans = dijkstra(S, T, 3 * N);
cout << (ans < 0 ? ans : ans / 3) << endl;
return 0;
}
| replace | 14 | 15 | 14 | 15 | 0 | |
p02991 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, l, r) for (long long i = (l); i < (r); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FOR(i, 1, n + 1)
#define RFOR(i, l, r) for (long long i = (l); i >= (r); --i)
#define RREP(i, n) RFOR(i, N - 1, 0)
#define RREPS(i, n) RFOR(i, N, 1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const int INF = 1e18;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5;
signed main() {
int N, M;
cin >> N >> M;
vector<int> Graph[3 * N];
REP(i, M) {
int a, b;
cin >> a >> b;
a--;
b--;
Graph[3 * a].pb(3 * b + 1);
Graph[3 * a + 1].pb(3 * b + 2);
Graph[3 * a + 2].pb(3 * b);
}
vector<int> depth(3 * N, INF);
int S, T;
cin >> S >> T;
S--;
T--;
queue<int> q;
q.push(3 * S);
depth[3 * S] = 0;
while (q.size()) {
int now = q.front();
q.pop();
for (auto v : Graph[now]) {
if (depth[v] < depth[now] + 1)
continue;
depth[v] = depth[now] + 1;
q.push(v);
}
}
cout << (depth[3 * T] == INF ? -1 : depth[3 * T] / 3) << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define FOR(i, l, r) for (long long i = (l); i < (r); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FOR(i, 1, n + 1)
#define RFOR(i, l, r) for (long long i = (l); i >= (r); --i)
#define RREP(i, n) RFOR(i, N - 1, 0)
#define RREPS(i, n) RFOR(i, N, 1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const int INF = 1e18;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5;
signed main() {
int N, M;
cin >> N >> M;
vector<int> Graph[3 * N];
REP(i, M) {
int a, b;
cin >> a >> b;
a--;
b--;
Graph[3 * a].pb(3 * b + 1);
Graph[3 * a + 1].pb(3 * b + 2);
Graph[3 * a + 2].pb(3 * b);
}
vector<int> depth(3 * N, INF);
int S, T;
cin >> S >> T;
S--;
T--;
queue<int> q;
q.push(3 * S);
depth[3 * S] = 0;
while (q.size()) {
int now = q.front();
q.pop();
for (auto v : Graph[now]) {
if (depth[v] != INF)
continue;
depth[v] = depth[now] + 1;
q.push(v);
}
}
cout << (depth[3 * T] == INF ? -1 : depth[3 * T] / 3) << endl;
} | replace | 57 | 58 | 57 | 58 | TLE | |
p02991 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
void _cin() {}
template <class Head, class... Tail> void _cin(Head &&head, Tail &&...tail) {
cin >> head;
_cin(forward<Tail>(tail)...);
}
void _cout() { cout << "\n"; }
template <class Head, class... Tail> void _cout(Head &&head, Tail &&...tail) {
cout << head;
_cout(forward<Tail>(tail)...);
}
int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }
#define Sq(x) (x) * (x)
#define For(i, n) for (int i = 0; i < (n); i++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) \
vector<T> sxs(xs.size() + 1); \
For(i, (int)xs.size()) sxs[i + 1] = sxs[i] + xs[i]
#define Cin(T, ...) \
T __VA_ARGS__; \
_cin(__VA_ARGS__)
#define Cins(T, n, xs) \
vector<T> xs(n); \
For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) \
vector<T> xs(n), ys(n); \
For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) \
vector<T> xs(n), ys(n), zs(n); \
For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) \
Vec2(T, n, m, xs); \
For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) \
unordered_map<T, int> map; \
Rep(n) { \
Cin(T, x); \
map[x]++; \
}
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) \
{ \
for (const auto &e : xs) \
cout << e << " "; \
cout << "\n"; \
}
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)
// constexpr int MOD = 1e9+7;
#include <queue>
int main(void) {
Cin(int, n, m);
vc<vc<int>> a(n, vc<int>()), b(n, vc<int>());
Rep(m) {
Cin(int, u, v);
u--, v--;
a[u].push_back(v);
}
Cin(int, s, t);
s--, t--;
auto f = [&](vc<int> v) {
vc<int> r;
vc<bool> e(n);
for (int i : v)
for (int j : a[i]) {
if (!e[j])
e[j] = true, r.push_back(j);
}
return r;
};
For(i, n) b[i] = f(f(f({i})));
constexpr int Inf = 2e9;
vc<int> d(n, Inf);
d[s] = 0;
using P = pair<int, int>;
priority_queue<P, vector<P>, greater<P>> q;
q.emplace(0, s);
while (!q.empty()) {
auto e = q.top();
q.pop();
if (e.second == t) {
Cout(e.first);
return 0;
}
if (e.first > d[e.second])
continue;
for (int i : b[e.second]) {
if (d[i] > d[e.second] + 1) {
d[i] = d[e.second] + 1;
q.emplace(d[i], i);
}
}
}
Cout(-1);
// Couts(d);
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
void _cin() {}
template <class Head, class... Tail> void _cin(Head &&head, Tail &&...tail) {
cin >> head;
_cin(forward<Tail>(tail)...);
}
void _cout() { cout << "\n"; }
template <class Head, class... Tail> void _cout(Head &&head, Tail &&...tail) {
cout << head;
_cout(forward<Tail>(tail)...);
}
int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }
#define Sq(x) (x) * (x)
#define For(i, n) for (int i = 0; i < (n); i++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) \
vector<T> sxs(xs.size() + 1); \
For(i, (int)xs.size()) sxs[i + 1] = sxs[i] + xs[i]
#define Cin(T, ...) \
T __VA_ARGS__; \
_cin(__VA_ARGS__)
#define Cins(T, n, xs) \
vector<T> xs(n); \
For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) \
vector<T> xs(n), ys(n); \
For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) \
vector<T> xs(n), ys(n), zs(n); \
For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) \
Vec2(T, n, m, xs); \
For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) \
unordered_map<T, int> map; \
Rep(n) { \
Cin(T, x); \
map[x]++; \
}
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) \
{ \
for (const auto &e : xs) \
cout << e << " "; \
cout << "\n"; \
}
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)
// constexpr int MOD = 1e9+7;
#include <queue>
int main(void) {
Cin(int, n, m);
vc<vc<int>> a(n, vc<int>()), b(n, vc<int>());
Rep(m) {
Cin(int, u, v);
u--, v--;
a[u].push_back(v);
}
Cin(int, s, t);
s--, t--;
auto f = [&](vc<int> v) {
vc<int> r;
vc<bool> e(n);
for (int i : v)
for (int j : a[i]) {
if (!e[j])
e[j] = true, r.push_back(j);
}
return r;
};
{
b[s] = f(f(f({s})));
if (Contains(b[s], t)) {
Cout(1);
return 0;
}
}
For(i, n) b[i] = f(f(f({i})));
constexpr int Inf = 2e9;
vc<int> d(n, Inf);
d[s] = 0;
using P = pair<int, int>;
priority_queue<P, vector<P>, greater<P>> q;
q.emplace(0, s);
while (!q.empty()) {
auto e = q.top();
q.pop();
if (e.second == t) {
Cout(e.first);
return 0;
}
if (e.first > d[e.second])
continue;
for (int i : b[e.second]) {
if (d[i] > d[e.second] + 1) {
d[i] = d[e.second] + 1;
q.emplace(d[i], i);
}
}
}
Cout(-1);
// Couts(d);
}
| insert | 96 | 96 | 96 | 105 | TLE | |
p02991 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x) \
sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \
c i) {
sim > struct rge {
c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i;
ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define int long long int
#define pb push_back
#define fe first
#define lb lower_bound
#define ub upper_bound
#define pii pair<pair<int, int>, pair<int, int>>
#define se second
#define endl "\n"
#define pi pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define bs binary_search
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rep1(i, a, b) for (int i = a; i <= b; i++)
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)x.size()
#define PI 3.14159265358979323846
const int N = 1e5 + 5;
int mod = 1e9 + 7, INF = 1e17;
int dx[4] = {0, 0, +1, -1};
int dy[4] = {+1, -1, 0, 0};
vi v[N];
int d[N], vis[N];
int l, r;
void bfs(int x) {
queue<int> q;
q.push(x);
vis[x] = 1;
while (!q.empty()) {
int nv = q.front();
q.pop();
for (auto to : v[nv]) {
if (!vis[to]) {
d[to] = d[nv] + 1;
vis[to] = 1;
q.push(to);
}
}
}
}
void solve() {
int n, m;
cin >> n >> m;
rep(i, 0, m) {
int x, y;
cin >> x >> y;
v[x].pb(y + n);
v[x + n].pb(y + 2 * n);
v[x + 2 * n].pb(y);
}
cin >> l >> r;
bfs(l);
if (d[r] != 0 && d[r] % 3 == 0)
cout << d[r] / 3 << endl;
else
cout << -1;
}
int32_t main() {
cool;
int t = 1;
// cin>>t;
while (t--)
solve();
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x) \
sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \
c i) {
sim > struct rge {
c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i;
ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define int long long int
#define pb push_back
#define fe first
#define lb lower_bound
#define ub upper_bound
#define pii pair<pair<int, int>, pair<int, int>>
#define se second
#define endl "\n"
#define pi pair<int, int>
#define vi vector<int>
#define vvi vector<vi>
#define bs binary_search
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rep1(i, a, b) for (int i = a; i <= b; i++)
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)x.size()
#define PI 3.14159265358979323846
const int N = 3e5 + 5;
int mod = 1e9 + 7, INF = 1e17;
int dx[4] = {0, 0, +1, -1};
int dy[4] = {+1, -1, 0, 0};
vi v[N];
int d[N], vis[N];
int l, r;
void bfs(int x) {
queue<int> q;
q.push(x);
vis[x] = 1;
while (!q.empty()) {
int nv = q.front();
q.pop();
for (auto to : v[nv]) {
if (!vis[to]) {
d[to] = d[nv] + 1;
vis[to] = 1;
q.push(to);
}
}
}
}
void solve() {
int n, m;
cin >> n >> m;
rep(i, 0, m) {
int x, y;
cin >> x >> y;
v[x].pb(y + n);
v[x + n].pb(y + 2 * n);
v[x + 2 * n].pb(y);
}
cin >> l >> r;
bfs(l);
if (d[r] != 0 && d[r] % 3 == 0)
cout << d[r] / 3 << endl;
else
cout << -1;
}
int32_t main() {
cool;
int t = 1;
// cin>>t;
while (t--)
solve();
return 0;
}
| replace | 58 | 59 | 58 | 59 | 0 | |
p02991 | C++ | Runtime Error | // Marcin Knapik
// before you read it
// make sure it's a good idea
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef long double ld;
#define boost \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define szy first
#define gi second
#define sz(a) (int)(a).size()
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
template <class T> inline bool setmin(T &a, T b) {
if (a > b)
return a = b, 1;
return 0;
}
template <class T> inline bool setmax(T &a, T b) {
if (a < b)
return a = b, 1;
return 0;
}
template <class T> inline T fast(T a, T b, T mod) {
ll res = 1;
while (b) {
if (b & 1)
res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
template <class T> inline T russian(T a, T b, T mod) {
ll res = 0;
while (b) {
if (b & 1)
res = (res + a) % mod;
a = (a + a) % mod;
b >>= 1;
}
return res;
}
template <class T> inline T sub(T a, T b, T mod) {
return ((a - b) + mod) % mod;
}
template <class T> istream &operator>>(istream &os, vector<T> &container) {
for (auto &u : container)
os >> u;
return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &container) {
for (auto &u : container)
os << u << " ";
return os;
}
template <typename T> inline T gcd(T a, T b) {
while (b)
swap(a %= b, b);
return a;
}
ld e = 2.7182818284590452353602874713526624;
ld PI = acos(-1);
ld eps = 1e-11;
const ll T = 1 << 19;
const ll INF = 1e9 + 7;
const ll BIG_INF = 1e18 + 5;
const long long N = 44 + 7;
ll n, m, k;
int s, t;
vvi G(N);
int odw[N][3];
void BFS() {
queue<pair<int, int>> kolejka;
odw[s][0] = 3;
kolejka.push({s, 0});
while (sz(kolejka)) {
ii akt = kolejka.front();
kolejka.pop();
int v = akt.first;
int val = akt.second;
int nast = (val + 1) % 3;
for (auto &u : G[v]) {
// cout << v << ' ' << val << ' ' << u << ' ' << nast << endl;
if (!odw[u][nast]) {
odw[u][nast] = odw[v][val] + 1;
kolejka.push({u, nast});
}
}
}
}
int main() {
boost;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
G[a].pb(b);
// G[b].pb(a);
}
cin >> s >> t;
odw[s][0] = 3;
BFS();
cout << odw[t][0] / 3 - 1 << '\n';
for (int i = 1; i <= 3; i++) {
for (int j = 0; j < 3; j++) {
// cout << odw[i][j] << ' ';
}
// cout << endl;
}
} | // Marcin Knapik
// before you read it
// make sure it's a good idea
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef long double ld;
#define boost \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define szy first
#define gi second
#define sz(a) (int)(a).size()
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
template <class T> inline bool setmin(T &a, T b) {
if (a > b)
return a = b, 1;
return 0;
}
template <class T> inline bool setmax(T &a, T b) {
if (a < b)
return a = b, 1;
return 0;
}
template <class T> inline T fast(T a, T b, T mod) {
ll res = 1;
while (b) {
if (b & 1)
res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res;
}
template <class T> inline T russian(T a, T b, T mod) {
ll res = 0;
while (b) {
if (b & 1)
res = (res + a) % mod;
a = (a + a) % mod;
b >>= 1;
}
return res;
}
template <class T> inline T sub(T a, T b, T mod) {
return ((a - b) + mod) % mod;
}
template <class T> istream &operator>>(istream &os, vector<T> &container) {
for (auto &u : container)
os >> u;
return os;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &container) {
for (auto &u : container)
os << u << " ";
return os;
}
template <typename T> inline T gcd(T a, T b) {
while (b)
swap(a %= b, b);
return a;
}
ld e = 2.7182818284590452353602874713526624;
ld PI = acos(-1);
ld eps = 1e-11;
const ll T = 1 << 19;
const ll INF = 1e9 + 7;
const ll BIG_INF = 1e18 + 5;
const long long N = 1e6 + 7;
ll n, m, k;
int s, t;
vvi G(N);
int odw[N][3];
void BFS() {
queue<pair<int, int>> kolejka;
odw[s][0] = 3;
kolejka.push({s, 0});
while (sz(kolejka)) {
ii akt = kolejka.front();
kolejka.pop();
int v = akt.first;
int val = akt.second;
int nast = (val + 1) % 3;
for (auto &u : G[v]) {
// cout << v << ' ' << val << ' ' << u << ' ' << nast << endl;
if (!odw[u][nast]) {
odw[u][nast] = odw[v][val] + 1;
kolejka.push({u, nast});
}
}
}
}
int main() {
boost;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
G[a].pb(b);
// G[b].pb(a);
}
cin >> s >> t;
odw[s][0] = 3;
BFS();
cout << odw[t][0] / 3 - 1 << '\n';
for (int i = 1; i <= 3; i++) {
for (int j = 0; j < 3; j++) {
// cout << odw[i][j] << ' ';
}
// cout << endl;
}
} | replace | 87 | 88 | 87 | 88 | 0 | |
p02991 | C++ | Time Limit Exceeded | #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using dd = double;
using vdd = std::vector<dd>;
using vvdd = std::vector<vdd>;
using vvvdd = std::vector<vvdd>;
const ll INF = 1LL << 45; // 10e5倍してもオーバーフローしない値
const ll MOD = 1000000007LL; // 998244353L;
const dd EPS = 1e-11;
typedef std::numeric_limits<double> dbl;
// cin,cout高速化のおまじない+桁数指定
struct Fast {
Fast() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(std::numeric_limits<double>::max_digits10);
}
} fast;
#define REPS(i, S, E) for (ll i = (S); i <= (E); i++)
#define REP(i, N) REPS(i, 0, N - 1)
#define DEPS(i, E, S) for (ll i = (E); i >= (S); i--)
#define DEP(i, N) DEPS(i, N - 1, 0)
#define EACH(e, v) for (auto &&e : v)
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline T MaxE(vector<T> &v, ll S, ll E) {
T m = v[S];
REPS(i, S, E) chmax(m, v[i]);
return m;
} // v[S]~v[E]の最大値
template <class T> inline T MinE(vector<T> &v, ll S, ll E) {
T m = v[S];
REPS(i, S, E) chmin(m, v[i]);
return m;
} // v[S]~v[E]の最小値
template <class T> inline T MaxE(vector<T> &v, ll N) {
return MaxE(v, 0, N - 1);
} // 先頭N個中の最大値
template <class T> inline T MinE(vector<T> &v, ll N) {
return MinE(v, 0, N - 1);
}
template <class T> inline T MaxE(vector<T> &v) { return MaxE(v, (ll)v.size()); }
template <class T> inline T MinE(vector<T> &v) { return MinE(v, (ll)v.size()); }
template <class T> inline ll MaxI(vector<T> &v, ll S, ll E) {
ll m = S;
REPS(i, S, E) {
if (v[i] > v[m])
m = i;
}
return m;
}
template <class T> inline ll MinI(vector<T> &v, ll S, ll E) {
ll m = S;
REPS(i, S, E) {
if (v[i] < v[m])
m = i;
}
return m;
}
template <class T> inline ll MaxI(vector<T> &v, ll N) {
return MaxI(v, 0, N - 1);
}
template <class T> inline ll MinI(vector<T> &v, ll N) {
return MinI(v, 0, N - 1);
}
template <class T> inline ll MaxI(vector<T> &v) {
return MaxI(v, (ll)v.size());
}
template <class T> inline ll MinI(vector<T> &v) {
return MinI(v, (ll)v.size());
}
template <class T> inline T Sum(vector<T> &v, ll S, ll E) {
T s = v[S];
REPS(i, S + 1, E) s += v[i];
return s;
}
template <class T> inline T Sum(vector<T> &v, ll N) { return Sum(v, 0, N - 1); }
template <class T> inline T Sum(vector<T> &v) { return Sum(v, v.size()); }
template <class T> inline T SumMOD(vector<T> &v, ll S, ll E) {
T s = v[S];
REPS(i, S + 1, E) s = (s + v[i]) % MOD;
return s;
}
template <class T> inline T SumMOD(vector<T> &v, ll N) {
return SumMOD(v, 0, N - 1);
}
template <class T> inline T SumMOD(vector<T> &v) { return SumMOD(v, v.size()); }
inline ll AddMOD(ll a, ll b) { return (a + b) % MOD; }
inline ll SubMOD(ll a, ll b) { return (a - b + MOD) % MOD; }
inline ll MulMOD(ll a, ll b) { return (a * b) % MOD; }
inline ll in() {
ll x;
cin >> x;
return x;
}
inline double inD() {
double x;
cin >> x;
return x;
}
inline string inS() {
string x;
cin >> x;
return std::move(x);
}
template <class T = ll> inline vector<T> in_v(ll N) {
vector<T> v(N);
REP(i, N) cin >> v[i];
return move(v);
}
inline void To0origin(vll &v) { EACH(e, v) e--; }
vvll in_Graph(ll nodeNum, ll edgeNum, bool isDirected) {
vvll to(nodeNum);
REP(i, edgeNum) {
ll v, u;
cin >> v >> u;
v--;
u--;
to[v].push_back(u);
if (!isDirected)
to[u].push_back(v);
}
return std::move(to);
}
ll N, M, S, T;
vvll to;
vll dist;
void bfs(ll s) {
queue<ll> que;
dist[s] = 0;
que.push(s);
while (!que.empty()) {
ll v = que.front();
que.pop();
// 2歩先の集合
vector<bool> visited(N);
vll buf2;
EACH(u, to[v]) {
EACH(w, to[u]) {
if (visited[w])
continue;
visited[w] = true;
buf2.push_back(w);
}
}
// 3歩先の集合
EACH(w, buf2) {
EACH(x, to[w]) {
if (dist[x] != -1)
continue;
dist[x] = dist[v] + 1;
que.push(x);
}
}
}
}
int main() {
cin >> N >> M;
to = in_Graph(N, M, true);
cin >> S >> T;
S--;
T--;
dist.resize(N, -1);
bfs(S);
cout << dist[T] << '\n';
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using dd = double;
using vdd = std::vector<dd>;
using vvdd = std::vector<vdd>;
using vvvdd = std::vector<vvdd>;
const ll INF = 1LL << 45; // 10e5倍してもオーバーフローしない値
const ll MOD = 1000000007LL; // 998244353L;
const dd EPS = 1e-11;
typedef std::numeric_limits<double> dbl;
// cin,cout高速化のおまじない+桁数指定
struct Fast {
Fast() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(std::numeric_limits<double>::max_digits10);
}
} fast;
#define REPS(i, S, E) for (ll i = (S); i <= (E); i++)
#define REP(i, N) REPS(i, 0, N - 1)
#define DEPS(i, E, S) for (ll i = (E); i >= (S); i--)
#define DEP(i, N) DEPS(i, N - 1, 0)
#define EACH(e, v) for (auto &&e : v)
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline T MaxE(vector<T> &v, ll S, ll E) {
T m = v[S];
REPS(i, S, E) chmax(m, v[i]);
return m;
} // v[S]~v[E]の最大値
template <class T> inline T MinE(vector<T> &v, ll S, ll E) {
T m = v[S];
REPS(i, S, E) chmin(m, v[i]);
return m;
} // v[S]~v[E]の最小値
template <class T> inline T MaxE(vector<T> &v, ll N) {
return MaxE(v, 0, N - 1);
} // 先頭N個中の最大値
template <class T> inline T MinE(vector<T> &v, ll N) {
return MinE(v, 0, N - 1);
}
template <class T> inline T MaxE(vector<T> &v) { return MaxE(v, (ll)v.size()); }
template <class T> inline T MinE(vector<T> &v) { return MinE(v, (ll)v.size()); }
template <class T> inline ll MaxI(vector<T> &v, ll S, ll E) {
ll m = S;
REPS(i, S, E) {
if (v[i] > v[m])
m = i;
}
return m;
}
template <class T> inline ll MinI(vector<T> &v, ll S, ll E) {
ll m = S;
REPS(i, S, E) {
if (v[i] < v[m])
m = i;
}
return m;
}
template <class T> inline ll MaxI(vector<T> &v, ll N) {
return MaxI(v, 0, N - 1);
}
template <class T> inline ll MinI(vector<T> &v, ll N) {
return MinI(v, 0, N - 1);
}
template <class T> inline ll MaxI(vector<T> &v) {
return MaxI(v, (ll)v.size());
}
template <class T> inline ll MinI(vector<T> &v) {
return MinI(v, (ll)v.size());
}
template <class T> inline T Sum(vector<T> &v, ll S, ll E) {
T s = v[S];
REPS(i, S + 1, E) s += v[i];
return s;
}
template <class T> inline T Sum(vector<T> &v, ll N) { return Sum(v, 0, N - 1); }
template <class T> inline T Sum(vector<T> &v) { return Sum(v, v.size()); }
template <class T> inline T SumMOD(vector<T> &v, ll S, ll E) {
T s = v[S];
REPS(i, S + 1, E) s = (s + v[i]) % MOD;
return s;
}
template <class T> inline T SumMOD(vector<T> &v, ll N) {
return SumMOD(v, 0, N - 1);
}
template <class T> inline T SumMOD(vector<T> &v) { return SumMOD(v, v.size()); }
inline ll AddMOD(ll a, ll b) { return (a + b) % MOD; }
inline ll SubMOD(ll a, ll b) { return (a - b + MOD) % MOD; }
inline ll MulMOD(ll a, ll b) { return (a * b) % MOD; }
inline ll in() {
ll x;
cin >> x;
return x;
}
inline double inD() {
double x;
cin >> x;
return x;
}
inline string inS() {
string x;
cin >> x;
return std::move(x);
}
template <class T = ll> inline vector<T> in_v(ll N) {
vector<T> v(N);
REP(i, N) cin >> v[i];
return move(v);
}
inline void To0origin(vll &v) { EACH(e, v) e--; }
vvll in_Graph(ll nodeNum, ll edgeNum, bool isDirected) {
vvll to(nodeNum);
REP(i, edgeNum) {
ll v, u;
cin >> v >> u;
v--;
u--;
to[v].push_back(u);
if (!isDirected)
to[u].push_back(v);
}
return std::move(to);
}
ll N, M, S, T;
vvll to;
vll dist;
void bfs(ll s) {
queue<ll> que;
dist[s] = 0;
que.push(s);
while (!que.empty()) {
ll v = que.front();
que.pop();
// 2歩先の集合
vector<bool> visited(N);
vll buf2;
EACH(u, to[v]) {
EACH(w, to[u]) {
if (visited[w])
continue;
visited[w] = true;
buf2.push_back(w);
}
}
// 3歩先の集合
EACH(w, buf2) {
EACH(x, to[w]) {
if (dist[x] != -1)
continue;
dist[x] = dist[v] + 1;
if (x == T)
return;
que.push(x);
}
}
}
}
int main() {
cin >> N >> M;
to = in_Graph(N, M, true);
cin >> S >> T;
S--;
T--;
dist.resize(N, -1);
bfs(S);
cout << dist[T] << '\n';
return 0;
}
| insert | 181 | 181 | 181 | 183 | TLE | |
p02991 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <vector>
#define rep(i, n) for (i = 0; i < n; i++)
#define P pair<int, int>
using namespace std;
int main() {
int a, b, c, d, e, f, i, j, n, m, s, t;
int dist[100000] = {};
rep(i, 100000) dist[i]--;
cin >> n >> m;
vector<vector<int>> v(3 * n);
rep(i, m) {
cin >> a >> b;
a--;
b--;
v[a].push_back(b + n);
v[a + n].push_back(b + n * 2);
v[a + 2 * n].push_back(b);
}
cin >> s >> t;
s--;
t--;
queue<P> q;
q.push(P(s, 0));
dist[s] = 0;
while (q.size()) {
int now = q.front().first;
int step = q.front().second;
q.pop();
rep(i, v[now].size()) {
int next = v[now][i];
if (dist[next] != -1)
continue;
q.push(P(next, step + 1));
dist[next] = dist[now] + 1;
}
}
e = dist[t];
if (e != -1)
e = e / 3;
cout << e;
return 0;
} | #include <algorithm>
#include <climits>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <vector>
#define rep(i, n) for (i = 0; i < n; i++)
#define P pair<int, int>
using namespace std;
int main() {
int a, b, c, d, e, f, i, j, n, m, s, t;
int dist[300000] = {};
rep(i, 300000) dist[i]--;
cin >> n >> m;
vector<vector<int>> v(3 * n);
rep(i, m) {
cin >> a >> b;
a--;
b--;
v[a].push_back(b + n);
v[a + n].push_back(b + n * 2);
v[a + 2 * n].push_back(b);
}
cin >> s >> t;
s--;
t--;
queue<P> q;
q.push(P(s, 0));
dist[s] = 0;
while (q.size()) {
int now = q.front().first;
int step = q.front().second;
q.pop();
rep(i, v[now].size()) {
int next = v[now][i];
if (dist[next] != -1)
continue;
q.push(P(next, step + 1));
dist[next] = dist[now] + 1;
}
}
e = dist[t];
if (e != -1)
e = e / 3;
cout << e;
return 0;
} | replace | 18 | 20 | 18 | 20 | 0 | |
p02991 | C++ | Time Limit Exceeded | #include <iostream>
#include <queue>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;
int main() {
// 頂点数と辺数
int N, M;
cin >> N >> M;
// グラフ入力受取 (ここでは無向グラフを想定)
Graph G(N), g(N);
for (int i = 0; i < M; ++i) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].push_back(b);
}
int s, t;
cin >> s >> t;
s--;
t--;
// BFS のためのデータ構造
vector<int> dist(N, -1), seen(N, -1); // 全頂点を「未訪問」に初期化
queue<int> que;
// 初期条件 (頂点 0 を初期ノードとする)
dist[s] = 0;
que.push(s); // 0 を橙色頂点にする
// BFS 開始 (キューが空になるまで探索を行う)
while (!que.empty()) {
int v = que.front(); // キューから先頭頂点を取り出す
que.pop();
// v から辿れる頂点をすべて調べる
for (int nv : G[v]) {
for (int nnv : G[nv]) {
for (int nnnv : G[nnv]) {
if (dist[nnnv] != -1)
continue;
dist[nnnv] = dist[v] + 1;
que.push(nnnv);
}
}
}
}
// 結果出力 (各頂点の頂点 0 からの距離を見る)
cout << dist[t] << endl;
} | #include <iostream>
#include <queue>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;
int main() {
// 頂点数と辺数
int N, M;
cin >> N >> M;
// グラフ入力受取 (ここでは無向グラフを想定)
Graph G(N), g(N);
for (int i = 0; i < M; ++i) {
int a, b;
cin >> a >> b;
a--;
b--;
G[a].push_back(b);
}
int s, t;
cin >> s >> t;
s--;
t--;
// BFS のためのデータ構造
vector<int> dist(N, -1), seen(N, -1); // 全頂点を「未訪問」に初期化
queue<int> que;
// 初期条件 (頂点 0 を初期ノードとする)
dist[s] = 0;
que.push(s); // 0 を橙色頂点にする
// BFS 開始 (キューが空になるまで探索を行う)
while (!que.empty()) {
int v = que.front(); // キューから先頭頂点を取り出す
que.pop();
// v から辿れる頂点をすべて調べる
for (int nv : G[v]) {
for (int nnv : G[nv]) {
for (int nnnv : G[nnv]) {
if (dist[nnnv] != -1)
continue;
dist[nnnv] = dist[v] + 1;
if (nnnv == t) {
cout << dist[nnnv] << endl;
return 0;
}
que.push(nnnv);
}
}
}
}
// 結果出力 (各頂点の頂点 0 からの距離を見る)
cout << dist[t] << endl;
}
| insert | 44 | 44 | 44 | 48 | TLE | |
p02991 | C++ | Runtime Error | #include "bits/stdc++.h"
#define rep(i, N) for (int(i) = 0; (i) < (N); (i)++)
#define debug(var) std::cout << #var << " : " << var;
using Graph = std::vector<std::vector<int>>;
int main() {
int N, M;
std::cin >> N >> M;
Graph G(N);
rep(i, N) {
int u, v;
std::cin >> u >> v;
G[u - 1].push_back(v - 1);
}
int S, T;
std::cin >> S >> T;
S--;
T--;
std::vector<std::array<int, 3>> memo(N, {-1, -1, -1});
memo[S][0] = 0;
std::queue<std::pair<int, int>> q;
q.push(std::make_pair(S, 0));
while (!q.empty()) {
auto cur = q.front();
q.pop();
for (auto &v : G[cur.first]) {
int tmp = ((cur.second) + 1) % 3;
if (memo[v][tmp] != -1)
continue;
memo[v][tmp] = memo[cur.first][cur.second] + 1;
q.push(std::make_pair(v, tmp));
}
}
int ans = memo[T][0];
if (ans != -1)
ans /= 3;
std::cout << ans;
return 0;
}
| #include "bits/stdc++.h"
#define rep(i, N) for (int(i) = 0; (i) < (N); (i)++)
#define debug(var) std::cout << #var << " : " << var;
using Graph = std::vector<std::vector<int>>;
int main() {
int N, M;
std::cin >> N >> M;
Graph G(N);
rep(i, M) {
int u, v;
std::cin >> u >> v;
G[u - 1].push_back(v - 1);
}
int S, T;
std::cin >> S >> T;
S--;
T--;
std::vector<std::array<int, 3>> memo(N, {-1, -1, -1});
memo[S][0] = 0;
std::queue<std::pair<int, int>> q;
q.push(std::make_pair(S, 0));
while (!q.empty()) {
auto cur = q.front();
q.pop();
for (auto &v : G[cur.first]) {
int tmp = ((cur.second) + 1) % 3;
if (memo[v][tmp] != -1)
continue;
memo[v][tmp] = memo[cur.first][cur.second] + 1;
q.push(std::make_pair(v, tmp));
}
}
int ans = memo[T][0];
if (ans != -1)
ans /= 3;
std::cout << ans;
return 0;
}
| replace | 11 | 12 | 11 | 12 | 0 | |
p02991 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
int vis[100008];
ll dist[100008];
vector<int> e[100008];
int n;
void add(int u, int v) {
e[u].pb(v + n);
e[u + n].pb(v + 2 * n);
e[u + 2 * n].pb(v);
}
int main() {
int m, i, j;
cin >> n >> m;
for (i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
add(u, v);
}
int s, t;
cin >> s >> t;
vis[s] = 1;
queue<int> q;
q.push(s);
int f = 0;
while (!q.empty()) {
int u = q.front();
q.pop();
if (u == t)
break;
for (auto v : e[u]) {
if (!vis[v]) {
q.push(v);
vis[v] = 1;
dist[v] = dist[u] + 1;
}
}
}
if (dist[t] != 0 && dist[t] % 3 == 0) {
cout << dist[t] / 3;
} else
cout << -1;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
int vis[300008];
ll dist[300008];
vector<int> e[300008];
int n;
void add(int u, int v) {
e[u].pb(v + n);
e[u + n].pb(v + 2 * n);
e[u + 2 * n].pb(v);
}
int main() {
int m, i, j;
cin >> n >> m;
for (i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
add(u, v);
}
int s, t;
cin >> s >> t;
vis[s] = 1;
queue<int> q;
q.push(s);
int f = 0;
while (!q.empty()) {
int u = q.front();
q.pop();
if (u == t)
break;
for (auto v : e[u]) {
if (!vis[v]) {
q.push(v);
vis[v] = 1;
dist[v] = dist[u] + 1;
}
}
}
if (dist[t] != 0 && dist[t] % 3 == 0) {
cout << dist[t] / 3;
} else
cout << -1;
return 0;
} | replace | 4 | 7 | 4 | 7 | 0 | |
p02992 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a, _n = n; i <= _n; ++i)
#define drep(i, a, n) for (int i = a, _n = n; i >= _n; --i)
#define debug(x) cout << #x << " = " << x << endl
const int N = 65000;
const int Mod = 1e9 + 7;
int n, k;
int L[N], R[N], Cnt[N];
long long dp[105][N];
int main() {
scanf("%d%d", &n, &k);
int y = 1, cnt = 0;
while (y <= k) {
int t = k / y;
int c = k / t;
L[++cnt] = y, R[cnt] = c;
y = c + 1;
}
rep(i, 1, cnt) dp[1][i] = Cnt[i] = R[i] - L[i] + 1;
rep(i, 2, n) {
long long Sum = 0;
rep(j, 1, cnt) {
(Sum += dp[i - 1][j]) %= Mod;
dp[i][cnt - j + 1] = Sum * Cnt[cnt - j + 1] % Mod;
}
}
long long Ans = 0;
rep(i, 1, cnt)(Ans += dp[n][i]) %= Mod;
cout << Ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a, _n = n; i <= _n; ++i)
#define drep(i, a, n) for (int i = a, _n = n; i >= _n; --i)
#define debug(x) cout << #x << " = " << x << endl
const int N = 65000;
const int Mod = 1e9 + 7;
int n, k;
int L[N], R[N], Cnt[N];
long long dp[105][N];
int main() {
scanf("%d%d", &n, &k);
swap(n, k);
int y = 1, cnt = 0;
while (y <= k) {
int t = k / y;
int c = k / t;
L[++cnt] = y, R[cnt] = c;
y = c + 1;
}
rep(i, 1, cnt) dp[1][i] = Cnt[i] = R[i] - L[i] + 1;
rep(i, 2, n) {
long long Sum = 0;
rep(j, 1, cnt) {
(Sum += dp[i - 1][j]) %= Mod;
dp[i][cnt - j + 1] = Sum * Cnt[cnt - j + 1] % Mod;
}
}
long long Ans = 0;
rep(i, 1, cnt)(Ans += dp[n][i]) %= Mod;
cout << Ans << endl;
return 0;
}
| insert | 17 | 17 | 17 | 18 | 0 | |
p02992 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long N, K;
const int MOD = 1000000007;
long long dp[101][50000] = {};
long long S[50000] = {};
long long num[50000];
int solve() {
int M = 0;
for (int i = 1; i <= N;) {
int j = N / i;
if (i <= j) {
num[M++] = 1;
++i;
} else {
num[M++] = N / j - i + 1;
i = N / j + 1;
}
}
dp[0][0] = 1;
for (int k = 0; k < K; ++k) {
memset(S, 0, sizeof(S));
for (int j = 0; j < M; ++j)
S[j + 1] = (S[j] + dp[k][j]) % MOD;
for (int j = 0; j < M; ++j)
dp[k + 1][j] = (S[M - j] * num[j]) % MOD;
}
int res = 0;
for (int j = 0; j <= M; ++j)
res = (res + dp[K][j]) % MOD;
return res;
}
int main() {
cin >> N >> K;
cout << solve() << endl;
} | #include <bits/stdc++.h>
using namespace std;
long long N, K;
const int MOD = 1000000007;
long long dp[101][110000] = {};
long long S[110000] = {};
long long num[110000];
int solve() {
int M = 0;
for (int i = 1; i <= N;) {
int j = N / i;
if (i <= j) {
num[M++] = 1;
++i;
} else {
num[M++] = N / j - i + 1;
i = N / j + 1;
}
}
dp[0][0] = 1;
for (int k = 0; k < K; ++k) {
memset(S, 0, sizeof(S));
for (int j = 0; j < M; ++j)
S[j + 1] = (S[j] + dp[k][j]) % MOD;
for (int j = 0; j < M; ++j)
dp[k + 1][j] = (S[M - j] * num[j]) % MOD;
}
int res = 0;
for (int j = 0; j <= M; ++j)
res = (res + dp[K][j]) % MOD;
return res;
}
int main() {
cin >> N >> K;
cout << solve() << endl;
} | replace | 4 | 7 | 4 | 7 | 0 | |
p02992 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;
constexpr ll MOD = 1000000007;
constexpr double EPS = 1e-10;
constexpr int dyx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n, k;
cin >> n >> k;
vector<int> quotients(1, 0);
for (int i = 1; i <= sqrt(n) + 1; ++i) {
quotients.push_back(n / i);
quotients.push_back(n / (n / i));
}
sort(quotients.begin(), quotients.end());
quotients.erase(unique(quotients.begin(), quotients.end()), quotients.end());
int m = quotients.size();
vector<int> inv_quotients_idx(m, -1);
{
int j = m - 1;
for (int i = 1; i < m; ++i) {
while (i <= j && quotients[i] * quotients[j] > n)
--j;
if (i > j)
break;
inv_quotients_idx[i] = j;
inv_quotients_idx[j] = i;
}
}
vector<vector<ll>> dp(k + 1, vector<ll>(m, 0));
for (int j = 1; j < m; ++j)
dp[0][j] = quotients[j];
for (int i = 1; i < k; ++i) {
for (int j = 1; j < m; ++j) {
dp[i][j] = (dp[i - 1][inv_quotients_idx[j]] *
(quotients[j] - quotients[j - 1])) %
MOD;
}
for (int j = 1; j < m; ++j) {
dp[i][j] += dp[i][j - 1];
dp[i][j] %= MOD;
}
}
cout << dp[k - 1][m - 1] << endl;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;
constexpr ll MOD = 1000000007;
constexpr double EPS = 1e-10;
constexpr int dyx[4][2] = {{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n, k;
cin >> n >> k;
vector<int> quotients(1, 0);
for (int i = 1; i <= min(n, ll(sqrt(n)) + 1); ++i) {
quotients.push_back(n / i);
quotients.push_back(n / (n / i));
}
sort(quotients.begin(), quotients.end());
quotients.erase(unique(quotients.begin(), quotients.end()), quotients.end());
int m = quotients.size();
vector<int> inv_quotients_idx(m, -1);
{
int j = m - 1;
for (int i = 1; i < m; ++i) {
while (i <= j && quotients[i] * quotients[j] > n)
--j;
if (i > j)
break;
inv_quotients_idx[i] = j;
inv_quotients_idx[j] = i;
}
}
vector<vector<ll>> dp(k + 1, vector<ll>(m, 0));
for (int j = 1; j < m; ++j)
dp[0][j] = quotients[j];
for (int i = 1; i < k; ++i) {
for (int j = 1; j < m; ++j) {
dp[i][j] = (dp[i - 1][inv_quotients_idx[j]] *
(quotients[j] - quotients[j - 1])) %
MOD;
}
for (int j = 1; j < m; ++j) {
dp[i][j] += dp[i][j - 1];
dp[i][j] %= MOD;
}
}
cout << dp[k - 1][m - 1] << endl;
} | replace | 35 | 36 | 35 | 36 | 0 | |
p02992 | C++ | Runtime Error | #include <cstdio>
using namespace std;
const long long MOD = 1000000000 + 7;
long long dp[40000][110];
int main() {
int n, k;
scanf("%d %d", &n, &k);
int last = n;
int tmp = 0, ss = 0;
for (int i = 1; i * i <= n; i++) {
dp[i][0] = last - n / (i + 1), last = n / (i + 1);
tmp = i;
ss += dp[i][0];
}
while (n - ss > 0) {
dp[++tmp][0] = 1;
ss++;
}
// for(int i = 1 ; i <= tmp ; i++) {
// printf("%d\n", dp[i][0]);
// }
for (int j = 1; j < k; j++) {
long long sum = 0;
for (int i = 1; i <= tmp; i++) {
sum += dp[tmp - i + 1][j - 1];
sum %= MOD;
dp[i][j] = sum * dp[i][0] % MOD;
}
}
long long ans = 0;
for (int i = 1; i <= tmp; i++) {
ans += dp[i][k - 1] % MOD;
}
printf("%lld\n", ans % MOD);
return 0;
} | #include <cstdio>
using namespace std;
const long long MOD = 1000000000 + 7;
long long dp[100000][110];
int main() {
int n, k;
scanf("%d %d", &n, &k);
int last = n;
int tmp = 0, ss = 0;
for (int i = 1; i * i <= n; i++) {
dp[i][0] = last - n / (i + 1), last = n / (i + 1);
tmp = i;
ss += dp[i][0];
}
while (n - ss > 0) {
dp[++tmp][0] = 1;
ss++;
}
// for(int i = 1 ; i <= tmp ; i++) {
// printf("%d\n", dp[i][0]);
// }
for (int j = 1; j < k; j++) {
long long sum = 0;
for (int i = 1; i <= tmp; i++) {
sum += dp[tmp - i + 1][j - 1];
sum %= MOD;
dp[i][j] = sum * dp[i][0] % MOD;
}
}
long long ans = 0;
for (int i = 1; i <= tmp; i++) {
ans += dp[i][k - 1] % MOD;
}
printf("%lld\n", ans % MOD);
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02992 | C++ | Runtime Error | #include "bits/stdc++.h"
#include <cassert>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
const int mod = 1000000007;
const int inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int dp[100][100000];
int M2[100005], M3[100005];
signed main() {
int n, k;
cin >> n >> k;
map<int, int> M, M1; // M1...nub->id
for (int i = 1; i * i <= n; i++) {
int x = n / i;
M[i] = n / i;
M[x] = n / x;
}
vector<int> v;
for (auto itr = M.begin(); itr != M.end(); itr++) {
v.push_back(itr->first);
}
int ld = 0;
rep(i, v.size()) {
dp[0][i] = v[i];
M1[v[i]] = i;
M2[i] = v[i];
M3[i] = v[i] - ld;
ld = v[i];
}
rep(i, k) {
rep(j, v.size()) {
dp[i + 1][j] += dp[i][M1[n / M2[j]]] * M3[j];
dp[i + 1][j] %= mod;
}
rep(j, v.size()) {
dp[i + 1][j + 1] += dp[i + 1][j];
dp[i + 1][j + 1] %= mod;
}
}
cout << dp[k - 1][v.size() - 1] << endl;
}
| #include "bits/stdc++.h"
#include <cassert>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
const int mod = 1000000007;
const int inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int dp[102][100000];
int M2[100005], M3[100005];
signed main() {
int n, k;
cin >> n >> k;
map<int, int> M, M1; // M1...nub->id
for (int i = 1; i * i <= n; i++) {
int x = n / i;
M[i] = n / i;
M[x] = n / x;
}
vector<int> v;
for (auto itr = M.begin(); itr != M.end(); itr++) {
v.push_back(itr->first);
}
int ld = 0;
rep(i, v.size()) {
dp[0][i] = v[i];
M1[v[i]] = i;
M2[i] = v[i];
M3[i] = v[i] - ld;
ld = v[i];
}
rep(i, k) {
rep(j, v.size()) {
dp[i + 1][j] += dp[i][M1[n / M2[j]]] * M3[j];
dp[i + 1][j] %= mod;
}
rep(j, v.size()) {
dp[i + 1][j + 1] += dp[i + 1][j];
dp[i + 1][j + 1] %= mod;
}
}
cout << dp[k - 1][v.size() - 1] << endl;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p02992 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
#define rep(i, x, y) \
for (i64 i = i64(x), i##_max_for_repmacro = i64(y); \
i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (const auto &v : vec) {
os << v << ",";
}
os << "]";
return os;
}
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T, size_t size> void fill(T (&ary)[size], const T &val) {
fill_n((T *)ary, size, val);
}
template <class T> T lower_gauss(T num, T den) {
assert(den != 0);
if (num == 0)
return 0;
if (num > 0 and den > 0)
return num / den;
if (num < 0 and den > 0)
return (num - den + 1) / den;
return lower_gauss(-num, -den);
}
template <class T> T upper_gauss(T num, T den) {
return lower_gauss(num, den) + (num % den == 0 ? 0 : 1);
}
void solve() {
const i64 mod = 1'000'000'007;
i64 N, K;
cin >> N >> K;
set<i64> a;
rep(i, 1, N) {
if (i * i > N)
break;
a.insert(i);
a.insert(N / i);
}
vector<i64> vals;
for (auto x : a)
vals.emplace_back(x);
map<i64, i64> count; // |lower_gauss(N/j) = i : 1<=j<=N| = count[i]
for (auto i : a) {
i64 lower; // lower_gauss(N/lower)>=i, lower_gauss(N/(lower-1))>i
i64 upper; // lower_gauss(N/upper)<i, lower_gauss(N/(upper-1))>=i
{
i64 lb = 0; // lower_gauss(N/lb) > i
i64 ub = N; // lower_gauss(N/ub) <=i
while (ub - lb > 1) {
i64 mid = (lb + ub) / 2;
if (N / mid <= i)
ub = mid;
else
lb = mid;
}
lower = ub;
}
{
i64 lb = 1; // lower_gauss(N/lb) >= i
i64 ub = N + 1; // upper_gauss(N/ub) < i
while (ub - lb > 1) {
i64 mid = (lb + ub) / 2;
if (N / mid < i)
ub = mid;
else
lb = mid;
}
upper = ub;
}
assert(N / lower >= i);
assert(N / upper < i);
count[i] = upper - lower;
}
map<i64, i64> idx;
rep(i, 0, vals.size()) idx[vals[i]] = i;
vector<vector<i64>> dp(K, vector<i64>(a.size()));
dp[0][0] = count[N / vals[0]];
rep(i, 1, vals.size()) {
dp[0][i] = (dp[0][i - 1] + count[N / vals[i]]) % mod;
}
rep(i, 1, K) {
dp[i][0] = dp[i - 1][idx[N]];
rep(j, 1, vals.size()) {
dp[i][j] = (dp[i][j - 1] +
dp[i - 1][idx[N / vals[j]]] * count[N / vals[j]] % mod) %
mod;
}
}
cout << dp[K - 1][idx[N]] << endl;
}
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(16);
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
#define rep(i, x, y) \
for (i64 i = i64(x), i##_max_for_repmacro = i64(y); \
i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << ", " << p.second << ")";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (const auto &v : vec) {
os << v << ",";
}
os << "]";
return os;
}
template <typename T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <typename T, size_t size> void fill(T (&ary)[size], const T &val) {
fill_n((T *)ary, size, val);
}
template <class T> T lower_gauss(T num, T den) {
assert(den != 0);
if (num == 0)
return 0;
if (num > 0 and den > 0)
return num / den;
if (num < 0 and den > 0)
return (num - den + 1) / den;
return lower_gauss(-num, -den);
}
template <class T> T upper_gauss(T num, T den) {
return lower_gauss(num, den) + (num % den == 0 ? 0 : 1);
}
void solve() {
const i64 mod = 1'000'000'007;
i64 N, K;
cin >> N >> K;
set<i64> a;
rep(i, 1, N + 1) {
if (i * i > N)
break;
a.insert(i);
a.insert(N / i);
}
vector<i64> vals;
for (auto x : a)
vals.emplace_back(x);
map<i64, i64> count; // |lower_gauss(N/j) = i : 1<=j<=N| = count[i]
for (auto i : a) {
i64 lower; // lower_gauss(N/lower)>=i, lower_gauss(N/(lower-1))>i
i64 upper; // lower_gauss(N/upper)<i, lower_gauss(N/(upper-1))>=i
{
i64 lb = 0; // lower_gauss(N/lb) > i
i64 ub = N; // lower_gauss(N/ub) <=i
while (ub - lb > 1) {
i64 mid = (lb + ub) / 2;
if (N / mid <= i)
ub = mid;
else
lb = mid;
}
lower = ub;
}
{
i64 lb = 1; // lower_gauss(N/lb) >= i
i64 ub = N + 1; // upper_gauss(N/ub) < i
while (ub - lb > 1) {
i64 mid = (lb + ub) / 2;
if (N / mid < i)
ub = mid;
else
lb = mid;
}
upper = ub;
}
assert(N / lower >= i);
assert(N / upper < i);
count[i] = upper - lower;
}
map<i64, i64> idx;
rep(i, 0, vals.size()) idx[vals[i]] = i;
vector<vector<i64>> dp(K, vector<i64>(a.size()));
dp[0][0] = count[N / vals[0]];
rep(i, 1, vals.size()) {
dp[0][i] = (dp[0][i - 1] + count[N / vals[i]]) % mod;
}
rep(i, 1, K) {
dp[i][0] = dp[i - 1][idx[N]];
rep(j, 1, vals.size()) {
dp[i][j] = (dp[i][j - 1] +
dp[i - 1][idx[N / vals[j]]] * count[N / vals[j]] % mod) %
mod;
}
}
cout << dp[K - 1][idx[N]] << endl;
}
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(16);
solve();
return 0;
}
| replace | 78 | 79 | 78 | 79 | 0 | |
p02992 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;
int main() {
int n, k;
cin >> n >> k;
if (k == 1) {
cout << 1 << endl;
return 0;
}
int rootn = sqrt(n), m = n / (rootn + 1), s = rootn + m + 1;
ll dp[k][s], cnt[s];
memset(dp, 0, sizeof(dp));
cnt[0] = 0;
FOR(i, 1, rootn + 1) cnt[i] = 1;
cnt[rootn + 1] = n / m - rootn;
for (int i = rootn + 2, j = m - 1; i < s; i++, j--) {
cnt[i] = n / j - n / (j + 1);
}
FOR(j, 1, s) { dp[0][j] = (cnt[j] + dp[0][j - 1]) % mod; }
FOR(i, 1, k) {
for (int j = 1, idx = s - 1; j < s; j++, idx--) {
dp[i][j] = (dp[i - 1][idx] * cnt[j]) % mod;
dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
}
}
cout << dp[k - 1][s - 1] << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int INF = 1000000005;
const long double EPS = 1e-10;
int main() {
int n, k;
cin >> n >> k;
if (n == 1) {
cout << 1 << endl;
return 0;
}
int rootn = sqrt(n), m = n / (rootn + 1), s = rootn + m + 1;
ll dp[k][s], cnt[s];
memset(dp, 0, sizeof(dp));
cnt[0] = 0;
FOR(i, 1, rootn + 1) cnt[i] = 1;
cnt[rootn + 1] = n / m - rootn;
for (int i = rootn + 2, j = m - 1; i < s; i++, j--) {
cnt[i] = n / j - n / (j + 1);
}
FOR(j, 1, s) { dp[0][j] = (cnt[j] + dp[0][j - 1]) % mod; }
FOR(i, 1, k) {
for (int j = 1, idx = s - 1; j < s; j++, idx--) {
dp[i][j] = (dp[i - 1][idx] * cnt[j]) % mod;
dp[i][j] = (dp[i][j] + dp[i][j - 1]) % mod;
}
}
cout << dp[k - 1][s - 1] << endl;
return 0;
} | replace | 17 | 18 | 17 | 18 | 0 | |
p02992 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
using std::bitset;
using std::complex;
using std::deque;
using std::iterator;
using std::map;
using std::multimap;
using std::multiset;
using std::pair;
using std::queue;
using std::set;
using std::stack;
using std::string;
using std::vector;
using std::ios_base;
using std::max;
using std::max_element;
using std::min;
using std::min_element;
using std::reverse;
using std::sort;
using std::stable_sort;
using std::swap;
using std::unique;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;
typedef complex<double> cd;
namespace MySpace {
struct Small_Segment_Tree {
vector<int> a;
int l, r;
private:
int __summ(int L, int R, int l, int r, int v) {
if (L <= l && r <= R)
return a[v];
if (R <= l || r <= L)
return 0;
int m = (l + r) / 2;
return __summ(L, R, l, m, 2 * v + 1) + __summ(L, R, m, r, 2 * v + 2);
}
void __set(int P, int l, int r, int v, int V) {
if (l + 1 == r) {
a[v] = V;
return;
}
int m = (l + r) / 2;
if (P < m) {
__set(P, l, m, 2 * v + 1, V);
a[v] = a[2 * v + 1] + a[2 * v + 2];
} else {
__set(P, m, r, 2 * v + 2, V);
a[v] = a[2 * v + 1] + a[2 * v + 2];
}
}
public:
int Summ(int L, int R) {
if (R < L)
return 0;
return __summ(L, R + 1, l, r, 0);
}
void Set(int P, int V) { __set(P, l, r, 0, V); }
Small_Segment_Tree(int _n) {
a.resize(4 * _n);
l = 0, r = _n;
}
};
long long inq(long long x, long long q, long long MOD) {
if (q == 0)
return 1;
long long l = inq(x, q / 2, MOD);
if (q % 2)
return l * l % MOD * x % MOD;
return l * l % MOD;
}
}; // namespace MySpace
using namespace MySpace;
#define F(i, n) for (int(i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()
const ll MOD = 1e9 + 7;
ll n, k;
ll ROOT;
ll dp[2][101][150000];
ll sigma[2][101][150000];
ll tagget_for_0 = 0;
ll tagget_for_1 = 0;
ll Compute[150000];
ll LL[150000];
ll RR[150000];
ll compute(ll x) {
if (Compute[x] != -1)
return Compute[x];
long long L = 0, R = 0;
ll l = 0, r = 1e9 + 77;
while (l + 1 < r) {
ll mid = (l + r) / 2;
if (n / mid > x)
l = mid;
else
r = mid;
}
L = r;
l = 0, r = 1e9 + 77;
while (l + 1 < r) {
ll mid = (l + r) / 2;
if (n / mid >= x)
l = mid;
else
r = mid;
}
R = l;
// cout << x << " : " << L << " " << R << endl;
LL[x] = L;
RR[x] = R;
return Compute[x] = R - L + 1;
}
ll oks(int vetka, int x) {
if (vetka == 0) {
return x <= tagget_for_0;
} else {
return x <= tagget_for_1;
}
return 0;
}
void calc(int t, int len, int x) {
if (t == 0) {
dp[t][len][x] = (sigma[0][len - 1][ROOT] + sigma[1][len - 1][x]) % MOD;
} else {
dp[t][len][x] = compute(x) * sigma[0][len - 1][x] % MOD;
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
if (n <= 3) {
cout << 100 / 0 << endl;
}
while (ROOT * ROOT <= n)
ROOT++;
for (int i = 1; i <= 49999; i++)
Compute[i] = -1;
for (int i = 1; i <= 49999; i++) {
compute(i);
}
for (int i = 1; i <= 49999; i++) {
if (LL[i] * LL[i] > n) {
tagget_for_0 = RR[i + 1];
tagget_for_1 = i;
}
}
// cout << tagget_for_0 << " " << tagget_for_1 << endl;
for (int i = 1; i <= 49999; i++) {
if (oks(0, i))
dp[0][1][i] = 1;
if (oks(1, i))
dp[1][1][i] = compute(i);
if (dp[1][1][i] > MOD || dp[0][1][i] > MOD) {
cout << 100 / 0;
return 0;
}
sigma[0][1][i] = (sigma[0][1][i - 1] + dp[0][1][i]) % MOD;
// sigma[1][1][i] = (sigma[1][1][i - 1] + dp[1][1][i]) % MOD;
}
for (int x = 49999; x >= 0; x--) {
sigma[1][1][x] = (sigma[1][1][x + 1] + dp[1][1][x]) % MOD;
}
for (int i = 2; i <= k; i++) {
for (int x = 1; x <= 49999; x++) {
if (oks(0, x))
calc(0, i, x);
if (oks(1, x))
calc(1, i, x);
sigma[0][i][x] = (sigma[0][i][x - 1] + dp[0][i][x]) % MOD;
}
for (int x = 49999; x >= 0; x--) {
sigma[1][i][x] = (sigma[1][i][x + 1] + dp[1][i][x]) % MOD;
}
}
ll ans = 0;
for (int i = 1; i <= 49999; i++) {
ans += (oks(0, i) * dp[0][k][i] + oks(1, i) * dp[1][k][i]) % MOD;
ans %= MOD;
}
cout << ans % MOD;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
using std::bitset;
using std::complex;
using std::deque;
using std::iterator;
using std::map;
using std::multimap;
using std::multiset;
using std::pair;
using std::queue;
using std::set;
using std::stack;
using std::string;
using std::vector;
using std::ios_base;
using std::max;
using std::max_element;
using std::min;
using std::min_element;
using std::reverse;
using std::sort;
using std::stable_sort;
using std::swap;
using std::unique;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;
typedef complex<double> cd;
namespace MySpace {
struct Small_Segment_Tree {
vector<int> a;
int l, r;
private:
int __summ(int L, int R, int l, int r, int v) {
if (L <= l && r <= R)
return a[v];
if (R <= l || r <= L)
return 0;
int m = (l + r) / 2;
return __summ(L, R, l, m, 2 * v + 1) + __summ(L, R, m, r, 2 * v + 2);
}
void __set(int P, int l, int r, int v, int V) {
if (l + 1 == r) {
a[v] = V;
return;
}
int m = (l + r) / 2;
if (P < m) {
__set(P, l, m, 2 * v + 1, V);
a[v] = a[2 * v + 1] + a[2 * v + 2];
} else {
__set(P, m, r, 2 * v + 2, V);
a[v] = a[2 * v + 1] + a[2 * v + 2];
}
}
public:
int Summ(int L, int R) {
if (R < L)
return 0;
return __summ(L, R + 1, l, r, 0);
}
void Set(int P, int V) { __set(P, l, r, 0, V); }
Small_Segment_Tree(int _n) {
a.resize(4 * _n);
l = 0, r = _n;
}
};
long long inq(long long x, long long q, long long MOD) {
if (q == 0)
return 1;
long long l = inq(x, q / 2, MOD);
if (q % 2)
return l * l % MOD * x % MOD;
return l * l % MOD;
}
}; // namespace MySpace
using namespace MySpace;
#define F(i, n) for (int(i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()
const ll MOD = 1e9 + 7;
ll n, k;
ll ROOT;
ll dp[2][101][150000];
ll sigma[2][101][150000];
ll tagget_for_0 = 0;
ll tagget_for_1 = 0;
ll Compute[150000];
ll LL[150000];
ll RR[150000];
ll compute(ll x) {
if (Compute[x] != -1)
return Compute[x];
long long L = 0, R = 0;
ll l = 0, r = 1e9 + 77;
while (l + 1 < r) {
ll mid = (l + r) / 2;
if (n / mid > x)
l = mid;
else
r = mid;
}
L = r;
l = 0, r = 1e9 + 77;
while (l + 1 < r) {
ll mid = (l + r) / 2;
if (n / mid >= x)
l = mid;
else
r = mid;
}
R = l;
// cout << x << " : " << L << " " << R << endl;
LL[x] = L;
RR[x] = R;
return Compute[x] = R - L + 1;
}
ll oks(int vetka, int x) {
if (vetka == 0) {
return x <= tagget_for_0;
} else {
return x <= tagget_for_1;
}
return 0;
}
void calc(int t, int len, int x) {
if (t == 0) {
dp[t][len][x] = (sigma[0][len - 1][ROOT] + sigma[1][len - 1][x]) % MOD;
} else {
dp[t][len][x] = compute(x) * sigma[0][len - 1][x] % MOD;
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> k;
if (n == 1) {
cout << 1;
return 0;
}
while (ROOT * ROOT <= n)
ROOT++;
for (int i = 1; i <= 49999; i++)
Compute[i] = -1;
for (int i = 1; i <= 49999; i++) {
compute(i);
}
for (int i = 1; i <= 49999; i++) {
if (LL[i] * LL[i] > n) {
tagget_for_0 = RR[i + 1];
tagget_for_1 = i;
}
}
// cout << tagget_for_0 << " " << tagget_for_1 << endl;
for (int i = 1; i <= 49999; i++) {
if (oks(0, i))
dp[0][1][i] = 1;
if (oks(1, i))
dp[1][1][i] = compute(i);
if (dp[1][1][i] > MOD || dp[0][1][i] > MOD) {
cout << 100 / 0;
return 0;
}
sigma[0][1][i] = (sigma[0][1][i - 1] + dp[0][1][i]) % MOD;
// sigma[1][1][i] = (sigma[1][1][i - 1] + dp[1][1][i]) % MOD;
}
for (int x = 49999; x >= 0; x--) {
sigma[1][1][x] = (sigma[1][1][x + 1] + dp[1][1][x]) % MOD;
}
for (int i = 2; i <= k; i++) {
for (int x = 1; x <= 49999; x++) {
if (oks(0, x))
calc(0, i, x);
if (oks(1, x))
calc(1, i, x);
sigma[0][i][x] = (sigma[0][i][x - 1] + dp[0][i][x]) % MOD;
}
for (int x = 49999; x >= 0; x--) {
sigma[1][i][x] = (sigma[1][i][x + 1] + dp[1][i][x]) % MOD;
}
}
ll ans = 0;
for (int i = 1; i <= 49999; i++) {
ans += (oks(0, i) * dp[0][k][i] + oks(1, i) * dp[1][k][i]) % MOD;
ans %= MOD;
}
cout << ans % MOD;
}
| replace | 180 | 182 | 180 | 183 | -11 | |
p02992 | C++ | Runtime Error | #include <bits/stdc++.h>
// g++ -std=c++11
using namespace std;
typedef long long ll;
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 // 10^9+7
ll N, K;
ll dp[105][10000];
map<ll, ll> momove[100000];
int main() {
cin >> N >> K;
set<ll> numset;
for (ll i = 1; i * i <= N; i++) {
numset.insert(i);
numset.insert(N / i);
}
vector<ll> nums;
for (ll num : numset) {
nums.push_back(num);
}
sort(nums.begin(), nums.end());
rep(i, nums.size()) {
if (i == 0) {
dp[0][i] = 1;
} else {
dp[0][i] = (nums[i] - nums[i - 1]) % DIV;
}
}
for (ll i = 1; i < K; i++) {
rep(j, nums.size()) {
dp[i - 1][j + 1] += dp[i - 1][j];
dp[i - 1][j + 1] %= DIV;
}
rep(j, nums.size()) {
// numsのj番目は numsのいくつ以下からもらえる?
ll prev =
lower_bound(nums.begin(), nums.end(), N / nums[j]) - nums.begin();
ll add;
if (j == 0) {
add = 1;
} else {
add = nums[j] - nums[j - 1];
add %= DIV;
}
dp[i][j] += dp[i - 1][prev] * add;
dp[i][j] %= DIV;
}
}
ll ans = 0;
rep(i, nums.size()) {
ans += dp[K - 1][i];
ans %= DIV;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
// g++ -std=c++11
using namespace std;
typedef long long ll;
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define DIV 1000000007 // 10^9+7
ll N, K;
ll dp[105][500000];
int main() {
cin >> N >> K;
set<ll> numset;
for (ll i = 1; i * i <= N; i++) {
numset.insert(i);
numset.insert(N / i);
}
vector<ll> nums;
for (ll num : numset) {
nums.push_back(num);
}
sort(nums.begin(), nums.end());
rep(i, nums.size()) {
if (i == 0) {
dp[0][i] = 1;
} else {
dp[0][i] = (nums[i] - nums[i - 1]) % DIV;
}
}
for (ll i = 1; i < K; i++) {
rep(j, nums.size()) {
dp[i - 1][j + 1] += dp[i - 1][j];
dp[i - 1][j + 1] %= DIV;
}
rep(j, nums.size()) {
// numsのj番目は numsのいくつ以下からもらえる?
ll prev =
lower_bound(nums.begin(), nums.end(), N / nums[j]) - nums.begin();
ll add;
if (j == 0) {
add = 1;
} else {
add = nums[j] - nums[j - 1];
add %= DIV;
}
dp[i][j] += dp[i - 1][prev] * add;
dp[i][j] %= DIV;
}
}
ll ans = 0;
rep(i, nums.size()) {
ans += dp[K - 1][i];
ans %= DIV;
}
cout << ans << endl;
}
| replace | 10 | 12 | 10 | 11 | 0 | |
p02992 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) for (int i = 0; i < n; ++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 0
#define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif
const ll LLINF = (1LL << 60);
const int INF = (1LL << 30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_K 110
#define MAX_ROOT_N 60010
ll N, K;
ll dp[MAX_K][MAX_ROOT_N];
ll sum[MAX_K][MAX_ROOT_N];
vector<pair<ll, ll>>
pat; // N / j を求めたときに、現れるユニークな数と、その回数
// [lb, ub) の範囲で val 以下の要素で最大のもののインデックスを返す
// なければ -1 を返す
// 同じ数が複数ある場合は一番小さいインデックスを返す
static inline ll bin_search4(const vector<pair<ll, ll>> &v, ll lb, ll ub,
ll val) {
lb--;
ub--;
while (ub - lb > 1) {
ll mid = (lb + ub) / 2;
if (v[mid].first >= val) {
ub = mid;
} else {
lb = mid;
}
}
// この時点で lb + 1 = ub
if (v[ub].first <= val) {
return ub;
}
if (lb < 0 || v[lb].first > val) {
return -1;
}
return lb;
}
// i まで見ていて、現在の値が pat[j].first のときのパターン数
ll dfs(ll i, ll j) {
if (i >= K) {
return 1;
}
// assert(i >= 0 && j >= 0);
// assert(i < MAX_K);
// assert(j < MAX_ROOT_N);
ll &ret = dp[i][j];
if (~ret) {
return ret;
}
ret = 0;
j = pat[j].first;
ll next_j = N / j;
// next_j が、 pat のインデックスでいうとどこにあたるか
ll next_j_ind = bin_search4(pat, 0, pat.size(), next_j);
// [1, next_j_ind] の和が答え
// assert(next_j_ind >= 0);
assert(next_j_ind < MAX_ROOT_N);
DBG("i: %lld j: %lld next_j: %lld next_j_ind: %lld\n", i, j, next_j,
next_j_ind);
if (~sum[i][next_j_ind]) {
return sum[i][next_j_ind];
}
// ll& sum_ret = sum[i][next_j_ind];
// if(~sum_ret) { return sum_ret; }
// sum_ret = 0;
// sum でもし有効なところまで終わっているなら、そこから続きだけ計算する
for (int k = 0; k <= next_j_ind; ++k) {
sum[i][k] = (dfs(i + 1, k) * pat[k].second) % MOD;
if (k != 0) {
sum[i][k] += sum[i][k - 1];
sum[i][k] %= MOD;
}
// sum_ret += (dfs(i+1, k) * pat[k].second) % MOD;
// sum_ret %= MOD;
}
ret = sum[i][next_j_ind];
return ret;
}
ll solve() {
for (ll j = 1; j <= N; ++j) {
ll next_j = N / j;
ll cnt = (N % j) / next_j;
pat.push_back(make_pair(j, cnt + 1));
DBG("j: %lld next_j: %lld cnt: %lld\n", j, next_j, cnt + 1);
j += cnt;
}
// printf("pat.size(): %zu\n", pat.size());
DBG("---\n");
MINUS(dp);
MINUS(sum);
return dfs(0, 0);
}
signed main() {
cin >> N >> K;
ll ans = solve();
printf("%lld\n", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) for (int i = 0; i < n; ++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 0
#define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif
const ll LLINF = (1LL << 60);
const int INF = (1LL << 30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_K 110
#define MAX_ROOT_N 80010
ll N, K;
ll dp[MAX_K][MAX_ROOT_N];
ll sum[MAX_K][MAX_ROOT_N];
vector<pair<ll, ll>>
pat; // N / j を求めたときに、現れるユニークな数と、その回数
// [lb, ub) の範囲で val 以下の要素で最大のもののインデックスを返す
// なければ -1 を返す
// 同じ数が複数ある場合は一番小さいインデックスを返す
static inline ll bin_search4(const vector<pair<ll, ll>> &v, ll lb, ll ub,
ll val) {
lb--;
ub--;
while (ub - lb > 1) {
ll mid = (lb + ub) / 2;
if (v[mid].first >= val) {
ub = mid;
} else {
lb = mid;
}
}
// この時点で lb + 1 = ub
if (v[ub].first <= val) {
return ub;
}
if (lb < 0 || v[lb].first > val) {
return -1;
}
return lb;
}
// i まで見ていて、現在の値が pat[j].first のときのパターン数
ll dfs(ll i, ll j) {
if (i >= K) {
return 1;
}
// assert(i >= 0 && j >= 0);
// assert(i < MAX_K);
// assert(j < MAX_ROOT_N);
ll &ret = dp[i][j];
if (~ret) {
return ret;
}
ret = 0;
j = pat[j].first;
ll next_j = N / j;
// next_j が、 pat のインデックスでいうとどこにあたるか
ll next_j_ind = bin_search4(pat, 0, pat.size(), next_j);
// [1, next_j_ind] の和が答え
// assert(next_j_ind >= 0);
assert(next_j_ind < MAX_ROOT_N);
DBG("i: %lld j: %lld next_j: %lld next_j_ind: %lld\n", i, j, next_j,
next_j_ind);
if (~sum[i][next_j_ind]) {
return sum[i][next_j_ind];
}
// ll& sum_ret = sum[i][next_j_ind];
// if(~sum_ret) { return sum_ret; }
// sum_ret = 0;
// sum でもし有効なところまで終わっているなら、そこから続きだけ計算する
for (int k = 0; k <= next_j_ind; ++k) {
sum[i][k] = (dfs(i + 1, k) * pat[k].second) % MOD;
if (k != 0) {
sum[i][k] += sum[i][k - 1];
sum[i][k] %= MOD;
}
// sum_ret += (dfs(i+1, k) * pat[k].second) % MOD;
// sum_ret %= MOD;
}
ret = sum[i][next_j_ind];
return ret;
}
ll solve() {
for (ll j = 1; j <= N; ++j) {
ll next_j = N / j;
ll cnt = (N % j) / next_j;
pat.push_back(make_pair(j, cnt + 1));
DBG("j: %lld next_j: %lld cnt: %lld\n", j, next_j, cnt + 1);
j += cnt;
}
// printf("pat.size(): %zu\n", pat.size());
DBG("---\n");
MINUS(dp);
MINUS(sum);
return dfs(0, 0);
}
signed main() {
cin >> N >> K;
ll ans = solve();
printf("%lld\n", ans);
return 0;
}
| replace | 21 | 22 | 21 | 22 | -11 | |
p02992 | C++ | Runtime Error | #pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef unsigned long long int ull;
typedef pair<ll, ll> P;
template <class T> using V = vector<T>;
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
const ll inf = (1e18);
// const ll mod=998244353;
const ll mod = 1000000007;
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
struct __INIT {
__INIT() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
} __init;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
struct mint {
using ull = unsigned long long int;
ull v;
mint(ll vv = 0) { s(vv % mod + mod); }
mint &s(ull vv) {
v = vv < mod ? vv : vv - mod;
return *this;
}
// オーバーロード
mint operator-() const { return mint() - *this; } // 符号反転
mint &operator+=(const mint &val) { return s(v + val.v); }
mint &operator-=(const mint &val) { return s(v + mod - val.v); }
mint &operator*=(const mint &val) {
v = ull(v) * val.v % mod;
return *this;
}
mint &operator/=(const mint &val) { return *this *= val.inv(); }
mint operator+(const mint &val) { return mint(*this) += val; }
mint operator-(const mint &val) { return mint(*this) -= val; }
mint operator*(const mint &val) { return mint(*this) *= val; }
mint operator/(const mint &val) { return mint(*this) /= val; }
mint pow(ll n) const {
mint res(1), x(*this);
while (n) {
if (n & 1)
res *= x;
x *= x;
n >>= 1;
}
return res;
}
mint inv() const { return pow(mod - 2); }
// 拡張ユークリッドの互除法
/* mint inv()const{
int x,y;
int g=extgcd(v,mod,x,y);
assert(g==1);
if(x<0)x+=mod;
return mint(x);
}*/
friend ostream &operator<<(ostream &os, const mint &val) {
return os << val.v;
} // 出力
bool operator<(const mint &val) const { return v < val.v; }
bool operator==(const mint &val) const { return v == val.v; }
bool operator>(const mint &val) const { return v > val.v; }
};
const ll MAX = 2000010; // 設定
mint fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void init() {
fac[0] = fac[1] = 1;
for (int i = 1; i < MAX; i++)
fac[i] = fac[i - 1] * i;
finv[MAX - 1] = fac[MAX - 1].inv();
for (int i = MAX - 2; i >= 0; i--)
finv[i] = finv[i + 1] * (i + 1);
for (int i = MAX - 2; i >= 1; i--)
inv[i] = finv[i] + fac[i - 1];
}
// 階乗
mint factor(ll n, ll k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * finv[k];
}
// 二項係数計算
mint 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];
}
// スターリング数 O(MAX^2)
template <class T> struct strling {
V<V<T>> S;
constexpr strling(int MAX) noexcept : S(MAX, V<T>(MAX, 0)) {
S[0][0] = 1;
for (int n = 1; n < MAX; n++) {
for (int k = 1; k <= n; k++) {
S[n][k] = S[n - 1][k - 1] + S[n - 1][k] * k;
}
}
}
constexpr T get(int n, int k) {
if (n < 0 || k < 0 || n < k)
return mint(0);
else
return S[n][k];
}
};
mint dp[105][100005];
mint num[100005];
int main() {
dp[0][0] = 1;
ll n, k;
cin >> n >> k;
ll m = 0;
for (ll i = 1; i <= n;) { // nを超えない積のペア
ll d = n / i;
if (d >= i) {
num[m++] = 1;
i++;
} else {
num[m++] = n / d - i + 1;
i = n / d + 1;
}
}
for (int i = 0; i < k; i++) {
V<mint> sum(m, mint(0));
for (int j = 0; j < m; j++)
sum[j + 1] = dp[i][j] + sum[j];
for (int j = 0; j < m; j++)
dp[i + 1][j] += sum[m - j] * num[j];
}
mint ans = 0;
for (int i = 0; i < m; i++)
ans += dp[k][i];
cout << ans << "\n";
} | #pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef unsigned long long int ull;
typedef pair<ll, ll> P;
template <class T> using V = vector<T>;
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()
const ll inf = (1e18);
// const ll mod=998244353;
const ll mod = 1000000007;
// ios_base::sync_with_stdio(false);
// cin.tie(NULL);
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
struct __INIT {
__INIT() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
}
} __init;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
struct mint {
using ull = unsigned long long int;
ull v;
mint(ll vv = 0) { s(vv % mod + mod); }
mint &s(ull vv) {
v = vv < mod ? vv : vv - mod;
return *this;
}
// オーバーロード
mint operator-() const { return mint() - *this; } // 符号反転
mint &operator+=(const mint &val) { return s(v + val.v); }
mint &operator-=(const mint &val) { return s(v + mod - val.v); }
mint &operator*=(const mint &val) {
v = ull(v) * val.v % mod;
return *this;
}
mint &operator/=(const mint &val) { return *this *= val.inv(); }
mint operator+(const mint &val) { return mint(*this) += val; }
mint operator-(const mint &val) { return mint(*this) -= val; }
mint operator*(const mint &val) { return mint(*this) *= val; }
mint operator/(const mint &val) { return mint(*this) /= val; }
mint pow(ll n) const {
mint res(1), x(*this);
while (n) {
if (n & 1)
res *= x;
x *= x;
n >>= 1;
}
return res;
}
mint inv() const { return pow(mod - 2); }
// 拡張ユークリッドの互除法
/* mint inv()const{
int x,y;
int g=extgcd(v,mod,x,y);
assert(g==1);
if(x<0)x+=mod;
return mint(x);
}*/
friend ostream &operator<<(ostream &os, const mint &val) {
return os << val.v;
} // 出力
bool operator<(const mint &val) const { return v < val.v; }
bool operator==(const mint &val) const { return v == val.v; }
bool operator>(const mint &val) const { return v > val.v; }
};
const ll MAX = 2000010; // 設定
mint fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void init() {
fac[0] = fac[1] = 1;
for (int i = 1; i < MAX; i++)
fac[i] = fac[i - 1] * i;
finv[MAX - 1] = fac[MAX - 1].inv();
for (int i = MAX - 2; i >= 0; i--)
finv[i] = finv[i + 1] * (i + 1);
for (int i = MAX - 2; i >= 1; i--)
inv[i] = finv[i] + fac[i - 1];
}
// 階乗
mint factor(ll n, ll k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * finv[k];
}
// 二項係数計算
mint 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];
}
// スターリング数 O(MAX^2)
template <class T> struct strling {
V<V<T>> S;
constexpr strling(int MAX) noexcept : S(MAX, V<T>(MAX, 0)) {
S[0][0] = 1;
for (int n = 1; n < MAX; n++) {
for (int k = 1; k <= n; k++) {
S[n][k] = S[n - 1][k - 1] + S[n - 1][k] * k;
}
}
}
constexpr T get(int n, int k) {
if (n < 0 || k < 0 || n < k)
return mint(0);
else
return S[n][k];
}
};
mint dp[105][100005];
mint num[100005];
int main() {
dp[0][0] = 1;
ll n, k;
cin >> n >> k;
ll m = 0;
for (ll i = 1; i <= n;) { // nを超えない積のペア
ll d = n / i;
if (d >= i) {
num[m++] = 1;
i++;
} else {
num[m++] = n / d - i + 1;
i = n / d + 1;
}
}
for (int i = 0; i < k; i++) {
V<mint> sum(m + 1, mint(0));
for (int j = 0; j < m; j++)
sum[j + 1] = dp[i][j] + sum[j];
for (int j = 0; j < m; j++)
dp[i + 1][j] += sum[m - j] * num[j];
}
mint ans = 0;
for (int i = 0; i < m; i++)
ans += dp[k][i];
cout << ans << "\n";
} | replace | 149 | 150 | 149 | 150 | -11 | |
p02992 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define FOR(i, m, n) for (int i = int(m); i < int(n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i, a) for (auto &i : a)
typedef pair<int, int> P;
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
const int INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;
int main() {
ll n, k;
cin >> n >> k;
VVLL dp(10000, VLL(40000, 0));
int h = 1;
VLL v;
for (; h * h <= n; h++) {
v.push_back(h);
v.push_back(n / h);
}
v.push_back(0);
sort(ALL(v));
dp[0][0] = 1;
REP(i, k + 1) {
REP(j, v.size()) {
dp[i][j + 1] += dp[i][j];
dp[i][j + 1] %= mod;
}
REP(j, v.size() - 1) {
dp[i + 1][j] = dp[i][v.size() - 2 - j] * (v[j + 1] - v[j]) % mod;
}
}
ll ans = 0;
cout << dp[k][v.size()] << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define FOR(i, m, n) for (int i = int(m); i < int(n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i, a) for (auto &i : a)
typedef pair<int, int> P;
template <class T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
const int INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;
int main() {
ll n, k;
cin >> n >> k;
VVLL dp(105, VLL(400000, 0));
int h = 1;
VLL v;
for (; h * h <= n; h++) {
v.push_back(h);
v.push_back(n / h);
}
v.push_back(0);
sort(ALL(v));
dp[0][0] = 1;
REP(i, k + 1) {
REP(j, v.size()) {
dp[i][j + 1] += dp[i][j];
dp[i][j + 1] %= mod;
}
REP(j, v.size() - 1) {
dp[i + 1][j] = dp[i][v.size() - 2 - j] * (v[j + 1] - v[j]) % mod;
}
}
ll ans = 0;
cout << dp[k][v.size()] << endl;
} | replace | 41 | 42 | 41 | 42 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p02992 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountl
#define m_p make_pair
#define inf 200000000000000
#define MAXN 1000001
#define eps 0.0000000001
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
string char_to_str(char c) {
string tem(1, c);
return tem;
}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
#define S second
#define F first
#define int long long
/////////////
signed main() {
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in", "r", stdin);
freopen("outputf.in", "w", stdout);
#endif
int n, k;
cin >> n >> k;
int r[50000][2];
int x = 0;
int la;
vector<int> v;
for (int i = 1; i * i <= n; ++i) {
r[x][0] = i;
r[x][1] = i;
++x;
la = i;
v.push_back(1);
}
// cout<<"!"<<endl;;
++la;
while (la <= n) {
r[x][0] = la;
int va = n / la;
if (va == 1) {
r[x][1] = n;
la = n + 1;
} else {
r[x][1] = n / (va);
la = n / (va) + 1;
}
v.push_back(1);
++x;
}
int mo = 1000000007;
for (int i = 0; i < x; ++i) {
// cout<<r[i][0]<<" "<<r[i][1]<<"\n";
}
for (int i = 2; i <= k; ++i) {
for (int j = 1; j < v.size(); ++j) {
v[j] = (v[j] * (r[j][1] - r[j][0] + 1)) % mo + v[j - 1];
v[j] %= mo;
}
reverse(v.begin(), v.end());
}
int ans = 0;
for (int i = 0; i < x; ++i) {
ans += (v[i] * (r[i][1] - r[i][0] + 1)) % mo;
ans %= mo;
// cout<<r[i]
// cout<<ans<<"\n";
// ans%=mo;
}
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountl
#define m_p make_pair
#define inf 200000000000000
#define MAXN 1000001
#define eps 0.0000000001
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
string char_to_str(char c) {
string tem(1, c);
return tem;
}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
#define S second
#define F first
#define int long long
/////////////
signed main() {
fastio;
#ifdef ANIKET_GOYAL
freopen("inputf.in", "r", stdin);
freopen("outputf.in", "w", stdout);
#endif
int n, k;
cin >> n >> k;
int r[500000][2];
int x = 0;
int la;
vector<int> v;
for (int i = 1; i * i <= n; ++i) {
r[x][0] = i;
r[x][1] = i;
++x;
la = i;
v.push_back(1);
}
// cout<<"!"<<endl;;
++la;
while (la <= n) {
r[x][0] = la;
int va = n / la;
if (va == 1) {
r[x][1] = n;
la = n + 1;
} else {
r[x][1] = n / (va);
la = n / (va) + 1;
}
v.push_back(1);
++x;
}
int mo = 1000000007;
for (int i = 0; i < x; ++i) {
// cout<<r[i][0]<<" "<<r[i][1]<<"\n";
}
for (int i = 2; i <= k; ++i) {
for (int j = 1; j < v.size(); ++j) {
v[j] = (v[j] * (r[j][1] - r[j][0] + 1)) % mo + v[j - 1];
v[j] %= mo;
}
reverse(v.begin(), v.end());
}
int ans = 0;
for (int i = 0; i < x; ++i) {
ans += (v[i] * (r[i][1] - r[i][0] + 1)) % mo;
ans %= mo;
// cout<<r[i]
// cout<<ans<<"\n";
// ans%=mo;
}
cout << ans;
} | replace | 38 | 39 | 38 | 39 | 0 | |
p02992 | C++ | Runtime Error | #include <cmath>
#include <iostream>
#define DIM 40000
#define mod 1000000007
using namespace std;
int n, k, i, j, r, nr, st, dr, mid;
int v[DIM], u[DIM], s[105][DIM];
int main() {
cin >> n >> k;
r = sqrt(n * 1.0);
for (i = 1; i <= r + r; i++) {
if (n / i <= r) {
break;
}
v[++nr] = i;
}
for (i = r; i >= 1; i--) {
v[++nr] = n / i;
}
for (i = 1; i <= nr; i++) {
st = 1;
dr = nr;
while (st <= dr) {
mid = (st + dr) / 2;
if (n / v[i] >= v[mid]) {
st = mid + 1;
} else {
dr = mid - 1;
}
}
u[i] = dr;
s[1][i] = s[1][i - 1] + v[i] - v[i - 1];
}
for (i = 2; i <= k; i++) {
for (j = 1; j <= nr; j++) {
s[i][j] = (s[i][j - 1] + s[i - 1][u[j]] * 1LL * (v[j] - v[j - 1])) % mod;
}
}
cout << s[k][nr];
}
| #include <cmath>
#include <iostream>
#define DIM 70000
#define mod 1000000007
using namespace std;
int n, k, i, j, r, nr, st, dr, mid;
int v[DIM], u[DIM], s[105][DIM];
int main() {
cin >> n >> k;
r = sqrt(n * 1.0);
for (i = 1; i <= r + r; i++) {
if (n / i <= r) {
break;
}
v[++nr] = i;
}
for (i = r; i >= 1; i--) {
v[++nr] = n / i;
}
for (i = 1; i <= nr; i++) {
st = 1;
dr = nr;
while (st <= dr) {
mid = (st + dr) / 2;
if (n / v[i] >= v[mid]) {
st = mid + 1;
} else {
dr = mid - 1;
}
}
u[i] = dr;
s[1][i] = s[1][i - 1] + v[i] - v[i - 1];
}
for (i = 2; i <= k; i++) {
for (j = 1; j <= nr; j++) {
s[i][j] = (s[i][j - 1] + s[i - 1][u[j]] * 1LL * (v[j] - v[j - 1])) % mod;
}
}
cout << s[k][nr];
}
| replace | 2 | 3 | 2 | 3 | 0 | |
p02992 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;
#define SORT(c) sort((c).begin(), (c).end())
#define BACKSORT(c) sort((c).begin(), (c).end(), std::greater<LL>())
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SP << " " <<
LL mod = 1000000007;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
LL N, K;
cin >> N >> K;
LL M = 0;
REP(i, N) {
if (i * i > N) {
M = i - 1;
break;
}
}
vector<LL> nums(200000, 1);
REP(i, M) { nums[2 * M - 1 - i] = N / (i + 1) - N / (i + 2); }
nums[M] = N / M - M;
vector<LL> dp(200000, 0);
REP(i, 2 * M) { dp[i] = nums[i]; }
REP(i, K - 1) {
vector<LL> newdp(200000, 0);
LL sum = 0;
REP(j, 2 * M) {
sum += dp[j];
sum %= mod;
newdp[2 * M - 1 - j] = (nums[2 * M - 1 - j] * sum) % mod;
}
REP(j, 2 * M) { dp[j] = newdp[j]; }
}
LL ans = 0;
REP(i, 2 * M) {
ans += dp[i];
ans %= mod;
}
cout << ans << endl;
}
// 1 -> 1~9
// 2 -> 1~4
// 3 -> 1~3
// ? -> 1~3
// 4~4 -> 1~2
// 5~9 -> 1
// 1 -> 1~11
// 2 -> 1~5
// 3 -> 1~3
// 4~5 -> 1~2
// 6~11 -> 1
// 1 -> 1~12
// 2 -> 1~6
// 3 -> 1~4
// 4 -> 1~3
// 5~6 -> 1~2
// 7~12 -> 1
| #include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;
#define SORT(c) sort((c).begin(), (c).end())
#define BACKSORT(c) sort((c).begin(), (c).end(), std::greater<LL>())
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SP << " " <<
LL mod = 1000000007;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
LL N, K;
cin >> N >> K;
LL M = 0;
REP(i, 200000) {
if (i * i > N) {
M = i - 1;
break;
}
}
vector<LL> nums(200000, 1);
REP(i, M) { nums[2 * M - 1 - i] = N / (i + 1) - N / (i + 2); }
nums[M] = N / M - M;
vector<LL> dp(200000, 0);
REP(i, 2 * M) { dp[i] = nums[i]; }
REP(i, K - 1) {
vector<LL> newdp(200000, 0);
LL sum = 0;
REP(j, 2 * M) {
sum += dp[j];
sum %= mod;
newdp[2 * M - 1 - j] = (nums[2 * M - 1 - j] * sum) % mod;
}
REP(j, 2 * M) { dp[j] = newdp[j]; }
}
LL ans = 0;
REP(i, 2 * M) {
ans += dp[i];
ans %= mod;
}
cout << ans << endl;
}
// 1 -> 1~9
// 2 -> 1~4
// 3 -> 1~3
// ? -> 1~3
// 4~4 -> 1~2
// 5~9 -> 1
// 1 -> 1~11
// 2 -> 1~5
// 3 -> 1~3
// 4~5 -> 1~2
// 6~11 -> 1
// 1 -> 1~12
// 2 -> 1~6
// 3 -> 1~4
// 4 -> 1~3
// 5~6 -> 1~2
// 7~12 -> 1
| replace | 24 | 25 | 24 | 25 | 0 | |
p02992 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, x, y) for (int i = x; i < y; i++)
#define print(A, x, n) \
rep(i, 0, n) { cout << (i ? " " : "") << A[i] x; } \
cout << endl;
#define pprint(A, y, m, n) \
rep(j, 0, m) { print(A[j], y, n); }
const long mod = 1e9 + 7;
const int size = 1e5;
const int inf = 1e9;
int main() {
int N, K;
cin >> N >> K;
int m = sqrt(N) + 1;
long dp[K + 1][m + 1][2];
rep(i, 1, m + 1) {
dp[0][i][0] = 1;
dp[0][i][1] = 1;
}
rep(i, 1, K + 1) {
long res = 0;
for (int j = 1; j <= m; j++) {
(res += dp[i - 1][j][0]) %= mod;
if (j == N / (N / j))
dp[i][j][1] = res;
}
if (m <= N / (m - 1))
dp[i][m][0] = dp[i][m - 1][1];
else
dp[i][m][0] = dp[i][m - 2][1];
for (int j = m - 1; j > 0; j--) {
if (j == N / (N / j)) {
dp[i][j][0] = ((N / j - N / (j + 1)) * dp[i - 1][j][1]) % mod;
(dp[i][j][0] += dp[i][j + 1][0]) %= mod;
} else
dp[i][j][0] = dp[i][j + 1][0];
}
}
cout << dp[K][1][0] << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, x, y) for (int i = x; i < y; i++)
#define print(A, x, n) \
rep(i, 0, n) { cout << (i ? " " : "") << A[i] x; } \
cout << endl;
#define pprint(A, y, m, n) \
rep(j, 0, m) { print(A[j], y, n); }
const long mod = 1e9 + 7;
const int size = 1e5;
const int inf = 1e9;
int main() {
int N, K;
cin >> N >> K;
if (N == 1) {
cout << 1 << endl;
return 0;
}
int m = sqrt(N) + 1;
long dp[K + 1][m + 1][2];
rep(i, 1, m + 1) {
dp[0][i][0] = 1;
dp[0][i][1] = 1;
}
rep(i, 1, K + 1) {
long res = 0;
for (int j = 1; j <= m; j++) {
(res += dp[i - 1][j][0]) %= mod;
if (j == N / (N / j))
dp[i][j][1] = res;
}
if (m <= N / (m - 1))
dp[i][m][0] = dp[i][m - 1][1];
else
dp[i][m][0] = dp[i][m - 2][1];
for (int j = m - 1; j > 0; j--) {
if (j == N / (N / j)) {
dp[i][j][0] = ((N / j - N / (j + 1)) * dp[i - 1][j][1]) % mod;
(dp[i][j][0] += dp[i][j + 1][0]) %= mod;
} else
dp[i][j][0] = dp[i][j + 1][0];
}
}
cout << dp[K][1][0] << endl;
} | insert | 14 | 14 | 14 | 18 | 0 | |
p02992 | C++ | Runtime Error | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
for (auto &e : t)
fill_v(e, v);
}
const int MAX_N = 1e6 + 1;
vector<long long> factorialMemo(MAX_N, -1); // factorialMemo[i] := i! mod p
vector<long long> inverseFactorialMemo(
MAX_N, -1); // inverseFactorialMemo[i] := (factorialMemo[i])^(-1)
bool initFinished = false;
template <long long mod> struct ModInt {
long long x;
ModInt() : x(0) {}
ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
ModInt &operator+=(const ModInt &p) {
if ((x += p.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator-=(const ModInt &p) {
if ((x += mod - p.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator*=(const ModInt &p) {
x = (1LL * x * p.x % mod);
return *this;
}
ModInt &operator/=(const ModInt &p) {
*this *= p.inverse();
return *this;
}
ModInt operator-() const { return ModInt(-x); }
ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
bool operator==(const ModInt &p) const { return x == p.x; }
bool operator!=(const ModInt &p) const { return x != p.x; }
ModInt inverse() const {
long long a = x, b = mod, u = 1, v = 0, t;
while (b > 0) {
t = a / b;
swap(a -= t * b, b);
swap(u -= t * v, v);
}
return ModInt(u);
}
ModInt pow(int64_t n) const {
ModInt ret(1), mul(x);
while (n > 0) {
if (n & 1)
ret *= mul;
mul *= mul;
n >>= 1;
}
return ret;
}
friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
friend istream &operator>>(istream &is, ModInt &a) {
int64_t t;
is >> t;
a = ModInt<mod>(t);
return (is);
}
static long long get_mod() { return mod; }
static void factorialInit() {
factorialMemo[0] = 1;
for (ll i = 0; i < MAX_N - 1; i++) {
factorialMemo[i + 1] = ModInt<mod>(factorialMemo[i] * (i + 1)).x;
}
initFinished = true;
}
static ModInt factorial(ll n) {
if (!initFinished) {
factorialInit();
}
return factorialMemo[n];
}
static ModInt Combination(ll n, ll k) {
if (n < k)
return 0;
return factorial(n) / (factorial(n - k) * factorial(k));
}
};
using mint = ModInt<(int)1e9 + 7>;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N, K;
cin >> N >> K;
set<int> s;
for (size_t i = 1; i * i < N; i++) {
s.insert(i);
s.insert(N / i);
}
vint ktov;
map<int, int> vtok;
for (auto &&i : s) {
ktov.push_back(i);
}
for (size_t i = 0; i < ktov.size(); i++) {
vtok[ktov[i]] = i;
}
auto DP = make_v<mint>(K + 1, ktov.size());
map<int, mint> c;
for (auto &&i : ktov) {
c[i] = mint(N / i - N / (i + 1));
}
vector<mint> acc(ktov.size() + 1), tmp = acc;
DP[0][vtok[N]] = 1;
partial_sum(all(DP[0]), ++acc.begin());
for (int i = 0; i < K; i++) {
for (auto &&p : tmp) {
p = 0;
}
for (int j = 0; j < ktov.size(); j++) {
DP[i + 1][j] = c[ktov[j]] * (acc.back() - acc[vtok[N / ktov[j]]]);
tmp[j + 1] = tmp[j] + DP[i + 1][j];
}
acc = tmp;
}
mint ans = 0;
for (auto &&i : DP.back()) {
ans += i;
}
cout << ans;
return 0;
} | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
for (auto &e : t)
fill_v(e, v);
}
const int MAX_N = 1e6 + 1;
vector<long long> factorialMemo(MAX_N, -1); // factorialMemo[i] := i! mod p
vector<long long> inverseFactorialMemo(
MAX_N, -1); // inverseFactorialMemo[i] := (factorialMemo[i])^(-1)
bool initFinished = false;
template <long long mod> struct ModInt {
long long x;
ModInt() : x(0) {}
ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
ModInt &operator+=(const ModInt &p) {
if ((x += p.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator-=(const ModInt &p) {
if ((x += mod - p.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator*=(const ModInt &p) {
x = (1LL * x * p.x % mod);
return *this;
}
ModInt &operator/=(const ModInt &p) {
*this *= p.inverse();
return *this;
}
ModInt operator-() const { return ModInt(-x); }
ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
bool operator==(const ModInt &p) const { return x == p.x; }
bool operator!=(const ModInt &p) const { return x != p.x; }
ModInt inverse() const {
long long a = x, b = mod, u = 1, v = 0, t;
while (b > 0) {
t = a / b;
swap(a -= t * b, b);
swap(u -= t * v, v);
}
return ModInt(u);
}
ModInt pow(int64_t n) const {
ModInt ret(1), mul(x);
while (n > 0) {
if (n & 1)
ret *= mul;
mul *= mul;
n >>= 1;
}
return ret;
}
friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
friend istream &operator>>(istream &is, ModInt &a) {
int64_t t;
is >> t;
a = ModInt<mod>(t);
return (is);
}
static long long get_mod() { return mod; }
static void factorialInit() {
factorialMemo[0] = 1;
for (ll i = 0; i < MAX_N - 1; i++) {
factorialMemo[i + 1] = ModInt<mod>(factorialMemo[i] * (i + 1)).x;
}
initFinished = true;
}
static ModInt factorial(ll n) {
if (!initFinished) {
factorialInit();
}
return factorialMemo[n];
}
static ModInt Combination(ll n, ll k) {
if (n < k)
return 0;
return factorial(n) / (factorial(n - k) * factorial(k));
}
};
using mint = ModInt<(int)1e9 + 7>;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int N, K;
cin >> N >> K;
set<int> s;
for (size_t i = 1; i * i <= N; i++) {
s.insert(i);
s.insert(N / i);
}
vint ktov;
map<int, int> vtok;
for (auto &&i : s) {
ktov.push_back(i);
}
for (size_t i = 0; i < ktov.size(); i++) {
vtok[ktov[i]] = i;
}
auto DP = make_v<mint>(K + 1, ktov.size());
map<int, mint> c;
for (auto &&i : ktov) {
c[i] = mint(N / i - N / (i + 1));
}
vector<mint> acc(ktov.size() + 1), tmp = acc;
DP[0][vtok[N]] = 1;
partial_sum(all(DP[0]), ++acc.begin());
for (int i = 0; i < K; i++) {
for (auto &&p : tmp) {
p = 0;
}
for (int j = 0; j < ktov.size(); j++) {
DP[i + 1][j] = c[ktov[j]] * (acc.back() - acc[vtok[N / ktov[j]]]);
tmp[j + 1] = tmp[j] + DP[i + 1][j];
}
acc = tmp;
}
mint ans = 0;
for (auto &&i : DP.back()) {
ans += i;
}
cout << ans;
return 0;
} | replace | 147 | 148 | 147 | 148 | 0 | |
p02992 | C++ | Runtime Error | //
// main.cpp
//
// https://atcoder.jp/contests/abc133/tasks/abc132_f
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
struct Mod {
static ll BASE;
ll value = 0;
static ll residue(ll value) { return (value % BASE + BASE) % BASE; }
Mod(ll value) : value(residue(value)) {}
Mod operator+(const Mod &rhs) { return Mod(value + rhs.value); }
Mod operator-(const Mod &rhs) { return Mod(value - rhs.value); }
Mod operator*(const Mod &rhs) { return Mod(value * rhs.value); }
void operator*=(const Mod &rhs) { *this = *this * rhs; }
};
ll Mod::BASE = 1000000007;
int main(int argc, char *argv[]) {
int N;
int K;
cin >> N >> K;
// floors = { floor(N/n) | 1 <= n <= N } を昇順にソートしたもの
// (O(sqrt(N))で求める方針に修正予定)
set<int> floors_set;
for (int n = 1; n * (n + 1) <= N; n++) {
floors_set.insert(N / n);
}
for (int n = *floors_set.begin(); n >= 1; n--) {
floors_set.insert(n);
}
vector<int> floors;
for (int n : floors_set) {
floors.push_back(n);
}
unordered_map<int, int> inv_floors;
for (int i = 0; i < floors.size(); i++) {
inv_floors[floors[i]] = i;
}
// dp_a[k][i] = 長さkの列で末尾の数が(floors[f-1],
// floors[f]]の範囲にはいるものの個数
vector<vector<Mod>> dp_a;
vector<Mod> dp_a_init;
dp_a_init.resize(floors.size(), Mod(0));
dp_a.resize(K + 1, dp_a_init);
// dp_b[k][i] = 長さkの列で末尾の数が(0, floors[f]]の範囲にはいるものの個数
vector<vector<Mod>> dp_b;
vector<Mod> dp_b_init;
dp_b_init.resize(floors.size(), Mod(0));
dp_b.resize(K + 1, dp_b_init);
for (int i = 0; i < floors.size(); i++) {
dp_b[0][i] = Mod(1);
}
for (int k = 1; k <= K; k++) {
for (int f_idx = 0; f_idx < floors.size(); f_idx++) {
Mod range(1);
if (f_idx > 1) {
range = Mod(floors[f_idx]) - Mod(floors[f_idx - 1]);
}
int f = floors[f_idx];
dp_a[k][f_idx] = range * dp_b[k - 1][inv_floors[N / f]];
if (f_idx == 0) {
dp_b[k][f_idx] = dp_b[k - 1][floors.size() - 1];
} else {
dp_b[k][f_idx] = dp_b[k][f_idx - 1] + dp_a[k][f_idx];
}
}
}
cout << dp_b[K][floors.size() - 1].value << endl;
return 0;
}
| //
// main.cpp
//
// https://atcoder.jp/contests/abc133/tasks/abc132_f
#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
struct Mod {
static ll BASE;
ll value = 0;
static ll residue(ll value) { return (value % BASE + BASE) % BASE; }
Mod(ll value) : value(residue(value)) {}
Mod operator+(const Mod &rhs) { return Mod(value + rhs.value); }
Mod operator-(const Mod &rhs) { return Mod(value - rhs.value); }
Mod operator*(const Mod &rhs) { return Mod(value * rhs.value); }
void operator*=(const Mod &rhs) { *this = *this * rhs; }
};
ll Mod::BASE = 1000000007;
int main(int argc, char *argv[]) {
int N;
int K;
cin >> N >> K;
// floors = { floor(N/n) | 1 <= n <= N } を昇順にソートしたもの
// (O(sqrt(N))で求める方針に修正予定)
set<int> floors_set;
if (N >= 2) {
for (int n = 1; n * (n + 1) <= N; n++) {
floors_set.insert(N / n);
}
for (int n = *floors_set.begin(); n >= 1; n--) {
floors_set.insert(n);
}
} else {
floors_set.insert(1);
}
vector<int> floors;
for (int n : floors_set) {
floors.push_back(n);
}
unordered_map<int, int> inv_floors;
for (int i = 0; i < floors.size(); i++) {
inv_floors[floors[i]] = i;
}
// dp_a[k][i] = 長さkの列で末尾の数が(floors[f-1],
// floors[f]]の範囲にはいるものの個数
vector<vector<Mod>> dp_a;
vector<Mod> dp_a_init;
dp_a_init.resize(floors.size(), Mod(0));
dp_a.resize(K + 1, dp_a_init);
// dp_b[k][i] = 長さkの列で末尾の数が(0, floors[f]]の範囲にはいるものの個数
vector<vector<Mod>> dp_b;
vector<Mod> dp_b_init;
dp_b_init.resize(floors.size(), Mod(0));
dp_b.resize(K + 1, dp_b_init);
for (int i = 0; i < floors.size(); i++) {
dp_b[0][i] = Mod(1);
}
for (int k = 1; k <= K; k++) {
for (int f_idx = 0; f_idx < floors.size(); f_idx++) {
Mod range(1);
if (f_idx > 1) {
range = Mod(floors[f_idx]) - Mod(floors[f_idx - 1]);
}
int f = floors[f_idx];
dp_a[k][f_idx] = range * dp_b[k - 1][inv_floors[N / f]];
if (f_idx == 0) {
dp_b[k][f_idx] = dp_b[k - 1][floors.size() - 1];
} else {
dp_b[k][f_idx] = dp_b[k][f_idx - 1] + dp_a[k][f_idx];
}
}
}
cout << dp_b[K][floors.size() - 1].value << endl;
return 0;
}
| replace | 50 | 55 | 50 | 59 | 0 | |
p02992 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (i = 0; i < n; i++)
#define int long long
using namespace std;
int mod = 1000000007;
int n, k;
vector<int> gL;
vector<int> gR;
vector<int> dp[101];
signed main() {
int i, j;
cin >> n >> k;
for (i = 1; i < n;) {
int st = i, ed = n + 1, mid; // oooxxx, [st, ed)
while (ed - st >= 2) {
mid = (st + ed) / 2;
if (n / i == n / mid)
st = mid;
else
ed = mid;
}
// i ≦ m ≦ stなる整数mについて、[n / m]は同じ値を取る
gL.push_back(i);
gR.push_back(st);
i = st + 1;
}
int sz = gL.size();
rep(i, k + 1) {
dp[i].resize(sz);
rep(j, sz) dp[i][j] = 0;
}
dp[0][0] = 1;
rep(i, k) {
int ssum = 0;
rep(j, sz) {
ssum += dp[i][j];
ssum %= mod;
int rj = sz - 1 - j;
dp[i + 1][rj] += ssum * (gR[rj] - gL[rj] + 1) % mod;
dp[i + 1][rj] %= mod;
}
}
int ans = 0;
rep(j, sz) {
ans += dp[k][j];
ans %= mod;
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (i = 0; i < n; i++)
#define int long long
using namespace std;
int mod = 1000000007;
int n, k;
vector<int> gL;
vector<int> gR;
vector<int> dp[101];
signed main() {
int i, j;
cin >> n >> k;
for (i = 1; i <= n;) {
int st = i, ed = n + 1, mid; // oooxxx, [st, ed)
while (ed - st >= 2) {
mid = (st + ed) / 2;
if (n / i == n / mid)
st = mid;
else
ed = mid;
}
// i ≦ m ≦ stなる整数mについて、[n / m]は同じ値を取る
gL.push_back(i);
gR.push_back(st);
i = st + 1;
}
int sz = gL.size();
rep(i, k + 1) {
dp[i].resize(sz);
rep(j, sz) dp[i][j] = 0;
}
dp[0][0] = 1;
rep(i, k) {
int ssum = 0;
rep(j, sz) {
ssum += dp[i][j];
ssum %= mod;
int rj = sz - 1 - j;
dp[i + 1][rj] += ssum * (gR[rj] - gL[rj] + 1) % mod;
dp[i + 1][rj] %= mod;
}
}
int ans = 0;
rep(j, sz) {
ans += dp[k][j];
ans %= mod;
}
cout << ans << endl;
return 0;
} | replace | 26 | 27 | 26 | 27 | 0 | |
p02992 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
namespace mint {
int md = 1e9 + 7;
inline void add(int &a, int b) {
assert(0 <= a && a < md && 0 <= b && b < md);
a += b;
if (a >= md)
a -= md;
}
inline void sub(int &a, int b) {
assert(0 <= a && a < md && 0 <= b && b < md);
a -= b;
if (a < 0)
a += md;
}
inline int sum(int a, int b) {
assert(0 <= a && a < md && 0 <= b && b < md);
add(a, b);
return a;
}
inline int dif(int a, int b) {
assert(0 <= a && a < md && 0 <= b && b < md);
sub(a, b);
return a;
}
template <class... A> inline int prod(A... args) {
long long ret = 1;
for (int a : initializer_list<int>{args...}) {
assert(0 <= a && a < md);
ret *= a;
ret %= md;
}
return (int)(ret % md);
}
inline void mul(int &a, int b) {
assert(0 <= a && a < md && 0 <= b && b < md);
a = prod(a, b);
}
inline int inv(int a) {
assert(0 <= a && a < md);
a %= md;
if (a < 0)
a += md;
int b = md, u = 0, v = 1;
while (a) {
int t = b / a;
b -= a * t;
swap(a, b);
u -= v * t;
swap(u, v);
}
assert(b == 1);
if (u < 0)
u += md;
return u;
}
inline int quot(int a, int b) {
assert(0 <= a && a < md && 0 <= b && b < md);
return prod(a, inv(b));
}
inline void div(int &a, int b) {
assert(0 <= a && a < md && 0 <= b && b < md);
a = quot(a, b);
}
inline int pow(int a, long long b) {
assert(0 <= a && a < md);
int res = 1;
for (; b; b >>= 1) {
if (b & 1)
mul(res, a);
mul(a, a);
}
return res;
}
namespace factorials {
int sz;
vector<int> fact, finv;
void init(int n) {
sz = n;
fact.resize(n);
finv.resize(n);
fact[0] = 1;
for (int i = 1; i < n; i++)
fact[i] = prod(fact[i - 1], i);
finv[n - 1] = inv(fact[n - 1]);
for (int i = n - 2; i >= 0; i--)
finv[i] = prod(finv[i + 1], i + 1);
}
} // namespace factorials
inline int fct(int i) {
using namespace factorials;
assert(0 <= i && i < sz);
return fact[i];
}
inline int fnv(int i) {
using namespace factorials;
assert(0 <= i && i < sz);
return finv[i];
}
inline int binom(int n, int k) {
using namespace factorials;
assert(0 <= n && n < sz);
if (0 < k || n < k)
return 0;
return prod(fact[n], finv[k], finv[n - k]);
}
} // namespace mint
int main() {
std::cin.tie(0);
std::cin.sync_with_stdio(false);
int n, k;
std::cin >> n >> k;
int sqrt = [n] {
auto ck = [&](int x) { return x * x <= n; };
int ok = 0, ng = n + 1, md;
while (abs(ok - ng) > 1) {
md = (ok + ng) >> 1;
if (ck(md))
ok = md;
else
ng = md;
}
return ok;
}();
std::vector<int> a = [n, sqrt] {
std::vector<int> b(sqrt);
std::iota(b.begin(), b.end(), 1);
auto c = b;
std::for_each(c.begin(), c.end(), [n](int &x) { x = n / x; });
std::reverse(c.begin(), c.end());
if (b.back() == c.front())
c.erase(c.begin());
b.insert(b.end(), c.begin(), c.end());
return b;
}();
int N = a.size();
assert(N == sqrt * 2 || N == sqrt * 2 - 1);
assert(a[0] == 1);
assert(a[N - 1] == n);
auto w = a;
for (int i = N - 1; i >= 1; i--) {
w[i] -= w[i - 1];
}
auto lb = [&](int x) {
if (x <= sqrt)
return x - 1;
else
return N - (n / x);
};
std::vector<int> dp(N, 1);
auto make_cum = [&](const std::vector<int> &x) {
assert(((int)x.size() == N));
std::vector<int> y(N + 1, 0);
for (int i = 1; i <= N; i++) {
y[i] = mint::sum(y[i - 1], mint::prod(x[i - 1], w[i - 1]));
}
return y;
};
auto cum = make_cum(dp);
auto sum = [&](int x) {
assert(1 <= x && x <= n);
int i = lb(x);
assert(0 <= i && i < N);
assert(x <= a[i] && (i == 0 || a[i - 1] < x));
int ret = cum[i + 1];
mint::dif(ret, mint::prod(dp[i], a[i] - x));
return ret;
};
auto renew = [&] {
std::vector<int> new_dp(N);
for (int i = 0; i < N; i++) {
new_dp[i] = sum(n / a[i]);
}
dp = new_dp;
cum = make_cum(dp);
};
for (int i = 0; i < k - 1; i++)
renew();
std::cout << sum(n) << std::endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
namespace mint {
int md = 1e9 + 7;
inline void add(int &a, int b) {
assert(0 <= a && a < md && 0 <= b && b < md);
a += b;
if (a >= md)
a -= md;
}
inline void sub(int &a, int b) {
assert(0 <= a && a < md && 0 <= b && b < md);
a -= b;
if (a < 0)
a += md;
}
inline int sum(int a, int b) {
assert(0 <= a && a < md && 0 <= b && b < md);
add(a, b);
return a;
}
inline int dif(int a, int b) {
assert(0 <= a && a < md && 0 <= b && b < md);
sub(a, b);
return a;
}
template <class... A> inline int prod(A... args) {
long long ret = 1;
for (int a : initializer_list<int>{args...}) {
assert(0 <= a && a < md);
ret *= a;
ret %= md;
}
return (int)(ret % md);
}
inline void mul(int &a, int b) {
assert(0 <= a && a < md && 0 <= b && b < md);
a = prod(a, b);
}
inline int inv(int a) {
assert(0 <= a && a < md);
a %= md;
if (a < 0)
a += md;
int b = md, u = 0, v = 1;
while (a) {
int t = b / a;
b -= a * t;
swap(a, b);
u -= v * t;
swap(u, v);
}
assert(b == 1);
if (u < 0)
u += md;
return u;
}
inline int quot(int a, int b) {
assert(0 <= a && a < md && 0 <= b && b < md);
return prod(a, inv(b));
}
inline void div(int &a, int b) {
assert(0 <= a && a < md && 0 <= b && b < md);
a = quot(a, b);
}
inline int pow(int a, long long b) {
assert(0 <= a && a < md);
int res = 1;
for (; b; b >>= 1) {
if (b & 1)
mul(res, a);
mul(a, a);
}
return res;
}
namespace factorials {
int sz;
vector<int> fact, finv;
void init(int n) {
sz = n;
fact.resize(n);
finv.resize(n);
fact[0] = 1;
for (int i = 1; i < n; i++)
fact[i] = prod(fact[i - 1], i);
finv[n - 1] = inv(fact[n - 1]);
for (int i = n - 2; i >= 0; i--)
finv[i] = prod(finv[i + 1], i + 1);
}
} // namespace factorials
inline int fct(int i) {
using namespace factorials;
assert(0 <= i && i < sz);
return fact[i];
}
inline int fnv(int i) {
using namespace factorials;
assert(0 <= i && i < sz);
return finv[i];
}
inline int binom(int n, int k) {
using namespace factorials;
assert(0 <= n && n < sz);
if (0 < k || n < k)
return 0;
return prod(fact[n], finv[k], finv[n - k]);
}
} // namespace mint
int main() {
std::cin.tie(0);
std::cin.sync_with_stdio(false);
int n, k;
std::cin >> n >> k;
int sqrt = [n] {
auto ck = [&](long long x) { return x * x <= n; };
int ok = 0, ng = n + 1, md;
while (abs(ok - ng) > 1) {
md = (ok + ng) >> 1;
if (ck(md))
ok = md;
else
ng = md;
}
return ok;
}();
std::vector<int> a = [n, sqrt] {
std::vector<int> b(sqrt);
std::iota(b.begin(), b.end(), 1);
auto c = b;
std::for_each(c.begin(), c.end(), [n](int &x) { x = n / x; });
std::reverse(c.begin(), c.end());
if (b.back() == c.front())
c.erase(c.begin());
b.insert(b.end(), c.begin(), c.end());
return b;
}();
int N = a.size();
assert(N == sqrt * 2 || N == sqrt * 2 - 1);
assert(a[0] == 1);
assert(a[N - 1] == n);
auto w = a;
for (int i = N - 1; i >= 1; i--) {
w[i] -= w[i - 1];
}
auto lb = [&](int x) {
if (x <= sqrt)
return x - 1;
else
return N - (n / x);
};
std::vector<int> dp(N, 1);
auto make_cum = [&](const std::vector<int> &x) {
assert(((int)x.size() == N));
std::vector<int> y(N + 1, 0);
for (int i = 1; i <= N; i++) {
y[i] = mint::sum(y[i - 1], mint::prod(x[i - 1], w[i - 1]));
}
return y;
};
auto cum = make_cum(dp);
auto sum = [&](int x) {
assert(1 <= x && x <= n);
int i = lb(x);
assert(0 <= i && i < N);
assert(x <= a[i] && (i == 0 || a[i - 1] < x));
int ret = cum[i + 1];
mint::dif(ret, mint::prod(dp[i], a[i] - x));
return ret;
};
auto renew = [&] {
std::vector<int> new_dp(N);
for (int i = 0; i < N; i++) {
new_dp[i] = sum(n / a[i]);
}
dp = new_dp;
cum = make_cum(dp);
};
for (int i = 0; i < k - 1; i++)
renew();
std::cout << sum(n) << std::endl;
return 0;
}
| replace | 114 | 115 | 114 | 115 | 0 | |
p02992 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define repn(i, n) for (int(i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for (int(i) = (n - 1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) \
int x; \
cin >> (x)
#define ii2(x, y) \
int x, y; \
cin >> (x) >> (y)
#define ii3(x, y, z) \
int x, y, z; \
cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define yn(x) cout << ((x) ? ("Yes") : ("No")) << endl
#define YN(x) cout << ((x) ? ("YES") : ("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)
inline void logger() { cout << endl; }
template <typename A, typename... B> void logger(const A &a, const B &...b) {
cout << a << " , ";
logger(b...);
}
typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 100005;
/* ...o(^-^)o... */
const int MAX_C = 100;
lint cmb[MAX_C][MAX_C];
void cmb_init() {
cmb[0][0] = 1;
repn(i, 50) rep(j, i + 1) {
if (j == 0)
cmb[i][0] = 1;
else if (j == i)
cmb[i][i] = 1;
else
cmb[i][j] = cmb[i - 1][j - 1] + cmb[i - 1][j];
}
}
lint dp[101][40000];
int main() {
lint n;
int k;
cin >> n >> k;
vector<lint> c;
for (lint i = 1; i * i <= n; i++) {
lint j = n / i;
c.push_back(i);
c.push_back(j);
}
sort(all(c));
int m = c.size();
rep(j, m) dp[1][j] = c[j];
for (int i = 2; i <= k; i++) {
rep(j, m) {
if (j == 0) {
dp[i][0] = dp[i - 1][m - 1];
continue;
}
dp[i][j] =
(dp[i][j - 1] + ((c[j] - c[j - 1]) * dp[i - 1][m - j - 1]) % MOD) %
MOD;
}
}
out(dp[k][m - 1]);
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define repn(i, n) for (int(i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for (int(i) = (n - 1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) \
int x; \
cin >> (x)
#define ii2(x, y) \
int x, y; \
cin >> (x) >> (y)
#define ii3(x, y, z) \
int x, y, z; \
cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define yn(x) cout << ((x) ? ("Yes") : ("No")) << endl
#define YN(x) cout << ((x) ? ("YES") : ("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)
inline void logger() { cout << endl; }
template <typename A, typename... B> void logger(const A &a, const B &...b) {
cout << a << " , ";
logger(b...);
}
typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 100005;
/* ...o(^-^)o... */
const int MAX_C = 100;
lint cmb[MAX_C][MAX_C];
void cmb_init() {
cmb[0][0] = 1;
repn(i, 50) rep(j, i + 1) {
if (j == 0)
cmb[i][0] = 1;
else if (j == i)
cmb[i][i] = 1;
else
cmb[i][j] = cmb[i - 1][j - 1] + cmb[i - 1][j];
}
}
lint dp[105][80000];
int main() {
lint n;
int k;
cin >> n >> k;
vector<lint> c;
for (lint i = 1; i * i <= n; i++) {
lint j = n / i;
c.push_back(i);
c.push_back(j);
}
sort(all(c));
int m = c.size();
rep(j, m) dp[1][j] = c[j];
for (int i = 2; i <= k; i++) {
rep(j, m) {
if (j == 0) {
dp[i][0] = dp[i - 1][m - 1];
continue;
}
dp[i][j] =
(dp[i][j - 1] + ((c[j] - c[j - 1]) * dp[i - 1][m - j - 1]) % MOD) %
MOD;
}
}
out(dp[k][m - 1]);
} | replace | 54 | 55 | 54 | 55 | 0 | |
p02992 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
int n, k;
ll dp[56666][111];
vector<int> v;
int main() {
scanf("%d%d", &n, &k);
int l = 1, r = 1;
while (r + 1 <= n) {
v.push_back(r);
l = r + 1;
r = n / (n / l);
}
v.push_back(r);
sort(v.begin(), v.end());
dp[0][1] = v[0];
for (int i = 1; i < v.size(); i++)
dp[i][1] = v[i] - v[i - 1];
ll ans = 0;
for (int i = 2; i <= k; i++) {
int r = v.size() - 1;
ll now = 0;
for (int j = 0; j < v.size(); j++) {
now = (now + dp[j][i - 1]) % mod;
while (v[r] >= n / v[j] && r >= 0) {
dp[r][i] = now * (r == 0 ? v[r] : v[r] - v[r - 1]) % mod;
r--;
}
}
}
for (int i = 0; i < v.size(); i++)
ans += dp[i][k];
printf("%lld\n", ans % mod);
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
int n, k;
ll dp[66666][111];
vector<int> v;
int main() {
scanf("%d%d", &n, &k);
int l = 1, r = 1;
while (r + 1 <= n) {
v.push_back(r);
l = r + 1;
r = n / (n / l);
}
v.push_back(r);
sort(v.begin(), v.end());
dp[0][1] = v[0];
for (int i = 1; i < v.size(); i++)
dp[i][1] = v[i] - v[i - 1];
ll ans = 0;
for (int i = 2; i <= k; i++) {
int r = v.size() - 1;
ll now = 0;
for (int j = 0; j < v.size(); j++) {
now = (now + dp[j][i - 1]) % mod;
while (v[r] >= n / v[j] && r >= 0) {
dp[r][i] = now * (r == 0 ? v[r] : v[r] - v[r - 1]) % mod;
r--;
}
}
}
for (int i = 0; i < v.size(); i++)
ans += dp[i][k];
printf("%lld\n", ans % mod);
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p02992 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[100][100000];
ll arr[100000];
const ll mod = 1e9 + 7;
int main() {
ll n, k;
cin >> n >> k;
ll sqrt_n = sqrt(n);
for (ll i = 1, sum = 0; i <= 2 * sqrt_n; i++) {
if (i <= sqrt_n) {
arr[i]++;
sum++;
} else {
arr[i] += n / (2 * sqrt_n - i + 1) - sum;
sum += arr[i];
}
dp[0][i] = sum;
}
for (ll i = 1; i <= k; i++)
for (ll j = 0; j < 2 * sqrt_n; j++)
dp[i][j + 1] = (dp[i - 1][sqrt_n * 2 - j] * arr[j + 1] + dp[i][j]) % mod;
cout << dp[k - 1][sqrt_n * 2] << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[105][200000];
ll arr[100000];
const ll mod = 1e9 + 7;
int main() {
ll n, k;
cin >> n >> k;
ll sqrt_n = sqrt(n);
for (ll i = 1, sum = 0; i <= 2 * sqrt_n; i++) {
if (i <= sqrt_n) {
arr[i]++;
sum++;
} else {
arr[i] += n / (2 * sqrt_n - i + 1) - sum;
sum += arr[i];
}
dp[0][i] = sum;
}
for (ll i = 1; i <= k; i++)
for (ll j = 0; j < 2 * sqrt_n; j++)
dp[i][j + 1] = (dp[i - 1][sqrt_n * 2 - j] * arr[j + 1] + dp[i][j]) % mod;
cout << dp[k - 1][sqrt_n * 2] << endl;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02992 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10, mod = 1e9 + 7;
int a, b, f[maxn], k;
map<int, int, greater<int>> dp, dp2;
unordered_map<int, int> fre;
void plusle(int &a, int b) {
a += b;
if (a >= mod)
a -= mod;
return;
}
void minun(int &a, int b) {
a -= b;
if (a < 0)
a += mod;
return;
}
int add(int a, int b) {
a += b;
if (a >= mod)
a -= mod;
return a;
}
int mul(int a, int b) { return (int)(((long long)a * b) % mod); }
int main() {
int n;
scanf("%d%d", &n, &k);
fre.reserve(1 << 17);
fre.max_load_factor(0.25);
int cc = n, pt = 1;
while (cc) {
// cout<<cc<<'\n';
int x = n / cc;
dp[x] = (n / x - n / (x + 1));
fre[x] = dp[x];
cc = (n / (x + 1));
}
int sum = 0;
// for(auto i:dp)
// printf("%d %d\n",i.first,i.second);
while (k--) {
// cout<<'g'<<'\n';
int last = -1;
// dp2.clear();
for (auto &it : dp) {
dp2[it.first] = (last == -1) ? it.second : add(last, it.second);
last = dp2[it.first];
}
for (auto &it : dp) {
dp[it.first] = mul(fre[it.first], dp2[n / (it.first)]);
}
}
printf("%d\n", dp[n]);
}
| #include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10, mod = 1e9 + 7;
int a, b, f[maxn], k;
map<int, int, greater<int>> dp, dp2;
unordered_map<int, int> fre;
void plusle(int &a, int b) {
a += b;
if (a >= mod)
a -= mod;
return;
}
void minun(int &a, int b) {
a -= b;
if (a < 0)
a += mod;
return;
}
int add(int a, int b) {
a += b;
if (a >= mod)
a -= mod;
return a;
}
int mul(int a, int b) { return (int)(((long long)a * b) % mod); }
int main() {
int n;
scanf("%d%d", &n, &k);
fre.reserve(1 << 17);
fre.max_load_factor(0.25);
int cc = n, pt = 1;
while (cc) {
// cout<<cc<<'\n';
int x = n / cc;
dp[x] = (n / x - n / (x + 1));
fre[x] = dp[x];
cc = (n / (x + 1));
}
int sum = 0;
// for(auto i:dp)
// printf("%d %d\n",i.first,i.second);
while (k--) {
// cout<<'g'<<'\n';
int last = -1;
// dp2.clear();
for (auto &it : dp) {
dp2[it.first] = (last == -1) ? it.second : add(last, it.second);
last = dp2[it.first];
}
for (auto &it : dp) {
it.second = mul(fre[it.first], dp2[n / (it.first)]);
}
}
printf("%d\n", dp[n]);
}
| replace | 51 | 52 | 51 | 52 | TLE | |
p02992 | C++ | Runtime Error | #include <cstdio>
#include <iostream>
#include <vector>
#define N 40000
using namespace std;
typedef long long ll;
ll n, k, en, M = 1e9 + 7, d[N], s[N];
vector<int> c;
int main() {
ll i, t;
cin >> n >> k;
c.push_back(0);
for (i = 1; i <= n;) {
t = n / (n / i);
c.push_back(t);
i = t + 1;
}
en = c.size() - 1;
for (i = en; i; i--) {
c[i] -= c[i - 1];
s[i] = 1;
}
while (k--) {
for (i = 1; i <= en; i++)
d[i] = s[en - i + 1] * c[i] % M;
for (i = 1; i <= en; i++)
s[i] = (s[i - 1] + d[i]) % M;
}
cout << s[en];
return 0;
} | #include <cstdio>
#include <iostream>
#include <vector>
#define N 100000
using namespace std;
typedef long long ll;
ll n, k, en, M = 1e9 + 7, d[N], s[N];
vector<int> c;
int main() {
ll i, t;
cin >> n >> k;
c.push_back(0);
for (i = 1; i <= n;) {
t = n / (n / i);
c.push_back(t);
i = t + 1;
}
en = c.size() - 1;
for (i = en; i; i--) {
c[i] -= c[i - 1];
s[i] = 1;
}
while (k--) {
for (i = 1; i <= en; i++)
d[i] = s[en - i + 1] * c[i] % M;
for (i = 1; i <= en; i++)
s[i] = (s[i - 1] + d[i]) % M;
}
cout << s[en];
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02992 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long dp[32005][2][105];
long long prefixSum[32005][2][105];
int N, K;
/*long long dp(int i, int mode, int k){
printf("%d %d %d\n", i, mode, k);
if(k == 0){
return 1;
}else if(memo[i][mode][k] != -1){
return memo[i][mode][k];
}else if(mode == 0){
long long ans = 0;
// mode 0 means that limit on current element is i
for(int j = 1; j <= i; j ++){
// the limit on the previous element is N/j
ans += dp(j, 1, k-1);
}
return memo[i][mode][k] = ans%MOD;
}else if(mode == 1){
long long ans = 0;
// mode 1 means that limit on current element is N/i
// considering j <= sqrt(N) (j refers to mode 0)
int limit1 = (int)(floor(sqrt(N))+1e-9);
for(int j = 1; j <= limit1; j ++){
// the limit on the previous element is N/j
ans += dp(j, 1, k-1);
}
// considering N/j >= N/i, in other words, j >= i (j refers to
mode 1)
// in this case, j may not be integer, but observe that the
limit is the same as if j = ceil(j) for(int j = i; j < limit1; j ++){
// the limit on the previous element is j, (N/j)-N/(j+1)
elements share the same number of ways ans += ((N/j)-(N/(j+1)))*dp(j, 0,
k-1)%MOD;
}
return memo[i][mode][k] = ans%MOD;
}else{
throw;
}
}*/
int main() {
scanf("%d%d", &N, &K);
// assert(N%2 == 0);
// memset(memo, -1, sizeof(memo));
int limit1 = (int)(floor(sqrt(N)) + 1e-9);
int limit2 = (int)(floor(sqrt(N - 2)) + 1e-9);
for (int i = 0; i <= limit1; i++) {
dp[i][1][0] = dp[i][0][0] = 1;
}
for (int k = 1; k <= K; k++) {
// do prefix sum of k-1
prefixSum[0][0][k - 1] = 0;
prefixSum[0][1][k - 1] = 0;
for (int i = 1; i <= limit1 + 1; i++) {
prefixSum[i][0][k - 1] = prefixSum[i - 1][0][k - 1] + dp[i][1][k - 1];
prefixSum[i][1][k - 1] =
prefixSum[i - 1][1][k - 1] +
(((N / i) - (N / (i + 1))) * dp[i][0][k - 1] % MOD);
}
// do the actual dp
for (int i = 1; i <= limit1; i++) {
dp[i][0][k] = (prefixSum[i][0][k - 1] - prefixSum[0][0][k - 1]) % MOD;
dp[i][1][k] = (prefixSum[limit1][0][k - 1] - prefixSum[0][0][k - 1] +
prefixSum[limit2][1][k - 1] - prefixSum[i - 1][1][k - 1]) %
MOD;
}
}
printf("%lld", dp[1][1][K]);
}
| #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long dp[32005][2][105];
long long prefixSum[32005][2][105];
int N, K;
/*long long dp(int i, int mode, int k){
printf("%d %d %d\n", i, mode, k);
if(k == 0){
return 1;
}else if(memo[i][mode][k] != -1){
return memo[i][mode][k];
}else if(mode == 0){
long long ans = 0;
// mode 0 means that limit on current element is i
for(int j = 1; j <= i; j ++){
// the limit on the previous element is N/j
ans += dp(j, 1, k-1);
}
return memo[i][mode][k] = ans%MOD;
}else if(mode == 1){
long long ans = 0;
// mode 1 means that limit on current element is N/i
// considering j <= sqrt(N) (j refers to mode 0)
int limit1 = (int)(floor(sqrt(N))+1e-9);
for(int j = 1; j <= limit1; j ++){
// the limit on the previous element is N/j
ans += dp(j, 1, k-1);
}
// considering N/j >= N/i, in other words, j >= i (j refers to
mode 1)
// in this case, j may not be integer, but observe that the
limit is the same as if j = ceil(j) for(int j = i; j < limit1; j ++){
// the limit on the previous element is j, (N/j)-N/(j+1)
elements share the same number of ways ans += ((N/j)-(N/(j+1)))*dp(j, 0,
k-1)%MOD;
}
return memo[i][mode][k] = ans%MOD;
}else{
throw;
}
}*/
int main() {
scanf("%d%d", &N, &K);
// assert(N%2 == 0);
// memset(memo, -1, sizeof(memo));
int limit1 = (int)(floor(sqrt(N)) + 1e-9);
int limit2 = limit1 - (N / limit1 == limit1);
for (int i = 0; i <= limit1; i++) {
dp[i][1][0] = dp[i][0][0] = 1;
}
for (int k = 1; k <= K; k++) {
// do prefix sum of k-1
prefixSum[0][0][k - 1] = 0;
prefixSum[0][1][k - 1] = 0;
for (int i = 1; i <= limit1 + 1; i++) {
prefixSum[i][0][k - 1] = prefixSum[i - 1][0][k - 1] + dp[i][1][k - 1];
prefixSum[i][1][k - 1] =
prefixSum[i - 1][1][k - 1] +
(((N / i) - (N / (i + 1))) * dp[i][0][k - 1] % MOD);
}
// do the actual dp
for (int i = 1; i <= limit1; i++) {
dp[i][0][k] = (prefixSum[i][0][k - 1] - prefixSum[0][0][k - 1]) % MOD;
dp[i][1][k] = (prefixSum[limit1][0][k - 1] - prefixSum[0][0][k - 1] +
prefixSum[limit2][1][k - 1] - prefixSum[i - 1][1][k - 1]) %
MOD;
}
}
printf("%lld", dp[1][1][K]);
}
| replace | 59 | 60 | 59 | 60 | -11 | |
p02992 | C++ | Runtime Error | // #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long int;
using int64 = long long int;
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chadd(T &a, T b) { a = a + b; }
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
// ModInt begin
using ll = long long;
template <ll mod> struct ModInt {
ll v;
ll mod_pow(ll x, ll n) const {
return (!n) ? 1 : (mod_pow((x * x) % mod, n / 2) * ((n & 1) ? x : 1)) % mod;
}
ModInt(ll a = 0) : v(a >= mod ? a % mod : a) {}
ModInt operator+(const ModInt &b) const {
return (v + b.v >= mod ? ModInt(v + b.v - mod) : ModInt(v + b.v));
}
ModInt operator-() const { return ModInt(-v); }
ModInt operator-(const ModInt &b) const {
return (v - b.v < 0 ? ModInt(v - b.v + mod) : ModInt(v - b.v));
}
ModInt operator*(const ModInt &b) const { return (v * b.v) % mod; }
ModInt operator/(const ModInt &b) const {
return (v * mod_pow(b.v, mod - 2)) % mod;
}
bool operator==(const ModInt &b) const { return v == b.v; }
ModInt &operator+=(const ModInt &b) {
v += b.v;
if (v >= mod)
v -= mod;
return *this;
}
ModInt &operator-=(const ModInt &b) {
v -= b.v;
if (v < 0)
v += mod;
return *this;
}
ModInt &operator*=(const ModInt &b) {
(v *= b.v) %= mod;
return *this;
}
ModInt &operator/=(const ModInt &b) {
(v *= mod_pow(b.v, mod - 2)) %= mod;
return *this;
}
ModInt pow(ll x) { return ModInt(mod_pow(v, x)); }
// operator int() const { return int(v); }
// operator long long int() const { return v; }
};
template <ll mod> ostream &operator<<(ostream &out, ModInt<mod> a) {
return out << a.v;
}
template <ll mod> istream &operator>>(istream &in, ModInt<mod> &a) {
in >> a.v;
return in;
}
// ModInt end
using mint = ModInt<MOD>;
mint dp[100][31700 * 2], coeff[31700];
int main() {
int N, K;
cin >> N >> K;
dp[0][1] = mint(1);
int sq = 1;
while (sq * sq < N)
sq++;
if (sq * sq > N)
sq--;
for (int i = 1; i <= sq; i++) {
int v = N / i;
coeff[i] = mint(max(0, v - sq));
}
for (int i = 1; i <= sq; i++) {
coeff[i] -= coeff[i + 1];
}
for (int i = 0; i < K; i++) {
for (int x = 1; x <= sq; x++) {
// 1 から sq まで全部一様に足す (いもす的に)
dp[i + 1][1] += dp[i][x];
dp[i + 1][sq + 1] -= dp[i][x];
// dp[i][sq+x] にある値を然るべきところに配る
dp[i + 1][1] += dp[i][sq + x] * coeff[x];
dp[i + 1][x + 1] -= dp[i][sq + x] * coeff[x];
// dp[i+1][sq+x] に値を配る
dp[i + 1][sq + x] += dp[i][x];
dp[i + 1][sq + sq + 1] -= dp[i][x];
}
for (int x = 1; x <= 2 * sq; x++) {
dp[i + 1][x] += dp[i + 1][x - 1];
}
}
mint ans(0);
for (int i = 1; i <= sq; i++) {
mint v = dp[K][i];
ans += v;
}
for (int i = sq; i >= 1; i--) {
coeff[i] += coeff[i + 1];
}
mint sub(0);
for (int i = sq + 1; i <= 2 * sq; i++) {
mint v = dp[K][i] - sub;
sub += v;
ans += v * coeff[i - sq];
}
cout << ans << endl;
return 0;
}
| // #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using ll = long long int;
using int64 = long long int;
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chadd(T &a, T b) { a = a + b; }
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
// ModInt begin
using ll = long long;
template <ll mod> struct ModInt {
ll v;
ll mod_pow(ll x, ll n) const {
return (!n) ? 1 : (mod_pow((x * x) % mod, n / 2) * ((n & 1) ? x : 1)) % mod;
}
ModInt(ll a = 0) : v(a >= mod ? a % mod : a) {}
ModInt operator+(const ModInt &b) const {
return (v + b.v >= mod ? ModInt(v + b.v - mod) : ModInt(v + b.v));
}
ModInt operator-() const { return ModInt(-v); }
ModInt operator-(const ModInt &b) const {
return (v - b.v < 0 ? ModInt(v - b.v + mod) : ModInt(v - b.v));
}
ModInt operator*(const ModInt &b) const { return (v * b.v) % mod; }
ModInt operator/(const ModInt &b) const {
return (v * mod_pow(b.v, mod - 2)) % mod;
}
bool operator==(const ModInt &b) const { return v == b.v; }
ModInt &operator+=(const ModInt &b) {
v += b.v;
if (v >= mod)
v -= mod;
return *this;
}
ModInt &operator-=(const ModInt &b) {
v -= b.v;
if (v < 0)
v += mod;
return *this;
}
ModInt &operator*=(const ModInt &b) {
(v *= b.v) %= mod;
return *this;
}
ModInt &operator/=(const ModInt &b) {
(v *= mod_pow(b.v, mod - 2)) %= mod;
return *this;
}
ModInt pow(ll x) { return ModInt(mod_pow(v, x)); }
// operator int() const { return int(v); }
// operator long long int() const { return v; }
};
template <ll mod> ostream &operator<<(ostream &out, ModInt<mod> a) {
return out << a.v;
}
template <ll mod> istream &operator>>(istream &in, ModInt<mod> &a) {
in >> a.v;
return in;
}
// ModInt end
using mint = ModInt<MOD>;
mint dp[101][31700 * 2], coeff[31700];
int main() {
int N, K;
cin >> N >> K;
dp[0][1] = mint(1);
int sq = 1;
while (sq * sq < N)
sq++;
if (sq * sq > N)
sq--;
for (int i = 1; i <= sq; i++) {
int v = N / i;
coeff[i] = mint(max(0, v - sq));
}
for (int i = 1; i <= sq; i++) {
coeff[i] -= coeff[i + 1];
}
for (int i = 0; i < K; i++) {
for (int x = 1; x <= sq; x++) {
// 1 から sq まで全部一様に足す (いもす的に)
dp[i + 1][1] += dp[i][x];
dp[i + 1][sq + 1] -= dp[i][x];
// dp[i][sq+x] にある値を然るべきところに配る
dp[i + 1][1] += dp[i][sq + x] * coeff[x];
dp[i + 1][x + 1] -= dp[i][sq + x] * coeff[x];
// dp[i+1][sq+x] に値を配る
dp[i + 1][sq + x] += dp[i][x];
dp[i + 1][sq + sq + 1] -= dp[i][x];
}
for (int x = 1; x <= 2 * sq; x++) {
dp[i + 1][x] += dp[i + 1][x - 1];
}
}
mint ans(0);
for (int i = 1; i <= sq; i++) {
mint v = dp[K][i];
ans += v;
}
for (int i = sq; i >= 1; i--) {
coeff[i] += coeff[i + 1];
}
mint sub(0);
for (int i = sq + 1; i <= 2 * sq; i++) {
mint v = dp[K][i] - sub;
sub += v;
ans += v * coeff[i - sq];
}
cout << ans << endl;
return 0;
}
| replace | 97 | 98 | 97 | 98 | 0 | |
p02992 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int main() {
int N, K;
cin >> N >> K;
unordered_map<int, int> mp;
int l = 1, r = 2, count = 0;
mp[0] = 1;
while (r <= N) {
count++;
l = r;
r = N / (N / l) + 1;
mp[count] = r - l;
}
long long dp[120][1000000];
for (int i = 0; i < K; i++) {
long long sum = 0;
for (int j = count; j >= 0; j--) {
if (i == 0) {
dp[0][j] = mp[j];
continue;
}
long long a = mp[j];
sum += dp[i - 1][count - j];
sum %= MOD;
dp[i][j] = sum * a;
dp[i][j] %= MOD;
}
}
long long answer = 0;
for (int i = 0; i <= count; i++) {
answer += dp[K - 1][i];
answer %= MOD;
}
cout << answer << endl;
} | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
int main() {
int N, K;
cin >> N >> K;
unordered_map<int, int> mp;
int l = 1, r = 2, count = 0;
mp[0] = 1;
while (r <= N) {
count++;
l = r;
r = N / (N / l) + 1;
mp[count] = r - l;
}
long long dp[120][100000];
for (int i = 0; i < K; i++) {
long long sum = 0;
for (int j = count; j >= 0; j--) {
if (i == 0) {
dp[0][j] = mp[j];
continue;
}
long long a = mp[j];
sum += dp[i - 1][count - j];
sum %= MOD;
dp[i][j] = sum * a;
dp[i][j] %= MOD;
}
}
long long answer = 0;
for (int i = 0; i <= count; i++) {
answer += dp[K - 1][i];
answer %= MOD;
}
cout << answer << endl;
} | replace | 15 | 16 | 15 | 16 | -11 | |
p02992 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x " = " << x << endl)
#define WATCHR(a, b) \
TRACE(for (auto it = a; it != b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) \
TRACE({ \
cout << #V " = "; \
WATCHR(V.begin(), V.end()); \
})
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
template <typename T> void ckmin(T &a, const T &b) { a = min(a, b); }
template <typename T> void ckmax(T &a, const T &b) { a = max(a, b); }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
namespace __input {
template <typename T1, typename T2>
istream &operator>>(istream &i, pair<T1, T2> &p) {
i >> p.first >> p.second;
return i;
}
template <typename T, size_t N>
istream &operator>>(istream &i, array<T, N> &v) {
for (auto &e : v) {
i >> e;
}
return i;
}
template <typename T> istream &operator>>(istream &i, vector<T> &v) {
for (auto &e : v) {
i >> e;
}
return i;
}
} // namespace __input
using namespace __input;
namespace __output {
template <typename T1, typename T2>
ostream &operator<<(ostream &o, const pair<T1, T2> &t) {
return o << "(" << t.first << ", " << t.second << ")";
}
template <typename T, size_t N>
ostream &operator<<(ostream &o, const array<T, N> &a) {
o << "[";
for (int i = 0; i < N; i++) {
if (i)
o << ", ";
o << a[i];
}
return o << "]";
}
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) {
o << "[";
for (int i = 0; i < sz(v); i++) {
if (i)
o << ", ";
o << v[i];
}
return o << "]";
}
} // namespace __output
using namespace __output;
template <int MOD> struct modnum {
int v;
modnum() : v(0) {}
modnum(ll _v) : v(_v % MOD) {
if (v < 0)
v += MOD;
}
explicit operator int() const { return v; }
friend istream &operator>>(istream &i, modnum &n) {
ll v;
i >> v;
n = modnum(v);
return i;
}
friend ostream &operator<<(ostream &o, const modnum &n) { return o << n.v; }
friend bool operator==(const modnum &a, const modnum &b) {
return a.v == b.v;
}
friend bool operator!=(const modnum &a, const modnum &b) {
return a.v != b.v;
}
modnum &operator+=(const modnum &o) {
v += o.v;
if (v >= MOD)
v -= MOD;
return *this;
}
modnum &operator-=(const modnum &o) {
v -= o.v;
if (v < 0)
v += MOD;
return *this;
}
modnum &operator*=(const modnum &o) {
v = int(ll(v) * ll(o.v) % MOD);
return *this;
}
modnum operator-() {
modnum res;
if (v)
res.v = MOD - v;
return res;
}
friend modnum operator+(const modnum &a, const modnum &b) {
return modnum(a) += b;
}
friend modnum operator-(const modnum &a, const modnum &b) {
return modnum(a) -= b;
}
friend modnum operator*(const modnum &a, const modnum &b) {
return modnum(a) *= b;
}
modnum pow(ll e) const {
if (e == 0)
return 1;
if (e & 1)
return *this * this->pow(e - 1);
return (*this * *this).pow(e / 2);
}
modnum inv() const {
int g = MOD, x = 0, y = 1;
for (int r = v; r != 0;) {
int q = g / r;
g %= r;
swap(g, r);
x -= q * y;
swap(x, y);
}
assert(g == 1);
assert(y == MOD || y == -MOD);
return x < 0 ? x + MOD : x;
}
modnum &operator/=(const modnum &o) { return (*this) *= o.inv(); }
friend modnum operator/(const modnum &a, const modnum &b) {
return modnum(a) /= modnum(b);
}
static int totient() {
int tot = MOD, tmp = MOD;
for (int p = 2; p * p <= tmp; p++)
if (tmp % p == 0) {
tot = tot / p * (p - 1);
while (tmp % p == 0)
tmp /= p;
}
if (tmp > 1)
tot = tot / tmp * (tmp - 1);
return tot;
}
static int primitive_root() {
if (MOD == 1)
return 0;
if (MOD == 2)
return 1;
int tot = totient(), tmp = tot;
vi tot_pr;
for (int p = 2; p * p <= tmp; p++)
if (tot % p == 0) {
tot_pr.push_back(p);
while (tmp % p == 0)
tmp /= p;
}
if (tmp > 1)
tot_pr.push_back(tmp);
for (int r = 2; r < MOD; r++)
if (__gcd(r, MOD) == 1) {
bool root = true;
for (int p : tot_pr)
root &= modnum(r).pow(tot / p) != 1;
if (root)
return r;
}
assert(false);
}
static modnum generator() {
static modnum g = primitive_root();
return g;
}
static int discrete_log(modnum v) {
static const int M = ceil(sqrt(MOD));
static unordered_map<int, int> table;
if (table.empty()) {
modnum e = 1;
for (int i = 0; i < M; i++) {
table[e.v] = i;
e *= generator();
}
}
static modnum f = generator().pow(totient() - M);
for (int i = 0; i < M; i++) {
if (table.count(v.v))
return table[v.v] + i * M;
v *= f;
}
assert(false);
}
static modnum fact(int n) {
static vector<modnum<MOD>> fact = {1};
for (assert(n >= 0); fact.size() <= n;)
fact.push_back(fact.back() * fact.size());
return fact[n];
}
static modnum finv(int n) {
static vector<modnum<MOD>> finv = {1};
for (assert(n >= 0); finv.size() <= n;)
finv.push_back(finv.back() / finv.size());
return finv[n];
}
static modnum ncr(int n, int r) {
if (r < 0 || n < r)
return 0;
return fact(n) * finv(r) * finv(n - r);
}
};
using mn = modnum<int(1e9 + 7)>;
using vmn = vector<mn>;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int N, K;
cin >> N >> K;
if (N == 1) {
cout << 1 << endl;
return 0;
}
vi bnd;
for (int i = 1; i * i <= N; i++) {
bnd.pb(i);
bnd.pb(N / i);
bnd.pb(N / i + 1);
}
sort(all(bnd));
bnd.erase(unique(all(bnd)), bnd.end());
vi uniq{bnd[0]}, divs{N};
FOR(i, 1, sz(bnd)) {
uniq.pb(bnd[i]);
divs.pb(N / bnd[i]);
}
int U = sz(uniq);
F0R(i, U - 1) {
assert(N / uniq[i] == divs[i]);
assert(N / uniq[i] == N / (uniq[i + 1] - 1));
}
vi canp(U - 1), elts(U - 1);
F0R(j, U - 1) {
canp[j] = j ? canp[j - 1] : U - 2;
while (canp[j] > 0 && (bnd[j + 1] - 1) * (bnd[canp[j] + 1] - 1) > N)
canp[j]--;
elts[j] = bnd[j + 1] - bnd[j];
}
vmn dp(U - 1, 1);
F0R(i, K) {
vmn upd(U - 1, 0);
F0R(j, sz(upd)) { upd[j] = elts[j] * dp[canp[j]]; }
F0R(j, sz(upd) - 1)
upd[j + 1] += upd[j];
swap(dp, upd);
}
cout << dp.back() << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x " = " << x << endl)
#define WATCHR(a, b) \
TRACE(for (auto it = a; it != b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) \
TRACE({ \
cout << #V " = "; \
WATCHR(V.begin(), V.end()); \
})
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto &a : x)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
template <typename T> void ckmin(T &a, const T &b) { a = min(a, b); }
template <typename T> void ckmax(T &a, const T &b) { a = max(a, b); }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
namespace __input {
template <typename T1, typename T2>
istream &operator>>(istream &i, pair<T1, T2> &p) {
i >> p.first >> p.second;
return i;
}
template <typename T, size_t N>
istream &operator>>(istream &i, array<T, N> &v) {
for (auto &e : v) {
i >> e;
}
return i;
}
template <typename T> istream &operator>>(istream &i, vector<T> &v) {
for (auto &e : v) {
i >> e;
}
return i;
}
} // namespace __input
using namespace __input;
namespace __output {
template <typename T1, typename T2>
ostream &operator<<(ostream &o, const pair<T1, T2> &t) {
return o << "(" << t.first << ", " << t.second << ")";
}
template <typename T, size_t N>
ostream &operator<<(ostream &o, const array<T, N> &a) {
o << "[";
for (int i = 0; i < N; i++) {
if (i)
o << ", ";
o << a[i];
}
return o << "]";
}
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) {
o << "[";
for (int i = 0; i < sz(v); i++) {
if (i)
o << ", ";
o << v[i];
}
return o << "]";
}
} // namespace __output
using namespace __output;
template <int MOD> struct modnum {
int v;
modnum() : v(0) {}
modnum(ll _v) : v(_v % MOD) {
if (v < 0)
v += MOD;
}
explicit operator int() const { return v; }
friend istream &operator>>(istream &i, modnum &n) {
ll v;
i >> v;
n = modnum(v);
return i;
}
friend ostream &operator<<(ostream &o, const modnum &n) { return o << n.v; }
friend bool operator==(const modnum &a, const modnum &b) {
return a.v == b.v;
}
friend bool operator!=(const modnum &a, const modnum &b) {
return a.v != b.v;
}
modnum &operator+=(const modnum &o) {
v += o.v;
if (v >= MOD)
v -= MOD;
return *this;
}
modnum &operator-=(const modnum &o) {
v -= o.v;
if (v < 0)
v += MOD;
return *this;
}
modnum &operator*=(const modnum &o) {
v = int(ll(v) * ll(o.v) % MOD);
return *this;
}
modnum operator-() {
modnum res;
if (v)
res.v = MOD - v;
return res;
}
friend modnum operator+(const modnum &a, const modnum &b) {
return modnum(a) += b;
}
friend modnum operator-(const modnum &a, const modnum &b) {
return modnum(a) -= b;
}
friend modnum operator*(const modnum &a, const modnum &b) {
return modnum(a) *= b;
}
modnum pow(ll e) const {
if (e == 0)
return 1;
if (e & 1)
return *this * this->pow(e - 1);
return (*this * *this).pow(e / 2);
}
modnum inv() const {
int g = MOD, x = 0, y = 1;
for (int r = v; r != 0;) {
int q = g / r;
g %= r;
swap(g, r);
x -= q * y;
swap(x, y);
}
assert(g == 1);
assert(y == MOD || y == -MOD);
return x < 0 ? x + MOD : x;
}
modnum &operator/=(const modnum &o) { return (*this) *= o.inv(); }
friend modnum operator/(const modnum &a, const modnum &b) {
return modnum(a) /= modnum(b);
}
static int totient() {
int tot = MOD, tmp = MOD;
for (int p = 2; p * p <= tmp; p++)
if (tmp % p == 0) {
tot = tot / p * (p - 1);
while (tmp % p == 0)
tmp /= p;
}
if (tmp > 1)
tot = tot / tmp * (tmp - 1);
return tot;
}
static int primitive_root() {
if (MOD == 1)
return 0;
if (MOD == 2)
return 1;
int tot = totient(), tmp = tot;
vi tot_pr;
for (int p = 2; p * p <= tmp; p++)
if (tot % p == 0) {
tot_pr.push_back(p);
while (tmp % p == 0)
tmp /= p;
}
if (tmp > 1)
tot_pr.push_back(tmp);
for (int r = 2; r < MOD; r++)
if (__gcd(r, MOD) == 1) {
bool root = true;
for (int p : tot_pr)
root &= modnum(r).pow(tot / p) != 1;
if (root)
return r;
}
assert(false);
}
static modnum generator() {
static modnum g = primitive_root();
return g;
}
static int discrete_log(modnum v) {
static const int M = ceil(sqrt(MOD));
static unordered_map<int, int> table;
if (table.empty()) {
modnum e = 1;
for (int i = 0; i < M; i++) {
table[e.v] = i;
e *= generator();
}
}
static modnum f = generator().pow(totient() - M);
for (int i = 0; i < M; i++) {
if (table.count(v.v))
return table[v.v] + i * M;
v *= f;
}
assert(false);
}
static modnum fact(int n) {
static vector<modnum<MOD>> fact = {1};
for (assert(n >= 0); fact.size() <= n;)
fact.push_back(fact.back() * fact.size());
return fact[n];
}
static modnum finv(int n) {
static vector<modnum<MOD>> finv = {1};
for (assert(n >= 0); finv.size() <= n;)
finv.push_back(finv.back() / finv.size());
return finv[n];
}
static modnum ncr(int n, int r) {
if (r < 0 || n < r)
return 0;
return fact(n) * finv(r) * finv(n - r);
}
};
using mn = modnum<int(1e9 + 7)>;
using vmn = vector<mn>;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int N, K;
cin >> N >> K;
if (N == 1) {
cout << 1 << endl;
return 0;
}
vi bnd;
for (int i = 1; i * i <= N; i++) {
bnd.pb(i);
bnd.pb(N / i - 1);
bnd.pb(N / i);
bnd.pb(N / i + 1);
}
sort(all(bnd));
bnd.erase(unique(all(bnd)), bnd.end());
vi uniq{bnd[0]}, divs{N};
FOR(i, 1, sz(bnd)) {
uniq.pb(bnd[i]);
divs.pb(N / bnd[i]);
}
int U = sz(uniq);
F0R(i, U - 1) {
assert(N / uniq[i] == divs[i]);
assert(N / uniq[i] == N / (uniq[i + 1] - 1));
}
vi canp(U - 1), elts(U - 1);
F0R(j, U - 1) {
canp[j] = j ? canp[j - 1] : U - 2;
while (canp[j] > 0 && (bnd[j + 1] - 1) * (bnd[canp[j] + 1] - 1) > N)
canp[j]--;
elts[j] = bnd[j + 1] - bnd[j];
}
vmn dp(U - 1, 1);
F0R(i, K) {
vmn upd(U - 1, 0);
F0R(j, sz(upd)) { upd[j] = elts[j] * dp[canp[j]]; }
F0R(j, sz(upd) - 1)
upd[j + 1] += upd[j];
swap(dp, upd);
}
cout << dp.back() << endl;
return 0;
}
| insert | 277 | 277 | 277 | 278 | -6 | effc5dcc-f42c-4190-957a-d0da72ac69c3.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02992/C++/s446232168.cpp:201: int main(): Assertion `N / uniq[i] == N / (uniq[i + 1] - 1)' failed.
|
p02992 | C++ | Runtime Error | // AtCoder
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
constexpr ll MOD = 1e9 + 7;
constexpr ll nmax = 1e5 + 10; // 1e9+10;
ll dp[110][nmax];
// constexpr ll nmax=1e2+10;//1e9+10;
// ll dp[5][nmax];
int main() {
#if LOCAL & 0
std::ifstream in("./test/sample-3.in");
std::cin.rdbuf(in.rdbuf());
#endif
ll N, K;
cin >> N >> K;
unordered_map<ll, ll> tbl; // N/jが何種類か
vector<ll> lim;
lim.reserve(N + 1); // 出てくる数
#if LOCAL & 0
for (ll i = 1; i <= N; ++i) {
++tbl[N / i];
// lim.push_back(N/i);
}
#endif
for (ll i = 1; i * i <= N; ++i) {
lim.push_back(i);
lim.push_back(N / i);
}
sort(lim.begin(), lim.end(), greater<ll>());
lim.erase(std::unique(lim.begin(), lim.end()), lim.end()); // 重複除く
lim.insert(lim.begin(), 0);
for (int i = 1; i < lim.size(); ++i) {
ll l = N / lim[i];
ll r = lim[i - 1] == 0 ? 0 : N / lim[i - 1];
tbl[lim[i]] = l - r;
}
dp[0][1] = 1;
for (ll k = 1; k <= K; ++k) {
// vector<ll> sum(N + 1,0); //累積和
vector<ll> sum(lim.size() + 10, 0);
// for(ll si = 1; si <= N; ++si) {
// sum[si]=sum[si-1]+dp[k-1][si];
//}
// unordered_map<ll,ll> sum; //累積和
for (ll si = 1; si <= lim.size(); ++si) {
sum[si] = sum[si - 1] + dp[k - 1][si];
}
for (ll si = 1; si <= lim.size(); ++si) {
ll sum_range = lim.size() - si;
ll multip = tbl[lim[si]];
dp[k][si] = sum[sum_range] * multip % MOD;
}
// for(ll m=1;m<=N;++m){
// for(ll a=1;a<=N/m;++a){
// dp[k][a]+=dp[k-1][m];
// }
// dp[k][m]=sum[N/m];
//}
}
// for(ll k=1;k<=K;++k){
// for(ll m=1;m<=N;++m){
// for(ll a=1;a<=N/m;++a){
// ll val=m*a;
// dp[k][val]+=dp[k-1][m];
// }
// }
// }
ll ans = 0;
for (auto &&v : dp[K]) {
ans += v;
ans %= MOD;
}
cout << ans << endl;
return 0;
} | // AtCoder
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
constexpr ll MOD = 1e9 + 7;
constexpr ll nmax = 1e5 + 10; // 1e9+10;
ll dp[110][nmax];
// constexpr ll nmax=1e2+10;//1e9+10;
// ll dp[5][nmax];
int main() {
#if LOCAL & 0
std::ifstream in("./test/sample-3.in");
std::cin.rdbuf(in.rdbuf());
#endif
ll N, K;
cin >> N >> K;
unordered_map<ll, ll> tbl; // N/jが何種類か
vector<ll> lim;
// lim.reserve(N+1); //出てくる数
#if LOCAL & 0
for (ll i = 1; i <= N; ++i) {
++tbl[N / i];
// lim.push_back(N/i);
}
#endif
for (ll i = 1; i * i <= N; ++i) {
lim.push_back(i);
lim.push_back(N / i);
}
sort(lim.begin(), lim.end(), greater<ll>());
lim.erase(std::unique(lim.begin(), lim.end()), lim.end()); // 重複除く
lim.insert(lim.begin(), 0);
for (int i = 1; i < lim.size(); ++i) {
ll l = N / lim[i];
ll r = lim[i - 1] == 0 ? 0 : N / lim[i - 1];
tbl[lim[i]] = l - r;
}
dp[0][1] = 1;
for (ll k = 1; k <= K; ++k) {
// vector<ll> sum(N + 1,0); //累積和
vector<ll> sum(lim.size() + 10, 0);
// for(ll si = 1; si <= N; ++si) {
// sum[si]=sum[si-1]+dp[k-1][si];
//}
// unordered_map<ll,ll> sum; //累積和
for (ll si = 1; si <= lim.size(); ++si) {
sum[si] = sum[si - 1] + dp[k - 1][si];
}
for (ll si = 1; si <= lim.size(); ++si) {
ll sum_range = lim.size() - si;
ll multip = tbl[lim[si]];
dp[k][si] = sum[sum_range] * multip % MOD;
}
// for(ll m=1;m<=N;++m){
// for(ll a=1;a<=N/m;++a){
// dp[k][a]+=dp[k-1][m];
// }
// dp[k][m]=sum[N/m];
//}
}
// for(ll k=1;k<=K;++k){
// for(ll m=1;m<=N;++m){
// for(ll a=1;a<=N/m;++a){
// ll val=m*a;
// dp[k][val]+=dp[k-1][m];
// }
// }
// }
ll ans = 0;
for (auto &&v : dp[K]) {
ans += v;
ans %= MOD;
}
cout << ans << endl;
return 0;
} | replace | 18 | 19 | 18 | 19 | 0 | |
p02992 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
vector<pair<int, int>> fa;
long long dp[101][40000];
int main() {
// cout<<sqrt(1000000000)<<endl;
long long n, k;
cin >> n >> k;
for (int i = 1; i * i <= n; i++) {
fa.push_back({i, 0});
fa.push_back({n / i, 0});
}
sort(fa.begin(), fa.end());
fa.erase(unique(fa.begin(), fa.end()), fa.end());
map<long long, long long> pos;
int m = (int)fa.size();
// cout<<m<<endl;
for (int i = 0; i < m - 1; i++) {
long long l = n / (fa[i + 1].first);
long long r = n / (fa[i].first);
fa[i].second = r - l;
}
fa.back().second = 1;
for (int i = 0; i < m; i++)
pos[fa[i].first] = i;
dp[0][pos[n]] = 1;
for (int i = 0; i < k; i++) {
for (int j = m - 2; j >= 0; j--)
dp[i][j] = (dp[i][j] % mod + dp[i][j + 1] % mod) % mod;
for (int j = 0; j < m; j++) {
int nj = pos[n / fa[j].first];
dp[i + 1][j] =
(dp[i + 1][j] % mod + (dp[i][nj] % mod * fa[j].second % mod) % mod) %
mod;
}
}
long long ans = 0;
for (int i = 0; i < m; i++)
ans = (ans % mod + dp[k][i] % mod) % mod;
cout << ans % mod << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
vector<pair<int, int>> fa;
long long dp[101][100000];
int main() {
// cout<<sqrt(1000000000)<<endl;
long long n, k;
cin >> n >> k;
for (int i = 1; i * i <= n; i++) {
fa.push_back({i, 0});
fa.push_back({n / i, 0});
}
sort(fa.begin(), fa.end());
fa.erase(unique(fa.begin(), fa.end()), fa.end());
map<long long, long long> pos;
int m = (int)fa.size();
// cout<<m<<endl;
for (int i = 0; i < m - 1; i++) {
long long l = n / (fa[i + 1].first);
long long r = n / (fa[i].first);
fa[i].second = r - l;
}
fa.back().second = 1;
for (int i = 0; i < m; i++)
pos[fa[i].first] = i;
dp[0][pos[n]] = 1;
for (int i = 0; i < k; i++) {
for (int j = m - 2; j >= 0; j--)
dp[i][j] = (dp[i][j] % mod + dp[i][j + 1] % mod) % mod;
for (int j = 0; j < m; j++) {
int nj = pos[n / fa[j].first];
dp[i + 1][j] =
(dp[i + 1][j] % mod + (dp[i][nj] % mod * fa[j].second % mod) % mod) %
mod;
}
}
long long ans = 0;
for (int i = 0; i < m; i++)
ans = (ans % mod + dp[k][i] % mod) % mod;
cout << ans % mod << endl;
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02992 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REP2(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1, )(__VA_ARGS__)
#define MOD 1000000007
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
for (size_t i = 0; i < v.size(); i++)
os << v[i] << (i + 1 == v.size() ? "" : ", ");
os << "}";
return os;
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
return os << "{" << p.first << ", " << p.second << "}";
}
template <class X> class SegmentTree {
int n;
vector<X> dat;
X identity;
X query_sub(int a, int b, int i, int l, int r) {
if (r <= a || b <= l)
return identity;
if (a <= l && r <= b)
return dat[i];
else {
X vl = query_sub(a, b, i * 2 + 1, l, (l + r) / 2);
X vr = query_sub(a, b, i * 2 + 2, (l + r) / 2, r);
return op(vl, vr);
}
}
X get_identity() {
return 0; // Range Sum Query
}
X op(X x, X y) {
return (x + y) % MOD; // Range Sum Query
}
public:
SegmentTree(int n_) {
n = 1;
while (n < n_)
n *= 2;
identity = get_identity();
dat = vector<X>(2 * n - 1, identity);
}
void update(int i, X x) {
i += n - 1;
dat[i] = x;
while (i > 0) {
i = (i - 1) / 2;
dat[i] = op(dat[i * 2 + 1], dat[i * 2 + 2]);
}
}
// [a, b)
X query(int a, int b) { return query_sub(a, b, 0, 0, n); }
X at(int i) { return dat[i + n - 1]; }
};
template <class X> class FenwickTree {
int n;
vector<X> a;
public:
FenwickTree(int n) : n(n), a(n + 1, 0) {}
X get(int i) {
X sm = 0;
for (; i > 0; i -= i & -i)
sm = (sm + a[i]) % MOD;
return sm;
}
void add(int i, X x) {
for (; i <= n; i += i & -i)
a[i] = (a[i] + x) % MOD;
}
X at(int i) { return (MOD + get(i) - get(i - 1)) % MOD; }
};
int main() {
int N, K;
cin >> N >> K;
vector<int> div;
set<int> st;
for (int i = 1; i <= 2 * sqrt(N); i++) {
st.insert(N / i);
st.insert(i);
}
for (auto x : st)
div.push_back(x);
// SegmentTree<long long> seg[2] = {
// SegmentTree<long long>(div.size()+1),
// SegmentTree<long long>(div.size()+1),
// };
FenwickTree<long long> seg[2] = {
FenwickTree<long long>(div.size() + 10),
FenwickTree<long long>(div.size() + 10),
};
map<int, int> mp;
for (int i = 0; i < div.size(); i++)
mp[div[i]] = i;
vector<vector<long long>> dp(K, vector<long long>(div.size()));
// seg[0].update(0, 1);
seg[0].add(1, 1);
for (int i = 1; i < div.size(); i++)
// seg[0].update(i, div[i]-div[i-1]);
seg[0].add(i + 1, div[i] - div[i - 1]);
for (int i = 1; i < K; i++) {
for (int j = 0; j < div.size(); j++) {
int x = div[j];
int y = N / x;
long long fac = 1;
if (j != 0)
fac = div[j] - div[j - 1];
// long long tmp = seg[(i-1)%2].query(0, mp[y]+1);
long long tmp = seg[(i - 1) % 2].get(mp[y] + 1);
tmp = (tmp * fac) % MOD;
// seg[i%2].update(j, tmp);
seg[i % 2].add(j + 1, ((MOD - seg[i % 2].at(j + 1)) % MOD + tmp) % MOD);
}
}
// long long ans = seg[(K-1)%2].query(0, div.size());
long long ans = seg[(K - 1) % 2].get(div.size());
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REP2(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1, )(__VA_ARGS__)
#define MOD 1000000007
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
for (size_t i = 0; i < v.size(); i++)
os << v[i] << (i + 1 == v.size() ? "" : ", ");
os << "}";
return os;
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
return os << "{" << p.first << ", " << p.second << "}";
}
template <class X> class SegmentTree {
int n;
vector<X> dat;
X identity;
X query_sub(int a, int b, int i, int l, int r) {
if (r <= a || b <= l)
return identity;
if (a <= l && r <= b)
return dat[i];
else {
X vl = query_sub(a, b, i * 2 + 1, l, (l + r) / 2);
X vr = query_sub(a, b, i * 2 + 2, (l + r) / 2, r);
return op(vl, vr);
}
}
X get_identity() {
return 0; // Range Sum Query
}
X op(X x, X y) {
return (x + y) % MOD; // Range Sum Query
}
public:
SegmentTree(int n_) {
n = 1;
while (n < n_)
n *= 2;
identity = get_identity();
dat = vector<X>(2 * n - 1, identity);
}
void update(int i, X x) {
i += n - 1;
dat[i] = x;
while (i > 0) {
i = (i - 1) / 2;
dat[i] = op(dat[i * 2 + 1], dat[i * 2 + 2]);
}
}
// [a, b)
X query(int a, int b) { return query_sub(a, b, 0, 0, n); }
X at(int i) { return dat[i + n - 1]; }
};
template <class X> class FenwickTree {
int n;
vector<X> a;
public:
FenwickTree(int n) : n(n), a(n + 1, 0) {}
X get(int i) {
X sm = 0;
for (; i > 0; i -= i & -i)
sm = (sm + a[i]) % MOD;
return sm;
}
void add(int i, X x) {
for (; i <= n; i += i & -i)
a[i] = (a[i] + x) % MOD;
}
X at(int i) { return (MOD + get(i) - get(i - 1)) % MOD; }
};
int main() {
int N, K;
cin >> N >> K;
if (N == 1) {
cout << 1 << endl;
return 0;
}
vector<int> div;
set<int> st;
for (int i = 1; i <= 2 * sqrt(N); i++) {
st.insert(N / i);
st.insert(i);
}
for (auto x : st)
div.push_back(x);
// SegmentTree<long long> seg[2] = {
// SegmentTree<long long>(div.size()+1),
// SegmentTree<long long>(div.size()+1),
// };
FenwickTree<long long> seg[2] = {
FenwickTree<long long>(div.size() + 10),
FenwickTree<long long>(div.size() + 10),
};
map<int, int> mp;
for (int i = 0; i < div.size(); i++)
mp[div[i]] = i;
vector<vector<long long>> dp(K, vector<long long>(div.size()));
// seg[0].update(0, 1);
seg[0].add(1, 1);
for (int i = 1; i < div.size(); i++)
// seg[0].update(i, div[i]-div[i-1]);
seg[0].add(i + 1, div[i] - div[i - 1]);
for (int i = 1; i < K; i++) {
for (int j = 0; j < div.size(); j++) {
int x = div[j];
int y = N / x;
long long fac = 1;
if (j != 0)
fac = div[j] - div[j - 1];
// long long tmp = seg[(i-1)%2].query(0, mp[y]+1);
long long tmp = seg[(i - 1) % 2].get(mp[y] + 1);
tmp = (tmp * fac) % MOD;
// seg[i%2].update(j, tmp);
seg[i % 2].add(j + 1, ((MOD - seg[i % 2].at(j + 1)) % MOD + tmp) % MOD);
}
}
// long long ans = seg[(K-1)%2].query(0, div.size());
long long ans = seg[(K - 1) % 2].get(div.size());
cout << ans << endl;
return 0;
} | insert | 88 | 88 | 88 | 92 | 0 | |
p02992 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9 + 7)
#define inf (int)(3e18 + 7)
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i < n; i++)
#define P pair<int, int>
#define PiP pair<int, pair<int, int>>
#define all(v) v.begin(), v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define vecunique(vec) \
sort(vec.begin(), vec.end()); \
decltype(vec)::iterator result = std::unique(vec.begin(), vec.end()); \
vec.erase(result, vec.end())
using namespace std;
bool prime(int x) {
for (int i = 2; i * i <= x; i++) {
if (x % i == 0)
return false;
}
return x > 1;
}
int gcd(int x, int y) {
if (y == 0)
return x;
return gcd(y, x % y);
}
int lcm(int x, int y) { return x / gcd(x, y) * y; }
int kai(int x, int y) {
int res = 1;
for (int i = x - y + 1; i <= x; i++) {
res *= i;
res %= mod;
}
return res;
}
int mod_pow(int x, int y) {
int res = 1;
while (y > 0) {
if (y & 1) {
res = res * x % mod;
}
x = x * x % mod;
y >>= 1;
}
return res;
}
int comb(int x, int y) {
if (y > x)
return 0;
return kai(x, y) * mod_pow(kai(y, y), mod - 2) % mod;
}
/*--------Library Zone!--------*/
int n, k;
int dp[100][100000];
int shu, cnt[100000];
signed main() {
cin >> n >> k;
for (int i = 1; i <= n;) {
if (n / i != n / (i + 1)) {
cnt[shu++] = 1;
i++;
} else {
int memo = n / (n / i) + 1;
cnt[shu++] = memo - i;
i = memo;
}
}
dp[0][1] = 1;
int sum[100000];
fill(sum, sum + 100000, 1);
rep(i, k) {
rep(j, shu + 1) { dp[i + 1][j] = sum[shu - j - 1] * cnt[j] % mod; }
fill(sum, sum + 100000, 0);
rep(j, shu + 1) {
sum[j] += dp[i + 1][j];
sum[j] %= mod;
sum[j + 1] += sum[j];
}
}
int ans = 0;
cout << sum[shu] << endl;
} | #include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9 + 7)
#define inf (int)(3e18 + 7)
#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i < n; i++)
#define P pair<int, int>
#define PiP pair<int, pair<int, int>>
#define all(v) v.begin(), v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define vecunique(vec) \
sort(vec.begin(), vec.end()); \
decltype(vec)::iterator result = std::unique(vec.begin(), vec.end()); \
vec.erase(result, vec.end())
using namespace std;
bool prime(int x) {
for (int i = 2; i * i <= x; i++) {
if (x % i == 0)
return false;
}
return x > 1;
}
int gcd(int x, int y) {
if (y == 0)
return x;
return gcd(y, x % y);
}
int lcm(int x, int y) { return x / gcd(x, y) * y; }
int kai(int x, int y) {
int res = 1;
for (int i = x - y + 1; i <= x; i++) {
res *= i;
res %= mod;
}
return res;
}
int mod_pow(int x, int y) {
int res = 1;
while (y > 0) {
if (y & 1) {
res = res * x % mod;
}
x = x * x % mod;
y >>= 1;
}
return res;
}
int comb(int x, int y) {
if (y > x)
return 0;
return kai(x, y) * mod_pow(kai(y, y), mod - 2) % mod;
}
/*--------Library Zone!--------*/
int n, k;
int dp[105][100000];
int shu, cnt[100000];
signed main() {
cin >> n >> k;
for (int i = 1; i <= n;) {
if (n / i != n / (i + 1)) {
cnt[shu++] = 1;
i++;
} else {
int memo = n / (n / i) + 1;
cnt[shu++] = memo - i;
i = memo;
}
}
dp[0][1] = 1;
int sum[100000];
fill(sum, sum + 100000, 1);
rep(i, k) {
rep(j, shu + 1) { dp[i + 1][j] = sum[shu - j - 1] * cnt[j] % mod; }
fill(sum, sum + 100000, 0);
rep(j, shu + 1) {
sum[j] += dp[i + 1][j];
sum[j] %= mod;
sum[j + 1] += sum[j];
}
}
int ans = 0;
cout << sum[shu] << endl;
} | replace | 58 | 59 | 58 | 59 | 0 | |
p02992 | C++ | Runtime Error | #include <cmath>
#include <iostream>
#include <numeric>
using namespace std;
constexpr int M = 1000000007;
int main() {
int N, K;
cin >> N >> K;
const int b = int(sqrt(N)) + 2;
long long dps[2][b], dpl[2][b];
int cur = 0, prev = 1;
dps[0][0] = dps[1][0] = dpl[0][0] = dpl[1][0] = 0;
for (int i = 1; i < b; i++) {
dps[prev][i] = i;
dpl[prev][i] = N / i;
}
while (--K) {
for (int i = 1; i < b; i++) {
dps[cur][i] =
(dps[cur][i - 1] + (N / i < b ? dps[prev][N / i] : dpl[prev][i])) % M;
}
for (int i = b - 1; i > 0; i--) {
dpl[cur][i] =
((i == b - 1 ? dps[cur][N / b] : dpl[cur][i + 1]) +
(N / (N / i) < b ? dps[prev][N / (N / i)] : dpl[prev][N / i]) *
(N / i - N / (i + 1))) %
M;
}
swap(prev, cur);
}
cout << dpl[prev][1] << endl;
}
| #include <cmath>
#include <iostream>
#include <numeric>
using namespace std;
constexpr int M = 1000000007;
int main() {
int N, K;
cin >> N >> K;
if (N == 1) {
cout << 1 << endl;
return 0;
}
const int b = int(sqrt(N)) + 2;
long long dps[2][b], dpl[2][b];
int cur = 0, prev = 1;
dps[0][0] = dps[1][0] = dpl[0][0] = dpl[1][0] = 0;
for (int i = 1; i < b; i++) {
dps[prev][i] = i;
dpl[prev][i] = N / i;
}
while (--K) {
for (int i = 1; i < b; i++) {
dps[cur][i] =
(dps[cur][i - 1] + (N / i < b ? dps[prev][N / i] : dpl[prev][i])) % M;
}
for (int i = b - 1; i > 0; i--) {
dpl[cur][i] =
((i == b - 1 ? dps[cur][N / b] : dpl[cur][i + 1]) +
(N / (N / i) < b ? dps[prev][N / (N / i)] : dpl[prev][N / i]) *
(N / i - N / (i + 1))) %
M;
}
swap(prev, cur);
}
cout << dpl[prev][1] << endl;
}
| insert | 9 | 9 | 9 | 13 | 0 | |
p02992 | C++ | Runtime Error | #include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define mod 1000000007
#define FOR(x, to) for (int x = 0; x < (to); x++)
#define FORR(x, arr) for (auto &x : arr)
#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define long long long
inline int rei() {
int x;
cin >> x;
return x;
}
inline long rel() {
long x;
cin >> x;
return x;
}
inline string res() {
string x;
cin >> x;
return x;
}
//-------------------------------------------------------
long DP[101][50000];
void Calc() {
long N = rei();
int K = rei();
vector<long> C;
{
int i;
int sq;
for (i = 1; i * i <= N; i++) {
C.push_back(1);
}
sq = i - 1;
if (N / sq - sq != 0) {
C.push_back(N / sq - sq);
}
for (i = sq; i >= 2; i--) {
C.push_back(N / (i - 1) - N / i);
}
}
DP[0][0] = 1;
for (int i = 1; i <= K; i++) {
long sum = 0;
for (int j = C.size() - 1; j >= 0; j--) {
sum += DP[i - 1][C.size() - 1 - j];
sum %= mod;
DP[i][j] = sum * C[j] % mod;
}
}
long ans = 0;
for (int i = 0; i < C.size(); i++) {
ans += DP[K][i];
}
ans %= mod;
cout << ans << endl;
}
int main(int argc, char **argv) {
ios::sync_with_stdio(false), cin.tie(0);
cout.tie(0);
Calc();
return 0;
} | #include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define mod 1000000007
#define FOR(x, to) for (int x = 0; x < (to); x++)
#define FORR(x, arr) for (auto &x : arr)
#define ALL(a) (a.begin()), (a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define long long long
inline int rei() {
int x;
cin >> x;
return x;
}
inline long rel() {
long x;
cin >> x;
return x;
}
inline string res() {
string x;
cin >> x;
return x;
}
//-------------------------------------------------------
long DP[101][100000];
void Calc() {
long N = rei();
int K = rei();
vector<long> C;
{
int i;
int sq;
for (i = 1; i * i <= N; i++) {
C.push_back(1);
}
sq = i - 1;
if (N / sq - sq != 0) {
C.push_back(N / sq - sq);
}
for (i = sq; i >= 2; i--) {
C.push_back(N / (i - 1) - N / i);
}
}
DP[0][0] = 1;
for (int i = 1; i <= K; i++) {
long sum = 0;
for (int j = C.size() - 1; j >= 0; j--) {
sum += DP[i - 1][C.size() - 1 - j];
sum %= mod;
DP[i][j] = sum * C[j] % mod;
}
}
long ans = 0;
for (int i = 0; i < C.size(); i++) {
ans += DP[K][i];
}
ans %= mod;
cout << ans << endl;
}
int main(int argc, char **argv) {
ios::sync_with_stdio(false), cin.tie(0);
cout.tie(0);
Calc();
return 0;
} | replace | 42 | 43 | 42 | 43 | 0 | |
p02992 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using cint = cpp_int;
*/
// Define
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
const ll mod = 998244353;
const ll inf = 1 << 30;
// const ll INF = LONG_MAX;
const ll INF = 1LL << 60;
const ull MAX = ULONG_MAX;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define elif else if
#define endl '\n'
#define space ' '
#define def inline auto
#define func inline constexpr ll
#define run(a) __attribute__((constructor)) def _##a()
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
#define input(a) scanf("%lld", &(a))
#define print(a) printf("%lld\n", (a))
#define fi first
#define se second
#define ok(a, b) (0 <= (a) && (a) < (b))
#define modulo(a) ((a % mod + mod) % mod)
template <class T> using vvector = vector<vector<T>>;
template <class T> using pvector = vector<pair<T, T>>;
template <class T>
using rpriority_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
// Debug
#define debug(...) \
{ \
cerr << __LINE__ << ": " << #__VA_ARGS__ << " = "; \
for (auto &&X : {__VA_ARGS__}) \
cerr << "[" << X << "] "; \
cerr << endl; \
}
#define dump(a, h, w) \
{ \
cerr << __LINE__ << ": " << #a << " = [" << endl; \
rep(__i, h) { \
rep(__j, w) cerr << a[__i][__j] << space; \
cerr << endl; \
} \
cerr << "]" << endl; \
}
#define vdump(a, n) \
{ \
cerr << __LINE__ << ": " << #a << " = ["; \
rep(__i, n) if (__i) cerr << space << a[__i]; \
else cerr << a[__i]; \
cerr << "]" << endl; \
}
struct edge {
ll to, cost;
edge(ll a, ll b) : to(a), cost(b) {}
};
struct position {
ll x, y;
position() {}
position(ll a, ll b) : x(a), y(b) {}
position next(ll i) { return {x + dx[i], y + dy[i]}; }
ll mdist() { return abs(x) + abs(y); }
double dist() { return sqrt(x * x + y * y); }
double norm(ll d) {
if (d == inf)
return max(x, y);
if (d == 1)
return mdist();
if (d == 2)
return dist();
return 0;
}
ll num(ll width) { return abs(x) * width + abs(y); }
bool operator==(position a) { return x == a.x && y == a.y; }
bool operator!=(position a) { return x != a.x || y != a.y; }
bool operator<(position a) { return x < a.x && y < a.y; }
bool operator>(position a) { return x > a.x && y > a.y; }
bool operator<=(position a) { return x <= a.x && y <= a.y; }
bool operator>=(position a) { return x >= a.x && y >= a.y; }
position operator+(position a) { return position(x + a.x, y + a.y); }
position operator-(position a) { return position(x - a.x, y - a.y); }
position operator*(position a) { return position(x * a.x, y * a.y); }
position operator/(position a) { return position(x / a.x, y / a.y); }
position operator%(position a) { return position(x % a.x, y % a.y); }
position complex(position a) {
return position(x * a.x - y * a.y, x * a.y + y * a.x);
}
/*
// for sort:
bool operator<(position a) { return x ^ a.x ? x < a.x : y < a.y; }
bool operator>(position a) { return x ^ a.x ? x > a.x : y > a.y; }
bool operator<=(position a) { return x ^ a.x ? x < a.x : y <= a.y; }
bool operator>=(position a) { return x ^ a.x ? x > a.x : y >= a.y; }
*/
};
position Origin = position(0, 0);
using pos = position;
using vec = position;
struct Range {
ll left, right;
Range() {}
Range(ll l, ll r) : left(l), right(r) {}
ll length() { return right - left; }
bool operator==(Range A) { return left == A.left && right == A.right; }
bool operator!=(Range A) { return !(Range(left, right) == A); }
bool operator>(Range A) { return left < A.left && right > A.right; }
bool operator<(Range A) { return left > A.left && right < A.right; }
bool operator>=(Range A) { return left <= A.left && right >= A.right; }
bool operator<=(Range A) { return left >= A.left && right <= A.right; }
};
// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i)
#define rep(i, n) for (ll i = 0, _##i = (n); i < _##i; ++i)
#define each(i, a) for (auto &&i : a)
#define loop() for (;;)
// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)
// Speed
run(0) { fasten, fout(10); }
#pragma GCC optimize("O3")
#pragma GCC target("avx")
// Gen-Test
#define RAND(a) \
{ \
random_device rnd; \
mt19937_64 a(rnd()); \
}
#define warning(A) \
if (!(A)) \
return 1
#define sin(a, b) ifstream a(b);
#define sout(a, b) ofstream a(b);
// Math
// #define gcd __gcd
func gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
func lcm(ll a, ll b) { return a * b / gcd(a, b); }
func sign(ll a) { return a ? abs(a) / a : 0; }
template <class T> def in() {
T A;
cin >> A;
return A;
}
template <class T>
def out(vector<vector<T>> A, ll H, ll W, char divc = space, char endc = endl) {
rep(i, H) {
rep(j, W) {
if (j)
cout << divc << A[i][j];
else
cout << A[i][j];
}
cout << endc;
}
}
ll DP[101][62000];
signed main() {
ll N, K;
cin >> N >> K;
ll N2 = sqrt(N), A[N2], sum = N2;
rep(i, N2) A[i] = N / (i + 1);
rep(i, N2 - 1) A[i] -= A[i + 1];
A[N2 - 1] -= N2;
rep(i, K + 1) rep(j, 2 * N2) DP[i][j] = 0;
DP[0][0] = 1;
rep(i, K) {
rep(j, 2 * N2) {
DP[i + 1][2 * N2 - j - 1] += DP[i][j];
DP[i + 1][2 * N2 - j - 1] %= MOD;
}
dec(j, 2 * N2 - 1, 1) {
DP[i + 1][j - 1] += DP[i + 1][j];
DP[i + 1][j - 1] %= MOD;
}
rep(j, N2) {
DP[i + 1][N2 + j] *= A[N2 - 1 - j];
DP[i + 1][N2 + j] %= MOD;
}
}
// vdump(A, N2);
// dump(DP, K + 1, 2 * N2);
ll res = 0;
rep(i, 2 * N2) {
res += DP[K][i];
res %= MOD;
}
cout << res << endl;
}
// 今年残り 331AC
// for compilation: g++ -Ofast -march=native -o _ _.cpp -std=c++20 | #include <bits/stdc++.h>
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using cint = cpp_int;
*/
// Define
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll dx[4] = {1, 0, -1, 0};
const ll dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
const ll mod = 998244353;
const ll inf = 1 << 30;
// const ll INF = LONG_MAX;
const ll INF = 1LL << 60;
const ull MAX = ULONG_MAX;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define elif else if
#define endl '\n'
#define space ' '
#define def inline auto
#define func inline constexpr ll
#define run(a) __attribute__((constructor)) def _##a()
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
#define input(a) scanf("%lld", &(a))
#define print(a) printf("%lld\n", (a))
#define fi first
#define se second
#define ok(a, b) (0 <= (a) && (a) < (b))
#define modulo(a) ((a % mod + mod) % mod)
template <class T> using vvector = vector<vector<T>>;
template <class T> using pvector = vector<pair<T, T>>;
template <class T>
using rpriority_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
// Debug
#define debug(...) \
{ \
cerr << __LINE__ << ": " << #__VA_ARGS__ << " = "; \
for (auto &&X : {__VA_ARGS__}) \
cerr << "[" << X << "] "; \
cerr << endl; \
}
#define dump(a, h, w) \
{ \
cerr << __LINE__ << ": " << #a << " = [" << endl; \
rep(__i, h) { \
rep(__j, w) cerr << a[__i][__j] << space; \
cerr << endl; \
} \
cerr << "]" << endl; \
}
#define vdump(a, n) \
{ \
cerr << __LINE__ << ": " << #a << " = ["; \
rep(__i, n) if (__i) cerr << space << a[__i]; \
else cerr << a[__i]; \
cerr << "]" << endl; \
}
struct edge {
ll to, cost;
edge(ll a, ll b) : to(a), cost(b) {}
};
struct position {
ll x, y;
position() {}
position(ll a, ll b) : x(a), y(b) {}
position next(ll i) { return {x + dx[i], y + dy[i]}; }
ll mdist() { return abs(x) + abs(y); }
double dist() { return sqrt(x * x + y * y); }
double norm(ll d) {
if (d == inf)
return max(x, y);
if (d == 1)
return mdist();
if (d == 2)
return dist();
return 0;
}
ll num(ll width) { return abs(x) * width + abs(y); }
bool operator==(position a) { return x == a.x && y == a.y; }
bool operator!=(position a) { return x != a.x || y != a.y; }
bool operator<(position a) { return x < a.x && y < a.y; }
bool operator>(position a) { return x > a.x && y > a.y; }
bool operator<=(position a) { return x <= a.x && y <= a.y; }
bool operator>=(position a) { return x >= a.x && y >= a.y; }
position operator+(position a) { return position(x + a.x, y + a.y); }
position operator-(position a) { return position(x - a.x, y - a.y); }
position operator*(position a) { return position(x * a.x, y * a.y); }
position operator/(position a) { return position(x / a.x, y / a.y); }
position operator%(position a) { return position(x % a.x, y % a.y); }
position complex(position a) {
return position(x * a.x - y * a.y, x * a.y + y * a.x);
}
/*
// for sort:
bool operator<(position a) { return x ^ a.x ? x < a.x : y < a.y; }
bool operator>(position a) { return x ^ a.x ? x > a.x : y > a.y; }
bool operator<=(position a) { return x ^ a.x ? x < a.x : y <= a.y; }
bool operator>=(position a) { return x ^ a.x ? x > a.x : y >= a.y; }
*/
};
position Origin = position(0, 0);
using pos = position;
using vec = position;
struct Range {
ll left, right;
Range() {}
Range(ll l, ll r) : left(l), right(r) {}
ll length() { return right - left; }
bool operator==(Range A) { return left == A.left && right == A.right; }
bool operator!=(Range A) { return !(Range(left, right) == A); }
bool operator>(Range A) { return left < A.left && right > A.right; }
bool operator<(Range A) { return left > A.left && right < A.right; }
bool operator>=(Range A) { return left <= A.left && right >= A.right; }
bool operator<=(Range A) { return left >= A.left && right <= A.right; }
};
// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i)
#define rep(i, n) for (ll i = 0, _##i = (n); i < _##i; ++i)
#define each(i, a) for (auto &&i : a)
#define loop() for (;;)
// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)
// Speed
run(0) { fasten, fout(10); }
#pragma GCC optimize("O3")
#pragma GCC target("avx")
// Gen-Test
#define RAND(a) \
{ \
random_device rnd; \
mt19937_64 a(rnd()); \
}
#define warning(A) \
if (!(A)) \
return 1
#define sin(a, b) ifstream a(b);
#define sout(a, b) ofstream a(b);
// Math
// #define gcd __gcd
func gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
func lcm(ll a, ll b) { return a * b / gcd(a, b); }
func sign(ll a) { return a ? abs(a) / a : 0; }
template <class T> def in() {
T A;
cin >> A;
return A;
}
template <class T>
def out(vector<vector<T>> A, ll H, ll W, char divc = space, char endc = endl) {
rep(i, H) {
rep(j, W) {
if (j)
cout << divc << A[i][j];
else
cout << A[i][j];
}
cout << endc;
}
}
ll DP[101][70000];
signed main() {
ll N, K;
cin >> N >> K;
ll N2 = sqrt(N), A[N2], sum = N2;
rep(i, N2) A[i] = N / (i + 1);
rep(i, N2 - 1) A[i] -= A[i + 1];
A[N2 - 1] -= N2;
rep(i, K + 1) rep(j, 2 * N2) DP[i][j] = 0;
DP[0][0] = 1;
rep(i, K) {
rep(j, 2 * N2) {
DP[i + 1][2 * N2 - j - 1] += DP[i][j];
DP[i + 1][2 * N2 - j - 1] %= MOD;
}
dec(j, 2 * N2 - 1, 1) {
DP[i + 1][j - 1] += DP[i + 1][j];
DP[i + 1][j - 1] %= MOD;
}
rep(j, N2) {
DP[i + 1][N2 + j] *= A[N2 - 1 - j];
DP[i + 1][N2 + j] %= MOD;
}
}
// vdump(A, N2);
// dump(DP, K + 1, 2 * N2);
ll res = 0;
rep(i, 2 * N2) {
res += DP[K][i];
res %= MOD;
}
cout << res << endl;
}
// 今年残り 331AC
// for compilation: g++ -Ofast -march=native -o _ _.cpp -std=c++20 | replace | 200 | 201 | 200 | 201 | 0 | |
p02992 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
vector<pair<long long, pair<long long, long long>>>
quotient_ranges(long long N) {
vector<pair<long long, pair<long long, long long>>> ans;
for (long long i = 1; i * i <= N; i++) {
ans.push_back(make_pair(N / i, make_pair(i, i)));
}
for (long long i = N / ((long long)sqrt(N) + 1); i >= 1; i--) {
ans.push_back(make_pair(i, make_pair(N / (i + 1) + 1, N / i)));
}
return ans;
}
int main() {
long long N;
int K;
cin >> N >> K;
vector<pair<long long, pair<long long, long long>>> A = quotient_ranges(N);
int cnt = A.size();
vector<vector<long long>> dp(K, vector<long long>(cnt, 0));
for (int i = 0; i < cnt - 1; i++) {
dp[0][i] = A[i].first - A[i + 1].first;
}
dp[0][cnt - 1] = 1;
for (int i = 0; i < K - 1; i++) {
for (int j = cnt - 1; j >= 0; j--) {
int k = cnt - 1;
long long sum = 0;
if (k >= 0) {
while ((long long)A[j].first * A[k].first <= N) {
sum += dp[i][k];
sum %= MOD;
k--;
if (k < 0) {
break;
}
}
}
dp[i + 1][j] += sum * dp[0][j];
dp[i + 1][j] %= MOD;
}
}
long long ans = 0;
for (int i = 0; i < cnt; i++) {
ans += dp[K - 1][i];
}
ans %= MOD;
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
vector<pair<long long, pair<long long, long long>>>
quotient_ranges(long long N) {
vector<pair<long long, pair<long long, long long>>> ans;
for (long long i = 1; i * i <= N; i++) {
ans.push_back(make_pair(N / i, make_pair(i, i)));
}
for (long long i = N / ((long long)sqrt(N) + 1); i >= 1; i--) {
ans.push_back(make_pair(i, make_pair(N / (i + 1) + 1, N / i)));
}
return ans;
}
int main() {
long long N;
int K;
cin >> N >> K;
vector<pair<long long, pair<long long, long long>>> A = quotient_ranges(N);
int cnt = A.size();
vector<vector<long long>> dp(K, vector<long long>(cnt, 0));
for (int i = 0; i < cnt - 1; i++) {
dp[0][i] = A[i].first - A[i + 1].first;
}
dp[0][cnt - 1] = 1;
for (int i = 0; i < K - 1; i++) {
int k = cnt - 1;
long long sum = 0;
for (int j = 0; j < cnt; j++) {
if (k >= 0) {
while ((long long)A[j].first * A[k].first <= N) {
sum += dp[i][k];
sum %= MOD;
k--;
if (k < 0) {
break;
}
}
}
dp[i + 1][j] += sum * dp[0][j];
dp[i + 1][j] %= MOD;
}
}
long long ans = 0;
for (int i = 0; i < cnt; i++) {
ans += dp[K - 1][i];
}
ans %= MOD;
cout << ans << endl;
} | replace | 26 | 29 | 26 | 29 | TLE | |
p02992 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll mod = 1e9 + 7, dp[100][100000];
int main() {
ll n, k;
cin >> n >> k;
fill(dp[0], dp[0] + 2 * ll(sqrt(n)) + 1, 0);
dp[0][1] = 1;
ll count = 0;
for (int i = 1; n / i > sqrt(n); i++)
count++;
count += ll(sqrt(n));
rep(i, k + 1) {
ll a = 1, sum = 0, b = count;
for (; n / a > sqrt(n); a++)
(sum += dp[i][a]) %= mod, dp[i + 1][b] = sum, b--;
for (int j = sqrt(n); j >= 1; j--) {
ll x = n / j - n / (j + 1);
(sum += dp[i][a] * x) %= mod;
dp[i + 1][b] = sum, b--;
a++;
}
}
cout << dp[k + 1][1] << "\n";
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll mod = 1e9 + 7, dp[110][200000];
int main() {
ll n, k;
cin >> n >> k;
fill(dp[0], dp[0] + 2 * ll(sqrt(n)) + 1, 0);
dp[0][1] = 1;
ll count = 0;
for (int i = 1; n / i > sqrt(n); i++)
count++;
count += ll(sqrt(n));
rep(i, k + 1) {
ll a = 1, sum = 0, b = count;
for (; n / a > sqrt(n); a++)
(sum += dp[i][a]) %= mod, dp[i + 1][b] = sum, b--;
for (int j = sqrt(n); j >= 1; j--) {
ll x = n / j - n / (j + 1);
(sum += dp[i][a] * x) %= mod;
dp[i + 1][b] = sum, b--;
a++;
}
}
cout << dp[k + 1][1] << "\n";
} | replace | 8 | 9 | 8 | 9 | 0 | |
p02992 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using Int = long long;
constexpr Int MOD = 1e9 + 7;
int main() {
int N, K;
cin >> N >> K;
vector<int> A, C;
{
int t = 1;
while (t < N) {
A.push_back(N / t);
C.push_back(N / (N / t));
t = N / (N / t) + 1;
}
}
int M = A.size();
vector<Int> dp(M, 1), dp2(M), sum(M);
for (int i = 1; i < K; i++) {
sum[0] = C[0] * dp[0] % MOD;
for (int j = 1; j < M; j++) {
sum[j] = (sum[j - 1] + (C[j] - C[j - 1]) * dp[j]) % MOD;
}
for (int j = 0; j < M; j++) {
int t = upper_bound(begin(C), end(C), A[j]) - begin(C) - 1;
dp2[j] = (sum[t] + (A[j] == C[t] ? 0 : (A[j] - C[t]) * dp[t + 1])) % MOD;
}
swap(dp2, dp);
}
Int ans = C[0] * dp[0];
for (int i = 1; i < M; i++) {
ans = (ans + (C[i] - C[i - 1]) * dp[i]) % MOD;
}
cout << ans << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using Int = long long;
constexpr Int MOD = 1e9 + 7;
int main() {
int N, K;
cin >> N >> K;
vector<int> A, C;
{
int t = 1;
while (t <= N) {
A.push_back(N / t);
C.push_back(N / (N / t));
t = N / (N / t) + 1;
}
}
int M = A.size();
vector<Int> dp(M, 1), dp2(M), sum(M);
for (int i = 1; i < K; i++) {
sum[0] = C[0] * dp[0] % MOD;
for (int j = 1; j < M; j++) {
sum[j] = (sum[j - 1] + (C[j] - C[j - 1]) * dp[j]) % MOD;
}
for (int j = 0; j < M; j++) {
int t = upper_bound(begin(C), end(C), A[j]) - begin(C) - 1;
dp2[j] = (sum[t] + (A[j] == C[t] ? 0 : (A[j] - C[t]) * dp[t + 1])) % MOD;
}
swap(dp2, dp);
}
Int ans = C[0] * dp[0];
for (int i = 1; i < M; i++) {
ans = (ans + (C[i] - C[i - 1]) * dp[i]) % MOD;
}
cout << ans << '\n';
return 0;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p02992 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) \
rep(i, n) { cout << a[i] << ' '; } \
cout << endl;
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;
const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 70000;
struct mint {
ll x;
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;
}
};
int main() {
ll n, k;
cin >> n >> k;
if (n == 1) {
cout << 1 << endl;
return 0;
}
ll base[N];
ll last;
for (int i = 1; i <= sqrt(n) + 2; i++) {
base[i] = i;
if (n / i <= i) {
last = i;
break;
}
}
int start, ref;
if (n / last == last) {
start = last + 1;
} else if (n / last < last) {
start = last;
}
int i_max;
for (int i = start, ref = last - 1; ref >= 1; i++, ref--) {
base[i] = n / ref;
i_max = i;
}
// if n=10, base={1,2,3,5,10}
for (int i = i_max; i >= 2; i--) {
base[i] = base[i] - base[i - 1];
}
// if n=10, base={1,1,1,2,5}
vector<vector<mint>> dp(k + 1, vector<mint>(i_max + 1));
// mint dp[101][N];
for (int i = 1; i <= i_max; i++) {
dp[1][i] = base[i];
}
for (int i = 2; i <= k; i++) {
dp[i][i_max + 1] = 0;
for (int j = i_max; j >= 1; j--) {
dp[i][j] = dp[i][j + 1] + dp[i - 1][i_max - j + 1];
}
for (int j = 1; j <= i_max; j++) {
dp[i][j] *= base[j];
}
}
// cout << i_max << endl;
mint ans = 0;
for (int i = 1; i <= i_max; i++) {
ans += dp[k][i];
}
cout << ans.x << endl;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) \
rep(i, n) { cout << a[i] << ' '; } \
cout << endl;
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;
const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 70000;
struct mint {
ll x;
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;
}
};
int main() {
ll n, k;
cin >> n >> k;
if (n == 1) {
cout << 1 << endl;
return 0;
}
ll base[N];
ll last;
for (int i = 1; i <= sqrt(n) + 2; i++) {
base[i] = i;
if (n / i <= i) {
last = i;
break;
}
}
int start, ref;
if (n / last == last) {
start = last + 1;
} else if (n / last < last) {
start = last;
}
int i_max;
for (int i = start, ref = last - 1; ref >= 1; i++, ref--) {
base[i] = n / ref;
i_max = i;
}
// if n=10, base={1,2,3,5,10}
for (int i = i_max; i >= 2; i--) {
base[i] = base[i] - base[i - 1];
}
// if n=10, base={1,1,1,2,5}
vector<vector<mint>> dp(k + 1, vector<mint>(i_max + 2));
// mint dp[101][N];
for (int i = 1; i <= i_max; i++) {
dp[1][i] = base[i];
}
for (int i = 2; i <= k; i++) {
dp[i][i_max + 1] = 0;
for (int j = i_max; j >= 1; j--) {
dp[i][j] = dp[i][j + 1] + dp[i - 1][i_max - j + 1];
}
for (int j = 1; j <= i_max; j++) {
dp[i][j] *= base[j];
}
}
// cout << i_max << endl;
mint ans = 0;
for (int i = 1; i <= i_max; i++) {
ans += dp[k][i];
}
cout << ans.x << endl;
}
| replace | 118 | 119 | 118 | 119 | -6 | Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
|
p02992 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using int64 = long long;
const int mod = 1e9 + 7;
const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
struct IoSetup {
IoSetup() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
cerr << fixed << setprecision(10);
}
} iosetup;
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
os << p.first << " " << p.second;
return os;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (int i = 0; i < (int)v.size(); i++) {
os << v[i] << (i + 1 != v.size() ? " " : "");
}
return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (T &in : v)
is >> in;
return is;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
template <typename T = int64> vector<T> make_v(size_t a) {
return vector<T>(a);
}
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
for (auto &e : t)
fill_v(e, v);
}
template <int mod> struct ModInt {
int x;
ModInt() : x(0) {}
ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
ModInt &operator+=(const ModInt &p) {
if ((x += p.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator-=(const ModInt &p) {
if ((x += mod - p.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator*=(const ModInt &p) {
x = (int)(1LL * x * p.x % mod);
return *this;
}
ModInt &operator/=(const ModInt &p) {
*this *= p.inverse();
return *this;
}
ModInt operator-() const { return ModInt(-x); }
ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
bool operator==(const ModInt &p) const { return x == p.x; }
bool operator!=(const ModInt &p) const { return x != p.x; }
ModInt inverse() const {
int a = x, b = mod, u = 1, v = 0, t;
while (b > 0) {
t = a / b;
swap(a -= t * b, b);
swap(u -= t * v, v);
}
return ModInt(u);
}
ModInt pow(int64_t n) const {
ModInt ret(1), mul(x);
while (n > 0) {
if (n & 1)
ret *= mul;
mul *= mul;
n >>= 1;
}
return ret;
}
friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
friend istream &operator>>(istream &is, ModInt &a) {
int64_t t;
is >> t;
a = ModInt<mod>(t);
return (is);
}
};
using modint = ModInt<mod>;
vector<int64_t> divisor(int64_t n) {
vector<int64_t> ret;
for (int64_t 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);
}
int main() {
int N, K;
cin >> N >> K;
int left = 1;
vector<pair<int, int>> range;
while (left <= N) {
int ok = left - 1, ng = N + 1;
while (ng - ok > 1) {
int mid = (ok + ng) / 2;
if (N / mid >= N / left)
ok = mid;
else
ng = mid;
}
range.emplace_back(left, ok);
left = ok + 1;
}
vector<modint> dp(range.size());
dp[0] = 1;
vector<int> correct(N);
for (int j = 0; j < range.size(); j++) {
int ok = -1, ng = range.size();
while (ng - ok > 1) {
int mid = (ok + ng) / 2;
if (1LL * range[mid].first * range[j].first <= N)
ok = mid;
else
ng = mid;
}
correct[j] = ok;
}
for (int i = 0; i < K; i++) {
vector<modint> dp2(range.size()), dp3(range.size());
for (int j = 0; j < range.size(); j++) {
if (~correct[j])
dp3[correct[j]] += dp[j];
}
modint add = 0;
for (int j = range.size() - 1; j >= 0; j--) {
add += dp3[j];
dp2[j] = add * (range[j].second - range[j].first + 1);
}
dp.swap(dp2);
}
modint ret;
for (auto &t : dp)
ret += t;
cout << ret << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using int64 = long long;
const int mod = 1e9 + 7;
const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
struct IoSetup {
IoSetup() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
cerr << fixed << setprecision(10);
}
} iosetup;
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
os << p.first << " " << p.second;
return os;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
is >> p.first >> p.second;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
for (int i = 0; i < (int)v.size(); i++) {
os << v[i] << (i + 1 != v.size() ? " " : "");
}
return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (T &in : v)
is >> in;
return is;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
template <typename T = int64> vector<T> make_v(size_t a) {
return vector<T>(a);
}
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
for (auto &e : t)
fill_v(e, v);
}
template <int mod> struct ModInt {
int x;
ModInt() : x(0) {}
ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
ModInt &operator+=(const ModInt &p) {
if ((x += p.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator-=(const ModInt &p) {
if ((x += mod - p.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator*=(const ModInt &p) {
x = (int)(1LL * x * p.x % mod);
return *this;
}
ModInt &operator/=(const ModInt &p) {
*this *= p.inverse();
return *this;
}
ModInt operator-() const { return ModInt(-x); }
ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
bool operator==(const ModInt &p) const { return x == p.x; }
bool operator!=(const ModInt &p) const { return x != p.x; }
ModInt inverse() const {
int a = x, b = mod, u = 1, v = 0, t;
while (b > 0) {
t = a / b;
swap(a -= t * b, b);
swap(u -= t * v, v);
}
return ModInt(u);
}
ModInt pow(int64_t n) const {
ModInt ret(1), mul(x);
while (n > 0) {
if (n & 1)
ret *= mul;
mul *= mul;
n >>= 1;
}
return ret;
}
friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
friend istream &operator>>(istream &is, ModInt &a) {
int64_t t;
is >> t;
a = ModInt<mod>(t);
return (is);
}
};
using modint = ModInt<mod>;
vector<int64_t> divisor(int64_t n) {
vector<int64_t> ret;
for (int64_t 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);
}
int main() {
int N, K;
cin >> N >> K;
int left = 1;
vector<pair<int, int>> range;
while (left <= N) {
int ok = left - 1, ng = N + 1;
while (ng - ok > 1) {
int mid = (ok + ng) / 2;
if (N / mid >= N / left)
ok = mid;
else
ng = mid;
}
range.emplace_back(left, ok);
left = ok + 1;
}
vector<modint> dp(range.size());
dp[0] = 1;
vector<int> correct(range.size());
for (int j = 0; j < range.size(); j++) {
int ok = -1, ng = range.size();
while (ng - ok > 1) {
int mid = (ok + ng) / 2;
if (1LL * range[mid].first * range[j].first <= N)
ok = mid;
else
ng = mid;
}
correct[j] = ok;
}
for (int i = 0; i < K; i++) {
vector<modint> dp2(range.size()), dp3(range.size());
for (int j = 0; j < range.size(); j++) {
if (~correct[j])
dp3[correct[j]] += dp[j];
}
modint add = 0;
for (int j = range.size() - 1; j >= 0; j--) {
add += dp3[j];
dp2[j] = add * (range[j].second - range[j].first + 1);
}
dp.swap(dp2);
}
modint ret;
for (auto &t : dp)
ret += t;
cout << ret << endl;
}
| replace | 182 | 183 | 182 | 183 | 0 | |
p02992 | C++ | Runtime Error | /*
[abc132] F - Small Products
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int MAX_R = 1e5;
const int MAX_K = 100;
const int MOD = 1e9 + 7;
class gf {
public:
int n;
gf() : n(0) {}
gf(int n) : n(n % MOD) {}
gf operator+(const gf x) const { return gf((n + x.n) % MOD); }
gf operator*(const gf x) const { return gf((1LL * n * x.n) % MOD); }
};
int N, K;
gf dp[MAX_K][MAX_R];
vector<int> t;
ll solve() {
for (int i = 1; i * i <= N; i++) {
t.push_back(i);
if (N / i != i) {
t.push_back(N / i);
}
}
sort(t.begin(), t.end(), greater<int>());
int T = t.size();
t.push_back(0);
for (int i = 1; i <= T; i++) {
dp[0][i] = 1;
}
for (int k = 1; k <= K; k++) {
for (int i = 1; i <= T; i++) {
dp[k][i] =
dp[k][i - 1] + dp[k - 1][T - i + 1] * (t[T - i] - t[T - i + 1]);
}
}
return dp[K][T].n;
}
int main() {
cin >> N >> K;
cout << solve() << endl;
return 0;
}
| /*
[abc132] F - Small Products
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int MAX_R = 1e5;
const int MAX_K = 100;
const int MOD = 1e9 + 7;
class gf {
public:
int n;
gf() : n(0) {}
gf(int n) : n(n % MOD) {}
gf operator+(const gf x) const { return gf((n + x.n) % MOD); }
gf operator*(const gf x) const { return gf((1LL * n * x.n) % MOD); }
};
int N, K;
gf dp[MAX_K + 1][MAX_R];
vector<int> t;
ll solve() {
for (int i = 1; i * i <= N; i++) {
t.push_back(i);
if (N / i != i) {
t.push_back(N / i);
}
}
sort(t.begin(), t.end(), greater<int>());
int T = t.size();
t.push_back(0);
for (int i = 1; i <= T; i++) {
dp[0][i] = 1;
}
for (int k = 1; k <= K; k++) {
for (int i = 1; i <= T; i++) {
dp[k][i] =
dp[k][i - 1] + dp[k - 1][T - i + 1] * (t[T - i] - t[T - i + 1]);
}
}
return dp[K][T].n;
}
int main() {
cin >> N >> K;
cout << solve() << endl;
return 0;
}
| replace | 25 | 26 | 25 | 26 | 0 | |
p02993 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s.at(1) == s.at(2) || s.at(2) == s.at(3) || s.at(3) == s.at(4)) {
cout << "Bad" << endl;
} else
cout << "Good" << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s.at(0) == s.at(1) || s.at(1) == s.at(2) || s.at(2) == s.at(3)) {
cout << "Bad" << endl;
} else
cout << "Good" << endl;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p02993 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s.at(0) == s.at(1) || s.at(1) == s.at(2) || s.at(2) == s.at(23))
cout << "Bad" << endl;
else
cout << "Good" << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s.at(0) == s.at(1) || s.at(1) == s.at(2) || s.at(2) == s.at(3))
cout << "Bad" << endl;
else
cout << "Good" << endl;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p02993 | C++ | Runtime Error | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
string s;
cin >> s;
rep(i, 3) {
if (s[i - 1] == s[i]) {
cout << "Bad";
return 0;
}
}
cout << "Good";
}
| #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
string s;
cin >> s;
rep(i, 3) {
if (s[i] == s[i + 1]) {
cout << "Bad";
return 0;
}
}
cout << "Good";
}
| replace | 10 | 11 | 10 | 11 | -6 | /usr/include/c++/12/bits/basic_string.h:1221: std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::reference std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator[](size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; reference = char&; size_type = long unsigned int]: Assertion '__pos <= size()' failed.
|
p02993 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
if (S.at(0) == S.at(1) || S.at(1) == S.at(2) || S.at(2) == S.at(3)) {
cout << "Bad" << endl;
} else {
cout << "Good" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
if (S.at(0) == S.at(1) || S.at(1) == S.at(2) || S.at(2) == S.at(3)) {
cout << "Bad" << endl;
} else {
cout << "Good" << endl;
}
} | insert | 5 | 5 | 5 | 6 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 0) >= this->size() (which is 0)
|
p02993 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(), x.end()
int main() {
string s;
cin >> s;
string prev = "A";
for (int i = 0; i < 4; i++) {
if (prev[0] == s[i]) {
cout << "Bad" << endl;
return 0;
}
prev[0] = s[i];
}
cout << "Good" << endl;
return 1;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORR(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define CHMIN(a, b) (a) = min((a), (b))
#define CHMAX(a, b) (a) = max((a), (b))
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define PRINT(x) cout << x << endl
#define all(x) x.begin(), x.end()
int main() {
string s;
cin >> s;
string prev = "A";
for (int i = 0; i < 4; i++) {
if (prev[0] == s[i]) {
cout << "Bad" << endl;
return 0;
}
prev[0] = s[i];
}
cout << "Good" << endl;
return 0;
} | replace | 36 | 37 | 36 | 37 | 0 | |
p02993 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
if (S.at(0) == S.at(1)) {
cout << "Bad" << endl;
}
else if (S.at(1) == S.at(2)) {
cout << "Bad" << endl;
}
else if (S.at(2) == S.at(3)) {
cout << "Bad" << endl;
}
else if (S.at(3) == S.at(4)) {
cout << "Bad" << endl;
}
else {
cout << "Good" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
if (S.at(0) == S.at(1)) {
cout << "Bad" << endl;
}
else if (S.at(1) == S.at(2)) {
cout << "Bad" << endl;
}
else if (S.at(2) == S.at(3)) {
cout << "Bad" << endl;
}
else {
cout << "Good" << endl;
}
} | delete | 19 | 23 | 19 | 19 | 0 | |
p02993 | C++ | Runtime Error | /*;
THE BEST IS YET TO COME
*/
#include <bits/stdc++.h>
using namespace std;
#define r(i, s, l) for (int i = s; i < l; i++)
#define rr(i, s, l) for (int i = s; i >= l; i--)
#define mod 1000000007
#define int long long
#define INT_BITS 32
#define ld long double
#define pp pair<int, int>
#define ss second
#define ff first
#define INF 1e18
#define N 2000005
#define all(a) a.begin(), a.end()
#define pb push_back
#define endl "\n"
using namespace std;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
signed main() {
int n;
cin >> n;
vector<int> c;
while (n > 0) {
c.pb(n % 10);
n = n / 10;
}
r(i, 0, c.size() - 1) if (c[i] == c[i + 1]) {
cout << "Bad";
return 0;
}
cout << "Good";
return 0;
}
| /*;
THE BEST IS YET TO COME
*/
#include <bits/stdc++.h>
using namespace std;
#define r(i, s, l) for (int i = s; i < l; i++)
#define rr(i, s, l) for (int i = s; i >= l; i--)
#define mod 1000000007
#define int long long
#define INT_BITS 32
#define ld long double
#define pp pair<int, int>
#define ss second
#define ff first
#define INF 1e18
#define N 2000005
#define all(a) a.begin(), a.end()
#define pb push_back
#define endl "\n"
using namespace std;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
signed main() {
string s;
cin >> s;
r(i, 0, s.length() - 1) if (s[i] == s[i + 1]) {
cout << "Bad";
return 0;
}
cout << "Good";
return 0;
}
| replace | 29 | 39 | 29 | 32 | 0 | |
p02993 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
bool A = false;
for (int i = 0; i < S.size(); i++) {
if (S.at(i) == S.at(i + 1))
A = true;
}
if (A == true)
cout << "Bad" << endl;
else if (A == false)
cout << "Good" << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
bool A = false;
for (int i = 0; i < S.size() - 1; i++) {
if (S.at(i) == S.at(i + 1))
A = true;
}
if (A == true)
cout << "Bad" << endl;
else if (A == false)
cout << "Good" << endl;
} | replace | 7 | 8 | 7 | 8 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 4) >= this->size() (which is 4)
|
p02993 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string s, answer = "Good";
cin >> s;
for (int i = 0; i < 4; ++i) {
if (s.at(i) == s.at(i + 1)) {
answer = "Bad";
break;
}
}
cout << answer << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string s, answer = "Good";
cin >> s;
for (int i = 0; i < 4; ++i) {
if (s[i] == s[i + 1]) {
answer = "Bad";
break;
}
}
cout << answer << endl;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p02993 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int num;
cin >> num;
if ((num / 10000) > 0)
return 0;
string s = to_string(num);
if (s.at(0) == s.at(1) || s.at(1) == s.at(2) || s.at(2) == s.at(3))
cout << "Bad" << endl;
else
cout << "Good" << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s.at(0) == s.at(1) || s.at(1) == s.at(2) || s.at(2) == s.at(3))
cout << "Bad" << endl;
else
cout << "Good" << endl;
} | replace | 5 | 10 | 5 | 8 | 0 | |
p02993 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
bool a = true;
for (int i = 0; i < 3; i++) {
if (s.at(i) == s.at(i + 1)) {
a = false;
break;
}
}
if (a) {
cout << "Good" << endl;
} else {
cout << "Bad" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
bool a = true;
for (int i = 0; i < 3; i++) {
if (s.at(i) == s.at(i + 1)) {
a = false;
break;
}
}
if (a) {
cout << "Good" << endl;
} else {
cout << "Bad" << endl;
}
}
| insert | 4 | 4 | 4 | 5 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 0) >= this->size() (which is 0)
|
p02993 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
if (S.at(0) != S.at(1) && S.at(1) != S.at(2) && S.at(2) != S.at(3) &&
S.at(3) != S.at(4)) {
cout << "Good" << endl;
} else {
cout << "Bad" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
if (S.at(0) != S.at(1) && S.at(1) != S.at(2) && S.at(2) != S.at(3)) {
cout << "Good" << endl;
} else {
cout << "Bad" << endl;
}
} | replace | 6 | 8 | 6 | 7 | 0 | |
p02993 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
if (S.at(0) != S.at(1) && S.at(1) != S.at(2) && S.at(2) != S.at(3) &&
S.at(3) != S.at(4)) {
cout << "Good" << endl;
} else {
cout << "Bad" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
if (S.at(0) != S.at(1) && S.at(1) != S.at(2) && S.at(2) != S.at(3)) {
cout << "Good" << endl;
} else {
cout << "Bad" << endl;
}
} | replace | 6 | 8 | 6 | 7 | 0 | |
p02993 | C++ | Runtime Error | #include <algorithm> // sort(ALL())
#include <iomanip>
#include <iostream>
#include <map> // 連想配列 map<string, int>
#include <math.h>
#include <queue> // push(), front(), pop() 先入れ先出し
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP1(i, n) for (int i = 1; i <= (n); i++)
#define pb push_back
#define mp make_pair
#define scan(argument) cin >> argument
#define prin(argument) cout << argument << endl
#define kaigyo cout << endl
#define EPS 1e-7
#define ALL(obj) (obj).begin(), (obj).end()
using ul = unsigned long;
using ll = long long;
using ld = long double;
using vint = vector<int>;
using vll = vector<ll>;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using vpint = vector<pint>;
using vpll = vector<pll>;
const int INF = (int)1e9 + 1;
const int MOD = (int)1e9 + 7;
#define INT(argu) (int)(argu + eps)
int x;
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
string s;
scan(s);
// int n = s.size();
REP(i, 3) {
if (s[i] == s[i + 1]) {
cout << "Bad" << endl;
exit(1);
}
}
// vint s(n);
// REP(i, n) scan(s[i]);
cout << "Good" << endl;
return 0;
}
| #include <algorithm> // sort(ALL())
#include <iomanip>
#include <iostream>
#include <map> // 連想配列 map<string, int>
#include <math.h>
#include <queue> // push(), front(), pop() 先入れ先出し
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP1(i, n) for (int i = 1; i <= (n); i++)
#define pb push_back
#define mp make_pair
#define scan(argument) cin >> argument
#define prin(argument) cout << argument << endl
#define kaigyo cout << endl
#define EPS 1e-7
#define ALL(obj) (obj).begin(), (obj).end()
using ul = unsigned long;
using ll = long long;
using ld = long double;
using vint = vector<int>;
using vll = vector<ll>;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using vpint = vector<pint>;
using vpll = vector<pll>;
const int INF = (int)1e9 + 1;
const int MOD = (int)1e9 + 7;
#define INT(argu) (int)(argu + eps)
int x;
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
string s;
scan(s);
// int n = s.size();
REP(i, 3) {
if (s[i] == s[i + 1]) {
cout << "Bad" << endl;
return 0;
}
}
// vint s(n);
// REP(i, n) scan(s[i]);
cout << "Good" << endl;
return 0;
}
| replace | 49 | 50 | 49 | 50 | 1 | |
p02993 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountl
#define m_p make_pair
#define inf 200000000000000
#define MAXN 1000001
#define eps 0.0000000001
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
string char_to_str(char c) {
string tem(1, c);
return tem;
}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
#define S second
#define F first
#define int long long
/////////////
signed main() {
fastio;
#ifndef ONLINE_JUDGE
freopen("inputf.in", "r", stdin);
freopen("outputf.in", "w", stdout);
#endif
string s;
cin >> s;
if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
cout << "Bad";
else {
cout << "Good";
}
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc __builtin_popcountl
#define m_p make_pair
#define inf 200000000000000
#define MAXN 1000001
#define eps 0.0000000001
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
string char_to_str(char c) {
string tem(1, c);
return tem;
}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//////////////
#define S second
#define F first
#define int long long
/////////////
signed main() {
fastio;
string s;
cin >> s;
if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
cout << "Bad";
else {
cout << "Good";
}
} | delete | 32 | 36 | 32 | 32 | 0 | |
p02993 | C++ | Runtime Error | #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
string s;
cin >> s;
for (int i = 0; i < 4; i++) {
if (s.at(i) == s.at(i + 1)) {
cout << "Bad" << endl;
return 0;
}
}
cout << "Good" << endl;
return 0;
}
| #include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
string s;
cin >> s;
for (int i = 0; i < 4; i++) {
if (s[i] == s[i + 1]) {
cout << "Bad" << endl;
return 0;
}
}
cout << "Good" << endl;
return 0;
}
| replace | 8 | 9 | 8 | 9 | 0 | |
p02993 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
bool a = true;
for (int i = 0; i < 4; i++) {
if (S.at(i) == S.at(i + 1)) {
a = false;
}
}
if (a) {
cout << "Good" << endl;
} else {
cout << "Bad" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
bool a = true;
for (int i = 0; i < 3; i++) {
if (S.at(i) == S.at(i + 1)) {
a = false;
}
}
if (a) {
cout << "Good" << endl;
} else {
cout << "Bad" << endl;
}
} | replace | 7 | 8 | 7 | 8 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 4) >= this->size() (which is 4)
|
p02993 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int i, c = 0;
int l = s.size();
for (i = 0; i < l; i++) {
if (s.at(i) == s.at(i + 1)) {
c++;
}
}
if (c == 0) {
cout << "Good" << endl;
} else {
cout << "Bad" << endl;
}
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int i, c = 0;
int l = s.size();
for (i = 0; i < l - 1; i++) {
if (s.at(i) == s.at(i + 1)) {
c++;
}
}
if (c == 0) {
cout << "Good" << endl;
} else {
cout << "Bad" << endl;
}
}
| replace | 8 | 9 | 8 | 9 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 4) >= this->size() (which is 4)
|
p02993 | Python | Runtime Error | import sys
def input():
return sys.stdin.readline()[:-1]
def main():
n = input()
if n[1] == n[2] or n[2] == n[3] or n[3] == n[4]:
print("Bad")
else:
print("Good")
if __name__ == "__main__":
main()
| import sys
def input():
return sys.stdin.readline()[:-1]
def main():
n = input()
if n[1] == n[2] or n[2] == n[3] or n[1] == n[0]:
print("Bad")
else:
print("Good")
if __name__ == "__main__":
main()
| replace | 9 | 10 | 9 | 10 | 0 | |
p02993 | Python | Runtime Error | s = list(map(int, input().split()))
if s[0] != s[1] and s[1] != s[2] and s[2] != s[3]:
print("Good")
else:
print("Bad")
| s = list(input())
if s[0] != s[1] and s[1] != s[2] and s[2] != s[3]:
print("Good")
else:
print("Bad")
| replace | 0 | 1 | 0 | 1 | IndexError: list index out of range | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02993/Python/s085447001.py", line 2, in <module>
if s[0] != s[1] and s[1] != s[2] and s[2] != s[3]:
IndexError: list index out of range
|
p02993 | Python | Runtime Error | S = input()
if S[1] == S[2] or S[2] == S[3] or S[3] == S[4]:
print("Bad")
else:
print("Good")
| S = input()
if S[0] == S[1] or S[1] == S[2] or S[2] == S[3]:
print("Bad")
else:
print("Good")
| replace | 1 | 2 | 1 | 2 | 0 | |
p02993 | Python | Runtime Error | import sys
fin = sys.stdin.readline
num = str(int(fin()))
readable = True
prev_num = num[0]
for i in range(1, 4):
cur_num = num[i]
if prev_num == cur_num:
readable = False
prev_num = cur_num
if readable:
print("Good")
else:
print("Bad")
| import sys
fin = sys.stdin.readline
num = str(fin()).split()[0]
readable = True
prev_num = num[0]
for i in range(1, 4):
cur_num = num[i]
if prev_num == cur_num:
readable = False
prev_num = cur_num
if readable:
print("Good")
else:
print("Bad")
| replace | 3 | 4 | 3 | 4 | 0 | |
p02993 | Python | Runtime Error | s = int(input())
ans = "Good"
s_temp = 99
for num in s:
if int(num) == s_temp:
ans = "Bad"
break
else:
s_temp = int(num)
print(ans)
| s = input()
ans = "Good"
s_temp = 99
for num in s:
if int(num) == s_temp:
ans = "Bad"
break
else:
s_temp = int(num)
print(ans)
| replace | 0 | 1 | 0 | 1 | TypeError: 'int' object is not iterable | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02993/Python/s013728744.py", line 7, in <module>
for num in s:
TypeError: 'int' object is not iterable
|
p02993 | Python | Runtime Error | cord = list(input())
cord_len = len(cord)
for i in range(cord - 1):
if cord[i] == cord[i + 1]:
print("Bad")
break
else:
print("Good")
| cord = list(input())
cord_len = len(cord)
for i in range(cord_len - 1):
if cord[i] == cord[i + 1]:
print("Bad")
break
else:
print("Good")
| replace | 2 | 3 | 2 | 3 | TypeError: unsupported operand type(s) for -: 'list' and 'int' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02993/Python/s564571845.py", line 3, in <module>
for i in range(cord - 1):
TypeError: unsupported operand type(s) for -: 'list' and 'int'
|
p02993 | Python | Runtime Error | s = list(input())
if s[0] == s[1] or s[1] == s[2] or s[2] == s[3] or s[3] == s[4]:
print("Bad")
else:
print("Good")
| s = list(input())
if s[0] == s[1] or s[1] == s[2] or s[2] == s[3]:
print("Bad")
else:
print("Good")
| replace | 2 | 3 | 2 | 3 | 0 | |
p02993 | Python | Runtime Error | s = str(int(input()))
if s[0] == s[1] or s[1] == s[2] or s[2] == s[3]:
print("Bad")
else:
print("Good")
| s = str(input())
if s[0] == s[1] or s[1] == s[2] or s[2] == s[3]:
print("Bad")
else:
print("Good")
| replace | 0 | 1 | 0 | 1 | 0 | |
p02993 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string A;
cin >> A;
bool flag = true;
for (int i = 0; i < 4; i++) {
if (A.at(i) == A.at(i + 1)) {
cout << "Bad" << endl;
flag = false;
break;
}
}
if (flag)
cout << "Good" << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string A;
cin >> A;
bool flag = true;
for (int i = 0; i < 3; i++) {
if (A.at(i) == A.at(i + 1)) {
cout << "Bad" << endl;
flag = false;
break;
}
}
if (flag)
cout << "Good" << endl;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p02993 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<char> a(4);
for (int i = 0; i < 4; i++)
cin >> a.at(i);
if (a.at(0) == a.at(1))
cout << "Bad";
else if (a.at(1) == a.at(2))
cout << "Bad";
else if (a.at(2) == a.at(3))
cout << "Bad";
else if (a.at(3) == a.at(4))
cout << "Bad";
else
cout << "Good";
} | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<char> a(4);
for (int i = 0; i < 4; i++)
cin >> a.at(i);
if (a.at(0) == a.at(1))
cout << "Bad";
else if (a.at(1) == a.at(2))
cout << "Bad";
else if (a.at(2) == a.at(3))
cout << "Bad";
else
cout << "Good";
} | delete | 14 | 16 | 14 | 14 | 0 | |
p02993 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
//
string str;
if (str.at(0) == str.at(1))
cout << "Bad";
else if (str.at(1) == str.at(2))
cout << "Bad";
else if (str.at(2) == str.at(3))
cout << "Bad";
else
cout << "Good";
//
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
//
string str;
cin >> str;
if (str.at(0) == str.at(1))
cout << "Bad";
else if (str.at(1) == str.at(2))
cout << "Bad";
else if (str.at(2) == str.at(3))
cout << "Bad";
else
cout << "Good";
//
}
| replace | 6 | 7 | 6 | 7 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 0) >= this->size() (which is 0)
|
p02993 | C++ | Runtime Error | #include <iostream>
#include <stack>/*** LIFO *** stack<type> var;
push(), top():to get data, pop():to remove, size(), empty() ***/
#include <string>
using namespace std;
#define Fp(I, STAT, END) for (int I = STAT; I < END; I++)
#define Fm(I, STAT, END) for (int I = STAT; I > END; I--)
int main() {
string S;
cin >> S;
Fp(i, 0, 3) {
if (S[i] == S[i + 1]) {
cout << "Bad" << endl;
return 1;
}
}
cout << "Good" << endl;
}
| #include <iostream>
#include <stack>/*** LIFO *** stack<type> var;
push(), top():to get data, pop():to remove, size(), empty() ***/
#include <string>
using namespace std;
#define Fp(I, STAT, END) for (int I = STAT; I < END; I++)
#define Fm(I, STAT, END) for (int I = STAT; I > END; I--)
int main() {
string S;
cin >> S;
Fp(i, 0, 3) {
if (S[i] == S[i + 1]) {
cout << "Bad" << endl;
return 0;
}
}
cout << "Good" << endl;
}
| replace | 15 | 16 | 15 | 16 | 1 | |
p02993 | C++ | Runtime Error | #include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unrolled-loops")
using namespace std;
#define inp "TestCode.inp"
#define out "TestCode.out"
#define FAST \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define FileInOut \
freopen(inp, "r", stdin); \
freopen(out, "w", stdout);
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define pi acos(-1)
#define pii pair<int, int>
#define ppiii pair<pair<int, int>, int>
#define INF 1000000
#define endl '\n'
#define ll long long
#define pq priority_queue
const int mod = 1e9 + 7;
int test = 1;
/*-----------------------------------------------*/
void nathan_on_osu(){FAST
#ifndef ONLINE_JUDGE
FileInOut
#endif // ONLINE_JUDGE
} /*-----------------------------------------------*/
string s;
int main() {
nathan_on_osu();
cin >> s;
for (int i = 0; i <= 2; i++) {
if (s[i] == s[i + 1]) {
cout << "Bad";
return 0;
}
}
cout << "Good";
}
| #include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unrolled-loops")
using namespace std;
#define inp "TestCode.inp"
#define out "TestCode.out"
#define FAST \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define FileInOut \
freopen(inp, "r", stdin); \
freopen(out, "w", stdout);
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define pi acos(-1)
#define pii pair<int, int>
#define ppiii pair<pair<int, int>, int>
#define INF 1000000
#define endl '\n'
#define ll long long
#define pq priority_queue
const int mod = 1e9 + 7;
int test = 1;
/*-----------------------------------------------*/
void nathan_on_osu(){FAST
#ifndef ONLINE_JUDGE
// FileInOut
#endif // ONLINE_JUDGE
} /*-----------------------------------------------*/
string s;
int main() {
nathan_on_osu();
cin >> s;
for (int i = 0; i <= 2; i++) {
if (s[i] == s[i + 1]) {
cout << "Bad";
return 0;
}
}
cout << "Good";
}
| replace | 32 | 33 | 32 | 33 | 0 | |
p02993 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s.at(1) == s.at(2)) {
cout << "Bad" << endl;
} else if (s.at(2) == s.at(3)) {
cout << "Bad" << endl;
} else if (s.at(3) == s.at(4)) {
cout << "Bad" << endl;
} else {
cout << "Good" << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
if (s.at(1) == s.at(2)) {
cout << "Bad" << endl;
} else if (s.at(2) == s.at(3)) {
cout << "Bad" << endl;
} else if (s.at(0) == s.at(1)) {
cout << "Bad" << endl;
} else {
cout << "Good" << endl;
}
} | replace | 10 | 11 | 10 | 11 | 0 | |
p02993 | C++ | Time Limit Exceeded | #include <stdio.h>
int main() {
int S = 0;
while (S < 1000 || S > 9999)
scanf("%d", &S);
if (S / 1000 % 10 == S / 100 % 10 || S / 100 % 10 == S / 10 % 10 ||
S / 10 % 10 == S % 10)
printf("Bad");
else
printf("Good");
return 0;
} | #include <stdio.h>
int main() {
int S = 0;
for (;;)
if (S < 10000 || S > 999)
break;
scanf("%d", &S);
if (S / 1000 % 10 == S / 100 % 10 || S / 100 % 10 == S / 10 % 10 ||
S / 10 % 10 == S % 10)
printf("Bad");
else
printf("Good");
return 0;
} | replace | 4 | 6 | 4 | 8 | TLE | |
p02993 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define pans cout << ans << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
string s;
cin >> s;
bool flag = false;
for (int i = 0; i < 3; i++) {
if (s[i] == s[i + 1]) {
flag = true;
}
}
int a = 0;
for (int i = 0; i < 10000000000; i++) {
a += 1;
}
if (flag) {
cout << "Bad" << endl;
} else {
cout << "Good" << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define pans cout << ans << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
string s;
cin >> s;
bool flag = false;
for (int i = 0; i < 3; i++) {
if (s[i] == s[i + 1]) {
flag = true;
}
}
int a = 0;
for (int i = 0; i < 1000000000; i++) {
a += 1;
}
if (flag) {
cout << "Bad" << endl;
} else {
cout << "Good" << endl;
}
return 0;
} | replace | 15 | 16 | 15 | 16 | TLE | |
p02993 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define pans cout << ans << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
string s;
cin >> s;
bool flag = false;
for (int i = 0; i < 3; i++) {
if (s[i] == s[i + 1]) {
flag = true;
}
}
int a = 0;
for (int i = 0; i < 2500000000; i++) {
a += 1;
}
if (flag) {
cout << "Bad" << endl;
} else {
cout << "Good" << endl;
}
return 0;
} | #include <bits/stdc++.h>
#define pans cout << ans << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
string s;
cin >> s;
bool flag = false;
for (int i = 0; i < 3; i++) {
if (s[i] == s[i + 1]) {
flag = true;
}
}
int a = 0;
for (int i = 0; i < 1500000000; i++) {
a += 1;
}
if (flag) {
cout << "Bad" << endl;
} else {
cout << "Good" << endl;
}
return 0;
} | replace | 15 | 16 | 15 | 16 | TLE | |
p02993 | C++ | Runtime Error | #include <iostream>
#include <string>
using namespace std;
int main() {
string s;
cin >> s;
int count = 0;
for (int i = 0; i < s.size(); i++) {
if (s.at(i) == s.at(i + 1)) {
count++;
}
}
if (count > 0) {
cout << "Bad" << endl;
} else {
cout << "Good" << endl;
}
} | #include <iostream>
#include <string>
using namespace std;
int main() {
string s;
cin >> s;
int count = 0;
for (int i = 0; i < s.size() - 1; i++) {
if (s.at(i) == s.at(i + 1)) {
count++;
}
}
if (count > 0) {
cout << "Bad" << endl;
} else {
cout << "Good" << endl;
}
} | replace | 8 | 9 | 8 | 9 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 4) >= this->size() (which is 4)
|
p02994 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>
int main() {
// std::cout << std::fixed << std::setprecision(10);
int n, l;
std::cin >> n >> l;
std::vector<int> a(n);
int val = 1000, ans = 0, sum = 0;
for (int i = 1; i < n + 1; i++) {
a[i] = l + i - 1;
std::cerr << a[i] << std::endl;
if (std::abs(a[i]) < val) {
ans = i;
val = std::abs(a[i]);
}
sum += a[i];
}
std::cout << sum - a[ans] << std::endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>
int main() {
// std::cout << std::fixed << std::setprecision(10);
int n, l;
std::cin >> n >> l;
std::vector<int> a(n);
int val = 1000, ans = 0, sum = 0;
for (int i = 0; i < n; i++) {
a[i] = l + i;
std::cerr << a[i] << std::endl;
if (std::abs(a[i]) < val) {
ans = i;
val = std::abs(a[i]);
}
sum += a[i];
}
std::cout << sum - a[ans] << std::endl;
return 0;
} | replace | 16 | 18 | 16 | 18 | 0 | 2
3
4
5
6
|
p02994 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a) (a).begin(), (a).end()
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;
}
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); // 3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
int n, l;
cin >> n >> l;
int tot = 0;
int mini = MOD;
rep(i, n) {
int ap = l + i;
tot += ap;
ap = abs(ap - 0);
mini = min(mini, ap);
}
cout << abs(abs(tot - 0) - abs(mini - 0)) * (tot / abs(tot - 0)) << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a) (a).begin(), (a).end()
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;
}
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); // 3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main() {
int n, l;
cin >> n >> l;
int tot = 0;
int mini = MOD;
rep(i, n) {
int ap = l + i;
tot += ap;
ap = abs(ap - 0);
mini = min(mini, ap);
}
cout << abs(abs(tot - 0) - abs(mini - 0)) *
(tot / (abs(tot - 0) == 0 ? 1 : abs(tot - 0)))
<< endl;
} | replace | 41 | 42 | 41 | 44 | 0 | |
p02994 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
// #include "graph.cpp"
#define ll long long
#define loop(i, n) for (int i = 0; i < n; ++i)
#define rep(i, x, n) for (int i = x; i <= n; ++i)
#define iteloop(type, data, name, it) \
for (type<data>::iterator it = name.begin(); it != name.end(); ++it)
using namespace std;
using namespace __gnu_pbds;
int getSum(int st, int en) {
int res = 0;
for (int i = st; i <= en; i++)
res += i;
return res;
}
int main() {
cin.sync_with_stdio(false), cin.tie(0), cout.tie(0);
/// freopen("in.txt","rt",stdin);
int n, l;
cin >> n >> l;
int st = l, en = l + n - 1;
if (st / abs(st) != en / abs(en)) {
cout << getSum(st, en) << endl;
return 0;
}
if (st / abs(st) == 1) {
cout << getSum(st, en) - st << endl;
} else {
cout << getSum(st, en) - en << endl;
}
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
// #include "graph.cpp"
#define ll long long
#define loop(i, n) for (int i = 0; i < n; ++i)
#define rep(i, x, n) for (int i = x; i <= n; ++i)
#define iteloop(type, data, name, it) \
for (type<data>::iterator it = name.begin(); it != name.end(); ++it)
using namespace std;
using namespace __gnu_pbds;
int getSum(int st, int en) {
int res = 0;
for (int i = st; i <= en; i++)
res += i;
return res;
}
int main() {
cin.sync_with_stdio(false), cin.tie(0), cout.tie(0);
/// freopen("in.txt","rt",stdin);
int n, l;
cin >> n >> l;
int st = l, en = l + n - 1;
if (st == 0 || en == 0) {
cout << getSum(st, en) << endl;
return 0;
}
if (st / abs(st) != en / abs(en)) {
cout << getSum(st, en) << endl;
return 0;
}
if (st / abs(st) == 1) {
cout << getSum(st, en) - st << endl;
} else {
cout << getSum(st, en) - en << endl;
}
}
| insert | 26 | 26 | 26 | 30 | 0 | |
p02994 | C++ | Runtime Error | #include <cmath>
#include <iostream>
using namespace std;
int main() {
int n, l;
cin >> n >> l;
int A[30];
int shuma = 0;
for (int i = 0; i < n; i++) {
A[i] = l + i;
shuma += A[i];
}
int max = abs(A[0]);
for (int i = 1; i < n; i++) {
if (abs(A[i]) < abs(max)) {
max = A[i];
}
}
cout << shuma - max;
return 0;
}
| #include <cmath>
#include <iostream>
using namespace std;
int main() {
int n, l;
cin >> n >> l;
int A[n];
int shuma = 0;
for (int i = 0; i < n; i++) {
A[i] = l + i;
shuma += A[i];
}
int max = abs(A[0]);
for (int i = 1; i < n; i++) {
if (abs(A[i]) < abs(max)) {
max = A[i];
}
}
cout << shuma - max;
return 0;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p02994 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, l;
cin >> n >> l;
vector<int> vec(n);
int sum = 0;
for (int i = 0; i < n; i++) {
sum += l + i;
vec.at(i) = l + i;
}
int eat = 0;
if (vec.at(0) > 0) {
eat = vec.at(0);
} else if (vec.at(n) < 0) {
eat = vec.at(n);
}
cout << sum - eat << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, l;
cin >> n >> l;
vector<int> vec(n);
int sum = 0;
for (int i = 0; i < n; i++) {
sum += l + i;
vec.at(i) = l + i;
}
int eat = 0;
if (vec.at(0) > 0) {
eat = vec.at(0);
} else if (vec.at(n - 1) < 0) {
eat = vec.at(n - 1);
}
cout << sum - eat << endl;
} | replace | 15 | 17 | 15 | 17 | 0 | |
p02994 | C++ | Runtime Error |
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N, L;
vector<int> apple;
vector<int> abs_apple;
cin >> N >> L;
for (int i = 0; i < N; i++) {
apple.push_back(L + i);
abs_apple.push_back(abs(L + i));
}
int x, y;
for (int i = 0; i < N; i++) {
if (abs_apple[i] < y) {
y = abs_apple[i];
x = i;
}
}
apple.erase(apple.begin() + x);
int total = 0;
for (int i = 0; i < N - 1; i++) {
total += apple[i];
}
cout << total << endl;
return 0;
} |
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N, L;
vector<int> apple;
vector<int> abs_apple;
cin >> N >> L;
for (int i = 0; i < N; i++) {
apple.push_back(L + i);
abs_apple.push_back(abs(L + i));
}
int x = 200, y = 300;
for (int i = 0; i < N; i++) {
if (abs_apple[i] < y) {
y = abs_apple[i];
x = i;
}
}
apple.erase(apple.begin() + x);
int total = 0;
for (int i = 0; i < N - 1; i++) {
total += apple[i];
}
cout << total << endl;
return 0;
} | replace | 15 | 16 | 15 | 16 | 0 | |
p02994 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1e9 + 7
using namespace std;
typedef long long ll;
int main() {
int N, L, sum = 0;
cin >> N >> L;
vector<int> r(N, 1000);
for (int i = 1; i <= N; i++) {
r[i] = L + i - 1;
sum += r[i];
}
int mi = 100000;
bool a = true;
for (int i = 1; i <= N; i++) {
mi = min(mi, abs(r[i]));
if (r[i] < 0) {
a = false;
}
}
if (a)
cout << sum - mi;
else {
cout << sum + mi;
}
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1e9 + 7
using namespace std;
typedef long long ll;
int main() {
int N, L, sum = 0;
cin >> N >> L;
vector<int> r(N + 1, 1000);
for (int i = 1; i <= N; i++) {
r[i] = L + i - 1;
sum += r[i];
}
int mi = 100000;
bool a = true;
for (int i = 1; i <= N; i++) {
mi = min(mi, abs(r[i]));
if (r[i] < 0) {
a = false;
}
}
if (a)
cout << sum - mi;
else {
cout << sum + mi;
}
} | replace | 10 | 11 | 10 | 11 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.