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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
p03000 | C++ | Runtime Error | #include <algorithm>
#include <bits/stdc++.h>
#include <stdint.h>
#include <vector>
using namespace std;
int main() {
int n, x;
cin >> n >> x;
vector<int> l(n, 0);
for (int i = 0; i < n; i++) {
cin >> l.at(i);
}
int h = 0;
int ans = 1;
int i = 0;
while (h <= x) {
h += l.at(i);
if (h > x) {
// 超えちゃってるので足さない
// cout << "Over" << endl;
} else {
ans++;
// cout << "Get " << h << ", " << ans << endl;
}
i++;
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <bits/stdc++.h>
#include <stdint.h>
#include <vector>
using namespace std;
int main() {
int n, x;
cin >> n >> x;
vector<int> l(n, 0);
for (int i = 0; i < n; i++) {
cin >> l.at(i);
}
int h = 0;
int ans = 1;
int i = 0;
while (h <= x && i < n) {
h += l.at(i);
if (h > x) {
// 超えちゃってるので足さない
// cout << "Over" << endl;
} else {
ans++;
// cout << "Get " << h << ", " << ans << endl;
}
i++;
}
cout << ans << endl;
return 0;
}
| replace | 20 | 21 | 20 | 21 | 0 | |
p03000 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */
/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i > (b); --i)
#define FOR_ALL(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define FOR_ALLR(i, c) \
for (__typeof((c).rbegin()) i = (c).rbegin(); i != (c).rend(); ++i)
#define SZ(array) (sizeof(array) / sizeof(array[0]))
#define lc(x) (x << 1) /* 2*x */
#define rc(x) (x << 1 | 1) /* 2*x+1 */
#define lowbit(x) (x & (-x)) /* 0b10100 -> 0b100 */
typedef long long LL;
typedef map<int, int> MII;
typedef pair<int, int> PII;
typedef set<int> SI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<int> VI;
typedef vector<string> VS;
/* check if a key is in container C */
template <class C> inline bool in_(const typename C::key_type &k, const C &A) {
return A.find(k) != A.end();
}
inline bool in_(const string &s, const string &S) {
return S.find(s) != string::npos;
}
int main() {
#ifdef foo_
freopen("foo", "rt", stdin);
#endif
ios::sync_with_stdio(false);
int n, x;
while (cin >> n >> x) {
VI L(n + 1);
FOR(i, 1, n + 1)
cin >> L[i];
VI D(2);
D[1] = 0;
FOR(i, 2, n + 2)
D[i] = D[i - 1] + L[i - 1];
int ans = 0;
FOR(i, 1, n + 2) if (D[i] <= x) ans++;
cout << ans << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
/* g++ -g -fsanitize=address -lasan -std=c++11 -Dfoo_ */
/* freopen("input.txt", "rt", stdin); */
/* freopen("output.txt", "wt", stdout); */
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i > (b); --i)
#define FOR_ALL(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define FOR_ALLR(i, c) \
for (__typeof((c).rbegin()) i = (c).rbegin(); i != (c).rend(); ++i)
#define SZ(array) (sizeof(array) / sizeof(array[0]))
#define lc(x) (x << 1) /* 2*x */
#define rc(x) (x << 1 | 1) /* 2*x+1 */
#define lowbit(x) (x & (-x)) /* 0b10100 -> 0b100 */
typedef long long LL;
typedef map<int, int> MII;
typedef pair<int, int> PII;
typedef set<int> SI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<int> VI;
typedef vector<string> VS;
/* check if a key is in container C */
template <class C> inline bool in_(const typename C::key_type &k, const C &A) {
return A.find(k) != A.end();
}
inline bool in_(const string &s, const string &S) {
return S.find(s) != string::npos;
}
int main() {
#ifdef foo_
freopen("foo", "rt", stdin);
#endif
ios::sync_with_stdio(false);
int n, x;
while (cin >> n >> x) {
VI L(n + 1);
FOR(i, 1, n + 1)
cin >> L[i];
VI D(n + 2);
D[1] = 0;
FOR(i, 2, n + 2)
D[i] = D[i - 1] + L[i - 1];
int ans = 0;
FOR(i, 1, n + 2) if (D[i] <= x) ans++;
cout << ans << endl;
}
return 0;
}
| replace | 49 | 50 | 49 | 50 | 0 | |
p03000 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
int main() {
int n, x;
int i;
int D = 0;
int cnt = 1;
vector<int> l(n);
cin >> n >> x;
for (i = 0; i < n; i++) {
cin >> l[i];
D += l[i];
if (D <= x) {
cnt++;
}
}
cout << cnt << endl;
return 0;
} | #include <iostream>
#include <vector>
using namespace std;
int main() {
long n, x;
long i;
long D = 0;
long cnt = 1;
vector<long> l(n);
cin >> n >> x;
for (i = 0; i < n; i++) {
cin >> l[i];
D += l[i];
if (D <= x) {
cnt++;
}
}
cout << cnt << endl;
return 0;
} | replace | 5 | 10 | 5 | 10 | 0 | |
p03000 | 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
#define pb push_back
#define For(i, s, e) for (ll i = (s); i < (e); i++)
#define Debug_array(a, n) \
for (ll i = (0); i < (n); i++) \
cout << a[i] << " "
#define Foe(i, s, e) for (ll i = (s); i <= (e); i++)
#define Fod(i, s, e) for (ll i = (s)-1; i >= (e); i--)
#define Mod 1000000007
#define pii pair<ll, ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
// #define random_shuffle(indices.begin(), indices.end());
// std::random_device rd;
// std::mt19937 g(rd());
// std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
#define MAX 5002
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n, x;
cin >> n >> x;
ll f[MAX];
memset(f, 0, sizeof(f));
f[0] = 1;
ll a[n];
For(i, 0, n) cin >> a[i];
ll d = 0;
For(i, 0, n) {
d = d + a[i];
f[d]++;
}
ll ans = 0;
For(i, 0, x + 1) ans += f[i];
cout << ans << 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
#define pb push_back
#define For(i, s, e) for (ll i = (s); i < (e); i++)
#define Debug_array(a, n) \
for (ll i = (0); i < (n); i++) \
cout << a[i] << " "
#define Foe(i, s, e) for (ll i = (s); i <= (e); i++)
#define Fod(i, s, e) for (ll i = (s)-1; i >= (e); i--)
#define Mod 1000000007
#define pii pair<ll, ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
// #define random_shuffle(indices.begin(), indices.end());
// std::random_device rd;
// std::mt19937 g(rd());
// std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
#define MAX 100000
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n, x;
cin >> n >> x;
ll f[MAX];
memset(f, 0, sizeof(f));
f[0] = 1;
ll a[n];
For(i, 0, n) cin >> a[i];
ll d = 0;
For(i, 0, n) {
d = d + a[i];
f[d]++;
}
ll ans = 0;
For(i, 0, x + 1) ans += f[i];
cout << ans << endl;
} | replace | 32 | 33 | 32 | 33 | 0 | |
p03000 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vch = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for (auto &i : vec)
#define vin(vec) \
for (auto &i : vec) \
cin >> i
#define all(v) v.begin(), v.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 ll mod = 1000000007;
const ll inf = 1LL << 60;
int main() {
ll n, x;
cin >> n >> x;
vll l(n);
vin(l);
ll ans = 0;
while (x >= 0) {
x -= l.at(ans);
ans++;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vch = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for (auto &i : vec)
#define vin(vec) \
for (auto &i : vec) \
cin >> i
#define all(v) v.begin(), v.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 ll mod = 1000000007;
const ll inf = 1LL << 60;
int main() {
ll n, x;
cin >> n >> x;
vll l(n);
vin(l);
ll ans = 1;
while (ans <= n) {
x -= l.at(ans - 1);
if (x < 0)
break;
ans++;
}
cout << ans << endl;
} | replace | 45 | 48 | 45 | 50 | 0 | |
p03000 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// for(int i = 0; i < n; i++)
int main() {
int n, x, d = 0, a = 0;
cin >> n >> x;
vector<int> l(n);
for (int i = 0; i < n; i++)
cin >> l.at(i);
while (d <= x) {
d += l.at(a);
a++;
}
cout << a << endl;
} | #include <bits/stdc++.h>
using namespace std;
// for(int i = 0; i < n; i++)
int main() {
int n, x, d = 0, a = 0;
cin >> n >> x;
vector<int> l(n);
for (int i = 0; i < n; i++)
cin >> l.at(i);
a = n + 1;
for (int i = 0; i < n; i++) {
x -= l.at(i);
if (x < 0) {
a = i + 1;
break;
}
}
cout << a << endl;
} | replace | 10 | 13 | 10 | 17 | 0 | |
p03000 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, X;
cin >> N >> X;
vector<int> L(N);
for (int i = 0; i < N; i++) {
cin >> L.at(i);
}
int D = 0;
int ans = 0;
while (D <= X) {
D += L.at(ans);
ans++;
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, X;
cin >> N >> X;
vector<int> L(N);
for (int i = 0; i < N; i++) {
cin >> L.at(i);
}
int D = 0;
int ans = 1;
while (ans <= N) {
D += L.at(ans - 1);
if (D > X)
break;
ans++;
}
cout << ans << endl;
}
| replace | 11 | 14 | 11 | 16 | 0 | |
p03000 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
int main() {
int n, x, s;
cin >> n >> x;
vector<int> l(n), d(n);
rep(i, n) cin >> l.at(i);
for (int i = 1; i < n + 1; i++) {
d.at(0) = 0;
d.at(i) = d.at(i - 1) + l.at(i - 1);
if (d.at(i) <= x)
s++;
}
s++;
cout << s << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
int main() {
int n, x, s;
cin >> n >> x;
vector<int> l(n), d(n + 1);
rep(i, n) cin >> l.at(i);
for (int i = 1; i < n + 1; i++) {
d.at(0) = 0;
d.at(i) = d.at(i - 1) + l.at(i - 1);
if (d.at(i) <= x)
s++;
}
s++;
cout << s << endl;
} | replace | 8 | 9 | 8 | 9 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 3) >= this->size() (which is 3)
|
p03000 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#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(n) begin(n), end(n)
#define IN(a, x, b) (a <= x && x < b)
#define INIT \
std::ios::sync_with_stdio(false); \
std::cin.tie(0);
template <class T> inline T CHMAX(T &a, const T b) {
return a = (a < b) ? b : a;
}
template <class T> inline T CHMIN(T &a, const T b) {
return a = (a > b) ? b : a;
}
const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
int main() {
INIT;
int N, X;
cin >> N >> X;
vector<int> L(N);
REP(i, N) { cin >> L.at(i); }
vector<int> D(N);
int ans = 0;
D.at(0) = 0;
if (D.at(0) <= X)
ans++;
FOR(i, 1, N + 1) {
D.at(i) = D.at(i - 1) + L.at(i - 1);
if (D.at(i) <= X)
ans++;
}
printf("%d\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#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(n) begin(n), end(n)
#define IN(a, x, b) (a <= x && x < b)
#define INIT \
std::ios::sync_with_stdio(false); \
std::cin.tie(0);
template <class T> inline T CHMAX(T &a, const T b) {
return a = (a < b) ? b : a;
}
template <class T> inline T CHMIN(T &a, const T b) {
return a = (a > b) ? b : a;
}
const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
int main() {
INIT;
int N, X;
cin >> N >> X;
vector<int> L(N);
REP(i, N) cin >> L.at(i);
vector<int> D(N + 1);
int ans = 0;
D.at(0) = 0;
if (D.at(0) <= X)
ans++;
FOR(i, 1, N + 1) {
D.at(i) = D.at(i - 1) + L.at(i - 1);
if (D.at(i) <= X)
ans++;
}
printf("%d\n", ans);
return 0;
} | replace | 29 | 31 | 29 | 31 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 3) >= this->size() (which is 3)
|
p03000 | C++ | Runtime Error | //{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a, b, c, x, ...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__, rep3, rep2, loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__, rrep3, rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, begin, end) \
for (int i = (int)(begin), i##_end = (int)(end); i < i##_end; ++i)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, begin, end) \
for (int i = (int)(end - 1), i##_end = (int)(begin); i >= i##_end; --i)
#define foreach(x, a) for (auto &x : a)
#define each(x, a) for (auto &x : a)
template <class T> void Sort(T &a) { sort(a.begin(), a.end()); }
template <class T, class Compare> void Sort(T &a, Compare comp) {
sort(a.begin(), a.end(), comp);
}
template <class T> void Reverse(T &a) { reverse(a.begin(), a.end()); }
using ll = long long;
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &j) {
o << "{" << j.first << ", " << j.second << "}";
return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U> &j) {
o << "{";
for (auto t = j.begin(); t != j.end(); ++t)
o << (t != j.begin() ? ", " : "") << *t;
o << "}";
return o;
}
template <class T> ostream &operator<<(ostream &o, const set<T> &j) {
o << "{";
for (auto t = j.begin(); t != j.end(); ++t)
o << (t != j.begin() ? ", " : "") << *t;
o << "}";
return o;
}
template <class T> ostream &operator<<(ostream &o, const multiset<T> &j) {
o << "{";
for (auto t = j.begin(); t != j.end(); ++t)
o << (t != j.begin() ? ", " : "") << *t;
o << "}";
return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &j) {
o << "{";
for (int i = 0; i < (int)j.size(); ++i)
o << (i > 0 ? ", " : "") << j[i];
o << "}";
return o;
}
#ifdef LOCAL
inline void dump(void) { cerr << endl; }
template <class Head, class... Tail>
inline void dump(Head &&head, Tail &&...tail) {
cerr << head << " ";
dump(tail...);
}
#define debug(...) \
do { \
cerr << "[L." << __LINE__ << "]\t" << #__VA_ARGS__ << "="; \
dump(__VA_ARGS__); \
} while (0)
#else
#define dump(...)
#define debug(...)
#endif
template <class T, class U> inline bool chmax(T &a, U b) {
return (b > a) ? (a = b, true) : false;
}
template <class T, class U> inline bool chmin(T &a, U b) {
return (b < a) ? (a = b, true) : false;
}
struct IoSetup {
IoSetup() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
cerr << fixed << setprecision(10);
};
} ioSetup;
class in {
int n;
public:
in() {}
in(int n_) : n(n_){};
template <class T> operator T() {
T ret;
cin >> ret;
return ret;
}
template <class T> operator vector<T>() {
vector<T> ret(n);
for (int i = 0; i < n; i++)
cin >> ret[i];
return ret;
}
};
template <class T> void print(const T &a) { cout << a; }
void out() { cout << '\n'; }
template <class T> void out(const T &t) {
print(t);
cout << '\n';
}
template <class Head, class... Tail>
void out(const Head &head, const Tail &...tail) {
print(head);
cout << " ";
out(tail...);
}
template <std::uint_fast64_t Mod> class Modular {
using u64 = std::uint_fast64_t;
public:
u64 a;
constexpr Modular(const u64 x = 0) noexcept : a(x % Mod) {}
constexpr u64 val() const noexcept { return a; }
constexpr Modular operator+(const Modular rhs) const noexcept {
return Modular(*this) += rhs;
}
constexpr Modular operator-(const Modular rhs) const noexcept {
return Modular(*this) -= rhs;
}
constexpr Modular operator*(const Modular rhs) const noexcept {
return Modular(*this) *= rhs;
}
constexpr Modular operator/(const Modular rhs) const noexcept {
return Modular(*this) /= rhs;
}
constexpr bool operator==(const Modular rhs) const noexcept {
return Modular(*this).val() == rhs.val();
}
Modular &operator+=(const Modular rhs) noexcept {
a += rhs.a;
if (a >= Mod)
a -= Mod;
return *this;
}
Modular &operator-=(const Modular rhs) noexcept {
if (a < rhs.a)
a += Mod;
a -= rhs.a;
return *this;
}
Modular &operator++() noexcept { return *this += 1; }
Modular &operator--() noexcept { return *this -= 1; }
Modular &operator*=(const Modular rhs) noexcept {
a = a * rhs.a % Mod;
return *this;
}
Modular &operator/=(Modular rhs) noexcept {
u64 exp = Mod - 2;
while (exp) {
if (exp % 2)
*this *= rhs;
rhs *= rhs;
exp /= 2;
}
return *this;
}
};
template <std::uint_fast64_t Mod>
ostream &operator<<(ostream &os, const Modular<Mod> &m) {
return os << m.a;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const double pi = acos(-1);
const double eps = 1e-9;
const ll inf = 1001001001;
const ll mod = (ll)1e9 + 7;
using mint = Modular<mod>;
//}}}
int main() {
int N = in();
int X = in();
vector<int> L = in();
int sum = 0;
int ans = 1;
rep(i, N) {
sum += L[i];
if (sum <= X)
ans++;
}
out(ans);
}
| //{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a, b, c, x, ...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__, rep3, rep2, loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__, rrep3, rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, begin, end) \
for (int i = (int)(begin), i##_end = (int)(end); i < i##_end; ++i)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, begin, end) \
for (int i = (int)(end - 1), i##_end = (int)(begin); i >= i##_end; --i)
#define foreach(x, a) for (auto &x : a)
#define each(x, a) for (auto &x : a)
template <class T> void Sort(T &a) { sort(a.begin(), a.end()); }
template <class T, class Compare> void Sort(T &a, Compare comp) {
sort(a.begin(), a.end(), comp);
}
template <class T> void Reverse(T &a) { reverse(a.begin(), a.end()); }
using ll = long long;
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &j) {
o << "{" << j.first << ", " << j.second << "}";
return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U> &j) {
o << "{";
for (auto t = j.begin(); t != j.end(); ++t)
o << (t != j.begin() ? ", " : "") << *t;
o << "}";
return o;
}
template <class T> ostream &operator<<(ostream &o, const set<T> &j) {
o << "{";
for (auto t = j.begin(); t != j.end(); ++t)
o << (t != j.begin() ? ", " : "") << *t;
o << "}";
return o;
}
template <class T> ostream &operator<<(ostream &o, const multiset<T> &j) {
o << "{";
for (auto t = j.begin(); t != j.end(); ++t)
o << (t != j.begin() ? ", " : "") << *t;
o << "}";
return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &j) {
o << "{";
for (int i = 0; i < (int)j.size(); ++i)
o << (i > 0 ? ", " : "") << j[i];
o << "}";
return o;
}
#ifdef LOCAL
inline void dump(void) { cerr << endl; }
template <class Head, class... Tail>
inline void dump(Head &&head, Tail &&...tail) {
cerr << head << " ";
dump(tail...);
}
#define debug(...) \
do { \
cerr << "[L." << __LINE__ << "]\t" << #__VA_ARGS__ << "="; \
dump(__VA_ARGS__); \
} while (0)
#else
#define dump(...)
#define debug(...)
#endif
template <class T, class U> inline bool chmax(T &a, U b) {
return (b > a) ? (a = b, true) : false;
}
template <class T, class U> inline bool chmin(T &a, U b) {
return (b < a) ? (a = b, true) : false;
}
struct IoSetup {
IoSetup() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
cerr << fixed << setprecision(10);
};
} ioSetup;
class in {
int n;
public:
in() {}
in(int n_) : n(n_){};
template <class T> operator T() {
T ret;
cin >> ret;
return ret;
}
template <class T> operator vector<T>() {
vector<T> ret(n);
for (int i = 0; i < n; i++)
cin >> ret[i];
return ret;
}
};
template <class T> void print(const T &a) { cout << a; }
void out() { cout << '\n'; }
template <class T> void out(const T &t) {
print(t);
cout << '\n';
}
template <class Head, class... Tail>
void out(const Head &head, const Tail &...tail) {
print(head);
cout << " ";
out(tail...);
}
template <std::uint_fast64_t Mod> class Modular {
using u64 = std::uint_fast64_t;
public:
u64 a;
constexpr Modular(const u64 x = 0) noexcept : a(x % Mod) {}
constexpr u64 val() const noexcept { return a; }
constexpr Modular operator+(const Modular rhs) const noexcept {
return Modular(*this) += rhs;
}
constexpr Modular operator-(const Modular rhs) const noexcept {
return Modular(*this) -= rhs;
}
constexpr Modular operator*(const Modular rhs) const noexcept {
return Modular(*this) *= rhs;
}
constexpr Modular operator/(const Modular rhs) const noexcept {
return Modular(*this) /= rhs;
}
constexpr bool operator==(const Modular rhs) const noexcept {
return Modular(*this).val() == rhs.val();
}
Modular &operator+=(const Modular rhs) noexcept {
a += rhs.a;
if (a >= Mod)
a -= Mod;
return *this;
}
Modular &operator-=(const Modular rhs) noexcept {
if (a < rhs.a)
a += Mod;
a -= rhs.a;
return *this;
}
Modular &operator++() noexcept { return *this += 1; }
Modular &operator--() noexcept { return *this -= 1; }
Modular &operator*=(const Modular rhs) noexcept {
a = a * rhs.a % Mod;
return *this;
}
Modular &operator/=(Modular rhs) noexcept {
u64 exp = Mod - 2;
while (exp) {
if (exp % 2)
*this *= rhs;
rhs *= rhs;
exp /= 2;
}
return *this;
}
};
template <std::uint_fast64_t Mod>
ostream &operator<<(ostream &os, const Modular<Mod> &m) {
return os << m.a;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
const double pi = acos(-1);
const double eps = 1e-9;
const ll inf = 1001001001;
const ll mod = (ll)1e9 + 7;
using mint = Modular<mod>;
//}}}
int main() {
int N = in();
int X = in();
vector<int> L = in(N);
int sum = 0;
int ans = 1;
rep(i, N) {
sum += L[i];
if (sum <= X)
ans++;
}
out(ans);
}
| replace | 193 | 194 | 193 | 194 | 0 | |
p03000 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, X;
cin >> N >> X;
int zahyou = 0, count = 1;
vector<int> vec;
for (int i = 0; i < N; i++) {
cin >> vec.at(i);
zahyou += vec.at(i);
if (zahyou > X) {
break;
}
count++;
}
cout << count << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, X;
cin >> N >> X;
int zahyou = 0, count = 1;
vector<int> vec(N);
for (int i = 0; i < N; i++) {
cin >> vec.at(i);
zahyou += vec.at(i);
if (zahyou > X) {
break;
}
count++;
}
cout << count << endl;
}
| replace | 6 | 7 | 6 | 7 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)
|
p03000 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
int main() {
int N, X;
cin >> N >> X;
vector<int> L(N);
for (int i = 0; i < N; i++)
cin >> L.at(i);
int sum = 0, count = 1;
for (int i = 0;; i++) {
sum += L.at(i);
if (sum <= X)
count++;
else
break;
}
cout << count << endl;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
int main() {
int N, X;
cin >> N >> X;
vector<int> L(N);
for (int i = 0; i < N; i++)
cin >> L.at(i);
int sum = 0, count = 1;
for (int i = 0; i < N; i++) {
sum += L.at(i);
if (sum <= X)
count++;
else
break;
}
cout << count << endl;
}
| replace | 13 | 14 | 13 | 14 | 0 | |
p03000 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int N, X;
cin >> N >> X;
vector<int> L(N);
rep(i, N) { cin >> L.at(i); }
int D = 0;
int cnt = 0;
while (D <= X) {
D += L.at(cnt);
cnt++;
}
cout << cnt << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
int N, X;
cin >> N >> X;
vector<int> L(N);
rep(i, N) { cin >> L.at(i); }
int D = 0;
int cnt = 0;
while (D <= X) {
if (cnt == N) {
cnt++;
break;
}
D += L.at(cnt);
cnt++;
}
cout << cnt << endl;
}
| insert | 16 | 16 | 16 | 20 | 0 | |
p03000 | Python | Runtime Error | N, X = map(int, input().split())
positions = list(map(int, input().split()))
ans = 1
D = 0
for i in range(N + 1):
if D + positions[i] <= X:
D += positions[i]
ans += 1
else:
print(ans)
exit()
print(ans)
| N, X = map(int, input().split())
positions = list(map(int, input().split()))
ans = 1
D = 0
for i in range(N):
if D + positions[i] <= X:
D += positions[i]
ans += 1
else:
print(ans)
exit()
print(ans)
| replace | 6 | 7 | 6 | 7 | 0 | |
p03000 | Python | Runtime Error | a, b = map(int, input().split())
c = list(map(int, input().split()))
d = 1
e = 0
for i in range(a):
e += c[i]
if e <= b:
d += 1
print(d)
a, b = map(int, input().split())
c = list(map(int, input().split()))
d = 1
e = 0
for i in range(a):
e += c[i]
if e <= b:
d += 1
else:
break
print(d)
| a, b = map(int, input().split())
c = list(map(int, input().split()))
d = 1
e = 0
for i in range(a):
e += c[i]
if e <= b:
d += 1
else:
break
print(d)
| delete | 0 | 9 | 0 | 0 | EOFError: EOF when reading a line | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03000/Python/s443147037.py", line 10, in <module>
a, b = map(int, input().split())
EOFError: EOF when reading a line
|
p03000 | Python | Runtime Error | n, x = map(int, input().split())
ls = list(map(int, input().split()))
d = 0
count = 0
while d <= x:
d += ls[count]
count += 1
print(count)
| n, x = map(int, input().split())
ls = list(map(int, input().split()))
d = 0
count = 1
for a in ls:
d += a
if d <= x:
count += 1
print(count)
| replace | 4 | 8 | 4 | 9 | 0 | |
p03000 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, X;
cin >> N >> X;
vector<int> data(5);
for (int i = 0; i < N; i++) {
cin >> data.at(i);
}
int count = 1;
int total = 0;
for (int i = 0; i < N; i++) {
total += data.at(i);
if (total <= X) {
count++;
}
}
cout << count << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N, X;
cin >> N >> X;
vector<int> data(N);
for (int i = 0; i < N; i++) {
cin >> data.at(i);
}
int count = 1;
int total = 0;
for (int i = 0; i < N; i++) {
total += data.at(i);
if (total <= X) {
count++;
}
}
cout << count << endl;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p03000 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
long long n, x;
cin >> n >> x;
vector<int> vec(n);
rep(i, n) cin >> vec.at(i);
long long d = 0;
long long i = 0;
while (d <= x) {
d += vec.at(i);
i++;
}
cout << i << endl;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
long long n, x;
cin >> n >> x;
vector<int> vec(n);
rep(i, n) cin >> vec.at(i);
vector<int> d(n + 1);
rep(i, n) d.at(i + 1) = d.at(i) + vec.at(i);
int ans = 0;
rep(i, n + 1) if (d.at(i) <= x) ans++;
cout << ans << endl;
}
| replace | 9 | 16 | 9 | 14 | 0 | |
p03000 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(s, t) \
for (int s = 0; s < t; s++) \
;
using namespace std;
using ll = long long;
int main() {
int n, x, k;
cin >> n >> x;
vector<int> l(n + 1);
l[0] = 0;
for (int i = 0; i < n; i++) {
cin >> k;
l[i + 1] = l[i] + k;
}
int ans = 0;
for (int i = 0; i <= n; i++) {
while (l[i] <= x) {
ans++;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(s, t) \
for (int s = 0; s < t; s++) \
;
using namespace std;
using ll = long long;
int main() {
int n, x, k;
cin >> n >> x;
vector<int> l(n + 1);
l[0] = 0;
for (int i = 0; i < n; i++) {
cin >> k;
l[i + 1] = l[i] + k;
}
int ans = 0;
for (int i = 0; i <= n; i++) {
if (l[i] <= x) {
ans++;
}
}
cout << ans << endl;
} | replace | 24 | 25 | 24 | 25 | TLE | |
p03000 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, x;
cin >> n >> x;
vector<int> l(n);
for (int i = 0; i < n; ++i) {
cin >> l.at(i);
}
int position = 0;
int ans = 0;
while (position <= x) {
position += l.at(ans);
ans++;
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, x;
cin >> n >> x;
vector<int> l(n);
for (int i = 0; i < n; ++i) {
cin >> l.at(i);
}
int position = 0;
int ans = 1;
for (int j = 0; j < n; ++j) {
position += l.at(j);
if (position <= x)
ans++;
}
cout << ans << endl;
}
| replace | 12 | 16 | 12 | 17 | 0 | |
p03000 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, X;
cin >> N >> X;
vector<int> L(N);
for (int i = 0; i < N; i++) {
cin >> L.at(i);
}
int distance = 0;
int number = 0;
while (distance <= X) {
distance += L.at(number);
number++;
}
cout << number << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, X;
cin >> N >> X;
vector<int> L(N);
for (int i = 0; i < N; i++) {
cin >> L.at(i);
}
int distance = 0;
int number = 0;
while (distance <= X && number <= N) {
if (number < N) {
distance += L.at(number);
}
number++;
}
cout << number << endl;
} | replace | 11 | 13 | 11 | 15 | 0 | |
p03000 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int X, N;
cin >> N >> X;
vector<int> L(N);
for (int i = 0; i < N; i++)
cin >> L.at(i);
int count = 0;
int Dn = 0;
for (int i = 0; Dn < X + 1; i++) {
count++;
Dn += L.at(i);
}
cout << count << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int X, N;
cin >> N >> X;
vector<int> L(N);
for (int i = 0; i < N; i++)
cin >> L.at(i);
int count = 0;
int Dn = 0;
for (int i = 0; Dn < X + 1; i++) {
count++;
Dn += L.at(i);
if (i == N - 1) {
if (Dn < X + 1)
count++;
break;
}
}
cout << count << endl;
} | insert | 14 | 14 | 14 | 19 | 0 | |
p03000 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, x;
cin >> n >> x;
vector<long long> l(n + 1);
for (int i = 0; i < n; i++) {
cin >> l[i];
}
vector<long long> dp(n);
dp[0] = 0;
for (int i = 1; i < n + 1; i++) {
dp[i] = dp[i - 1] + l[i - 1];
}
int ans = 0;
for (int j = 0; j < n + 1; j++) {
if (dp[j] <= x) {
ans++;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, x;
cin >> n >> x;
vector<long long> l(n + 1);
for (int i = 0; i < n; i++) {
cin >> l[i];
}
vector<long long> dp(n + 1);
dp[0] = 0;
for (int i = 1; i < n + 1; i++) {
dp[i] = dp[i - 1] + l[i - 1];
}
int ans = 0;
for (int j = 0; j < n + 1; j++) {
if (dp[j] <= x) {
ans++;
}
}
cout << ans << endl;
}
| replace | 10 | 11 | 10 | 11 | -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)
|
p03000 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, x;
int i = 0;
int xxx = 0;
cin >> n >> x;
vector<int> l(n);
while (i < n) {
cin >> l.at(i++);
}
i = 0;
while (xxx <= x) {
i++;
if (i <= n) {
xxx += l.at(i - 1);
}
}
cout << i << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, x;
int i = 0;
int xxx = 0;
cin >> n >> x;
vector<int> l(n);
while (i < n) {
cin >> l.at(i++);
}
i = 0;
while (xxx <= x) {
i++;
if (i <= n) {
xxx += l.at(i - 1);
} else {
break;
}
}
cout << i << endl;
return 0;
}
| insert | 18 | 18 | 18 | 20 | 0 | |
p03000 | C++ | Runtime Error | #include <iostream>
using namespace std;
int L[101];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, X;
cin >> N >> X;
for (int i = 0; i < N; i++)
cin >> L[i];
int d = 0;
int ans = 0;
int idx = 0;
while (d <= X) {
ans++;
d += L[idx];
idx++;
}
cout << ans << endl;
return 0;
} | #include <iostream>
using namespace std;
int L[101];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, X;
cin >> N >> X;
for (int i = 0; i < N; i++)
cin >> L[i];
int d = 0;
int ans = 0;
int idx = 0;
while (d <= X) {
ans++;
if (idx == N)
break;
d += L[idx];
idx++;
}
cout << ans << endl;
return 0;
} | insert | 17 | 17 | 17 | 19 | 0 | |
p03000 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
int n, x;
cin >> n >> x;
vector<ll> v(n), vv(n);
for (int i = 0; i < n; ++i)
cin >> v[i];
vv[0] = v[0];
for (int i = 1; i <= n; ++i)
vv[i] = vv[i - 1] + v[i];
int cnt = 1;
for (int i = 0; i < n; ++i)
if (vv[i] <= x)
cnt++;
cout << cnt << endl;
return 0;
} | #include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
int n, x;
cin >> n >> x;
vector<ll> v(n), vv(n);
for (int i = 0; i < n; ++i)
cin >> v[i];
vv[0] = v[0];
for (int i = 1; i < n; ++i)
vv[i] = vv[i - 1] + v[i];
int cnt = 1;
for (int i = 0; i < n; ++i)
if (vv[i] <= x)
cnt++;
cout << cnt << endl;
return 0;
} | replace | 11 | 12 | 11 | 12 | -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)
|
p03000 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, x;
cin >> n >> x;
vector<int> l(n);
for (int i = 0; i < n; i++)
cin >> l.at(i);
int count = 1;
int y = 0;
for (int i = 0; i <= n; i++) {
y += l.at(i);
if (y <= x)
count++;
else
break;
}
cout << count << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, x;
cin >> n >> x;
vector<int> l(n);
for (int i = 0; i < n; i++)
cin >> l.at(i);
int count = 1;
int y = 0;
for (int i = 0; i < n; i++) {
y += l.at(i);
if (y <= x)
count++;
else
break;
}
cout << count << endl;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p03000 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int l[105];
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n, x, d = 0, b = 1;
cin >> n >> x;
for (int i = 1; i <= n; ++i) {
cin >> l[i];
}
while (1) {
d = d + l[b];
if (d > x)
break;
b++;
}
cout << b << '\n';
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int l[105];
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int n, x, d = 0, b = 1;
cin >> n >> x;
for (int i = 1; i <= n; ++i) {
cin >> l[i];
}
while (b < n + 1) {
d = d + l[b];
if (d > x)
break;
b++;
}
cout << b << '\n';
return 0;
} | replace | 16 | 17 | 16 | 17 | 0 | |
p03000 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, X;
cin >> N >> X;
vector<int> Vec(N);
for (int i = 0; i < N; i++) {
cin >> Vec.at(i);
}
int count = 0;
while (X > -1 && count < N + 2) {
X -= Vec.at(count);
count++;
}
cout << count << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, X;
cin >> N >> X;
vector<int> Vec(N);
for (int i = 0; i < N; i++) {
cin >> Vec.at(i);
}
int count = 1;
while (count < N + 1) {
X -= Vec.at(count - 1);
if (X > -1) {
count++;
} else {
break;
}
}
cout << count << endl;
} | replace | 10 | 14 | 10 | 18 | 0 | |
p03000 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
int n;
int l[110];
int s[110];
int x;
int main() {
scanf("%d%d", &n, &x);
s[0] = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &(l[i]));
s[i + 1] = s[i] + l[i];
}
int p = 0;
while (s[p] <= x)
p++;
printf("%d\n", p);
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
int n;
int l[110];
int s[110];
int x;
int main() {
scanf("%d%d", &n, &x);
s[0] = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &(l[i]));
s[i + 1] = s[i] + l[i];
}
int p = 0;
while (p <= n && s[p] <= x)
p++;
printf("%d\n", p);
return 0;
}
| replace | 29 | 30 | 29 | 30 | 0 | |
p03000 | C++ | Runtime Error | #include <iostream>
#include <vector>
int main() {
int n, x;
std::cin >> n >> x;
std::vector<int> point(n);
for (auto &e : point)
std::cin >> e;
auto p = 0, count = 0;
while (p <= x) {
p += point.at(count);
++count;
}
std::cout << count;
return 0;
} | #include <iostream>
#include <vector>
int main() {
int n, x;
std::cin >> n >> x;
std::vector<int> point(n);
for (auto &e : point)
std::cin >> e;
auto p = 0, count = 0;
try {
while (p <= x) {
p += point.at(count);
++count;
}
} catch (...) {
count++;
}
std::cout << count;
return 0;
} | replace | 11 | 14 | 11 | 18 | 0 | |
p03000 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> vec(n);
int ans = 0;
int d = 0;
for (int i = 0; i < n; i++) {
cin >> vec.at(i);
}
for (int i = 0; d <= m; i++) {
ans++;
d += vec.at(i);
}
cout << ans;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> vec(n);
int ans = 0;
int d = 0;
for (int i = 0; i < n; i++) {
cin >> vec.at(i);
}
for (int i = 0; d <= m; i++) {
ans++;
if (ans == n + 1)
break;
d += vec.at(i);
}
cout << ans;
}
| insert | 14 | 14 | 14 | 16 | 0 | |
p03000 | C++ | Runtime Error | ///////////////////////////////////////////////////////////
#include <algorithm>
#include <array>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
///////////////////////////////////////////////////////////
#define ll long long
#define ull insigned lon long
///////////////////////////////////////////////////////////
int absolute(int n);
void input(vector<int> &vec);
void print(vector<int> vec);
void upsort(vector<int> &vec);
void downsort(vector<int> &vec);
int maxvec(vector<int> vec);
int minvec(vector<int> vec);
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
int main() {
int N, X;
cin >> N >> X;
vector<int> L(N);
input(L);
vector<int> D(N + 1);
D.at(0) = 0;
D.at(1) = L.at(0);
for (int i = 0; i < N; ++i) {
if (D.at(i) <= X && D.at(i + 1) > X) {
cout << i + 1 << endl;
return 0;
}
D.at(i + 2) = D.at(i + 1) + L.at(i + 1);
}
cout << N + 1 << endl;
return 0;
}
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
int absolute(int n) {
if (n < 0) {
return (-n);
}
return n;
}
void input(vector<int> &vec) {
for (size_t i = 0; i < vec.size(); ++i) {
cin >> vec.at(i);
}
}
void print(vector<int> vec) {
for (size_t i = 0; i < vec.size(); ++i) {
cout << vec.at(i) << " ";
}
cout << endl;
}
void upsort(vector<int> &vec) { sort(vec.begin(), vec.end()); }
void downsort(vector<int> &vec) {
sort(vec.begin(), vec.end(), greater<int>());
}
int maxvec(vector<int> vec) {
int m = vec.at(0);
for (size_t i = 0; i < vec.size(); ++i) {
m = max(m, vec.at(i));
}
return m;
}
int minvec(vector<int> vec) {
int m = vec.at(0);
for (size_t i = 0; i < vec.size(); ++i) {
m = min(m, vec.at(i));
}
return m;
}
/////////////////////////////////////////////////////////// | ///////////////////////////////////////////////////////////
#include <algorithm>
#include <array>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
///////////////////////////////////////////////////////////
#define ll long long
#define ull insigned lon long
///////////////////////////////////////////////////////////
int absolute(int n);
void input(vector<int> &vec);
void print(vector<int> vec);
void upsort(vector<int> &vec);
void downsort(vector<int> &vec);
int maxvec(vector<int> vec);
int minvec(vector<int> vec);
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
int main() {
int N, X;
cin >> N >> X;
vector<int> L(N);
input(L);
vector<int> D(N + 1);
D.at(0) = 0;
D.at(1) = L.at(0);
for (int i = 0; i < N; ++i) {
if (D.at(i) <= X && D.at(i + 1) > X) {
cout << i + 1 << endl;
return 0;
}
if (i < N - 1) {
D.at(i + 2) = D.at(i + 1) + L.at(i + 1);
}
}
cout << N + 1 << endl;
return 0;
}
///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
int absolute(int n) {
if (n < 0) {
return (-n);
}
return n;
}
void input(vector<int> &vec) {
for (size_t i = 0; i < vec.size(); ++i) {
cin >> vec.at(i);
}
}
void print(vector<int> vec) {
for (size_t i = 0; i < vec.size(); ++i) {
cout << vec.at(i) << " ";
}
cout << endl;
}
void upsort(vector<int> &vec) { sort(vec.begin(), vec.end()); }
void downsort(vector<int> &vec) {
sort(vec.begin(), vec.end(), greater<int>());
}
int maxvec(vector<int> vec) {
int m = vec.at(0);
for (size_t i = 0; i < vec.size(); ++i) {
m = max(m, vec.at(i));
}
return m;
}
int minvec(vector<int> vec) {
int m = vec.at(0);
for (size_t i = 0; i < vec.size(); ++i) {
m = min(m, vec.at(i));
}
return m;
}
/////////////////////////////////////////////////////////// | replace | 33 | 34 | 33 | 36 | 0 | |
p03000 | C++ | Runtime Error | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, X;
cin >> N >> X;
vector<int> L(N);
for (int i = 0; i < N; i++)
cin >> L[i];
int sum = 0;
int cnt = 0;
int i = 0;
while (sum <= X) {
cnt += 1;
sum += L[i];
if (cnt == N + 1)
break;
i++;
}
cout << cnt << endl;
} | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, X;
cin >> N >> X;
vector<int> L(N);
for (int i = 0; i < N; i++)
cin >> L[i];
int sum = 0;
int cnt = 0;
int i = 0;
while (sum <= X) {
cnt += 1;
if (i == N)
break;
sum += L[i];
if (cnt == N + 1)
break;
i++;
}
cout << cnt << endl;
} | insert | 15 | 15 | 15 | 17 | 0 | |
p03000 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define str string
#define rep(x, y) for (int i = x; i < y; i++)
#define REP(x, y) for (int j = x; j < y; j++)
#define all(x) x.begin(), x.end()
#define elif else if
// vectordefine
#define vint vector<int>
#define vc vector<char>
#define vtr vector<string>
#define pb(n) push_back(n)
// queuedefine
#define qint queue<int>
#define qc queue<char>
#define qstr queue<str>
// mapdefine
#define mint map<int>
#define mc map<char>
// pairdefine
#define pint pair<int, int>
#define pis pair<int, str>
#define pic pair<int, char>
#define pci pair<char, int>
#define mod 100000007
// main
signed main() {
int N, M, O, P, count = 0, count2 = mod, count3 = 0, stack = 0;
str S, T;
cin >> N >> M;
vint b(N);
rep(0, N) cin >> b[i];
vint a(N + 1);
a[0] = 0;
rep(1, N + 2) { a[i] = a[i - 1] + b[i - 1]; }
rep(0, N + 1) if (M >= a[i]) count += 1;
cout << count << endl;
}
| #include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define str string
#define rep(x, y) for (int i = x; i < y; i++)
#define REP(x, y) for (int j = x; j < y; j++)
#define all(x) x.begin(), x.end()
#define elif else if
// vectordefine
#define vint vector<int>
#define vc vector<char>
#define vtr vector<string>
#define pb(n) push_back(n)
// queuedefine
#define qint queue<int>
#define qc queue<char>
#define qstr queue<str>
// mapdefine
#define mint map<int>
#define mc map<char>
// pairdefine
#define pint pair<int, int>
#define pis pair<int, str>
#define pic pair<int, char>
#define pci pair<char, int>
#define mod 100000007
// main
signed main() {
int N, M, O, P, count = 0, count2 = mod, count3 = 0, stack = 0;
str S, T;
cin >> N >> M;
vint b(N);
rep(0, N) cin >> b[i];
vint a(N + 1);
a[0] = 0;
rep(1, N + 1) { a[i] = a[i - 1] + b[i - 1]; }
rep(0, N + 1) if (M >= a[i]) count += 1;
cout << count << endl;
}
| replace | 36 | 37 | 36 | 37 | 0 | |
p03000 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int N, X;
cin >> N >> X;
vector<int> v(N);
vector<int> s(N);
for (int i = 0; i < N; i++)
cin >> v[i];
for (int i = 0; i <= N; i++) {
s[i + 1] = s[i] + v[i];
}
int ans = 1;
for (int i = 1; i <= N; i++) {
if (s[i] > X)
break;
ans++;
}
cout << ans << endl;
} | #include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int N, X;
cin >> N >> X;
vector<int> v(N + 10);
vector<int> s(N + 10);
for (int i = 0; i < N; i++)
cin >> v[i];
for (int i = 0; i <= N; i++) {
s[i + 1] = s[i] + v[i];
}
int ans = 1;
for (int i = 1; i <= N; i++) {
if (s[i] > X)
break;
ans++;
}
cout << ans << endl;
} | replace | 7 | 9 | 7 | 9 | 0 | |
p03000 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define _GLIBCXX_DEBUG
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pii pair<long long, long long>
#define ppii pair<long long, pair<long long, long long>>
#define all(x) (x).begin(), (x).end()
#define rep(x) for (int i = 0; i < (x); i++)
#define repj(x) for (int j = 0; j < (x); j++)
#define REP(i, x) for (int(i) = 0; (i) < (x); (i)++)
#define rrep(x) for (int i = (x); i >= 0; i--)
#define mod 1000000007
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
typedef vector<vector<long long>> vii;
typedef long long lint;
typedef long long ll;
lint qp(int a, ll b) {
int ans = 1;
do {
if (b & 1)
ans = 1ll * ans * a;
a = 1ll * a * a;
} while (b >>= 1);
return ans;
}
lint qp(int a, ll b, int mo) {
int ans = 1;
do {
if (b & 1)
ans = 1ll * ans * a % mo;
a = 1ll * a * a % mo;
} while (b >>= 1);
return ans;
}
lint gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
long long INF = 1e14;
const int MAX_N = 1 << 17;
const int cf = 100010;
///////////////////////////////////////////////////////////////////////////////
int L[100000];
int main(void) {
int n, x;
cin >> n >> x;
rep(n) cin >> L[i];
int c = 0;
int lyn = 0;
while (lyn <= x) {
lyn += L[c];
c++;
}
cout << c << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define _GLIBCXX_DEBUG
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pii pair<long long, long long>
#define ppii pair<long long, pair<long long, long long>>
#define all(x) (x).begin(), (x).end()
#define rep(x) for (int i = 0; i < (x); i++)
#define repj(x) for (int j = 0; j < (x); j++)
#define REP(i, x) for (int(i) = 0; (i) < (x); (i)++)
#define rrep(x) for (int i = (x); i >= 0; i--)
#define mod 1000000007
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl;
typedef vector<vector<long long>> vii;
typedef long long lint;
typedef long long ll;
lint qp(int a, ll b) {
int ans = 1;
do {
if (b & 1)
ans = 1ll * ans * a;
a = 1ll * a * a;
} while (b >>= 1);
return ans;
}
lint qp(int a, ll b, int mo) {
int ans = 1;
do {
if (b & 1)
ans = 1ll * ans * a % mo;
a = 1ll * a * a % mo;
} while (b >>= 1);
return ans;
}
lint gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
long long INF = 1e14;
const int MAX_N = 1 << 17;
const int cf = 100010;
///////////////////////////////////////////////////////////////////////////////
int L[100000];
int main(void) {
int n, x;
cin >> n >> x;
rep(n) cin >> L[i];
int c = 0;
int lyn = 0;
while (lyn <= x) {
lyn += L[c];
c++;
if (c == n + 1)
break;
}
cout << c << endl;
return 0;
}
| insert | 65 | 65 | 65 | 67 | 0 | |
p03000 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, X;
cin >> N >> X;
vector<int> L(N);
for (int i = 0; i < N; i++) {
cin >> L.at(i);
}
int sum = 0;
int num = 0;
for (int i = 0; sum <= X; i++) {
sum += L.at(i);
num++;
}
cout << num;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N, X;
cin >> N >> X;
vector<int> L(N);
for (int i = 0; i < N; i++) {
cin >> L.at(i);
}
int sum = 0;
int num = 0;
for (int i = 0; sum <= X; i++) {
sum += L.at(i);
num++;
if (i == N - 1) {
if (sum <= X) {
num++;
}
break;
}
}
cout << num;
}
| insert | 15 | 15 | 15 | 21 | 0 | |
p03000 | C++ | Runtime Error | #include <iostream>
#include <vector>
int main() {
int n, x;
std::cin >> n >> x;
std::vector<int> l;
l.push_back(0);
for (int i = 0; i < n; i++) {
int t;
std::cin >> t;
l[i + 1] = (t + l[i]);
}
int s = 0;
int i;
for (i = 0; i <= n; i++) {
if (l[i] <= x) {
s++;
}
}
std::cout << s << std::endl;
return 0;
} | #include <iostream>
#include <vector>
int main() {
int n, x;
std::cin >> n >> x;
std::vector<int> l(n + 1);
l[0] = 0;
for (int i = 0; i < n; i++) {
int t;
std::cin >> t;
l[i + 1] = (t + l[i]);
}
int s = 0;
int i;
for (i = 0; i <= n; i++) {
if (l[i] <= x) {
s++;
}
}
std::cout << s << std::endl;
return 0;
} | replace | 6 | 8 | 6 | 8 | 0 | |
p03001 | C++ | Runtime Error | /// ..:: In The Name Of God ::..
#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 endl '\n'
#define INF 2e9
#define int ll
#define vi vector<int>
#define de deque<int>
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end() // 全範囲指定を簡略化
typedef long long ll;
using namespace std;
// 配列の要素数は sizeof(ar)/sizeof(ar[0]) で求める
signed main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int W, H, x, y;
cin >> W >> H >> x >> y;
double ans = (double)W * H / 2;
if (x + x == W && y + y == H) {
printf("%.10Lf %d\n", ans, x + x == W && y + y == H);
}
}
| /// ..:: In The Name Of God ::..
#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 endl '\n'
#define INF 2e9
#define int ll
#define vi vector<int>
#define de deque<int>
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end() // 全範囲指定を簡略化
typedef long long ll;
using namespace std;
// 配列の要素数は sizeof(ar)/sizeof(ar[0]) で求める
signed main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int W, H, x, y;
cin >> W >> H >> x >> y;
double ans = (double)W * H / 2;
printf("%.10f %d\n", ans, x + x == W && y + y == H);
return 0;
}
| replace | 29 | 32 | 29 | 33 | 0 | |
p03001 | C++ | Runtime Error | #include <stdio.h>
int main() {
int n, m, x, y;
double s;
while (~scanf("%d%d%d%d", &n, &m, &x, &y)) {
s = n * m / 2;
if (n % 2 == 0 && m % 2 == 0 && n / x == 2 && m / y == 2) {
printf("%.7lf 1\n", s);
} else {
printf("%.7lf 0\n", s);
}
}
} | #include <stdio.h>
int main() {
int w, h, x, y;
while (~scanf("%d%d%d%d", &w, &h, &x, &y)) {
double z1, z2;
z1 = w / 2.0;
z2 = h / 2.0;
if (x == z1 && y == z2)
printf("%lf %d\n", double(w) * double(h) / 2, 1);
else
printf("%lf %d\n", double(w) * double(h) / 2, 0);
}
} | replace | 2 | 12 | 2 | 11 | 0 | |
p03001 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
int main() {
double H, W, x, y;
cin >> W >> H >> x >> y;
if ((x == 0 || x == W) && (y == 0 || y == H)) {
printf("%.12lf 0\n", H * W / 2);
return 0;
}
if ((W * y == H * x) || (W * y == H * (W - x))) {
if ((2 * x == W) && (2 * y == H)) {
printf("%.12lf 1\n", H * W / 2);
} else {
printf("%.12lf 0\n", H * W / 2);
}
return 0;
}
if ((x == 0 || x == W) || (y == 0 || y == H)) {
printf("%.12lf 0\n", H * W / 2);
return 1;
}
double tate = min(H * x, H * (W - x));
double yoko = min(y * W, (H - y) * W);
printf("%.12lf %d\n", max(tate, yoko), (tate == yoko));
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
int main() {
double H, W, x, y;
cin >> W >> H >> x >> y;
if ((x == 0 || x == W) && (y == 0 || y == H)) {
printf("%.12lf 0\n", H * W / 2);
return 0;
}
if ((W * y == H * x) || (W * y == H * (W - x))) {
if ((2 * x == W) && (2 * y == H)) {
printf("%.12lf 1\n", H * W / 2);
} else {
printf("%.12lf 0\n", H * W / 2);
}
return 0;
}
printf("%.12lf 0\n", H * W / 2);
return 0;
}
| replace | 20 | 27 | 20 | 22 | 0 | |
p03001 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep_r(i, n, m) for (int i = m; i < n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) \
for (auto itr : x) { \
debug(itr); \
}
template <class T> inline void chmax(T &ans, T t) {
if (t > ans)
ans = t;
}
template <class T> inline void chmin(T &ans, T t) {
if (t < ans)
ans = t;
}
int main() {
double w, h, x, y;
cin >> w >> h >> x >> y;
cout << fixed;
cout << setprecision(12);
if ((x == w and y == h) or (x == 0 and y == h) or (x == w and y == 0) or
(x == 0 and y == 0)) {
cout << (h * w) / 2 << " " << 0 << endl;
return 0;
}
double tx = w / 2, ty = h / 2;
if (x == tx and y == ty) {
cout << (h * w) / 2 << " " << 1 << endl;
return 0;
}
if (x < tx and y > ty) {
double cx = x + tx;
if (cx / tx == y / ty) {
cout << (h * w) / 2 << " " << 0 << endl;
return 0;
}
} else if (x > tx and y < ty) {
double cy = y + ty;
if (x / tx == cy / ty) {
cout << (h * w) / 2 << " " << 0 << endl;
return 0;
}
}
if (x / tx == y / ty) {
cout << (h * w) / 2 << " " << 0 << endl;
return 0;
}
if ((x == 0 or x == w or y == 0 or y == h)) {
cout << (h * w) / 2 << " " << 0 << endl;
return 0;
}
{
double s1 = x * h, s2 = (w - x) * h;
double h1 = y * w, h2 = (h - y) * w;
// cout << s1 << " " << s2 << " " << h1 << " " << h2 << endl;
assert(false);
cout << max(min(s1, s2), min(h1, h2)) << " ";
if (min(s1, s2) == min(h1, h2)) {
cout << 1 << endl;
} else {
cout << 0 << endl;
}
}
}
| #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep_r(i, n, m) for (int i = m; i < n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) \
for (auto itr : x) { \
debug(itr); \
}
template <class T> inline void chmax(T &ans, T t) {
if (t > ans)
ans = t;
}
template <class T> inline void chmin(T &ans, T t) {
if (t < ans)
ans = t;
}
int main() {
double w, h, x, y;
cin >> w >> h >> x >> y;
cout << fixed;
cout << setprecision(12);
if ((x == w and y == h) or (x == 0 and y == h) or (x == w and y == 0) or
(x == 0 and y == 0)) {
cout << (h * w) / 2 << " " << 0 << endl;
return 0;
}
double tx = w / 2, ty = h / 2;
if (x == tx and y == ty) {
cout << (h * w) / 2 << " " << 1 << endl;
return 0;
}
if (x < tx and y > ty) {
double cx = x + tx;
if (cx / tx == y / ty) {
cout << (h * w) / 2 << " " << 0 << endl;
return 0;
}
} else if (x > tx and y < ty) {
double cy = y + ty;
if (x / tx == cy / ty) {
cout << (h * w) / 2 << " " << 0 << endl;
return 0;
}
}
if (x / tx == y / ty) {
cout << (h * w) / 2 << " " << 0 << endl;
return 0;
}
if ((x == 0 or x == w or y == 0 or y == h)) {
cout << (h * w) / 2 << " " << 0 << endl;
return 0;
}
{ cout << (h * w) / 2 << " " << 0 << endl; }
}
| replace | 87 | 99 | 87 | 88 | -6 | 62912dba-56bc-450d-b844-ed61b0db20c1.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03001/C++/s818677345.cpp:82: int main(): Assertion `false' failed.
|
p03001 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1000000007;
#define FOR(i, start, end) for (uint64_t i = start; i < end; i++)
#define REP(i, n) FOR(i, 0, n)
typedef long long ll;
typedef unsigned long long ull;
// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
uint64_t temp;
while (m % n != 0) {
temp = n;
n = m % n;
m = temp;
}
return n;
}
uint64_t lcm(uint64_t m, uint64_t n) { return (m * n) / gcd(m, n); }
// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector<uint64_t>> &v) {
for (uint64_t i = 0; i < v.size(); i++) {
v[i][0] = 1;
v[i][i] = 1;
}
for (uint64_t k = 1; k < v.size(); k++) {
for (uint64_t j = 1; j < k; j++) {
v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
v[k][j] %= MOD;
}
}
}
// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {
uint64_t prod = a * b;
return (prod / b != a);
}
// 素因数分解
void primeFactorization(
uint64_t a, list<uint64_t> &factors) { // 素因数分解を出力するプログラム
long i, sq;
if (a % 2 == 0) { // 偶数の場合
factors.push_back(2);
primeFactorization(a / 2, factors); // 2で割った値で再帰
return;
}
sq = sqrt(a);
for (i = 3; i <= sq; i += 2) { // 3以上√a以下の奇数の場合
if (a % i == 0) {
factors.push_back(i);
primeFactorization(a / i, factors); // 割れた値で再帰
return;
}
}
// 偶数でも3以上√a以下の奇数の場合でも割り切れない場合
if (a != 1) { // aが1でないなら、a自身は素数
factors.push_back(a);
}
}
// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m
int64_t modinv(int64_t a, int64_t m) {
int64_t b = m, u = 1, v = 0;
while (b) {
int64_t t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
// 円周率
// M_PI
// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;
// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;
signed main() {
ll w, h, x, y;
cin >> w >> h >> x >> y;
cout << fixed << setprecision(9) << (w * h) / 2.0 << " ";
if (w / x == 2 && (w % x) == 0 && h / y == 2 && (h % y) == 0) {
cout << "1" << endl;
;
} else {
cout << "0" << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1000000007;
#define FOR(i, start, end) for (uint64_t i = start; i < end; i++)
#define REP(i, n) FOR(i, 0, n)
typedef long long ll;
typedef unsigned long long ull;
// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
uint64_t temp;
while (m % n != 0) {
temp = n;
n = m % n;
m = temp;
}
return n;
}
uint64_t lcm(uint64_t m, uint64_t n) { return (m * n) / gcd(m, n); }
// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector<uint64_t>> &v) {
for (uint64_t i = 0; i < v.size(); i++) {
v[i][0] = 1;
v[i][i] = 1;
}
for (uint64_t k = 1; k < v.size(); k++) {
for (uint64_t j = 1; j < k; j++) {
v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
v[k][j] %= MOD;
}
}
}
// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {
uint64_t prod = a * b;
return (prod / b != a);
}
// 素因数分解
void primeFactorization(
uint64_t a, list<uint64_t> &factors) { // 素因数分解を出力するプログラム
long i, sq;
if (a % 2 == 0) { // 偶数の場合
factors.push_back(2);
primeFactorization(a / 2, factors); // 2で割った値で再帰
return;
}
sq = sqrt(a);
for (i = 3; i <= sq; i += 2) { // 3以上√a以下の奇数の場合
if (a % i == 0) {
factors.push_back(i);
primeFactorization(a / i, factors); // 割れた値で再帰
return;
}
}
// 偶数でも3以上√a以下の奇数の場合でも割り切れない場合
if (a != 1) { // aが1でないなら、a自身は素数
factors.push_back(a);
}
}
// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m
int64_t modinv(int64_t a, int64_t m) {
int64_t b = m, u = 1, v = 0;
while (b) {
int64_t t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0)
u += m;
return u;
}
// 円周率
// M_PI
// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;
// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;
signed main() {
ll w, h, x, y;
cin >> w >> h >> x >> y;
cout << fixed << setprecision(9) << (w * h) / 2.0 << " ";
if (x > 0 && w / x == 2 && (w % x) == 0 && y > 0 && h / y == 2 &&
(h % y) == 0) {
cout << "1" << endl;
;
} else {
cout << "0" << endl;
}
return 0;
}
| replace | 103 | 104 | 103 | 105 | 0 | |
p03001 | Python | Runtime Error | W, H, x, y = map(int, input().split())
ans = [min(x, W - x) * H, min(y, H - y) * W]
if (
(x == 0 and y == 0)
or (x == W and y == 0)
or (x == 0 and y == H)
or (x == W and y == H)
):
print(W * H / 2, 0)
elif y / x == H / W:
if x == W / 2 and y == H / 2:
print(W * H / 2, 1)
else:
print(W * H / 2, 0)
else:
print(max(ans), int(ans[0] == ans[1]))
| W, H, x, y = map(int, input().split())
print(W * H / 2, 1 if W / 2 == x and H / 2 == y else 0)
| replace | 2 | 18 | 2 | 3 | 0 | |
p03001 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
long a, b, c, d;
cin >> a >> b >> c >> d;
cout << a * b / c << ' ' << (a == 2 * c && b == 2 * d) << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
long a, b, c, d;
cin >> a >> b >> c >> d;
cout << a * b / 2.0 << ' ' << (a == 2 * c && b == 2 * d) << endl;
}
| replace | 6 | 7 | 6 | 7 | 0 | |
p03001 | Python | Runtime Error | # 真ん中を通れば必ず二分できてこれが最大値だが、自分自身が真ん中の座標の場合は自分自信を通るどんな直線も二分できる
w, h, x, y = map(int, input().split())
ans1 = (w * h) / 2.0
ans2 = 1 if w // x == h // y == 2 else 0
print(ans1, ans2)
| # 真ん中を通れば必ず二分できてこれが最大値だが、自分自身が真ん中の座標の場合は自分自信を通るどんな直線も二分できる
w, h, x, y = map(int, input().split())
ans1 = (w * h) / 2.0
ans2 = 1 if w / 2 == x and h / 2 == y else 0
print(ans1, ans2)
| replace | 3 | 4 | 3 | 4 | 0 | |
p03001 | Python | Runtime Error | W, H, x, y = map(int, input().split())
jufuku = 0
if x == 0 and y == 0:
if y / x == H / W:
naname = W * H / 2
jufuku = 1
kiri = naname
else:
# 縦
tate = min((W - x) * H, x * H)
# 横
yoko = min(W * (H - y), W * y)
if tate == yoko:
jufuku = 1
kiri = max(tate, yoko)
print(kiri, jufuku)
| W, H, x, y = map(int, input().split())
jufuku = 0
if W / 2 == x and H / 2 == y:
jufuku = 1
print(W * H / 2, jufuku)
| replace | 2 | 16 | 2 | 5 | 0 | |
p03001 | Python | Runtime Error | W, H, x, y = map(int, input().split())
print(W * H / 2, 1 if W / x == 2 and H / y == 2 else 0)
| W, H, x, y = map(int, input().split())
print(W * H / 2, 1 if x != 0 and y != 0 and W / x == 2 and H / y == 2 else 0)
| replace | 1 | 2 | 1 | 2 | 0 | |
p03001 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
uint64_t w, h, x, y;
cin >> w >> h >> x >> y;
vector<double> ws;
ws.push_back((h - y) * w);
ws.push_back(y * w);
vector<double> hs;
hs.push_back(h * (w - x));
hs.push_back(h * x);
vector<double> ds;
if (x > 0 && y > 0) {
double dx = h / (y / x);
double dy = w * (y / x);
if (fabs(w - dx) < DBL_EPSILON || dx < w) {
ds.push_back(dx * h / 2);
ds.push_back(w * h - ds[0]);
} else {
ds.push_back(w * dy / 2);
ds.push_back(w * h - ds[0]);
}
} else {
ds.push_back(0);
ds.push_back(0);
}
sort(ws.begin(), ws.end(), greater<double>());
sort(hs.begin(), hs.end(), greater<double>());
sort(ds.begin(), ds.end(), greater<double>());
vector<double> tmp(3);
tmp[0] = ws[1];
tmp[1] = hs[1];
tmp[2] = ds[1];
sort(tmp.begin(), tmp.end(), greater<double>());
cout << tmp[0] << endl;
bool b = false;
for (int i = 0; i < tmp.size(); ++i) {
for (int j = 0; j < tmp.size(); ++j) {
if (i == j)
continue;
if (fabs(tmp[i] - tmp[j]) < DBL_EPSILON) {
b = true;
break;
}
}
}
if (b) {
cout << 1 << endl;
} else {
cout << 0 << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
uint64_t w, h, x, y;
cin >> w >> h >> x >> y;
cout << w * h / (double)2 << endl;
cout << (x + x == w && y + y == h) << endl;
return 0;
} | replace | 7 | 61 | 7 | 9 | 0 | |
p03001 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <vector>
using namespace std;
int main() {
int n, m, x, y;
cin >> n >> m >> x >> y;
map<long long, int> cnt;
long long a = 1ll * n * x, b = 1ll * n * (m - x);
if (a > 0 && b > 0)
cnt[min(a, b)]++;
a = 1ll * m * x, b = 1ll * m * (n - x);
if (a > 0 && b > 0)
cnt[min(a, b)]++;
auto it = *(--cnt.end());
cout << it.first << " " << it.second - 1 << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <vector>
using namespace std;
int main() {
int n, m, x, y;
cin >> n >> m >> x >> y;
fixed(cout);
cout.precision(12);
cout << (1ll * n * m) / 2.0 << " ";
if (n % 2 == 0 && m % 2 == 0 && x == n / 2 && y == m / 2) {
cout << 1 << endl;
} else {
cout << 0 << endl;
}
return 0;
}
| replace | 23 | 32 | 23 | 31 | 0 | |
p03001 | C++ | Runtime Error | #include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;
using namespace std;
using ll = long long;
int main(int argc, char *argv[]) {
ll w, h, x, y;
cin >> w >> h >> x >> y;
cout << fixed << setprecision(20) << (double)w * h / (double)2 << " ";
if (x == w / 2 && y == h / 2 && (w % x == 0) && (h % y == 0)) {
MSG(1)
} else {
MSG(0)
}
return 0;
}
| #include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;
using namespace std;
using ll = long long;
int main(int argc, char *argv[]) {
ll w, h, x, y;
cin >> w >> h >> x >> y;
cout << fixed << setprecision(20) << (double)w * h / (double)2 << " ";
if (x == w / 2 && y == h / 2 && x != 0 && y != 0 && (w % x == 0) &&
(h % y == 0)) {
MSG(1)
} else {
MSG(0)
}
return 0;
}
| replace | 18 | 19 | 18 | 20 | 0 | |
p03001 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int w, h, x, y;
cin >> w >> h >> x >> y;
cout << setprecision(15) << (double)w * h / 2.0 << " ";
cout << (w / x * 2 == w && h / y * 2 == h ? 1 : 0) << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int w, h, x, y;
cin >> w >> h >> x >> y;
cout << setprecision(15) << (double)w * h / 2.0 << " ";
cout << (x && y && w / x / 2 * x * 2 == w && h / y / 2 * y * 2 == h ? 1 : 0)
<< endl;
return 0;
} | replace | 9 | 10 | 9 | 11 | 0 | |
p03001 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
int main() {
int W, H, x, y;
cin >> W >> H >> x >> y;
printf("%.9f %d\n", W * H / 2.0, W * H / (x * y) == 4.0);
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
int main() {
double W, H, x, y;
cin >> W >> H >> x >> y;
printf("%.9f %d\n", W * H / 2.0, W * H / (x * y) == 4.0);
}
| replace | 11 | 12 | 11 | 12 | 0 | |
p03001 | C++ | Runtime Error | #include <iomanip>
#include <iostream>
using namespace std;
int w, h, x, y;
int main() {
cin >> w >> h >> x >> y;
cout << setprecision(20) << (long double)w * (long double)h / 2.0 << " ";
if (w / 2 == x && h / 2 == y && w % x == 0 && h % y == 0)
cout << 1 << endl;
else
cout << 0 << endl;
return 0;
} | #include <iomanip>
#include <iostream>
using namespace std;
int w, h, x, y;
int main() {
cin >> w >> h >> x >> y;
cout << (double)w * (double)h / 2.0 << " ";
if (x == 0 || y == 0) {
cout << 0 << endl;
return 0;
}
if (w / 2 == x && h / 2 == y && w % x == 0 && h % y == 0)
cout << 1 << endl;
else
cout << 0 << endl;
return 0;
} | replace | 9 | 10 | 9 | 14 | 0 | |
p03001 | C++ | Runtime Error | #include <stdio.h>
int main() {
long long w, h, x, y;
double s;
int t;
while (~scanf("%lld%lld%lld%lld", &w, &h, &x, &y)) {
t = 0;
s = (double)w * (double)h / 2;
if (w % 2 == 0 && h % 2 == 0 && x == w / 2 && y == h / 2)
t = 1;
printf("%.6llf %d\n", s, t);
}
return 0;
} | #include <stdio.h>
int main() {
long long w, h, x, y;
double s;
int t;
while (~scanf("%lld%lld%lld%lld", &w, &h, &x, &y)) {
t = 0;
s = (double)w * (double)h / 2;
if (w % 2 == 0 && h % 2 == 0 && x == w / 2 && y == h / 2)
t = 1;
printf("%.6lf %d\n", s, t);
}
return 0;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p03001 | C++ | Runtime Error | #include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; // 1e18
const double EPS = 1e-10;
int main(void) {
std::cout << std::fixed << std::setprecision(10);
ll W, H, x, y;
cin >> W >> H >> x >> y;
printf("%llf %d\n", (double)W * (double)H / 2, (x + x == W) && (y + y == H));
return (0);
} | #include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; // 1e18
const double EPS = 1e-10;
int main(void) {
std::cout << std::fixed << std::setprecision(10);
ll W, H, x, y;
cin >> W >> H >> x >> y;
printf("%lf %d\n", (double)W * (double)H / 2, (x + x == W) && (y + y == H));
return (0);
} | replace | 13 | 14 | 13 | 14 | 0 | |
p03001 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define PRI(n) cout << n << " " << endl;
#define PRI2(n, m) cout << n << " " << m << " " << endl;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, t, n) for (int i = t; i <= (int)n; ++i)
const char alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
const ll MOD = 1e9 + 7;
struct edge;
struct UnionFind;
bool isPrime(ll x);
ll GCD(ll a, ll b);
ll LCM(ll a, ll b);
ll nCr(int n, int r);
struct UnionFind {
vector<int> par;
vector<int> rank;
UnionFind(int N) {
for (int i = 0; i < N; ++i) {
par.push_back(i);
rank.push_back(0);
}
}
int find(int x) {
if (par[x] == x)
return x;
else
return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)
return;
if (rank[x] < rank[y])
par[x] = y;
else {
par[y] = x;
if (rank[x] == rank[y])
rank[x]++;
}
}
bool same(int x, int y) { return find(x) == find(y); }
};
ll M, N;
int main() {
ll H, W, x, y;
cin >> H >> W >> x >> y;
int ansS = 0;
if (H % x == 0 && W % y == 0)
ansS = 1;
double d1 = min(x * W, (H - x) * W);
double d2 = min(y * H, (W - y) * H);
printf("%10f %d", max(d1, d2), ansS);
return 0;
}
struct edge {
int to, cost;
bool flag = false;
};
bool isPrime(ll x) {
if (x == 0)
return 0;
if (x == 1)
return 0;
if (x == 2)
return 1;
if (x % 2 == 0)
return 0;
FOR(i, 3, x - 1) {
if (x % i == 0)
return 0;
}
return 1;
}
ll GCD(ll a, ll b) {
if (b == 0)
return a;
return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
ll gcd = GCD(a, b);
return a / gcd * b;
}
ll nCr(int n, int r) {
vector<ll> C(r + 1);
C[0] = 1;
FOR(i, 1, n)
for (int j = min(i, r); j < 1; --j) C[j] = (C[j] + C[j - 1]) % MOD;
return C[r];
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define PRI(n) cout << n << " " << endl;
#define PRI2(n, m) cout << n << " " << m << " " << endl;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, t, n) for (int i = t; i <= (int)n; ++i)
const char alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
const ll MOD = 1e9 + 7;
struct edge;
struct UnionFind;
bool isPrime(ll x);
ll GCD(ll a, ll b);
ll LCM(ll a, ll b);
ll nCr(int n, int r);
struct UnionFind {
vector<int> par;
vector<int> rank;
UnionFind(int N) {
for (int i = 0; i < N; ++i) {
par.push_back(i);
rank.push_back(0);
}
}
int find(int x) {
if (par[x] == x)
return x;
else
return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)
return;
if (rank[x] < rank[y])
par[x] = y;
else {
par[y] = x;
if (rank[x] == rank[y])
rank[x]++;
}
}
bool same(int x, int y) { return find(x) == find(y); }
};
ll M, N;
int main() {
ll H, W, x, y;
cin >> H >> W >> x >> y;
int ans = 0;
if (x == 0 || y == 0)
ans = 0;
else if (x * 2 == H && y * 2 == W)
ans = 1;
printf("%10f %d", double(H) * double(W) / 2, ans);
return 0;
}
struct edge {
int to, cost;
bool flag = false;
};
bool isPrime(ll x) {
if (x == 0)
return 0;
if (x == 1)
return 0;
if (x == 2)
return 1;
if (x % 2 == 0)
return 0;
FOR(i, 3, x - 1) {
if (x % i == 0)
return 0;
}
return 1;
}
ll GCD(ll a, ll b) {
if (b == 0)
return a;
return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
ll gcd = GCD(a, b);
return a / gcd * b;
}
ll nCr(int n, int r) {
vector<ll> C(r + 1);
C[0] = 1;
FOR(i, 1, n)
for (int j = min(i, r); j < 1; --j) C[j] = (C[j] + C[j - 1]) % MOD;
return C[r];
}
| replace | 78 | 84 | 78 | 84 | 0 | |
p03001 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
long W, H, x, y;
cin >> W >> H >> x >> y;
cout << fixed << (double(W) * double(H) / 2) << " "
<< ((H % y == 0 && W % x == 0) ? 1 : 0) << endl;
}
| #include <iostream>
using namespace std;
int main() {
long W, H, x, y;
cin >> W >> H >> x >> y;
cout << ((double)W * (double)H / 2.0) << " "
<< ((x + x == W && y + y == H) ? 1 : 0) << endl;
}
| replace | 7 | 9 | 7 | 9 | 0 | |
p03001 | C++ | Runtime Error | #include <stdio.h>
#define ll long long
int main() {
ll w, h, x, y;
double ans1 = 0;
scanf("%lld%lld%lld%lld", &w, &h, &x, &y);
ans1 = (double)((w * h) / 2.0);
if (w % x == 0 && h % y == 0) {
printf("%.6lf 1\n", ans1);
} else {
printf("%.6lf 0\n", ans1);
}
}
| #include <stdio.h>
#define ll long long
int main() {
ll w, h, x, y;
double ans1 = 0;
scanf("%lld%lld%lld%lld", &w, &h, &x, &y);
ans1 = (double)((w * h) / 2.0);
if (w == 2 * x && h == 2 * y) {
printf("%.6lf 1\n", ans1);
} else {
printf("%.6lf 0\n", ans1);
}
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p03001 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;
int main() {
LL W, H, x, y;
std::cin >> W >> H >> x >> y;
LL X = (y < H - y) ? y * W : (H - y) * W;
LL Y = (x < W - x) ? x * H : (W - x) * H;
if (y == H - y && x == W - x) {
double ans = y * W;
printf("%.9f 1\n", ans);
assert(false);
} else {
double ans = std::max(X, Y);
printf("%.9f 0\n", ans);
}
}
| #include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
constexpr int kMod = 1000000007;
typedef long long LL;
int main() {
LL W, H, x, y;
std::cin >> W >> H >> x >> y;
double ans = (double)(W * H) / 2;
bool b = ((x == W - x) && (y == H - y));
printf("%lf %d\n", ans, b);
}
| replace | 18 | 30 | 18 | 21 | 0 | |
p03001 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int N, X;
int L[100];
L[0] = 0;
cin >> N >> X;
for (int i = 1; i <= N; i++) {
cin >> L[i];
L[i] += L[i - 1];
}
bool a = false;
for (int i = 0; i <= N; i++) {
if (X < L[i]) {
cout << i << endl;
a = true;
break;
}
}
if (!a) {
cout << N + 1 << endl;
}
}
| #include <iostream>
using namespace std;
int main() {
double W, H, x, y;
cin >> W >> H >> x >> y;
cout << W * H / 2.0 << " " << (x * 2 == W && y * 2 == H) << endl;
}
| replace | 5 | 24 | 5 | 8 | 0 | |
p03001 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("Input.txt", "r", stdin);
freopen("Output.txt", "w", stdout);
#endif
double W, H, x, y;
cin >> W >> H >> x >> y;
cout << fixed;
cout << setprecision(10);
double area = (W * H) / 2;
double midx = W / 2;
double midy = H / 2;
if (midx == x && midy == y)
cout << area << " " << 1 << endl;
else
cout << area << " " << 0 << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
double W, H, x, y;
cin >> W >> H >> x >> y;
cout << fixed;
cout << setprecision(10);
double area = (W * H) / 2;
double midx = W / 2;
double midy = H / 2;
if (midx == x && midy == y)
cout << area << " " << 1 << endl;
else
cout << area << " " << 0 << endl;
return 0;
} | delete | 7 | 12 | 7 | 7 | 0 | |
p03001 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, x, i;
cin >> n >> x;
long long int arr[n];
for (i = 0; i < n; i++)
cin >> arr[i];
long long int d = 0;
i = 0;
long long int count = 0;
do {
count++;
d = d + arr[i];
i++;
} while (d <= x && count <= n + 1);
cout << count << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
double w, h, x, y, area;
cin >> w >> h >> x >> y;
cout << (w * h) / 2;
if (x == w / 2 && y == h / 2) {
cout << " 1" << endl;
} else
cout << " 0" << endl;
return 0;
} | replace | 3 | 17 | 3 | 11 | 0 | |
p03001 | C++ | Runtime Error | #include <assert.h>
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
i64 w, h, x, y;
cin >> w >> h >> x >> y;
if ((x == 0 && y == 0) || (x == w && y == 0) || (x == w && y == h) ||
(x == 0 && y == h))
return -1; // cout << fixed << setprecision(10) << (double)w * h / 2 << " 0"
// << endl;
else if (x * 2 == w || y * 2 == h)
return -1; // cout << fixed << setprecision(10) << (double)w * h / 2 << (x
// == 0 || x == h || y == 0 || y == w ? " 0" : " 1") << endl;
else
cout << fixed << setprecision(10)
<< max(min(w - x, x) * h, min(h - y, y) * w) << " 0" << endl;
return 0;
}
| #include <assert.h>
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
i64 w, h, x, y;
cin >> w >> h >> x >> y;
cout << fixed << setprecision(10) << (double)w * h / 2 << " "
<< (x * 2 == w && y * 2 == h ? 1 : 0) << endl;
return 0;
}
| replace | 8 | 18 | 8 | 10 | 255 | |
p03001 | C++ | Runtime Error | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath> // abs() for float, and fabs()
#include <cstdlib> // abs() for integer 絶対値求めやつ
#include <iomanip> //浮動小数点数を出力する制度の指定
#include <limits>
#include <numeric>
#include <string>
#include <type_traits>
#include <vector>
// 使い方 数値をnumとして cout<<setprecision(n)<<num ;nは桁数
#define rep(i, n) for (int i = 0; i < (n); i++)
#define SORT(a) sort((a).begin(), (a).end())
#define REV(a) reverse((a).begin(), (a).end())
using namespace std;
using ll = long long;
#define INF 2000000000
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;
}
#define che(a, string) cout << "//" << string << "==" << (a) << "//" << endl;
bool IsInt(double a) {
int b = a / 1;
if (a == b) {
return true;
} else {
return false;
}
}
/*覚えてないことメaモ
数値型から文字列に変換 to_string(number);これは簡単
文字列から数値型に変換 stoi(number)
文字列からllに変換 stoll(number)*/
// ここから書き始める
// 実験
int main() {
ll w, h, x, y;
cin >> w >> h >> x >> y;
// 正確にxがwの半分 y がhの半分なら複数ある。
int way = 0;
// wとhの半分を正確にとる それって、w/xが2.0になっればいいんじゃね?
if ((w / x) == 2 && w % x == 0 && (h / y) == 0 && h % y == 0) {
way = 1;
}
cout << 1. * (w * h) / 2. << " " << way << endl;
}
| #include <algorithm>
#include <bits/stdc++.h>
#include <cmath> // abs() for float, and fabs()
#include <cstdlib> // abs() for integer 絶対値求めやつ
#include <iomanip> //浮動小数点数を出力する制度の指定
#include <limits>
#include <numeric>
#include <string>
#include <type_traits>
#include <vector>
// 使い方 数値をnumとして cout<<setprecision(n)<<num ;nは桁数
#define rep(i, n) for (int i = 0; i < (n); i++)
#define SORT(a) sort((a).begin(), (a).end())
#define REV(a) reverse((a).begin(), (a).end())
using namespace std;
using ll = long long;
#define INF 2000000000
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;
}
#define che(a, string) cout << "//" << string << "==" << (a) << "//" << endl;
bool IsInt(double a) {
int b = a / 1;
if (a == b) {
return true;
} else {
return false;
}
}
/*覚えてないことメaモ
数値型から文字列に変換 to_string(number);これは簡単
文字列から数値型に変換 stoi(number)
文字列からllに変換 stoll(number)*/
// ここから書き始める
// 実験
int main() {
ll w, h, x, y;
cin >> w >> h >> x >> y;
// 正確にxがwの半分 y がhの半分なら複数ある。
int way = 0;
// wとhの半分を正確にとる それって、w/xが2.0になっればいいんじゃね?
if (x != 0 && y != 0) {
if ((w / x) == 2 && w % x == 0 && (h / y) == 2 && h % y == 0) {
way = 1;
}
}
cout << 1. * (w * h) / 2. << " " << way << endl;
}
| replace | 55 | 57 | 55 | 59 | 0 | |
p03003 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <deque>
#include <fstream>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
constexpr long long int MOD = 1000000007LL;
long long int search(const int s, const int t, const std::vector<int> &s_list,
const std::vector<int> &t_list,
std::vector<std::vector<long long int>> &memo) {
if (s >= s_list.size() || t >= t_list.size())
return 1;
else if (memo[s][t] >= 0)
return memo[s][t];
else if (s_list[s] == t_list[t])
return memo[s][t] = (search(s + 1, t, s_list, t_list, memo) +
search(s, t + 1, s_list, t_list, memo)) %
MOD;
else
return memo[s][t] = (search(s + 1, t, s_list, t_list, memo) +
search(s, t + 1, s_list, t_list, memo) -
search(s + 1, t + 1, s_list, t_list, memo)) %
MOD;
}
int main() {
int n, m;
std::cin >> n >> m;
std::vector<int> s_list(n), t_list(m);
for (auto &s : s_list)
std::cin >> s;
for (auto &t : t_list)
std::cin >> t;
std::vector<std::vector<long long int>> memo(
n, std::vector<long long int>(m, -1));
std::cout << search(0, 0, s_list, t_list, memo) << std::endl;
}
| #include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <deque>
#include <fstream>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
constexpr long long int MOD = 1000000007LL;
long long int search(const int s, const int t, const std::vector<int> &s_list,
const std::vector<int> &t_list,
std::vector<std::vector<long long int>> &memo) {
if (s >= s_list.size() || t >= t_list.size())
return 1;
else if (memo[s][t] >= 0)
return memo[s][t];
else if (s_list[s] == t_list[t])
return memo[s][t] = (search(s + 1, t, s_list, t_list, memo) +
search(s, t + 1, s_list, t_list, memo)) %
MOD;
else
return memo[s][t] = (search(s + 1, t, s_list, t_list, memo) +
search(s, t + 1, s_list, t_list, memo) -
search(s + 1, t + 1, s_list, t_list, memo)) %
MOD;
}
int main() {
int n, m;
std::cin >> n >> m;
std::vector<int> s_list(n), t_list(m);
for (auto &s : s_list)
std::cin >> s;
for (auto &t : t_list)
std::cin >> t;
std::vector<std::vector<long long int>> memo(
n + 1, std::vector<long long int>(m + 1, -1));
for (auto i = 0; i <= m; ++i) {
memo[n][i] = 1;
}
for (auto i = 0; i <= n; ++i) {
memo[i][m] = 1;
}
for (int i = n - 1; i >= 0; --i) {
for (int j = m - 1; j >= 0; --j) {
if (s_list[i] == t_list[j]) {
memo[i][j] = (memo[i + 1][j] + memo[i][j + 1]) % MOD;
} else {
memo[i][j] =
(memo[i + 1][j] + memo[i][j + 1] - memo[i + 1][j + 1] + MOD) % MOD;
}
}
}
std::cout << memo[0][0] << std::endl;
}
| replace | 49 | 51 | 49 | 67 | TLE | |
p03003 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
// auto mod int
const int mod = 1000000007;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
int main() {
int n, m;
cin >> n >> m;
vector<int> s(n), t(m);
rep(i, n) cin >> s[i];
rep(i, m) cin >> t[i];
vector<vector<mint>> dp(n + 1, vector<mint>(m + 1));
dp[0][0] = 1;
rep(i, n) dp[i + 1][0] = 1;
rep(j, n) dp[0][j + 1] = 1;
rep(i, n) rep(j, m) {
dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j];
if (s[i] != t[j]) {
dp[i + 1][j + 1] -= dp[i][j];
}
}
cout << dp[n][m] << endl;
}
| #include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
// auto mod int
const int mod = 1000000007;
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }
int main() {
int n, m;
cin >> n >> m;
vector<int> s(n), t(m);
rep(i, n) cin >> s[i];
rep(i, m) cin >> t[i];
vector<vector<mint>> dp(n + 1, vector<mint>(m + 1));
dp[0][0] = 1;
rep(i, n) dp[i + 1][0] = 1;
rep(j, m) dp[0][j + 1] = 1;
rep(i, n) rep(j, m) {
dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j];
if (s[i] != t[j]) {
dp[i + 1][j + 1] -= dp[i][j];
}
}
cout << dp[n][m] << endl;
}
| replace | 64 | 65 | 64 | 65 | 0 | |
p03003 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
// #undef DEBUG // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T> void debug(T value) { std::cerr << value; }
template <typename T, typename... Ts> void debug(T value, Ts... args) {
std::cerr << value << ", ";
debug(args...);
}
#define dbg(...) \
do { \
cerr << #__VA_ARGS__ << ": "; \
debug(__VA_ARGS__); \
cerr << " (L" << __LINE__ << ")" << endl; \
} while (0)
#else
#define dbg(...)
#endif
void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T &value, Ts &...args) {
std::cin >> value;
read_from_cin(args...);
}
#define in(type, ...) \
type __VA_ARGS__; \
read_from_cin(__VA_ARGS__);
template <typename T> void write_to_cout(const T &value) {
std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T &value, const Ts &...args) {
std::cout << value << ' ';
write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using ll = long long;
using namespace std;
template <int Mod> class ModInt {
public:
ModInt() : n_(0) {}
ModInt(long long n) : n_(n % Mod) {
if (n_ < 0) {
// In C++, (-n)%m == -(n%m).
n_ += Mod;
}
}
ModInt &operator+=(const ModInt &m) {
n_ += m.n_;
if (n_ >= Mod) {
n_ -= Mod;
}
return *this;
}
ModInt &operator++() { return (*this) += 1; }
ModInt &operator-=(const ModInt &m) {
n_ -= m.n_;
if (n_ < 0) {
n_ += Mod;
}
return *this;
}
ModInt &operator--() { return (*this) -= 1; }
ModInt &operator*=(const ModInt &m) {
n_ *= m.n_;
n_ %= Mod;
return *this;
}
ModInt &operator/=(const ModInt &m) {
*this *= m.Inv();
return *this;
}
#define DEFINE_BINARY_OPERATOR(op) \
ModInt operator op(const ModInt &m) const { return ModInt(*this) op## = m; }
DEFINE_BINARY_OPERATOR(+)
DEFINE_BINARY_OPERATOR(-)
DEFINE_BINARY_OPERATOR(*)
DEFINE_BINARY_OPERATOR(/)
#undef DEFINE_BINARY_OPERATOR
#define DEFINE_COMPARISON_OPERATOR(op) \
bool operator op(const ModInt &m) const { return n_ op m.n_; }
DEFINE_COMPARISON_OPERATOR(!=)
DEFINE_COMPARISON_OPERATOR(<)
DEFINE_COMPARISON_OPERATOR(<=)
DEFINE_COMPARISON_OPERATOR(==)
DEFINE_COMPARISON_OPERATOR(>)
DEFINE_COMPARISON_OPERATOR(>=)
#undef BDEFINE_COMPARISON_OPERATOR
ModInt operator-() const { return ModInt(-n_); }
ModInt Pow(int n) const {
if (n < 0) {
return Inv().Pow(-n);
}
// a * b ^ n = answer.
ModInt a = 1, b = *this;
while (n != 0) {
if (n & 1) {
a *= b;
}
n /= 2;
b *= b;
}
return a;
}
ModInt Inv() const {
// Compute the inverse based on Fermat's little theorem. Note that this only
// works when n_ and Mod are relatively prime. The theorem says that
// n_^(Mod-1) = 1 (mod Mod). So we can compute n_^(Mod-2).
return Pow(Mod - 2);
}
long long value() const { return n_; }
static ModInt Fact(int n) {
for (int i = fact_.size(); i <= n; ++i) {
fact_.push_back(i == 0 ? 1 : fact_.back() * i);
}
return fact_[n];
}
static ModInt Comb(int n, int k) { return Perm(n, k) / Fact(k); }
static ModInt CombSlow(int n, int k) { return PermSlow(n, k) / Fact(k); }
static ModInt Perm(int n, int k) {
#if DEBUG
assert(n <= 1000000 &&
"n is too large. If k is small, consider using PermSlow.");
#endif
return Fact(n) / Fact(n - k);
}
static ModInt PermSlow(int n, int k) {
ModInt p = 1;
for (int i = 0; i < k; ++i) {
p *= (n - i);
}
return p;
}
private:
long long n_;
static std::vector<ModInt> fact_;
};
template <int Mod> std::vector<ModInt<Mod>> ModInt<Mod>::fact_;
template <int Mod>
std::ostream &operator<<(std::ostream &out, const ModInt<Mod> &m) {
out << m.value();
return out;
}
using mint = ModInt<1000000007>;
int main() {
in(int, n, m);
vector<int> s(n);
rep(i, n) cin >> s[i];
vector<int> t(m);
rep(i, m) cin >> t[i];
vector<vector<mint>> dp(n + 1, vector<mint>(m + 1));
rep(i, n + 1) dp[i][0] = 1;
rep(i, m + 1) dp[0][i] = 1;
rep(i, n) rep(j, m) {
dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1] - dp[i][j];
if (s[i] == t[j])
dp[i + 1][j + 1] += dp[i][j];
}
rep(i, n + 1) {
rep(j, m + 1) cerr << dp[i][j] << " ";
cerr << endl;
}
out(dp[n][m]);
}
| #include <bits/stdc++.h>
// #undef DEBUG // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T> void debug(T value) { std::cerr << value; }
template <typename T, typename... Ts> void debug(T value, Ts... args) {
std::cerr << value << ", ";
debug(args...);
}
#define dbg(...) \
do { \
cerr << #__VA_ARGS__ << ": "; \
debug(__VA_ARGS__); \
cerr << " (L" << __LINE__ << ")" << endl; \
} while (0)
#else
#define dbg(...)
#endif
void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T &value, Ts &...args) {
std::cin >> value;
read_from_cin(args...);
}
#define in(type, ...) \
type __VA_ARGS__; \
read_from_cin(__VA_ARGS__);
template <typename T> void write_to_cout(const T &value) {
std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T &value, const Ts &...args) {
std::cout << value << ' ';
write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using ll = long long;
using namespace std;
template <int Mod> class ModInt {
public:
ModInt() : n_(0) {}
ModInt(long long n) : n_(n % Mod) {
if (n_ < 0) {
// In C++, (-n)%m == -(n%m).
n_ += Mod;
}
}
ModInt &operator+=(const ModInt &m) {
n_ += m.n_;
if (n_ >= Mod) {
n_ -= Mod;
}
return *this;
}
ModInt &operator++() { return (*this) += 1; }
ModInt &operator-=(const ModInt &m) {
n_ -= m.n_;
if (n_ < 0) {
n_ += Mod;
}
return *this;
}
ModInt &operator--() { return (*this) -= 1; }
ModInt &operator*=(const ModInt &m) {
n_ *= m.n_;
n_ %= Mod;
return *this;
}
ModInt &operator/=(const ModInt &m) {
*this *= m.Inv();
return *this;
}
#define DEFINE_BINARY_OPERATOR(op) \
ModInt operator op(const ModInt &m) const { return ModInt(*this) op## = m; }
DEFINE_BINARY_OPERATOR(+)
DEFINE_BINARY_OPERATOR(-)
DEFINE_BINARY_OPERATOR(*)
DEFINE_BINARY_OPERATOR(/)
#undef DEFINE_BINARY_OPERATOR
#define DEFINE_COMPARISON_OPERATOR(op) \
bool operator op(const ModInt &m) const { return n_ op m.n_; }
DEFINE_COMPARISON_OPERATOR(!=)
DEFINE_COMPARISON_OPERATOR(<)
DEFINE_COMPARISON_OPERATOR(<=)
DEFINE_COMPARISON_OPERATOR(==)
DEFINE_COMPARISON_OPERATOR(>)
DEFINE_COMPARISON_OPERATOR(>=)
#undef BDEFINE_COMPARISON_OPERATOR
ModInt operator-() const { return ModInt(-n_); }
ModInt Pow(int n) const {
if (n < 0) {
return Inv().Pow(-n);
}
// a * b ^ n = answer.
ModInt a = 1, b = *this;
while (n != 0) {
if (n & 1) {
a *= b;
}
n /= 2;
b *= b;
}
return a;
}
ModInt Inv() const {
// Compute the inverse based on Fermat's little theorem. Note that this only
// works when n_ and Mod are relatively prime. The theorem says that
// n_^(Mod-1) = 1 (mod Mod). So we can compute n_^(Mod-2).
return Pow(Mod - 2);
}
long long value() const { return n_; }
static ModInt Fact(int n) {
for (int i = fact_.size(); i <= n; ++i) {
fact_.push_back(i == 0 ? 1 : fact_.back() * i);
}
return fact_[n];
}
static ModInt Comb(int n, int k) { return Perm(n, k) / Fact(k); }
static ModInt CombSlow(int n, int k) { return PermSlow(n, k) / Fact(k); }
static ModInt Perm(int n, int k) {
#if DEBUG
assert(n <= 1000000 &&
"n is too large. If k is small, consider using PermSlow.");
#endif
return Fact(n) / Fact(n - k);
}
static ModInt PermSlow(int n, int k) {
ModInt p = 1;
for (int i = 0; i < k; ++i) {
p *= (n - i);
}
return p;
}
private:
long long n_;
static std::vector<ModInt> fact_;
};
template <int Mod> std::vector<ModInt<Mod>> ModInt<Mod>::fact_;
template <int Mod>
std::ostream &operator<<(std::ostream &out, const ModInt<Mod> &m) {
out << m.value();
return out;
}
using mint = ModInt<1000000007>;
int main() {
in(int, n, m);
vector<int> s(n);
rep(i, n) cin >> s[i];
vector<int> t(m);
rep(i, m) cin >> t[i];
vector<vector<mint>> dp(n + 1, vector<mint>(m + 1));
rep(i, n + 1) dp[i][0] = 1;
rep(i, m + 1) dp[0][i] = 1;
rep(i, n) rep(j, m) {
dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1];
if (s[i] != t[j])
dp[i + 1][j + 1] -= dp[i][j];
}
out(dp[n][m]);
}
| replace | 169 | 176 | 169 | 172 | TLE | |
p03003 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout << d << endl;
#define coutd(d) cout << std::setprecision(10) << d << endl;
#define cinline(n) getline(cin, n);
#define replace_all(s, b, a) replace(s.begin(), s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
inline bool inside(int y, int x, int H, int W) {
return (y >= 0 && x >= 0 && y < H && x < W);
}
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
ll dp0[2005][2005];
ll dp1[2005][2005];
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<ll> s(n), t(m);
rep(i, n) cin >> s[i];
rep(i, m) cin >> t[i];
dp0[0][0] = 1;
rep(i, n + 1) rep(j, m + 1) {
(dp0[i + 1][j] += dp0[i][j]) %= MOD;
(dp1[i][j] += dp0[i][j]) %= MOD;
(dp1[i][j + 1] += dp1[i][j]) %= MOD;
if (s[i] == t[j])
(dp0[i + j][j + 1] += dp1[i][j]) %= MOD;
}
ll ans = dp1[n][m] % MOD;
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout << d << endl;
#define coutd(d) cout << std::setprecision(10) << d << endl;
#define cinline(n) getline(cin, n);
#define replace_all(s, b, a) replace(s.begin(), s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
inline bool inside(int y, int x, int H, int W) {
return (y >= 0 && x >= 0 && y < H && x < W);
}
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
ll dp0[2005][2005];
ll dp1[2005][2005];
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<ll> s(n), t(m);
rep(i, n) cin >> s[i];
rep(i, m) cin >> t[i];
dp0[0][0] = 1;
rep(i, n + 1) rep(j, m + 1) {
(dp0[i + 1][j] += dp0[i][j]) %= MOD;
(dp1[i][j] += dp0[i][j]) %= MOD;
(dp1[i][j + 1] += dp1[i][j]) %= MOD;
if (s[i] == t[j])
(dp0[i + 1][j + 1] += dp1[i][j]) %= MOD;
}
ll ans = dp1[n][m] % MOD;
cout << ans << endl;
}
| replace | 78 | 79 | 78 | 79 | 0 | |
p03003 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl '\n'
ll n, m;
ll dp[1005][1005];
ll mod = (1e9) + 7;
int main() {
std::ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
ll arr[n + 1];
ll brr[m + 1];
for (ll i = 1; i <= n; i++)
cin >> arr[i];
for (ll i = 1; i <= m; i++)
cin >> brr[i];
memset(dp, 0, sizeof(dp));
/*for(ll i=0;i<=n;i++){
dp[i][0]=1;
}
for(ll j=0;j<=m;j++){
dp[0][j]=1;
}*/
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= m; j++) {
if (arr[i] == brr[j]) {
dp[i][j] = (1 + dp[i][j - 1] + dp[i - 1][j] + mod) % mod;
} else {
dp[i][j] =
(-dp[i - 1][j - 1] + dp[i][j - 1] + dp[i - 1][j] + mod) % mod;
}
}
}
cout << (dp[n][m] + 1) % mod << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl '\n'
ll n, m;
ll dp[2005][2005];
ll mod = (1e9) + 7;
int main() {
std::ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
ll arr[n + 1];
ll brr[m + 1];
for (ll i = 1; i <= n; i++)
cin >> arr[i];
for (ll i = 1; i <= m; i++)
cin >> brr[i];
memset(dp, 0, sizeof(dp));
/*for(ll i=0;i<=n;i++){
dp[i][0]=1;
}
for(ll j=0;j<=m;j++){
dp[0][j]=1;
}*/
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= m; j++) {
if (arr[i] == brr[j]) {
dp[i][j] = (1 + dp[i][j - 1] + dp[i - 1][j] + mod) % mod;
} else {
dp[i][j] =
(-dp[i - 1][j - 1] + dp[i][j - 1] + dp[i - 1][j] + mod) % mod;
}
}
}
cout << (dp[n][m] + 1) % mod << endl;
}
| replace | 8 | 9 | 8 | 9 | 0 | |
p03003 | C++ | Runtime Error | #include <bits/stdc++.h>
#define REP(i, m, n) for (int(i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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;
}
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9 + 7;
// const int MOD = 1e9+7;
const ll LINF = 1LL << 60;
template <int MOD> struct Fp {
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
if (val < 0)
val += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; }
constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
constexpr Fp &operator+=(const Fp &r) noexcept {
val += r.val;
if (val >= MOD)
val -= MOD;
return *this;
}
constexpr Fp &operator-=(const Fp &r) noexcept {
val -= r.val;
if (val < 0)
val += MOD;
return *this;
}
constexpr Fp &operator*=(const Fp &r) noexcept {
val = val * r.val % MOD;
return *this;
}
constexpr Fp &operator/=(const Fp &r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
val = val * u % MOD;
if (val < 0)
val += MOD;
return *this;
}
constexpr bool operator==(const Fp &r) const noexcept {
return this->val == r.val;
}
constexpr bool operator!=(const Fp &r) const noexcept {
return this->val != r.val;
}
friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept {
return os << x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
if (n == 0)
return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1)
t = t * a;
return t;
}
};
const int MOD = 1000000007;
using mint = Fp<MOD>;
const int MAXN = 2000;
const int MAXM = 2000;
mint dp0[MAXN + 1][MAXM + 1];
mint dp1[MAXN + 1][MAXM + 1];
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector<int> s(n + 1, 0), t(m + 1, 0);
rep(i, n) cin >> s[i];
rep(i, m) cin >> t[i];
dp0[0][0] = 1;
rep(i, n + 1) {
rep(j, m + 1) {
dp0[i + 1][j] += dp0[i][j];
dp1[i][j] += dp0[i][j];
dp1[i][j + 1] += dp1[i][j];
if (s[i] == t[j])
dp0[i + 1][j + 1] += dp1[i][j];
}
}
mint ans = dp1[n][m];
cout << ans.val << endl;
return 0;
} | #include <bits/stdc++.h>
#define REP(i, m, n) for (int(i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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;
}
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9 + 7;
// const int MOD = 1e9+7;
const ll LINF = 1LL << 60;
template <int MOD> struct Fp {
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
if (val < 0)
val += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; }
constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
constexpr Fp &operator+=(const Fp &r) noexcept {
val += r.val;
if (val >= MOD)
val -= MOD;
return *this;
}
constexpr Fp &operator-=(const Fp &r) noexcept {
val -= r.val;
if (val < 0)
val += MOD;
return *this;
}
constexpr Fp &operator*=(const Fp &r) noexcept {
val = val * r.val % MOD;
return *this;
}
constexpr Fp &operator/=(const Fp &r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
val = val * u % MOD;
if (val < 0)
val += MOD;
return *this;
}
constexpr bool operator==(const Fp &r) const noexcept {
return this->val == r.val;
}
constexpr bool operator!=(const Fp &r) const noexcept {
return this->val != r.val;
}
friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept {
return os << x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
if (n == 0)
return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1)
t = t * a;
return t;
}
};
const int MOD = 1000000007;
using mint = Fp<MOD>;
const int MAXN = 2005;
const int MAXM = 2005;
mint dp0[MAXN + 1][MAXM + 1];
mint dp1[MAXN + 1][MAXM + 1];
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int n, m;
cin >> n >> m;
vector<int> s(n + 1, 0), t(m + 1, 0);
rep(i, n) cin >> s[i];
rep(i, m) cin >> t[i];
dp0[0][0] = 1;
rep(i, n + 1) {
rep(j, m + 1) {
dp0[i + 1][j] += dp0[i][j];
dp1[i][j] += dp0[i][j];
dp1[i][j + 1] += dp1[i][j];
if (s[i] == t[j])
dp0[i + 1][j + 1] += dp1[i][j];
}
}
mint ans = dp1[n][m];
cout << ans.val << endl;
return 0;
} | replace | 91 | 93 | 91 | 93 | 0 | |
p03003 | C++ | Runtime Error | #include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod = 1000000007;
const int max_n = 1011;
int main() {
int n, a[max_n], m, b[max_n];
cin >> n >> m;
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
for (int i = 0; i < m; ++i) {
scanf("%d", &b[i]);
}
int dp[max_n][max_n];
for (int i = 0; i <= max(n, m); ++i) {
dp[i][0] = 1;
dp[0][i] = 1;
}
for (int i = 1; i <= n; ++i) {
for (int q = 1; q <= m; ++q) {
dp[i][q] = 0;
if (i)
dp[i][q] += dp[i - 1][q];
if (q)
dp[i][q] += dp[i][q - 1];
if (i && q && a[i - 1] != b[q - 1])
dp[i][q] -= dp[i - 1][q - 1];
if (dp[i][q] < 0)
dp[i][q] += mod;
dp[i][q] %= mod;
/*if (a[i - 1] == b[q - 1]) {
dp[i][q] = dp[i - 1][q - 1] * 2 % mod;
} else {
dp[i][q] = 0;
if (i) dp[i][q] += dp[i - 1][q];
if (q) dp[i][q] += dp[i][q - 1];
if (i && q) dp[i][q] -= dp[i - 1][q - 1];
if (dp[i][q] < 0) dp[i][q] += mod;
dp[i][q] %= mod;
}*/
// cout << i << " " << q << " " << dp[i][q] << endl;
}
}
cout << dp[n][m] << endl;
} | #include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef long double ld;
const int mod = 1000000007;
const int max_n = 2011;
int main() {
int n, a[max_n], m, b[max_n];
cin >> n >> m;
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
for (int i = 0; i < m; ++i) {
scanf("%d", &b[i]);
}
int dp[max_n][max_n];
for (int i = 0; i <= max(n, m); ++i) {
dp[i][0] = 1;
dp[0][i] = 1;
}
for (int i = 1; i <= n; ++i) {
for (int q = 1; q <= m; ++q) {
dp[i][q] = 0;
if (i)
dp[i][q] += dp[i - 1][q];
if (q)
dp[i][q] += dp[i][q - 1];
if (i && q && a[i - 1] != b[q - 1])
dp[i][q] -= dp[i - 1][q - 1];
if (dp[i][q] < 0)
dp[i][q] += mod;
dp[i][q] %= mod;
/*if (a[i - 1] == b[q - 1]) {
dp[i][q] = dp[i - 1][q - 1] * 2 % mod;
} else {
dp[i][q] = 0;
if (i) dp[i][q] += dp[i - 1][q];
if (q) dp[i][q] += dp[i][q - 1];
if (i && q) dp[i][q] -= dp[i - 1][q - 1];
if (dp[i][q] < 0) dp[i][q] += mod;
dp[i][q] %= mod;
}*/
// cout << i << " " << q << " " << dp[i][q] << endl;
}
}
cout << dp[n][m] << endl;
} | replace | 9 | 10 | 9 | 10 | 0 | |
p03003 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cin;
using std::cout;
using std::endl;
template <typename T> std::vector<T> make_v(size_t a) {
return std::vector<T>(a);
}
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return std::vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
int main() {
int n, m;
scanf("%d%d", &n, &m);
std::vector<int> a(n), b(n);
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
for (int i = 0; i < m; i++)
scanf("%d", &b[i]);
const int MOD = 1e9 + 7;
std::vector<i64> s(m + 1, 1);
s[0] = 0;
auto dp = make_v<i64>(n + 1, m + 1);
dp[0][0] = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i] == b[j])
(dp[i + 1][j + 1] += s[j + 1]) %= MOD;
}
i64 tmp = 0;
for (int j = 0; j <= m; j++) {
(s[j] += tmp) %= MOD;
(tmp += dp[i + 1][j]) %= MOD;
}
}
i64 ans = 0;
for (auto v : dp)
for (auto w : v)
(ans += w) %= MOD;
printf("%lld\n", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cin;
using std::cout;
using std::endl;
template <typename T> std::vector<T> make_v(size_t a) {
return std::vector<T>(a);
}
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return std::vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
int main() {
int n, m;
scanf("%d%d", &n, &m);
std::vector<int> a(n), b(m);
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
for (int i = 0; i < m; i++)
scanf("%d", &b[i]);
const int MOD = 1e9 + 7;
std::vector<i64> s(m + 1, 1);
s[0] = 0;
auto dp = make_v<i64>(n + 1, m + 1);
dp[0][0] = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (a[i] == b[j])
(dp[i + 1][j + 1] += s[j + 1]) %= MOD;
}
i64 tmp = 0;
for (int j = 0; j <= m; j++) {
(s[j] += tmp) %= MOD;
(tmp += dp[i + 1][j]) %= MOD;
}
}
i64 ans = 0;
for (auto v : dp)
for (auto w : v)
(ans += w) %= MOD;
printf("%lld\n", ans);
return 0;
}
| replace | 18 | 19 | 18 | 19 | 0 | |
p03003 | C++ | Runtime Error | #include <iostream>
using namespace std;
long long MOD = 1000000007;
int main() {
// input
long long N, M;
cin >> N >> M;
long long S[N + 1], T[N + 1];
long long i, j;
for (i = 1; i <= N; i++) {
cin >> S[i];
}
for (j = 1; j <= M; j++) {
cin >> T[j];
}
// calc
long long sum[N + 1][M + 1];
for (i = 0; i <= N; i++) {
sum[i][0] = 1;
}
for (j = 0; j <= M; j++) {
sum[0][j] = 1;
}
for (i = 1; i <= N; i++) {
for (j = 1; j <= M; j++) {
if (S[i] == T[j]) {
sum[i][j] = sum[i - 1][j] + sum[i][j - 1];
sum[i][j] %= MOD;
} else {
sum[i][j] = sum[i - 1][j] + sum[i][j - 1] + MOD - sum[i - 1][j - 1];
sum[i][j] %= MOD;
}
}
}
// answer
cout << sum[N][M] << endl;
system("pause");
return 0;
} | #include <iostream>
using namespace std;
long long MOD = 1000000007;
int main() {
// input
long long N, M;
cin >> N >> M;
long long S[N + 1], T[M + 1];
long long i, j;
for (i = 1; i <= N; i++) {
cin >> S[i];
}
for (j = 1; j <= M; j++) {
cin >> T[j];
}
// calc
long long sum[N + 1][M + 1];
for (i = 0; i <= N; i++) {
sum[i][0] = 1;
}
for (j = 0; j <= M; j++) {
sum[0][j] = 1;
}
for (i = 1; i <= N; i++) {
for (j = 1; j <= M; j++) {
if (S[i] == T[j]) {
sum[i][j] = sum[i - 1][j] + sum[i][j - 1];
sum[i][j] %= MOD;
} else {
sum[i][j] = sum[i - 1][j] + sum[i][j - 1] + MOD - sum[i - 1][j - 1];
sum[i][j] %= MOD;
}
}
}
// answer
cout << sum[N][M] << endl;
system("pause");
return 0;
} | replace | 9 | 10 | 9 | 10 | 0 | sh: 1: pause: not found
|
p03003 | C++ | Runtime Error |
// #pragma GCC optimize ("-O3")
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <type_traits>
#include <typeinfo>
#include <unordered_map>
#include <vector>
#ifdef _MSC_VER
#include <intrin.h>
#define popcnt __popcnt64
// # define __builtin_popcount __popcnt
#else
#define popcnt __builtin_popcountll
#endif
// #include "boost/variant.hpp"
using namespace std;
typedef long long ll;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;
#define rep(i, N, M) for (ll i = N, i##_len = (M); i < i##_len; ++i)
#define rep_skip(i, N, M, ...) \
for (ll i = N, i##_len = (M); i < i##_len; i += (skip))
#define rrep(i, N, M) for (ll i = (M)-1, i##_len = (N - 1); i > i##_len; --i)
#define pb push_back
#define fir first
#define sec second
typedef pair<double, double> pd;
typedef pair<ll, ll> pll;
template <int n> struct tll_impl {
using type = decltype(tuple_cat(tuple<ll>(),
declval<typename tll_impl<n - 1>::type>()));
};
template <> struct tll_impl<1> {
using type = tuple<ll>;
};
template <int n> using tll = typename tll_impl<n>::type;
template <class T> constexpr ll SZ(T &v) { return static_cast<ll>(v.size()); };
template <int n, typename T> struct vec_t_impl {
using type = vector<typename vec_t_impl<n - 1, T>::type>;
};
template <typename T> struct vec_t_impl<1, T> {
using type = vector<T>;
};
template <int n, typename T> using vec_t = typename vec_t_impl<n, T>::type;
// check
static_assert(is_same<vec_t<3, ll>, vector<vector<vector<ll>>>>::value, "");
// decompose vector into basetype and dimension.
template <typename T> struct vec_dec {
static constexpr int dim = 0;
using type = T;
};
template <typename T> struct vec_dec<vector<T>> {
static constexpr int dim = vec_dec<T>::dim + 1;
using type = typename vec_dec<T>::type;
};
static_assert(is_same<typename vec_dec<vec_t<3, ll>>::type, ll>::value, "");
static_assert(vec_dec<vec_t<3, ll>>::dim == 3, "");
template <typename T = ll> vector<T> makev(size_t a) { return vector<T>(a); }
template <typename T = ll, typename... Ts> auto makev(size_t a, Ts... ts) {
return vector<decltype(makev<T>(ts...))>(a, makev<T>(ts...));
}
// ex: auto dp = makev<ll>(4,5) => vector<vector<ll>> dp(4,vector<ll>(5));
// check if T is vector
template <typename T> struct is_vector : std::false_type {};
template <typename T> struct is_vector<vector<T>> : std::true_type {};
static_assert(is_vector<vector<ll>>::value == true &&
is_vector<ll>::value == false,
"");
// check if T is vector
template <typename T> struct is_pair : std::false_type {};
template <typename T, typename S>
struct is_pair<pair<T, S>> : std::true_type {};
static_assert(is_pair<pll>::value == true && is_pair<ll>::value == false, "");
template <typename T, typename V,
typename enable_if<!is_vector<T>::value, nullptr_t>::type = nullptr>
void fill_v(T &t, const V &v) {
t = v;
}
template <typename T, typename V,
typename enable_if<is_vector<T>::value, nullptr_t>::type = nullptr>
void fill_v(T &t, const V &v) {
for (auto &&x : t)
fill_v(x, v);
}
// ex: fill_v(dp, INF);
template <typename T,
typename enable_if<!is_vector<T>::value && !is_pair<T>::value,
nullptr_t>::type = nullptr>
void read(T &x) {
cin >> x;
}
template <typename T,
typename enable_if<is_pair<T>::value, nullptr_t>::type = nullptr>
void read(T &x) {
read(x.first);
read(x.second);
}
template <typename T,
typename enable_if<is_vector<T>::value, nullptr_t>::type = nullptr>
void read(T &x) {
rep(i, 0, x.size()) read(x[i]);
}
template <typename T, typename Delim_t = string,
typename enable_if<!is_vector<T>::value, nullptr_t>::type = nullptr>
void write(T &x, Delim_t delim = " ") {
cout << x << delim;
}
template <typename T, typename Delim_t = string,
typename enable_if<is_vector<T>::value, nullptr_t>::type = nullptr>
void write(T &x, Delim_t delim = " ") {
rep(i, 0, x.size()) write(x[i], (i == (x.size() - 1) ? "" : delim));
cout << '\n';
}
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
template <typename T>
using pq_greater = priority_queue<T, vector<T>, greater<T>>;
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define perm(c) \
sort(all(c)); \
for (bool c##perm = 1; c##perm; c##perm = next_permutation(all(c)))
template <typename T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <typename T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
vll seq(ll i, ll j) {
vll res(j - i);
rep(k, i, j) res[k] = i + k;
return res;
}
constexpr ll POW_0(ll x, ll y) {
if (y == 0)
return 1;
if (y == 1)
return x;
if (y == 2)
return x * x;
if (y % 2 == 0)
return POW_0(POW_0(x, y / 2), 2LL);
return ((POW_0(POW_0(x, y / 2), 2LL)) * (x));
}
constexpr ll POW(ll x, ll y, ll mod = MOD) {
if (mod == 0)
return POW_0(x, y);
if (y == 0)
return 1;
if (y == 1)
return x % mod;
if (y == 2)
return x * x % mod;
if (y % 2 == 0)
return POW(POW(x, y / 2, mod), 2LL, mod) % mod;
return ((POW(POW(x, y / 2, mod), 2LL, mod)) * (x % mod)) % mod;
}
template <typename Inputs, typename Functor,
typename T = typename Inputs::value_type>
void sort_by(Inputs &inputs, Functor f) {
std::sort(std::begin(inputs), std::end(inputs),
[&f](const T &lhs, const T &rhs) { return f(lhs) < f(rhs); });
}
template <typename Inputs, typename Functor,
typename T = typename Inputs::value_type>
void stable_sort_by(Inputs &inputs, Functor f) {
std::stable_sort(
std::begin(inputs), std::end(inputs),
[&f](const T &lhs, const T &rhs) { return f(lhs) < f(rhs); });
}
template <typename Inputs> void sort_uniq(Inputs &inputs) {
sort(all(inputs));
inputs.erase(unique(all(inputs)), inputs.end());
}
ll div_ferm(ll a, ll b, ll mod) { return (a * POW(b, mod - 2, mod)) % mod; }
// === Modint ===
template <std::uint_fast64_t Modulus = MOD> class modint {
using u64 = std::uint_fast64_t;
public:
u64 a;
constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
// constexpr modint(const modint& rhs) noexcept {
// this->a = rhs.value();
// }
// constexpr modint &operator=(const modint &rhs) noexcept {
// this->a = rhs.value();
// return *this;
// }
constexpr u64 value() const noexcept { return a; }
constexpr modint operator+(const modint rhs) const noexcept {
return modint(*this) += rhs;
}
constexpr modint operator-(const modint rhs) const noexcept {
return modint(*this) -= rhs;
}
constexpr modint operator*(const modint rhs) const noexcept {
return modint(*this) *= rhs;
}
constexpr modint operator/(const modint rhs) const noexcept {
return modint(*this) /= rhs;
}
modint &operator+=(const modint rhs) noexcept {
a += rhs.a;
if (a >= Modulus) {
a -= Modulus;
}
return *this;
}
modint &operator-=(const modint rhs) noexcept {
if (a < rhs.a) {
a += Modulus;
}
a -= rhs.a;
return *this;
}
modint &operator*=(const modint rhs) noexcept {
a = a * rhs.a % Modulus;
return *this;
}
modint &operator/=(modint rhs) noexcept {
u64 exp = Modulus - 2;
while (exp) {
if (exp % 2) {
*this *= rhs;
}
rhs *= rhs;
exp /= 2;
}
return *this;
}
modint &operator++() noexcept { return *this += modint(1); }
modint &operator++(int) noexcept {
auto t = *this;
*this += modint(1);
return t;
}
modint &operator--() noexcept { return *this -= modint(1); }
modint &operator--(int) noexcept {
auto t = *this;
*this -= modint(1);
return t;
}
constexpr bool operator==(const modint rhs) const noexcept {
return a == rhs.value();
}
constexpr bool operator!=(const modint rhs) const noexcept {
return a != rhs.value();
}
constexpr bool operator<(const modint rhs) const noexcept {
return a < rhs.value();
}
// should be moved to Google Test
// constexpr void test(){
// constexpr auto x = modint<5>(3);
// constexpr auto y = modint<5>(4);
// constexpr auto z = modint<5>(2);
// static_assert(x + y == z, "");
// static_assert(x != y, "");
// static_assert(++x == y && x++ != y && x == --y && x != y--, "");
// static_assert(x + 6 == y, "");
// static_assert(x / 2 == y, "");
//
//}
};
template <uint_fast64_t Modulus>
ostream &operator<<(ostream &o, const modint<Modulus> &t) {
o << t.value();
return o;
}
template <uint_fast64_t Modulus>
istream &operator>>(istream &in, modint<Modulus> &t) {
uint_fast64_t x;
in >> x;
t = modint<Modulus>(x);
return in;
}
template <uint_fast64_t Modulus> modint<Modulus> POW(modint<Modulus> x, ll n) {
return modint<Modulus>(POW(x.value(), n, Modulus));
}
// === Mll ===
template <typename T = ll, T MOD = MOD> struct Mint {
T v;
Mint() : v(0) {}
// Mint(signed v) :v(v) {}
Mint(long long t) {
v = t % MOD;
if (v < 0)
v += MOD;
}
Mint inv() { return pow(MOD - 2); }
Mint &operator+=(Mint a) {
v += a.v;
if (v >= MOD)
v -= MOD;
return *this;
}
Mint &operator-=(Mint a) {
v += MOD - a.v;
if (v >= MOD)
v -= MOD;
return *this;
}
Mint &operator*=(Mint a) {
v = 1LL * v * a.v % MOD;
return *this;
}
Mint &operator/=(Mint a) { return (*this) *= a.inv(); }
Mint operator+(Mint a) const { return Mint(v) += a; };
Mint operator-(Mint a) const { return Mint(v) -= a; };
Mint operator*(Mint a) const { return Mint(v) *= a; };
Mint operator/(Mint a) const { return Mint(v) /= a; };
Mint operator-() { return v ? MOD - v : v; }
bool operator==(const Mint a) const { return v == a.v; }
bool operator!=(const Mint a) const { return v != a.v; }
bool operator<(const Mint a) const { return v < a.v; }
static Mint pow(Mint v, long long k) {
Mint res(1), tmp(v);
while (k) {
if (k & 1)
res *= tmp;
tmp *= tmp;
k >>= 1;
}
return res;
}
// find x s.t. a^x = b
static T log(Mint a, Mint b) {
const T sq = 40000;
unordered_map<T, T> dp;
dp.reserve(sq);
Mint res(1);
for (ll r = 0; r < sq; r++) {
if (!dp.count(res))
dp[res] = r;
res *= a;
}
Mint p = pow(a.inv(), sq);
res = b;
for (ll q = 0; q <= MOD / sq + 1; q++) {
if (dp.count(res)) {
T idx = q * sq + dp[res];
if (idx > 0)
return idx;
}
res *= p;
}
return T(-1);
}
static vector<Mint> fact, finv, invs;
static void init(ll n) {
if (n + 1 <= (signed)fact.size())
return;
fact.assign(n + 1, 1);
finv.assign(n + 1, 1);
invs.assign(n + 1, 1);
for (ll i = 1; i <= n; i++)
fact[i] = fact[i - 1] * Mint(i);
finv[n] = Mint(1) / fact[n];
for (ll i = n; i >= 1; i--)
finv[i - 1] = finv[i] * Mint(i);
for (ll i = 1; i <= n; i++)
invs[i] = finv[i] * fact[i - 1];
}
static Mint comb(long long n, ll k) {
Mint res(1);
for (ll i = 0; i < k; i++) {
res *= Mint(n - i);
res /= Mint(i + 1);
}
return res;
}
static Mint C(ll n, ll k) {
if (n < k || k < 0)
return Mint(0);
init(n);
return fact[n] * finv[n - k] * finv[k];
}
static Mint P(ll n, ll k) {
if (n < k || k < 0)
return Mint(0);
init(n);
return fact[n] * finv[n - k];
}
static Mint H(ll n, ll k) {
if (n < 0 || k < 0)
return Mint(0);
if (!n && !k)
return Mint(1);
init(n + k - 1);
return C(n + k - 1, k);
}
static Mint S(ll n, ll k) {
Mint res;
init(k);
for (ll i = 1; i <= k; i++) {
Mint tmp = C(k, i) * Mint(i).pow(n);
if ((k - i) & 1)
res -= tmp;
else
res += tmp;
}
return res *= finv[k];
}
static vector<vector<Mint>> D(ll n, ll m) {
vector<vector<Mint>> dp(n + 1, vector<Mint>(m + 1, 0));
dp[0][0] = Mint(1);
for (ll i = 0; i <= n; i++) {
for (ll j = 1; j <= m; j++) {
if (i - j >= 0)
dp[i][j] = dp[i][j - 1] + dp[i - j][j];
else
dp[i][j] = dp[i][j - 1];
}
}
return dp;
}
static Mint B(ll n, ll k) {
Mint res;
for (ll j = 1; j <= k; j++)
res += S(n, j);
return res;
}
static Mint montmort(ll n) {
Mint res;
init(n);
for (ll k = 2; k <= n; k++) {
if (k & 1)
res -= finv[k];
else
res += finv[k];
}
return res *= fact[n];
}
static Mint LagrangePolynomial(vector<Mint> &y, Mint t) {
ll n = y.size() - 1;
if (t.v <= n)
return y[t.v];
init(n + 1);
Mint num(1);
for (ll i = 0; i <= n; i++)
num *= t - Mint(i);
Mint res;
for (ll i = 0; i <= n; i++) {
Mint tmp = y[i] * num / (t - Mint(i)) * finv[i] * finv[n - i];
if ((n - i) & 1)
res -= tmp;
else
res += tmp;
}
return res;
}
};
class Combination {
// this calculates combination (nCk).
// Constructor runs in O(MAX).
// get(n,k) returns nCk in O(1).
ll N_MAX, mod;
vll fac;
vll finv;
vll inv;
public:
Combination(ll mod = MOD, ll N_MAX = 210000)
: mod(mod), N_MAX(max(N_MAX, 2LL)), fac(vll(N_MAX + 1)),
finv(vll(N_MAX + 1)), inv(vll(N_MAX + 1)) {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
pre_process(2LL, N_MAX + 1);
}
ll operator()(ll n, ll k) {
if (N_MAX < n)
pre_process(N_MAX + 1, n + 1);
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
private:
void pre_process(ll m, ll n) {
if (N_MAX < n) {
fac.resize(n);
inv.resize(n);
finv.resize(n);
}
rep(i, m, n) {
fac[i] = fac[i - 1] * i % mod;
inv[i] = mod - inv[mod % i] * (mod / i) % mod;
finv[i] = finv[i - 1] * inv[i] % mod;
}
}
};
ll choose(int n, int r) { // O(r) for small n
ll acc = 1;
rep(i, 0, r) acc = acc * (n - i) / (i + 1);
return acc;
}
ll gcd(ll a, ll b) {
if (a % b == 0)
return b;
else
return gcd(b, a % b);
}
vll getDivisors(ll n) {
vll res;
ll i = 1;
for (; i * i < n; i++) {
if (n % i == 0) {
res.push_back(i);
res.push_back(n / i);
}
}
if (i * i == n)
res.push_back(i);
sort(res.begin(), res.end());
return res;
}
vll getDivisors(ll n, ll m) {
// O(sqrt(min(n,m)))
if (n > m)
swap(n, m);
vll res;
ll i = 1;
for (; i * i < n; i++) {
if (n % i == 0) {
if (m % i == 0)
res.push_back(i);
if (m % (n / i) == 0)
res.push_back(n / i);
}
}
if (i * i == n)
if (m % i == 0)
res.push_back(i);
sort(res.begin(), res.end());
return res;
}
vector<pll> prime_factorize(ll n) {
vector<pll> res;
for (ll p = 2; p * p <= n; ++p) {
if (n % p != 0)
continue;
ll num = 0;
while (n % p == 0) {
++num;
n /= p;
}
res.push_back({p, num});
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
#include <sstream>
#include <string>
#include <vector>
using namespace std;
vector<string> split(const string &s, char delim) {
vector<string> elems;
stringstream ss(s);
string item;
while (getline(ss, item, delim)) {
if (!item.empty()) {
elems.push_back(item);
}
}
return elems;
}
// ============================ Header =================================
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
ll n, m;
cin >> n >> m;
vll s(n), t(m);
read(s);
read(t);
vector<modint<MOD>> dp(n + 1);
vvll dict(m + 1);
vector<modint<MOD>> S(m + 2);
rep(i, 0, n) {
rrep(j, 0, m) {
if (s[i] == t[j]) {
if (j == 0) {
dp[j] += 1;
} else
dp[j] += S[j] + 1;
}
}
fill_v(S, 0);
rep(j, 0, m + 1) { S[j + 1] = S[j] + dp[j]; }
}
modint<> tot = 0;
rep(i, 0, m) tot += dp[i];
cout << tot + 1 << endl;
;
return 0;
}
|
// #pragma GCC optimize ("-O3")
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <type_traits>
#include <typeinfo>
#include <unordered_map>
#include <vector>
#ifdef _MSC_VER
#include <intrin.h>
#define popcnt __popcnt64
// # define __builtin_popcount __popcnt
#else
#define popcnt __builtin_popcountll
#endif
// #include "boost/variant.hpp"
using namespace std;
typedef long long ll;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;
#define rep(i, N, M) for (ll i = N, i##_len = (M); i < i##_len; ++i)
#define rep_skip(i, N, M, ...) \
for (ll i = N, i##_len = (M); i < i##_len; i += (skip))
#define rrep(i, N, M) for (ll i = (M)-1, i##_len = (N - 1); i > i##_len; --i)
#define pb push_back
#define fir first
#define sec second
typedef pair<double, double> pd;
typedef pair<ll, ll> pll;
template <int n> struct tll_impl {
using type = decltype(tuple_cat(tuple<ll>(),
declval<typename tll_impl<n - 1>::type>()));
};
template <> struct tll_impl<1> {
using type = tuple<ll>;
};
template <int n> using tll = typename tll_impl<n>::type;
template <class T> constexpr ll SZ(T &v) { return static_cast<ll>(v.size()); };
template <int n, typename T> struct vec_t_impl {
using type = vector<typename vec_t_impl<n - 1, T>::type>;
};
template <typename T> struct vec_t_impl<1, T> {
using type = vector<T>;
};
template <int n, typename T> using vec_t = typename vec_t_impl<n, T>::type;
// check
static_assert(is_same<vec_t<3, ll>, vector<vector<vector<ll>>>>::value, "");
// decompose vector into basetype and dimension.
template <typename T> struct vec_dec {
static constexpr int dim = 0;
using type = T;
};
template <typename T> struct vec_dec<vector<T>> {
static constexpr int dim = vec_dec<T>::dim + 1;
using type = typename vec_dec<T>::type;
};
static_assert(is_same<typename vec_dec<vec_t<3, ll>>::type, ll>::value, "");
static_assert(vec_dec<vec_t<3, ll>>::dim == 3, "");
template <typename T = ll> vector<T> makev(size_t a) { return vector<T>(a); }
template <typename T = ll, typename... Ts> auto makev(size_t a, Ts... ts) {
return vector<decltype(makev<T>(ts...))>(a, makev<T>(ts...));
}
// ex: auto dp = makev<ll>(4,5) => vector<vector<ll>> dp(4,vector<ll>(5));
// check if T is vector
template <typename T> struct is_vector : std::false_type {};
template <typename T> struct is_vector<vector<T>> : std::true_type {};
static_assert(is_vector<vector<ll>>::value == true &&
is_vector<ll>::value == false,
"");
// check if T is vector
template <typename T> struct is_pair : std::false_type {};
template <typename T, typename S>
struct is_pair<pair<T, S>> : std::true_type {};
static_assert(is_pair<pll>::value == true && is_pair<ll>::value == false, "");
template <typename T, typename V,
typename enable_if<!is_vector<T>::value, nullptr_t>::type = nullptr>
void fill_v(T &t, const V &v) {
t = v;
}
template <typename T, typename V,
typename enable_if<is_vector<T>::value, nullptr_t>::type = nullptr>
void fill_v(T &t, const V &v) {
for (auto &&x : t)
fill_v(x, v);
}
// ex: fill_v(dp, INF);
template <typename T,
typename enable_if<!is_vector<T>::value && !is_pair<T>::value,
nullptr_t>::type = nullptr>
void read(T &x) {
cin >> x;
}
template <typename T,
typename enable_if<is_pair<T>::value, nullptr_t>::type = nullptr>
void read(T &x) {
read(x.first);
read(x.second);
}
template <typename T,
typename enable_if<is_vector<T>::value, nullptr_t>::type = nullptr>
void read(T &x) {
rep(i, 0, x.size()) read(x[i]);
}
template <typename T, typename Delim_t = string,
typename enable_if<!is_vector<T>::value, nullptr_t>::type = nullptr>
void write(T &x, Delim_t delim = " ") {
cout << x << delim;
}
template <typename T, typename Delim_t = string,
typename enable_if<is_vector<T>::value, nullptr_t>::type = nullptr>
void write(T &x, Delim_t delim = " ") {
rep(i, 0, x.size()) write(x[i], (i == (x.size() - 1) ? "" : delim));
cout << '\n';
}
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
template <typename T>
using pq_greater = priority_queue<T, vector<T>, greater<T>>;
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define perm(c) \
sort(all(c)); \
for (bool c##perm = 1; c##perm; c##perm = next_permutation(all(c)))
template <typename T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <typename T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
vll seq(ll i, ll j) {
vll res(j - i);
rep(k, i, j) res[k] = i + k;
return res;
}
constexpr ll POW_0(ll x, ll y) {
if (y == 0)
return 1;
if (y == 1)
return x;
if (y == 2)
return x * x;
if (y % 2 == 0)
return POW_0(POW_0(x, y / 2), 2LL);
return ((POW_0(POW_0(x, y / 2), 2LL)) * (x));
}
constexpr ll POW(ll x, ll y, ll mod = MOD) {
if (mod == 0)
return POW_0(x, y);
if (y == 0)
return 1;
if (y == 1)
return x % mod;
if (y == 2)
return x * x % mod;
if (y % 2 == 0)
return POW(POW(x, y / 2, mod), 2LL, mod) % mod;
return ((POW(POW(x, y / 2, mod), 2LL, mod)) * (x % mod)) % mod;
}
template <typename Inputs, typename Functor,
typename T = typename Inputs::value_type>
void sort_by(Inputs &inputs, Functor f) {
std::sort(std::begin(inputs), std::end(inputs),
[&f](const T &lhs, const T &rhs) { return f(lhs) < f(rhs); });
}
template <typename Inputs, typename Functor,
typename T = typename Inputs::value_type>
void stable_sort_by(Inputs &inputs, Functor f) {
std::stable_sort(
std::begin(inputs), std::end(inputs),
[&f](const T &lhs, const T &rhs) { return f(lhs) < f(rhs); });
}
template <typename Inputs> void sort_uniq(Inputs &inputs) {
sort(all(inputs));
inputs.erase(unique(all(inputs)), inputs.end());
}
ll div_ferm(ll a, ll b, ll mod) { return (a * POW(b, mod - 2, mod)) % mod; }
// === Modint ===
template <std::uint_fast64_t Modulus = MOD> class modint {
using u64 = std::uint_fast64_t;
public:
u64 a;
constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
// constexpr modint(const modint& rhs) noexcept {
// this->a = rhs.value();
// }
// constexpr modint &operator=(const modint &rhs) noexcept {
// this->a = rhs.value();
// return *this;
// }
constexpr u64 value() const noexcept { return a; }
constexpr modint operator+(const modint rhs) const noexcept {
return modint(*this) += rhs;
}
constexpr modint operator-(const modint rhs) const noexcept {
return modint(*this) -= rhs;
}
constexpr modint operator*(const modint rhs) const noexcept {
return modint(*this) *= rhs;
}
constexpr modint operator/(const modint rhs) const noexcept {
return modint(*this) /= rhs;
}
modint &operator+=(const modint rhs) noexcept {
a += rhs.a;
if (a >= Modulus) {
a -= Modulus;
}
return *this;
}
modint &operator-=(const modint rhs) noexcept {
if (a < rhs.a) {
a += Modulus;
}
a -= rhs.a;
return *this;
}
modint &operator*=(const modint rhs) noexcept {
a = a * rhs.a % Modulus;
return *this;
}
modint &operator/=(modint rhs) noexcept {
u64 exp = Modulus - 2;
while (exp) {
if (exp % 2) {
*this *= rhs;
}
rhs *= rhs;
exp /= 2;
}
return *this;
}
modint &operator++() noexcept { return *this += modint(1); }
modint &operator++(int) noexcept {
auto t = *this;
*this += modint(1);
return t;
}
modint &operator--() noexcept { return *this -= modint(1); }
modint &operator--(int) noexcept {
auto t = *this;
*this -= modint(1);
return t;
}
constexpr bool operator==(const modint rhs) const noexcept {
return a == rhs.value();
}
constexpr bool operator!=(const modint rhs) const noexcept {
return a != rhs.value();
}
constexpr bool operator<(const modint rhs) const noexcept {
return a < rhs.value();
}
// should be moved to Google Test
// constexpr void test(){
// constexpr auto x = modint<5>(3);
// constexpr auto y = modint<5>(4);
// constexpr auto z = modint<5>(2);
// static_assert(x + y == z, "");
// static_assert(x != y, "");
// static_assert(++x == y && x++ != y && x == --y && x != y--, "");
// static_assert(x + 6 == y, "");
// static_assert(x / 2 == y, "");
//
//}
};
template <uint_fast64_t Modulus>
ostream &operator<<(ostream &o, const modint<Modulus> &t) {
o << t.value();
return o;
}
template <uint_fast64_t Modulus>
istream &operator>>(istream &in, modint<Modulus> &t) {
uint_fast64_t x;
in >> x;
t = modint<Modulus>(x);
return in;
}
template <uint_fast64_t Modulus> modint<Modulus> POW(modint<Modulus> x, ll n) {
return modint<Modulus>(POW(x.value(), n, Modulus));
}
// === Mll ===
template <typename T = ll, T MOD = MOD> struct Mint {
T v;
Mint() : v(0) {}
// Mint(signed v) :v(v) {}
Mint(long long t) {
v = t % MOD;
if (v < 0)
v += MOD;
}
Mint inv() { return pow(MOD - 2); }
Mint &operator+=(Mint a) {
v += a.v;
if (v >= MOD)
v -= MOD;
return *this;
}
Mint &operator-=(Mint a) {
v += MOD - a.v;
if (v >= MOD)
v -= MOD;
return *this;
}
Mint &operator*=(Mint a) {
v = 1LL * v * a.v % MOD;
return *this;
}
Mint &operator/=(Mint a) { return (*this) *= a.inv(); }
Mint operator+(Mint a) const { return Mint(v) += a; };
Mint operator-(Mint a) const { return Mint(v) -= a; };
Mint operator*(Mint a) const { return Mint(v) *= a; };
Mint operator/(Mint a) const { return Mint(v) /= a; };
Mint operator-() { return v ? MOD - v : v; }
bool operator==(const Mint a) const { return v == a.v; }
bool operator!=(const Mint a) const { return v != a.v; }
bool operator<(const Mint a) const { return v < a.v; }
static Mint pow(Mint v, long long k) {
Mint res(1), tmp(v);
while (k) {
if (k & 1)
res *= tmp;
tmp *= tmp;
k >>= 1;
}
return res;
}
// find x s.t. a^x = b
static T log(Mint a, Mint b) {
const T sq = 40000;
unordered_map<T, T> dp;
dp.reserve(sq);
Mint res(1);
for (ll r = 0; r < sq; r++) {
if (!dp.count(res))
dp[res] = r;
res *= a;
}
Mint p = pow(a.inv(), sq);
res = b;
for (ll q = 0; q <= MOD / sq + 1; q++) {
if (dp.count(res)) {
T idx = q * sq + dp[res];
if (idx > 0)
return idx;
}
res *= p;
}
return T(-1);
}
static vector<Mint> fact, finv, invs;
static void init(ll n) {
if (n + 1 <= (signed)fact.size())
return;
fact.assign(n + 1, 1);
finv.assign(n + 1, 1);
invs.assign(n + 1, 1);
for (ll i = 1; i <= n; i++)
fact[i] = fact[i - 1] * Mint(i);
finv[n] = Mint(1) / fact[n];
for (ll i = n; i >= 1; i--)
finv[i - 1] = finv[i] * Mint(i);
for (ll i = 1; i <= n; i++)
invs[i] = finv[i] * fact[i - 1];
}
static Mint comb(long long n, ll k) {
Mint res(1);
for (ll i = 0; i < k; i++) {
res *= Mint(n - i);
res /= Mint(i + 1);
}
return res;
}
static Mint C(ll n, ll k) {
if (n < k || k < 0)
return Mint(0);
init(n);
return fact[n] * finv[n - k] * finv[k];
}
static Mint P(ll n, ll k) {
if (n < k || k < 0)
return Mint(0);
init(n);
return fact[n] * finv[n - k];
}
static Mint H(ll n, ll k) {
if (n < 0 || k < 0)
return Mint(0);
if (!n && !k)
return Mint(1);
init(n + k - 1);
return C(n + k - 1, k);
}
static Mint S(ll n, ll k) {
Mint res;
init(k);
for (ll i = 1; i <= k; i++) {
Mint tmp = C(k, i) * Mint(i).pow(n);
if ((k - i) & 1)
res -= tmp;
else
res += tmp;
}
return res *= finv[k];
}
static vector<vector<Mint>> D(ll n, ll m) {
vector<vector<Mint>> dp(n + 1, vector<Mint>(m + 1, 0));
dp[0][0] = Mint(1);
for (ll i = 0; i <= n; i++) {
for (ll j = 1; j <= m; j++) {
if (i - j >= 0)
dp[i][j] = dp[i][j - 1] + dp[i - j][j];
else
dp[i][j] = dp[i][j - 1];
}
}
return dp;
}
static Mint B(ll n, ll k) {
Mint res;
for (ll j = 1; j <= k; j++)
res += S(n, j);
return res;
}
static Mint montmort(ll n) {
Mint res;
init(n);
for (ll k = 2; k <= n; k++) {
if (k & 1)
res -= finv[k];
else
res += finv[k];
}
return res *= fact[n];
}
static Mint LagrangePolynomial(vector<Mint> &y, Mint t) {
ll n = y.size() - 1;
if (t.v <= n)
return y[t.v];
init(n + 1);
Mint num(1);
for (ll i = 0; i <= n; i++)
num *= t - Mint(i);
Mint res;
for (ll i = 0; i <= n; i++) {
Mint tmp = y[i] * num / (t - Mint(i)) * finv[i] * finv[n - i];
if ((n - i) & 1)
res -= tmp;
else
res += tmp;
}
return res;
}
};
class Combination {
// this calculates combination (nCk).
// Constructor runs in O(MAX).
// get(n,k) returns nCk in O(1).
ll N_MAX, mod;
vll fac;
vll finv;
vll inv;
public:
Combination(ll mod = MOD, ll N_MAX = 210000)
: mod(mod), N_MAX(max(N_MAX, 2LL)), fac(vll(N_MAX + 1)),
finv(vll(N_MAX + 1)), inv(vll(N_MAX + 1)) {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
pre_process(2LL, N_MAX + 1);
}
ll operator()(ll n, ll k) {
if (N_MAX < n)
pre_process(N_MAX + 1, n + 1);
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
private:
void pre_process(ll m, ll n) {
if (N_MAX < n) {
fac.resize(n);
inv.resize(n);
finv.resize(n);
}
rep(i, m, n) {
fac[i] = fac[i - 1] * i % mod;
inv[i] = mod - inv[mod % i] * (mod / i) % mod;
finv[i] = finv[i - 1] * inv[i] % mod;
}
}
};
ll choose(int n, int r) { // O(r) for small n
ll acc = 1;
rep(i, 0, r) acc = acc * (n - i) / (i + 1);
return acc;
}
ll gcd(ll a, ll b) {
if (a % b == 0)
return b;
else
return gcd(b, a % b);
}
vll getDivisors(ll n) {
vll res;
ll i = 1;
for (; i * i < n; i++) {
if (n % i == 0) {
res.push_back(i);
res.push_back(n / i);
}
}
if (i * i == n)
res.push_back(i);
sort(res.begin(), res.end());
return res;
}
vll getDivisors(ll n, ll m) {
// O(sqrt(min(n,m)))
if (n > m)
swap(n, m);
vll res;
ll i = 1;
for (; i * i < n; i++) {
if (n % i == 0) {
if (m % i == 0)
res.push_back(i);
if (m % (n / i) == 0)
res.push_back(n / i);
}
}
if (i * i == n)
if (m % i == 0)
res.push_back(i);
sort(res.begin(), res.end());
return res;
}
vector<pll> prime_factorize(ll n) {
vector<pll> res;
for (ll p = 2; p * p <= n; ++p) {
if (n % p != 0)
continue;
ll num = 0;
while (n % p == 0) {
++num;
n /= p;
}
res.push_back({p, num});
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
#include <sstream>
#include <string>
#include <vector>
using namespace std;
vector<string> split(const string &s, char delim) {
vector<string> elems;
stringstream ss(s);
string item;
while (getline(ss, item, delim)) {
if (!item.empty()) {
elems.push_back(item);
}
}
return elems;
}
// ============================ Header =================================
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(12);
ll n, m;
cin >> n >> m;
vll s(n), t(m);
read(s);
read(t);
vector<modint<MOD>> dp(m + 1);
vvll dict(m + 1);
vector<modint<MOD>> S(m + 2);
rep(i, 0, n) {
rrep(j, 0, m) {
if (s[i] == t[j]) {
if (j == 0) {
dp[j] += 1;
} else
dp[j] += S[j] + 1;
}
}
fill_v(S, 0);
rep(j, 0, m + 1) { S[j + 1] = S[j] + dp[j]; }
}
modint<> tot = 0;
rep(i, 0, m) tot += dp[i];
cout << tot + 1 << endl;
;
return 0;
}
| replace | 677 | 678 | 677 | 678 | 0 | |
p03003 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <cmath> // 変数名にy1が使えなくなるかも…。
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
typedef __int128_t int128_t;
std::istream &
operator>>(std::istream &input,
int128_t &value) { // int128_tの入力。入力が64bitに収まる前提。
long long tmp;
input >> tmp;
value = tmp;
return input;
}
std::ostream &
operator<<(std::ostream &output,
const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。
output << (long long)value;
return output;
}
const int MAX_N = 1010;
const int MOD = 1e9 + 7;
int128_t N, M;
int128_t S[MAX_N], T[MAX_N];
int128_t dp[MAX_N][MAX_N][2][2] = {};
int128_t calc(int n, int m, int f1,
int f2) { // n,mまで選び終わって一致している。
if (dp[n][m][f1][f2] != -1) {
return dp[n][m][f1][f2];
}
int128_t ret = 0;
if (n == 0) {
if (f1 == 1 && f2 == 0) {
ret = 1;
} else {
ret = 0;
}
} else if (m == 0) {
if (f1 == 0 && f2 == 1) {
ret = 1;
} else {
ret = 0;
}
} else if (f1 == 1 && f2 == 1) {
if (S[n] == T[m]) {
ret += calc(n - 1, m - 1, 0, 0);
ret += calc(n - 1, m - 1, 1, 0);
ret += calc(n - 1, m - 1, 0, 1);
ret += calc(n - 1, m - 1, 1, 1);
ret %= MOD;
} else {
ret = 0;
}
} else if (f1 == 0 && f2 == 0) {
ret += calc(n - 1, m - 1, 0, 0);
ret += calc(n - 1, m - 1, 1, 0);
ret += calc(n - 1, m - 1, 0, 1);
ret += calc(n - 1, m - 1, 1, 1);
ret %= MOD;
} else if (f1 == 1) {
assert(f2 == 0);
ret += calc(n, m - 1, f1, 0);
ret += calc(n, m - 1, f1, 1);
ret %= MOD;
} else {
assert(f2 == 1);
ret += calc(n - 1, m, 0, f2);
ret += calc(n - 1, m, 1, f2);
ret %= MOD;
}
dp[n][m][f1][f2] = ret;
return ret;
}
int main(int argc, char **argv) {
std::cin >> N >> M;
for (int i = 1; i <= N; i++) {
std::cin >> S[i];
}
for (int i = 1; i <= M; i++) {
std::cin >> T[i];
}
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= M; j++) {
dp[i][j][0][0] = -1;
dp[i][j][0][1] = -1;
dp[i][j][1][0] = -1;
dp[i][j][1][1] = -1;
}
}
dp[0][0][1][1] = 1;
dp[0][0][0][0] = 0;
dp[0][0][0][1] = 0;
dp[0][0][1][0] = 0;
int128_t ret = 0;
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= M; j++) {
ret = (ret + calc(i, j, 1, 1)) % MOD;
// std::cout << i << " " << j << " " << ret << std::endl;
}
}
/*
std::cout << dp[2][2][0][0] << std::endl;
std::cout << dp[2][2][0][1] << std::endl;
std::cout << dp[2][2][1][0] << std::endl;
std::cout << dp[2][2][1][1] << std::endl;
std::cout << std::endl;
std::cout << dp[3][3][1][1] << std::endl;
*/
std::cout << ret << std::endl;
return 0;
} | #include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <cmath> // 変数名にy1が使えなくなるかも…。
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
typedef __int128_t int128_t;
std::istream &
operator>>(std::istream &input,
int128_t &value) { // int128_tの入力。入力が64bitに収まる前提。
long long tmp;
input >> tmp;
value = tmp;
return input;
}
std::ostream &
operator<<(std::ostream &output,
const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。
output << (long long)value;
return output;
}
const int MAX_N = 2010;
const int MOD = 1e9 + 7;
int128_t N, M;
int128_t S[MAX_N], T[MAX_N];
int128_t dp[MAX_N][MAX_N][2][2] = {};
int128_t calc(int n, int m, int f1,
int f2) { // n,mまで選び終わって一致している。
if (dp[n][m][f1][f2] != -1) {
return dp[n][m][f1][f2];
}
int128_t ret = 0;
if (n == 0) {
if (f1 == 1 && f2 == 0) {
ret = 1;
} else {
ret = 0;
}
} else if (m == 0) {
if (f1 == 0 && f2 == 1) {
ret = 1;
} else {
ret = 0;
}
} else if (f1 == 1 && f2 == 1) {
if (S[n] == T[m]) {
ret += calc(n - 1, m - 1, 0, 0);
ret += calc(n - 1, m - 1, 1, 0);
ret += calc(n - 1, m - 1, 0, 1);
ret += calc(n - 1, m - 1, 1, 1);
ret %= MOD;
} else {
ret = 0;
}
} else if (f1 == 0 && f2 == 0) {
ret += calc(n - 1, m - 1, 0, 0);
ret += calc(n - 1, m - 1, 1, 0);
ret += calc(n - 1, m - 1, 0, 1);
ret += calc(n - 1, m - 1, 1, 1);
ret %= MOD;
} else if (f1 == 1) {
assert(f2 == 0);
ret += calc(n, m - 1, f1, 0);
ret += calc(n, m - 1, f1, 1);
ret %= MOD;
} else {
assert(f2 == 1);
ret += calc(n - 1, m, 0, f2);
ret += calc(n - 1, m, 1, f2);
ret %= MOD;
}
dp[n][m][f1][f2] = ret;
return ret;
}
int main(int argc, char **argv) {
std::cin >> N >> M;
for (int i = 1; i <= N; i++) {
std::cin >> S[i];
}
for (int i = 1; i <= M; i++) {
std::cin >> T[i];
}
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= M; j++) {
dp[i][j][0][0] = -1;
dp[i][j][0][1] = -1;
dp[i][j][1][0] = -1;
dp[i][j][1][1] = -1;
}
}
dp[0][0][1][1] = 1;
dp[0][0][0][0] = 0;
dp[0][0][0][1] = 0;
dp[0][0][1][0] = 0;
int128_t ret = 0;
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= M; j++) {
ret = (ret + calc(i, j, 1, 1)) % MOD;
// std::cout << i << " " << j << " " << ret << std::endl;
}
}
/*
std::cout << dp[2][2][0][0] << std::endl;
std::cout << dp[2][2][0][1] << std::endl;
std::cout << dp[2][2][1][0] << std::endl;
std::cout << dp[2][2][1][1] << std::endl;
std::cout << std::endl;
std::cout << dp[3][3][1][1] << std::endl;
*/
std::cout << ret << std::endl;
return 0;
} | replace | 33 | 34 | 33 | 34 | 0 | |
p03003 | C++ | Runtime Error | #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()
#define rall(x) (x).rbegin(), (x).rend()
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;
template <typename T> T pow(T a, long long n, T e = 1) {
T ret = e;
while (n) {
if (n & 1)
ret *= a;
a *= a;
n >>= 1;
}
return ret;
}
template <int mod> struct ModInt {
int x;
ModInt() : x(0) {}
ModInt(long long x_) {
if ((x = x_ % mod + mod) >= mod)
x -= mod;
}
ModInt &operator+=(ModInt rhs) {
if ((x += rhs.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator-=(ModInt rhs) {
if ((x -= rhs.x) < 0)
x += mod;
return *this;
}
ModInt &operator*=(ModInt rhs) {
x = (unsigned long long)x * rhs.x % mod;
return *this;
}
ModInt &operator/=(ModInt rhs) {
x = (unsigned long long)x * rhs.inv().x % mod;
return *this;
}
ModInt operator-() const { return -x < 0 ? mod - x : -x; }
ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
bool operator==(ModInt rhs) const { return x == rhs.x; }
bool operator!=(ModInt rhs) const { return x != rhs.x; }
ModInt inv() const { return pow(*this, mod - 2); }
friend ostream &operator<<(ostream &s, ModInt<mod> a) {
s << a.x;
return s;
}
friend istream &operator>>(istream &s, ModInt<mod> &a) {
s >> a.x;
return s;
}
};
using mint = ModInt<1000000007>;
mint dp[2001][2001];
signed main() {
int n, m;
cin >> n >> m;
int s[n], t[m];
REP(i, n) cin >> s[i];
REP(i, m) cin >> t[i];
dp[0][0] = 1;
REP(i, n + 1) REP(j, m + 1) {
if (i > 0)
dp[i][j] += dp[i - 1][j];
if (j > 0)
dp[i][j] += dp[i][j - 1];
if (i > 0 and j > 0 and s[i - 1] != s[j - 1])
dp[i][j] -= dp[i - 1][j - 1];
}
cout << dp[n][m] << 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()
#define rall(x) (x).rbegin(), (x).rend()
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;
template <typename T> T pow(T a, long long n, T e = 1) {
T ret = e;
while (n) {
if (n & 1)
ret *= a;
a *= a;
n >>= 1;
}
return ret;
}
template <int mod> struct ModInt {
int x;
ModInt() : x(0) {}
ModInt(long long x_) {
if ((x = x_ % mod + mod) >= mod)
x -= mod;
}
ModInt &operator+=(ModInt rhs) {
if ((x += rhs.x) >= mod)
x -= mod;
return *this;
}
ModInt &operator-=(ModInt rhs) {
if ((x -= rhs.x) < 0)
x += mod;
return *this;
}
ModInt &operator*=(ModInt rhs) {
x = (unsigned long long)x * rhs.x % mod;
return *this;
}
ModInt &operator/=(ModInt rhs) {
x = (unsigned long long)x * rhs.inv().x % mod;
return *this;
}
ModInt operator-() const { return -x < 0 ? mod - x : -x; }
ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
bool operator==(ModInt rhs) const { return x == rhs.x; }
bool operator!=(ModInt rhs) const { return x != rhs.x; }
ModInt inv() const { return pow(*this, mod - 2); }
friend ostream &operator<<(ostream &s, ModInt<mod> a) {
s << a.x;
return s;
}
friend istream &operator>>(istream &s, ModInt<mod> &a) {
s >> a.x;
return s;
}
};
using mint = ModInt<1000000007>;
mint dp[2001][2001];
signed main() {
int n, m;
cin >> n >> m;
int s[n], t[m];
REP(i, n) cin >> s[i];
REP(i, m) cin >> t[i];
dp[0][0] = 1;
REP(i, n + 1) REP(j, m + 1) {
if (i > 0)
dp[i][j] += dp[i - 1][j];
if (j > 0)
dp[i][j] += dp[i][j - 1];
if (i > 0 and j > 0 and s[i - 1] != t[j - 1])
dp[i][j] -= dp[i - 1][j - 1];
}
cout << dp[n][m] << endl;
} | replace | 102 | 103 | 102 | 103 | 0 | |
p03003 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;
template <int MOD> struct Fp {
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
if (val < 0)
v += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; }
constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
constexpr Fp &operator+=(const Fp &r) noexcept {
val += r.val;
if (val >= MOD)
val -= MOD;
return *this;
}
constexpr Fp &operator-=(const Fp &r) noexcept {
val -= r.val;
if (val < 0)
val += MOD;
return *this;
}
constexpr Fp &operator*=(const Fp &r) noexcept {
val = val * r.val % MOD;
return *this;
}
constexpr Fp &operator/=(const Fp &r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
val = val * u % MOD;
if (val < 0)
val += MOD;
return *this;
}
constexpr bool operator==(const Fp &r) const noexcept {
return this->val == r.val;
}
constexpr bool operator!=(const Fp &r) const noexcept {
return this->val != r.val;
}
friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept {
return os << x.val;
}
friend constexpr istream &operator>>(istream &is, Fp<MOD> &x) noexcept {
return is >> x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
if (n == 0)
return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1)
t = t * a;
return t;
}
};
using mint = Fp<MOD>;
int main() {
#ifdef MYLOCAL
ifstream in("input.txt");
cin.rdbuf(in.rdbuf());
#endif
int N, M;
cin >> N >> M;
vector<int> S(N), T(N);
for (int i = 0; i < N; ++i)
cin >> S[i];
for (int i = 0; i < M; ++i)
cin >> T[i];
mint dp[2100][2100];
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for (int i = 0; i <= N; ++i) {
for (int j = 0; j <= M; ++j) {
if (i - 1 >= 0 && j - 1 >= 0 && S[i - 1] == T[j - 1]) {
dp[i][j] += dp[i - 1][j - 1];
}
if (i - 1 >= 0) {
dp[i][j] += dp[i - 1][j];
}
if (j - 1 >= 0) {
dp[i][j] += dp[i][j - 1];
}
if (i - 1 >= 0 && j - 1 >= 0) {
dp[i][j] -= dp[i - 1][j - 1];
}
}
}
cout << dp[N][M] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;
template <int MOD> struct Fp {
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
if (val < 0)
v += MOD;
}
constexpr int getmod() { return MOD; }
constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; }
constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; }
constexpr Fp &operator+=(const Fp &r) noexcept {
val += r.val;
if (val >= MOD)
val -= MOD;
return *this;
}
constexpr Fp &operator-=(const Fp &r) noexcept {
val -= r.val;
if (val < 0)
val += MOD;
return *this;
}
constexpr Fp &operator*=(const Fp &r) noexcept {
val = val * r.val % MOD;
return *this;
}
constexpr Fp &operator/=(const Fp &r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
val = val * u % MOD;
if (val < 0)
val += MOD;
return *this;
}
constexpr bool operator==(const Fp &r) const noexcept {
return this->val == r.val;
}
constexpr bool operator!=(const Fp &r) const noexcept {
return this->val != r.val;
}
friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept {
return os << x.val;
}
friend constexpr istream &operator>>(istream &is, Fp<MOD> &x) noexcept {
return is >> x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
if (n == 0)
return 1;
auto t = modpow(a, n / 2);
t = t * t;
if (n & 1)
t = t * a;
return t;
}
};
using mint = Fp<MOD>;
int main() {
#ifdef MYLOCAL
ifstream in("input.txt");
cin.rdbuf(in.rdbuf());
#endif
int N, M;
cin >> N >> M;
vector<int> S(N), T(M);
for (int i = 0; i < N; ++i)
cin >> S[i];
for (int i = 0; i < M; ++i)
cin >> T[i];
mint dp[2100][2100];
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
for (int i = 0; i <= N; ++i) {
for (int j = 0; j <= M; ++j) {
if (i - 1 >= 0 && j - 1 >= 0 && S[i - 1] == T[j - 1]) {
dp[i][j] += dp[i - 1][j - 1];
}
if (i - 1 >= 0) {
dp[i][j] += dp[i - 1][j];
}
if (j - 1 >= 0) {
dp[i][j] += dp[i][j - 1];
}
if (i - 1 >= 0 && j - 1 >= 0) {
dp[i][j] -= dp[i - 1][j - 1];
}
}
}
cout << dp[N][M] << endl;
return 0;
}
| replace | 83 | 84 | 83 | 84 | -11 | |
p03003 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
constexpr long long MOD = 1e9 + 7;
int s[1010], t[1010];
long long dp[1010][1010];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i)
cin >> s[i];
for (int j = 1; j <= m; ++j)
cin >> t[j];
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
dp[i][j] %= MOD;
if (s[i] == t[j]) {
dp[i][j] += dp[i - 1][j - 1] + 1;
dp[i][j] %= MOD;
}
}
}
if (dp[n][m] < 0)
dp[n][m] += MOD;
cout << (dp[n][m] + 1) % MOD << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
constexpr long long MOD = 1e9 + 7;
int s[2010], t[2010];
long long dp[2010][2010];
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i)
cin >> s[i];
for (int j = 1; j <= m; ++j)
cin >> t[j];
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
dp[i][j] %= MOD;
if (s[i] == t[j]) {
dp[i][j] += dp[i - 1][j - 1] + 1;
dp[i][j] %= MOD;
}
}
}
if (dp[n][m] < 0)
dp[n][m] += MOD;
cout << (dp[n][m] + 1) % MOD << endl;
return 0;
}
| replace | 14 | 16 | 14 | 16 | 0 | |
p03003 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
// #include <boost/multiprecision/cpp_int.hpp>
const double EPS = (1e-10);
using namespace std;
using Int = long long;
// using namespace boost::multiprecision;
const Int MOD = 1000000007;
long long mod_pow(long long x, long long n) {
long long res = 1;
for (int i = 0; i < 60; i++) {
if (n >> i & 1)
res = res * x % MOD;
x = x * x % MOD;
}
return res;
}
template <typename T> T gcd(T a, T b) { return b != 0 ? gcd(b, a % b) : a; }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
void fast_input() {
cin.tie(0);
ios::sync_with_stdio(false);
}
int dp[1005][1005];
int main(void) {
int N, M;
cin >> N >> M;
vector<int> S(N + 1);
vector<int> T(M + 1);
S[0] = 0;
T[0] = 0;
for (int i = 1; i <= N; i++) {
cin >> S[i];
}
for (int i = 1; i <= M; i++) {
cin >> T[i];
}
for (int i = 0; i <= N; i++) {
dp[i][0] = 1;
}
for (int i = 0; i <= M; i++) {
dp[0][i] = 1;
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++) {
dp[i][j] += (dp[i - 1][j] - dp[i - 1][j - 1] + MOD) % MOD;
dp[i][j] %= MOD;
dp[i][j] += (dp[i][j - 1] - dp[i - 1][j - 1] + MOD) % MOD;
dp[i][j] %= MOD;
dp[i][j] += dp[i - 1][j - 1];
dp[i][j] %= MOD;
if (S[i] == T[j]) {
dp[i][j] += dp[i - 1][j - 1];
dp[i][j] %= MOD;
}
}
}
cout << dp[N][M] << endl;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
// #include <boost/multiprecision/cpp_int.hpp>
const double EPS = (1e-10);
using namespace std;
using Int = long long;
// using namespace boost::multiprecision;
const Int MOD = 1000000007;
long long mod_pow(long long x, long long n) {
long long res = 1;
for (int i = 0; i < 60; i++) {
if (n >> i & 1)
res = res * x % MOD;
x = x * x % MOD;
}
return res;
}
template <typename T> T gcd(T a, T b) { return b != 0 ? gcd(b, a % b) : a; }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
void fast_input() {
cin.tie(0);
ios::sync_with_stdio(false);
}
int dp[2005][2005];
int main(void) {
int N, M;
cin >> N >> M;
vector<int> S(N + 1);
vector<int> T(M + 1);
S[0] = 0;
T[0] = 0;
for (int i = 1; i <= N; i++) {
cin >> S[i];
}
for (int i = 1; i <= M; i++) {
cin >> T[i];
}
for (int i = 0; i <= N; i++) {
dp[i][0] = 1;
}
for (int i = 0; i <= M; i++) {
dp[0][i] = 1;
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= M; j++) {
dp[i][j] += (dp[i - 1][j] - dp[i - 1][j - 1] + MOD) % MOD;
dp[i][j] %= MOD;
dp[i][j] += (dp[i][j - 1] - dp[i - 1][j - 1] + MOD) % MOD;
dp[i][j] %= MOD;
dp[i][j] += dp[i - 1][j - 1];
dp[i][j] %= MOD;
if (S[i] == T[j]) {
dp[i][j] += dp[i - 1][j - 1];
dp[i][j] %= MOD;
}
}
}
cout << dp[N][M] << endl;
}
| replace | 52 | 53 | 52 | 53 | 0 | |
p03003 | Python | Runtime Error | import itertools
N, M = [int(_) for _ in input().split()]
S = [int(_) for _ in input().split()]
T = [int(_) for _ in input().split()]
mod = 10**9 + 7
dp = [[1] * (N + 1)] + [[1] + [0] * M for _ in range(N)]
for n, m in itertools.product(range(N), range(M)):
dp[n + 1][m + 1] = dp[n][m + 1] + dp[n + 1][m] - dp[n][m]
if S[n] == T[m]:
dp[n + 1][m + 1] += dp[n][m]
dp[n + 1][m + 1] %= mod
print(dp[-1][-1])
| import itertools
N, M = [int(_) for _ in input().split()]
S = [int(_) for _ in input().split()]
T = [int(_) for _ in input().split()]
mod = 10**9 + 7
dp = [[1] * (M + 1)] + [[1] + [0] * M for _ in range(N)]
for n, m in itertools.product(range(N), range(M)):
dp[n + 1][m + 1] = dp[n][m + 1] + dp[n + 1][m] - dp[n][m]
if S[n] == T[m]:
dp[n + 1][m + 1] += dp[n][m]
dp[n + 1][m + 1] %= mod
print(dp[-1][-1])
| replace | 6 | 7 | 6 | 7 | 0 | |
p03003 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define P 1000000007
int main() {
long long N, M;
cin >> N >> M;
vector<long long> S(N), T(M);
for (long long i = 0; i < N; i++)
cin >> S[i];
for (long long i = 0; i < M; i++)
cin >> T[i];
vector<vector<long long>> DP(N, vector<long long>(M, 0));
for (long long s = 0; s < N; s++) {
for (long long t = 0; t < M; t++) {
if (s == 0 && t == 0) {
DP[s][t] = (S[s] == T[t]) + 1;
} else if (s == 0) {
DP[s][t] = ((S[s] == T[t]) + DP[s][t - 1]) % P;
} else if (t == 0) {
DP[s][t] = ((S[s] == T[t]) + DP[s - 1][t]) % P;
} else {
long long a = ((S[s] == T[t]) * (DP[s - 1][t - 1])) % P;
long long b =
((DP[s - 1][t] - DP[s - 1][t - 1]) % P + DP[s][t - 1]) % P;
DP[s][t] = (a + b) % P;
}
}
}
assert(DP[N - 1][M - 1] > 0);
cout << DP[N - 1][M - 1];
} | #include <bits/stdc++.h>
using namespace std;
#define P 1000000007
int main() {
long long N, M;
cin >> N >> M;
vector<long long> S(N), T(M);
for (long long i = 0; i < N; i++)
cin >> S[i];
for (long long i = 0; i < M; i++)
cin >> T[i];
vector<vector<long long>> DP(N, vector<long long>(M, 0));
for (long long s = 0; s < N; s++) {
for (long long t = 0; t < M; t++) {
if (s == 0 && t == 0) {
DP[s][t] = (S[s] == T[t]) + 1;
} else if (s == 0) {
DP[s][t] = ((S[s] == T[t]) + DP[s][t - 1]) % P;
} else if (t == 0) {
DP[s][t] = ((S[s] == T[t]) + DP[s - 1][t]) % P;
} else {
long long a = ((S[s] == T[t]) * (DP[s - 1][t - 1])) % P;
long long b =
((DP[s - 1][t] - DP[s - 1][t - 1]) % P + DP[s][t - 1]) % P;
DP[s][t] = (a + b) % P;
}
}
}
while (DP[N - 1][M - 1] < 0)
DP[N - 1][M - 1] += P;
assert(DP[N - 1][M - 1] >= 0);
cout << DP[N - 1][M - 1];
} | replace | 29 | 30 | 29 | 32 | 0 | |
p03003 | C++ | Memory Limit Exceeded | #include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rep3(i, m, n) for (int(i) = m; (i) <= (n); (i)++)
#define rep3rev(i, m, n) for (int(i) = m; (i) >= (n); (i)--)
#define all(a) (a.begin()), (a.end())
#define rall(a) (a.rbegin()), (a.rend())
#define MOD 1000000007;
ll dp[2020][2020];
ll ac[2001][100001];
int main() {
int n, m;
cin >> n >> m;
rep(i, 2020) rep(j, 2020) dp[i][j] = 0;
rep(i, n + 1) dp[i][0] = 1;
rep(i, m + 1) dp[0][i] = 1;
vector<long long int> s(n), t(m);
for (int i = 0; i < n; i++)
cin >> s[i];
for (int i = 0; i < m; i++)
cin >> t[i];
for (int i = 1; i < n + 1; i++)
for (int j = 0; j < 100001; j++)
ac[i][j] = 0;
for (int j = 0; j < 100001; j++)
ac[0][j] = 0;
for (int j = 1; j <= m; j++) {
for (int i = 0; i <= n; i++)
ac[i][t[j - 1]] = (ac[i][t[j - 1]] + dp[i][j - 1]) % MOD;
for (int i = 1; i <= n; i++) {
ll sum = 0;
// for(int k=j-1;k>=0;k--) if(s[i-1]==t[k]) sum = (dp[i-1][k] + sum) %
// MOD;
sum = (sum + ac[i - 1][s[i - 1]]) % MOD;
// cout << ac[i-1][s[i-1]] << endl;
dp[i][j] = (dp[i - 1][j] + sum) % MOD;
}
}
rep(i, n + 1) {
// rep(j,m+1) cout << dp[i][j] << " ";
// cout << endl;
}
cout << dp[n][m] << endl;
return 0;
} | #include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define rep3(i, m, n) for (int(i) = m; (i) <= (n); (i)++)
#define rep3rev(i, m, n) for (int(i) = m; (i) >= (n); (i)--)
#define all(a) (a.begin()), (a.end())
#define rall(a) (a.rbegin()), (a.rend())
#define MOD 1000000007;
ll dp[2020][2020];
int ac[2001][100001];
int main() {
int n, m;
cin >> n >> m;
rep(i, 2020) rep(j, 2020) dp[i][j] = 0;
rep(i, n + 1) dp[i][0] = 1;
rep(i, m + 1) dp[0][i] = 1;
vector<long long int> s(n), t(m);
for (int i = 0; i < n; i++)
cin >> s[i];
for (int i = 0; i < m; i++)
cin >> t[i];
for (int i = 1; i < n + 1; i++)
for (int j = 0; j < 100001; j++)
ac[i][j] = 0;
for (int j = 0; j < 100001; j++)
ac[0][j] = 0;
for (int j = 1; j <= m; j++) {
for (int i = 0; i <= n; i++)
ac[i][t[j - 1]] = (ac[i][t[j - 1]] + dp[i][j - 1]) % MOD;
for (int i = 1; i <= n; i++) {
ll sum = 0;
// for(int k=j-1;k>=0;k--) if(s[i-1]==t[k]) sum = (dp[i-1][k] + sum) %
// MOD;
sum = (sum + ac[i - 1][s[i - 1]]) % MOD;
// cout << ac[i-1][s[i-1]] << endl;
dp[i][j] = (dp[i - 1][j] + sum) % MOD;
}
}
rep(i, n + 1) {
// rep(j,m+1) cout << dp[i][j] << " ";
// cout << endl;
}
cout << dp[n][m] << endl;
return 0;
} | replace | 14 | 15 | 14 | 15 | MLE | |
p03003 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
using namespace std;
class RSAQ {
public:
typedef long long ll;
const int mod = 1e9 + 7;
// マージ可能な主データ型
struct D {
ll value;
D() : value(0) {} /*適切な値にする!!!!!!*/
D(ll value) : value(value) {}
bool operator<(D a) const { return value < a.value; }
};
// 遅延用の型
struct T {
int type; // 0 - empty , 1 - update
ll value;
T() : type(0), value(0) {}
T(int type, ll value) : type(type), value(value) {}
};
int n, n_;
vector<D> dat;
vector<T> td;
D returnD = D(0); // 範囲外の時に返す値。
RSAQ() { n = -1; }
RSAQ(int n_) : n_(n_) {
n = 1;
while (n < n_)
n *= 2;
td.resize(2 * n - 1, T());
dat.resize(2 * n - 1, D());
}
inline D merge(const D a, const D b) const {
return (a.value + b.value) % mod;
}
void delay(int k, int len) {
if (td[k].type == 0)
return;
ll type = td[k].type;
ll v = td[k].value;
td[k].type = 0;
td[k].value = 0;
len /= 2;
{
int l = k * 2 + 1;
dat[l].value += v * len;
td[l].type = type;
td[l].value += v;
}
{
int r = k * 2 + 2;
dat[r].value += v * len;
td[r].type = type;
td[r].value += v;
}
}
D write(int k, D x, int len) {
dat[k].value += x.value * len;
td[k].type = 1;
td[k].value += x.value;
return dat[k];
}
D dfs(int a, int b, D x, bool flag, int k, int l, int r) {
if (r <= a || b <= l)
return flag ? dat[k] : returnD;
if (a <= l && r <= b)
return flag ? write(k, x, r - l) : dat[k];
delay(k, r - l);
D vl = dfs(a, b, x, flag, k * 2 + 1, l, (l + r) / 2);
D vr = dfs(a, b, x, flag, k * 2 + 2, (l + r) / 2, r);
return flag ? (dat[k] = merge(vl, vr)) : merge(vl, vr);
}
//[l,r)の値にx加算
void add(int l, int r, ll x) {
assert(l <= r);
assert(0 <= l && l <= n);
assert(0 <= r && r <= n);
dfs(l, r, D(x), true, 0, 0, n);
}
//[l,r)の合計値を得る
ll get(int l, int r) {
assert(l <= r);
assert(0 <= l && l <= n);
assert(0 <= r && r <= n);
D res = dfs(l, r, D(), false, 0, 0, n);
return res.value;
}
};
const int N = 2005;
const int M = 2005;
const int mod = 1e9 + 7;
int n, m;
int A[N], B[M];
int dp[N][M];
signed main() {
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> A[i];
for (int i = 0; i < m; i++)
cin >> B[i];
RSAQ rmq(n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (A[i] == B[j]) {
dp[i][j] = rmq.get(0, j) + 1;
dp[i][j] %= mod;
}
}
for (int j = 0; j < m; j++) {
if (A[i] == B[j]) {
rmq.add(j, j + 1, dp[i][j]);
}
}
}
int ans = (rmq.get(0, m) + 1) % mod;
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define int long long
using namespace std;
class RSAQ {
public:
typedef long long ll;
const int mod = 1e9 + 7;
// マージ可能な主データ型
struct D {
ll value;
D() : value(0) {} /*適切な値にする!!!!!!*/
D(ll value) : value(value) {}
bool operator<(D a) const { return value < a.value; }
};
// 遅延用の型
struct T {
int type; // 0 - empty , 1 - update
ll value;
T() : type(0), value(0) {}
T(int type, ll value) : type(type), value(value) {}
};
int n, n_;
vector<D> dat;
vector<T> td;
D returnD = D(0); // 範囲外の時に返す値。
RSAQ() { n = -1; }
RSAQ(int n_) : n_(n_) {
n = 1;
while (n < n_)
n *= 2;
td.resize(2 * n - 1, T());
dat.resize(2 * n - 1, D());
}
inline D merge(const D a, const D b) const {
return (a.value + b.value) % mod;
}
void delay(int k, int len) {
if (td[k].type == 0)
return;
ll type = td[k].type;
ll v = td[k].value;
td[k].type = 0;
td[k].value = 0;
len /= 2;
{
int l = k * 2 + 1;
dat[l].value += v * len;
td[l].type = type;
td[l].value += v;
}
{
int r = k * 2 + 2;
dat[r].value += v * len;
td[r].type = type;
td[r].value += v;
}
}
D write(int k, D x, int len) {
dat[k].value += x.value * len;
td[k].type = 1;
td[k].value += x.value;
return dat[k];
}
D dfs(int a, int b, D x, bool flag, int k, int l, int r) {
if (r <= a || b <= l)
return flag ? dat[k] : returnD;
if (a <= l && r <= b)
return flag ? write(k, x, r - l) : dat[k];
delay(k, r - l);
D vl = dfs(a, b, x, flag, k * 2 + 1, l, (l + r) / 2);
D vr = dfs(a, b, x, flag, k * 2 + 2, (l + r) / 2, r);
return flag ? (dat[k] = merge(vl, vr)) : merge(vl, vr);
}
//[l,r)の値にx加算
void add(int l, int r, ll x) {
assert(l <= r);
assert(0 <= l && l <= n);
assert(0 <= r && r <= n);
dfs(l, r, D(x), true, 0, 0, n);
}
//[l,r)の合計値を得る
ll get(int l, int r) {
assert(l <= r);
assert(0 <= l && l <= n);
assert(0 <= r && r <= n);
D res = dfs(l, r, D(), false, 0, 0, n);
return res.value;
}
};
const int N = 2005;
const int M = 2005;
const int mod = 1e9 + 7;
int n, m;
int A[N], B[M];
int dp[N][M];
signed main() {
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> A[i];
for (int i = 0; i < m; i++)
cin >> B[i];
RSAQ rmq(m);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (A[i] == B[j]) {
dp[i][j] = rmq.get(0, j) + 1;
dp[i][j] %= mod;
}
}
for (int j = 0; j < m; j++) {
if (A[i] == B[j]) {
rmq.add(j, j + 1, dp[i][j]);
}
}
}
int ans = (rmq.get(0, m) + 1) % mod;
cout << ans << endl;
return 0;
}
| replace | 118 | 119 | 118 | 119 | 0 | |
p03003 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
#define double long double
#define endl "\n"
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define ms(v, x) memset(v, x, sizeof(v))
#define pii pair<int, int>
#define ff first
#define ss second
#define frr(i, n) for (int i = 0; i < n; i++)
#define td(v) v.begin(), v.end()
#define inf 1000000000 // 1e9
#define M 1000000007 // 1e9 + 7
using namespace std;
inline int mod(int n, int m) {
int ret = n % m;
if (ret < 0)
ret += m;
return ret;
}
int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
int exp(int a, int b, int m) {
if (b == 0)
return 1;
if (b == 1)
return mod(a, m);
int k = mod(exp(a, b / 2, m), m);
if (b & 1) {
return mod(a * mod(k * k, m), m);
} else
return mod(k * k, m);
}
int32_t main() {
fastio;
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
frr(i, n) cin >> a[i];
frr(i, m) cin >> b[i];
int dp[n + 1][m + 1];
frr(i, max(n, m) + 1) dp[i][0] = dp[0][i] = 1;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
dp[i][j] = mod(dp[i - 1][j] + dp[i][j - 1] -
(a[i - 1] == b[j - 1] ? 0 : dp[i - 1][j - 1]),
M);
cout << dp[n][m] << endl;
} | #include <bits/stdc++.h>
#define int long long
#define double long double
#define endl "\n"
#define fastio \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define ms(v, x) memset(v, x, sizeof(v))
#define pii pair<int, int>
#define ff first
#define ss second
#define frr(i, n) for (int i = 0; i < n; i++)
#define td(v) v.begin(), v.end()
#define inf 1000000000 // 1e9
#define M 1000000007 // 1e9 + 7
using namespace std;
inline int mod(int n, int m) {
int ret = n % m;
if (ret < 0)
ret += m;
return ret;
}
int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); }
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
int exp(int a, int b, int m) {
if (b == 0)
return 1;
if (b == 1)
return mod(a, m);
int k = mod(exp(a, b / 2, m), m);
if (b & 1) {
return mod(a * mod(k * k, m), m);
} else
return mod(k * k, m);
}
int32_t main() {
fastio;
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
frr(i, n) cin >> a[i];
frr(i, m) cin >> b[i];
int lim = max(n, m) + 1;
int dp[lim][lim];
frr(i, lim) dp[i][0] = dp[0][i] = 1;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
dp[i][j] = mod(dp[i - 1][j] + dp[i][j - 1] -
(a[i - 1] == b[j - 1] ? 0 : dp[i - 1][j - 1]),
M);
cout << dp[n][m] << endl;
} | replace | 45 | 47 | 45 | 48 | 0 | |
p03003 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#define P pair<int, int>
#define LL long long
#define LD long double
#define PLL pair<LL, LL>
#define mset(a, b) memset(a, b, sizeof(a))
#define PI acos(-1.0)
#define random(x) rand() % x
using namespace std;
const int inf = 0x3f3f3f3f;
const LL __64inf = 0x3f3f3f3f3f3f3f3f;
const int MAX = 1e5 + 5;
const int Mod = 1e9 + 7;
LL dp[1005][1005];
LL sum[1005][1005];
int main() {
int n, m;
cin >> n >> m;
vector<int> A(n), B(m);
for (int i = 0; i < n; i++)
cin >> A[i];
for (int i = 0; i < m; i++)
cin >> B[i];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
if (A[i - 1] == B[j - 1])
dp[i][j] = sum[i - 1][j - 1] + 1;
else
dp[i][j] = 0;
sum[i][j] =
(sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j]) % Mod;
if (sum[i][j] < 0)
sum[i][j] += Mod;
}
cout << sum[n][m] + 1 << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#define P pair<int, int>
#define LL long long
#define LD long double
#define PLL pair<LL, LL>
#define mset(a, b) memset(a, b, sizeof(a))
#define PI acos(-1.0)
#define random(x) rand() % x
using namespace std;
const int inf = 0x3f3f3f3f;
const LL __64inf = 0x3f3f3f3f3f3f3f3f;
const int MAX = 1e5 + 5;
const int Mod = 1e9 + 7;
LL dp[2005][2005];
LL sum[2005][2005];
int main() {
int n, m;
cin >> n >> m;
vector<int> A(n), B(m);
for (int i = 0; i < n; i++)
cin >> A[i];
for (int i = 0; i < m; i++)
cin >> B[i];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) {
if (A[i - 1] == B[j - 1])
dp[i][j] = sum[i - 1][j - 1] + 1;
else
dp[i][j] = 0;
sum[i][j] =
(sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j]) % Mod;
if (sum[i][j] < 0)
sum[i][j] += Mod;
}
cout << sum[n][m] + 1 << endl;
return 0;
} | replace | 27 | 29 | 27 | 29 | 0 | |
p03003 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
// #define MOD 998244353
#define INF 1145141919810893364
typedef pair<int, int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define OREP(i, n) for (int i = 1; i <= (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define GOODBYE \
cout << -1 << endl; \
return 0
#define Endl endl
signed main(void) {
int N, M;
const int MEM = 201;
int S[MEM], T[MEM];
int dp[MEM][MEM] = {};
cin >> N >> M;
REP(i, N) { cin >> S[i]; }
REP(i, M) { cin >> T[i]; }
dp[0][0] = 1;
REP(i, N + 1) {
REP(j, M + 1) {
if (i > 0)
dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
if (j > 0)
dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD;
if (i > 0 && j > 0 && S[i - 1] != T[j - 1])
dp[i][j] = (dp[i][j] - dp[i - 1][j - 1] + MOD) % MOD;
}
}
cout << dp[N][M] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
// #define MOD 998244353
#define INF 1145141919810893364
typedef pair<int, int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define OREP(i, n) for (int i = 1; i <= (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define GOODBYE \
cout << -1 << endl; \
return 0
#define Endl endl
signed main(void) {
int N, M;
const int MEM = 2019;
int S[MEM], T[MEM];
int dp[MEM][MEM] = {};
cin >> N >> M;
REP(i, N) { cin >> S[i]; }
REP(i, M) { cin >> T[i]; }
dp[0][0] = 1;
REP(i, N + 1) {
REP(j, M + 1) {
if (i > 0)
dp[i][j] = (dp[i][j] + dp[i - 1][j]) % MOD;
if (j > 0)
dp[i][j] = (dp[i][j] + dp[i][j - 1]) % MOD;
if (i > 0 && j > 0 && S[i - 1] != T[j - 1])
dp[i][j] = (dp[i][j] - dp[i - 1][j - 1] + MOD) % MOD;
}
}
cout << dp[N][M] << endl;
return 0;
}
| replace | 19 | 20 | 19 | 20 | 0 | |
p03003 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define MOD 1000000007
using namespace std;
int s[1008], t[1008];
long long dp[1008][1008];
int n, m;
int main() {
memset(dp, 0, sizeof(dp));
int i, j;
cin >> n >> m;
for (i = 1; i <= n; i++)
cin >> s[i];
for (i = 1; i <= m; i++)
cin >> t[i];
dp[0][0] = 1;
for (i = 1; i <= n; i++)
dp[i][0] = 1;
for (j = 1; j <= m; j++)
dp[0][j] = 1;
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
if (s[i] == t[j])
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
else {
dp[i][j] =
((dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]) % MOD + MOD) %
MOD;
}
}
}
cout << dp[n][m];
return 0;
} | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define MOD 1000000007
using namespace std;
int s[2008], t[2008];
long long dp[2008][2008];
int n, m;
int main() {
memset(dp, 0, sizeof(dp));
int i, j;
cin >> n >> m;
for (i = 1; i <= n; i++)
cin >> s[i];
for (i = 1; i <= m; i++)
cin >> t[i];
dp[0][0] = 1;
for (i = 1; i <= n; i++)
dp[i][0] = 1;
for (j = 1; j <= m; j++)
dp[0][j] = 1;
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
if (s[i] == t[j])
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % MOD;
else {
dp[i][j] =
((dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]) % MOD + MOD) %
MOD;
}
}
}
cout << dp[n][m];
return 0;
} | replace | 8 | 10 | 8 | 10 | 0 | |
p03003 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 2e3 + 10;
const int MOD = 1e9 + 7;
int a[maxn], b[maxn];
LL dp[maxn][maxn];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
for (int i = 1; i <= m; i++)
scanf("%d", &b[i]);
for (int i = 0; i <= n; i++)
dp[i][0] = 1;
for (int i = 0; i <= m; i++)
dp[0][i] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
dp[i][j] = ((dp[i - 1][j] + dp[i][j - 1]) % MOD - dp[i - 1][j - 1]) % MOD;
if (a[i] == b[j]) {
dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % MOD;
}
}
}
assert(dp[n][m] > MOD);
cout << ((dp[n][m] % MOD) + MOD) % MOD << endl;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 2e3 + 10;
const int MOD = 1e9 + 7;
int a[maxn], b[maxn];
LL dp[maxn][maxn];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
for (int i = 1; i <= m; i++)
scanf("%d", &b[i]);
for (int i = 0; i <= n; i++)
dp[i][0] = 1;
for (int i = 0; i <= m; i++)
dp[0][i] = 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
dp[i][j] = ((dp[i - 1][j] + dp[i][j - 1]) % MOD - dp[i - 1][j - 1]) % MOD;
if (a[i] == b[j]) {
dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % MOD;
}
}
}
cout << ((dp[n][m] % MOD) + MOD) % MOD << endl;
} | delete | 26 | 27 | 26 | 26 | -6 | 75db7b5d-3593-48a0-82c0-efaa3ed74ae6.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p03003/C++/s735334963.cpp:27: int main(): Assertion `dp[n][m] > MOD' failed.
|
p03003 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define int long long int
constexpr int MOD = 1000000007; // 10 ** 9 + 7
constexpr int SIZE = 2010;
int dp[SIZE][SIZE];
int sum[SIZE][SIZE];
void solve() {
int N, M;
cin >> N >> M;
vector<int> s(N);
for (auto &x : s) {
cin >> x;
}
vector<int> t(M);
for (auto &x : t) {
cin >> x;
}
for (int i = 0; i <= N; i++) {
sum[i][0] = 1;
}
for (int i = 0; i <= M; i++) {
sum[0][i] = 1;
}
int ret = 1;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
if (s[i] == t[j]) {
dp[i + 1][j + 1] = sum[i - 1][j - 1] + 1;
ret += dp[i + 1][j + 1];
}
sum[i + 1][j + 1] =
(sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + dp[i + 1][j + 1] + MOD) %
MOD;
}
}
cout << ret % MOD << endl;
}
signed main() {
solve();
return 0;
}
| #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define int long long int
constexpr int MOD = 1000000007; // 10 ** 9 + 7
constexpr int SIZE = 2010;
int dp[SIZE][SIZE];
int sum[SIZE][SIZE];
void solve() {
int N, M;
cin >> N >> M;
vector<int> s(N);
for (auto &x : s) {
cin >> x;
}
vector<int> t(M);
for (auto &x : t) {
cin >> x;
}
for (int i = 0; i <= N; i++) {
sum[i][0] = 1;
}
for (int i = 0; i <= M; i++) {
sum[0][i] = 1;
}
int ret = 1;
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
if (s[i] == t[j]) {
dp[i + 1][j + 1] = sum[i][j];
ret += dp[i + 1][j + 1];
}
sum[i + 1][j + 1] =
(sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + dp[i + 1][j + 1] + MOD) %
MOD;
}
}
cout << ret % MOD << endl;
}
signed main() {
solve();
return 0;
}
| replace | 42 | 43 | 42 | 43 | 0 | |
p03003 | Python | Time Limit Exceeded | N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
MOD = 10**9 + 7
dp = [[0] * (M + 2) for _ in range(N + 2)]
sdp = [[0] * (M + 2) for _ in range(N + 2)]
dp[0][0] = 1
sdp[1][1] = 1
for i in range(N + 1):
for j in range(M + 1):
if i - 1 >= 0 and j - 1 >= 0 and S[i - 1] == T[j - 1]:
dp[i][j] = sdp[i][j]
sdp[i + 1][j + 1] = sdp[i + 1][j] + sdp[i][j + 1] - sdp[i][j] + dp[i][j]
sdp[i + 1][j + 1] %= MOD
sdp[i + 1][j + 1] %= MOD
print(sdp[N + 1][M + 1])
| # dp[i][j] SとTの最後の文字を採用するような文字列の個数。これにより各DPテーブルの値が排反になる。元の文字列の最後を必ず採用するので
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
MOD = 10**9 + 7
dp = [[0] * (M + 2) for _ in range(N + 2)]
sdp = [[0] * (M + 2) for _ in range(N + 2)]
dp[0][0] = 1
sdp[1][1] = 1
for i in range(N + 1):
for j in range(M + 1):
if i - 1 >= 0 and j - 1 >= 0 and S[i - 1] == T[j - 1]:
dp[i][j] = sdp[i][j]
sdp[i + 1][j + 1] = sdp[i + 1][j] + sdp[i][j + 1] - sdp[i][j] + dp[i][j]
sdp[i + 1][j + 1] %= MOD
sdp[i + 1][j + 1] %= MOD
print(sdp[N + 1][M + 1])
| insert | 0 | 0 | 0 | 1 | TLE | |
p03003 | C++ | Runtime Error | //
// Created by keane on 19-6-16.
//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e3 + 50;
const ll mod = 1e9 + 7;
int n, m;
int a[N], b[N];
ll dp[N][N];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= m; i++) {
scanf("%d", &b[i]);
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i] == b[j]) {
dp[i][j] = dp[i - 1][j] + dp[i][j - 1] + 1;
} else {
dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
}
dp[i][j] %= mod;
}
}
printf("%lld\n", (dp[n][m] + 1 + mod) % mod);
} | //
// Created by keane on 19-6-16.
//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e3 + 50;
const ll mod = 1e9 + 7;
int n, m;
int a[N], b[N];
ll dp[N][N];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= m; i++) {
scanf("%d", &b[i]);
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i] == b[j]) {
dp[i][j] = dp[i - 1][j] + dp[i][j - 1] + 1;
} else {
dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
}
dp[i][j] %= mod;
}
}
printf("%lld\n", (dp[n][m] + 1 + mod) % mod);
} | replace | 6 | 7 | 6 | 7 | 0 | |
p03003 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define reps(i, s, n) for (int(i) = (s); (i) < (n); (i)++)
#define repr(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--)
#define all(v) (v).begin(), (v).end()
#define chmax(a, b) a = (((a) < (b)) ? (b) : (a))
#define chmin(a, b) a = (((a) > (b)) ? (b) : (a))
#define pb push_back
#define MOD 1000000007
#define inf 1000000000
#define llinf 1000000000000000
#define MAX 1000000
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
typedef vector<pint> vpint;
ll dp[2005][2005];
int main() {
int n, m;
cin >> n >> m;
vint a(n), b(n);
rep(i, n) cin >> a[i];
rep(i, m) cin >> b[i];
rep(i, n + 1) dp[i][0] = 1;
rep(i, m + 1) dp[0][i] = 1;
rep(i, n + 1) rep(j, m + 1) {
if (i == 0 || j == 0) {
continue;
}
// dp[i][j]=(dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%MOD;
if (a[i - 1] == b[j - 1]) {
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] + MOD) % MOD;
} else {
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + MOD) % MOD;
}
}
cout << dp[n][m] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define reps(i, s, n) for (int(i) = (s); (i) < (n); (i)++)
#define repr(i, n) for (int(i) = (n)-1; (i) >= 0; (i)--)
#define all(v) (v).begin(), (v).end()
#define chmax(a, b) a = (((a) < (b)) ? (b) : (a))
#define chmin(a, b) a = (((a) > (b)) ? (b) : (a))
#define pb push_back
#define MOD 1000000007
#define inf 1000000000
#define llinf 1000000000000000
#define MAX 1000000
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
typedef vector<pint> vpint;
ll dp[2005][2005];
int main() {
int n, m;
cin >> n >> m;
vll a(n), b(m);
rep(i, n) cin >> a[i];
rep(i, m) cin >> b[i];
rep(i, n + 1) dp[i][0] = 1;
rep(i, m + 1) dp[0][i] = 1;
rep(i, n + 1) rep(j, m + 1) {
if (i == 0 || j == 0) {
continue;
}
// dp[i][j]=(dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1])%MOD;
if (a[i - 1] == b[j - 1]) {
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] + MOD) % MOD;
} else {
dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1] + MOD) % MOD;
}
}
cout << dp[n][m] << endl;
}
| replace | 27 | 28 | 27 | 28 | 0 | |
p03003 | C++ | Time Limit Exceeded | #include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define INF 1LL << 60
template <typename T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <typename T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
int in() {
int x;
scanf("%d", &x);
return x;
}
ll lin() {
ll x;
scanf("%lld", &x);
return x;
}
int main() {
ll mod = 1e9 + 7;
int N, M;
cin >> N >> M;
vector<int> S(N), T(M);
REP(i, N) cin >> S[i];
REP(i, M) cin >> T[i];
vector<vector<ll>> dp(N + 1, vector<ll>(M + 1, 1));
FOR(i, 1, N)
FOR(j, 1, M) {
if (S[i - 1] == T[j - 1])
dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % mod;
else
dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1] + mod) % mod;
}
cerr << "debug" << endl;
FOR(i, 0, N) {
FOR(j, 0, M) { cerr << dp[i][j] << " "; }
cerr << endl;
}
cout << dp[N][M] << endl;
return 0;
} | #include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define INF 1LL << 60
template <typename T> void chmin(T &a, T b) {
if (a > b)
a = b;
}
template <typename T> void chmax(T &a, T b) {
if (a < b)
a = b;
}
int in() {
int x;
scanf("%d", &x);
return x;
}
ll lin() {
ll x;
scanf("%lld", &x);
return x;
}
int main() {
ll mod = 1e9 + 7;
int N, M;
cin >> N >> M;
vector<int> S(N), T(M);
REP(i, N) cin >> S[i];
REP(i, M) cin >> T[i];
vector<vector<ll>> dp(N + 1, vector<ll>(M + 1, 1));
FOR(i, 1, N)
FOR(j, 1, M) {
if (S[i - 1] == T[j - 1])
dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % mod;
else
dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1] + mod) % mod;
}
// cerr << "debug" << endl;
// FOR(i, 0, N) {
// FOR(j, 0, M) {
// cerr << dp[i][j] << " ";
// }
// cerr << endl;
// }
cout << dp[N][M] << endl;
return 0;
} | replace | 71 | 76 | 71 | 78 | TLE | |
p03003 | C++ | Runtime Error | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <random>
#include <vector>
using namespace std;
typedef long long int ll;
ll mod = 1e9 + 7;
ll dp[2010][2010], sum[2010][2010];
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<int> s(n), t(n);
for (int i = 0; i < n; i++) {
cin >> s[i];
}
for (int i = 0; i < m; i++) {
cin >> t[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (i) {
(sum[i][j] += sum[i - 1][j]) %= mod;
}
if (j) {
(sum[i][j] += sum[i][j - 1]) %= mod;
}
if (i && j) {
(sum[i][j] -= sum[i - 1][j - 1] - mod) %= mod;
dp[i][j] += sum[i - 1][j - 1];
}
dp[i][j]++;
dp[i][j] %= mod;
if (s[i] != t[j])
dp[i][j] = 0;
(sum[i][j] += dp[i][j]) %= mod;
}
}
cout << (sum[n - 1][m - 1] + 1) % mod << endl;
} | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <random>
#include <vector>
using namespace std;
typedef long long int ll;
ll mod = 1e9 + 7;
ll dp[2010][2010], sum[2010][2010];
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<int> s(n), t(m);
for (int i = 0; i < n; i++) {
cin >> s[i];
}
for (int i = 0; i < m; i++) {
cin >> t[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (i) {
(sum[i][j] += sum[i - 1][j]) %= mod;
}
if (j) {
(sum[i][j] += sum[i][j - 1]) %= mod;
}
if (i && j) {
(sum[i][j] -= sum[i - 1][j - 1] - mod) %= mod;
dp[i][j] += sum[i - 1][j - 1];
}
dp[i][j]++;
dp[i][j] %= mod;
if (s[i] != t[j])
dp[i][j] = 0;
(sum[i][j] += dp[i][j]) %= mod;
}
}
cout << (sum[n - 1][m - 1] + 1) % mod << endl;
} | replace | 16 | 17 | 16 | 17 | 0 | |
p03003 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll inf = 1e9 + 7;
ll n, m, s[2020], t[2020];
ll dp[2020][2020] = {};
vector<ll> s_list[100010], t_list[100010];
/*
ll solve(int k, int l) {
if (dp[k][l]) return dp[k][l];
if (k * l == 0) dp[k][l] = 1;
else {
}
dp[k][l] %= inf;
return dp[k][l];
}*/
int main(void) {
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> s[i];
s_list[s[i]].push_back(i);
}
for (int i = 0; i < m; i++) {
cin >> t[i];
}
dp[0][0] = 1;
for (int i = 0; i < n; i++)
dp[i + 1][0] = 1;
for (int j = 0; j < m; j++)
dp[0][j + 1] = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
dp[i + 1][j + 1] = dp[i + 1][j];
for (int k = 0; k < s_list[t[j]].size() && s_list[t[j]][k] < i + 1; k++) {
dp[i + 1][j + 1] += dp[s_list[t[j]][k]][j];
}
dp[i + 1][j + 1] %= inf;
}
}
cout << dp[n][m] << endl;
/*
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= m; j++) {
if (j != 0) cout << " ";
cout << dp[i][j];
}
cout << endl;
}*/
// cout << solve(n, m) << endl;
}
| #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll inf = 1e9 + 7;
ll n, m, s[2020], t[2020];
ll dp[2020][2020] = {};
vector<ll> s_list[100010], t_list[100010];
/*
ll solve(int k, int l) {
if (dp[k][l]) return dp[k][l];
if (k * l == 0) dp[k][l] = 1;
else {
}
dp[k][l] %= inf;
return dp[k][l];
}*/
int main(void) {
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> s[i];
s_list[s[i]].push_back(i);
}
for (int i = 0; i < m; i++) {
cin >> t[i];
}
dp[0][0] = 1;
for (int i = 0; i < n; i++)
dp[i + 1][0] = 1;
for (int j = 0; j < m; j++)
dp[0][j + 1] = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (s[i] == t[j])
dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1];
else
dp[i + 1][j + 1] = inf + dp[i + 1][j] + dp[i][j + 1] - dp[i][j];
dp[i + 1][j + 1] %= inf;
}
}
cout << dp[n][m] << endl;
/*
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= m; j++) {
if (j != 0) cout << " ";
cout << dp[i][j];
}
cout << endl;
}*/
// cout << solve(n, m) << endl;
}
| replace | 42 | 46 | 42 | 46 | TLE | |
p03003 | C++ | Runtime Error | #include <algorithm>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using P = pair<long, long>;
typedef long long int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define fillInt(xs) \
for (int i = 0; i < (xs).size(); i++) \
scanf("%d", &xs[i]);
#define fillLong(xs) \
for (int i = 0; i < (xs).size(); i++) \
scanf("%ld", &xs[i]);
#define fillDouble(xs) \
for (int i = 0; i < (xs).size(); i++) \
scanf("%lf", &xs[i]);
#define fillString(xs) \
for (int i = 0; i < (xs).size(); i++) \
cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
distance(as.begin(), lower_bound(as.begin(), as.end(), x))
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define concat(xs, ys) (xs).insert((xs).end(), (ys).begin(), (ys).end())
const int mod = 1000000007;
const int MAX_V = 100005;
struct mint {
ll x;
mint(ll x = 0) : x(x % mod) {}
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if (x < a.x) {
x += mod;
}
x -= a.x;
return *this;
}
mint &operator*=(const mint a) {
x = (x * a.x) % mod;
return *this;
}
mint &operator/=(const mint a) {
*this *= a.inv();
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 operator/(const mint a) const {
mint res(*this);
return res /= a;
}
mint pow(ll n) const {
mint a(*this);
mint res = 1;
while (n > 0) {
if (n & 1)
res *= a;
a *= a;
n >>= 1;
}
return res;
}
mint inv() const { return pow(mod - 2); }
};
mint dp[1005][1005];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<long> s(n);
vector<long> t(m);
fillLong(s);
fillLong(t);
rep(i, n + 1) { dp[i][0] = 1; }
rep(i, m + 1) { dp[0][i] = 1; }
rep(i, n) rep(j, m) {
dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j];
if (s[i] != t[j]) {
dp[i + 1][j + 1] -= dp[i][j];
}
}
cout << dp[n][m].x << endl;
}
| #include <algorithm>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using P = pair<long, long>;
typedef long long int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define fillInt(xs) \
for (int i = 0; i < (xs).size(); i++) \
scanf("%d", &xs[i]);
#define fillLong(xs) \
for (int i = 0; i < (xs).size(); i++) \
scanf("%ld", &xs[i]);
#define fillDouble(xs) \
for (int i = 0; i < (xs).size(); i++) \
scanf("%lf", &xs[i]);
#define fillString(xs) \
for (int i = 0; i < (xs).size(); i++) \
cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
distance(as.begin(), lower_bound(as.begin(), as.end(), x))
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define concat(xs, ys) (xs).insert((xs).end(), (ys).begin(), (ys).end())
const int mod = 1000000007;
const int MAX_V = 100005;
struct mint {
ll x;
mint(ll x = 0) : x(x % mod) {}
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if (x < a.x) {
x += mod;
}
x -= a.x;
return *this;
}
mint &operator*=(const mint a) {
x = (x * a.x) % mod;
return *this;
}
mint &operator/=(const mint a) {
*this *= a.inv();
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 operator/(const mint a) const {
mint res(*this);
return res /= a;
}
mint pow(ll n) const {
mint a(*this);
mint res = 1;
while (n > 0) {
if (n & 1)
res *= a;
a *= a;
n >>= 1;
}
return res;
}
mint inv() const { return pow(mod - 2); }
};
mint dp[2005][2005];
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
vector<long> s(n);
vector<long> t(m);
fillLong(s);
fillLong(t);
rep(i, n + 1) { dp[i][0] = 1; }
rep(i, m + 1) { dp[0][i] = 1; }
rep(i, n) rep(j, m) {
dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j];
if (s[i] != t[j]) {
dp[i + 1][j + 1] -= dp[i][j];
}
}
cout << dp[n][m].x << endl;
}
| replace | 117 | 118 | 117 | 118 | 0 | |
p03003 | C++ | Runtime Error | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
const int64_t MOD = 1000000000 + 7;
int main(void) {
cout << std::fixed << std::setprecision(10);
cin.tie(0);
std::ios::sync_with_stdio(false);
int64_t n, m;
cin >> n >> m;
std::vector<int64_t> s, t;
for (int i = 0; i < n; i++) {
int m1;
cin >> m1;
s.push_back(m1);
}
for (int i = 0; i < m; i++) {
int m1;
cin >> m1;
t.push_back(m1);
}
int64_t dp[2001][2001] = {};
int64_t cum[2001][2001] = {};
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (s[i] == t[j]) {
if (i == 0 || j == 0) {
dp[i][j] = 1;
} else {
dp[i][j] = 1 + cum[i - 1][j - 1];
}
} else {
dp[i][j] = 0;
}
// assert(dp[i][j]<INT64_MAX&&0<=dp[i][j]);
dp[i][j] %= MOD;
if (i == 0 && j == 0) {
cum[i][j] = dp[i][j];
} else if (i == 0) {
cum[i][j] = dp[i][j] + cum[i][j - 1];
} else if (j == 0) {
cum[i][j] = dp[i][j] + cum[i - 1][j];
} else {
cum[i][j] =
cum[i][j - 1] + cum[i - 1][j] - cum[i - 1][j - 1] + dp[i][j];
}
// assert(cum[i][j]<INT64_MAX&&0<=cum[i][j]);
cum[i][j] %= MOD;
}
}
int64_t result = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
result += dp[i][j];
result %= MOD;
}
}
result %= MOD;
assert(result < MOD && 0 <= result);
cout << result << endl;
return 0;
}
| #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
const int64_t MOD = 1000000000 + 7;
int main(void) {
cout << std::fixed << std::setprecision(10);
cin.tie(0);
std::ios::sync_with_stdio(false);
int64_t n, m;
cin >> n >> m;
std::vector<int64_t> s, t;
for (int i = 0; i < n; i++) {
int m1;
cin >> m1;
s.push_back(m1);
}
for (int i = 0; i < m; i++) {
int m1;
cin >> m1;
t.push_back(m1);
}
int64_t dp[2001][2001] = {};
int64_t cum[2001][2001] = {};
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (s[i] == t[j]) {
if (i == 0 || j == 0) {
dp[i][j] = 1;
} else {
dp[i][j] = 1 + cum[i - 1][j - 1];
}
} else {
dp[i][j] = 0;
}
// assert(dp[i][j]<INT64_MAX&&0<=dp[i][j]);
dp[i][j] %= MOD;
if (i == 0 && j == 0) {
cum[i][j] = dp[i][j];
} else if (i == 0) {
cum[i][j] = dp[i][j] + cum[i][j - 1];
} else if (j == 0) {
cum[i][j] = dp[i][j] + cum[i - 1][j];
} else {
cum[i][j] =
cum[i][j - 1] + cum[i - 1][j] - cum[i - 1][j - 1] + dp[i][j];
}
// assert(cum[i][j]<INT64_MAX&&0<=cum[i][j]);
if (cum[i][j] < 0)
cum[i][j] += MOD;
cum[i][j] %= MOD;
}
}
int64_t result = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
result += dp[i][j];
result %= MOD;
}
}
result %= MOD;
assert(result < MOD && 0 <= result);
cout << result << endl;
return 0;
}
| insert | 70 | 70 | 70 | 72 | -11 | |
p03003 | C++ | Runtime Error | #include <bits/stdc++.h>
#define w cout
#define e '\n'
#define int long long
#define all(v) (begin(v), end(v))
#define pb push_back
using namespace std;
const int N = 1e5 + 10, MOD = 1e9 + 7;
int dd[N], temp[N];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
int a[n + 1], b[n + 1];
for (int i = 0; i < n; i++)
cin >> a[i];
for (int j = 0; j < m; j++)
cin >> b[j];
int sum = 0;
for (int i = n - 1; i >= 0; i--) {
sum = 0;
for (int j = m - 1; j >= 0; j--) {
if (a[i] == b[j]) {
dd[j] += sum + 1;
dd[j] %= MOD;
}
sum += temp[j];
sum %= MOD;
}
for (int j = 0; j < m; j++) {
temp[j] = dd[j] % MOD;
}
}
int ans = 0;
for (int i = 0; i < m; i++) {
ans += dd[i];
ans = ans % MOD;
}
w << (ans + 1) % MOD;
}
| #include <bits/stdc++.h>
#define w cout
#define e '\n'
#define int long long
#define all(v) (begin(v), end(v))
#define pb push_back
using namespace std;
const int N = 1e5 + 10, MOD = 1e9 + 7;
int dd[N], temp[N];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
int a[n + 1], b[m + 1];
for (int i = 0; i < n; i++)
cin >> a[i];
for (int j = 0; j < m; j++)
cin >> b[j];
int sum = 0;
for (int i = n - 1; i >= 0; i--) {
sum = 0;
for (int j = m - 1; j >= 0; j--) {
if (a[i] == b[j]) {
dd[j] += sum + 1;
dd[j] %= MOD;
}
sum += temp[j];
sum %= MOD;
}
for (int j = 0; j < m; j++) {
temp[j] = dd[j] % MOD;
}
}
int ans = 0;
for (int i = 0; i < m; i++) {
ans += dd[i];
ans = ans % MOD;
}
w << (ans + 1) % MOD;
}
| replace | 17 | 18 | 17 | 18 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.