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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02851 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define F first
#define S second
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define PI 3.141592653589
// Input
#define in(a) scanf("%d", &a)
#define in2(a, b) scanf("%d%d", &a, &b)
#define in3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld", &a)
#define read(v, i, n) \
for (i = 0; i < n; i++) \
in(v[i])
#define twod(mat, i, j, n, m) \
rep(i, n) { rep(j, m) in(mat[i][j]); }
#define sc(ch) scanf("%c", &ch)
#define sstr(str) scanf("%s", str)
// Output
#define pr(a) printf("%d ", a)
#define pr2(a, b) printf("%d %d\n", a, b)
#define pr3(a, b, c) printf("%d %d %d\n", a, b, c)
#define out(a) printf("%d\n", a)
#define outl(a) printf("%lld\n", a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i, a, b) for (i = a; i < b; i++)
#define rep(i, n) for (i = 0; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lower(v, k) lower_bound(v.begin(), v.end(), k) - v.begin()
#define upper(v, k) upper_bound(v.begin(), v.end(), k) - v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v, i, n) \
for (i = 0; i < n; i++) \
pr(v[i]); \
lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << "\n";
err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int, int>
#define pli pair<ll, int>
#define triple tuple<int, int, int>
#define vi vector<int>
#define vii vector<pair<int, int>>
#define vvi vector<vector<int>>
#define viii vector<pair<pair<int, int>, int>>
#define vvii vector<vector<pair<int, int>>>
#define M 1000000000
#define N 200005 // check the limits, man
int main() {
int i, n, k, a;
in2(n, k);
vi v(n);
read(v, i, n);
vi sum(n + 1);
sum[0] = 0;
lp(i, 1, n + 1) {
sum[i] = sum[i - 1] + v[i - 1];
sum[i] %= k;
}
rep(i, n + 1) {
sum[i] -= (i % k);
if (sum[i] < 0)
sum[i] += k;
}
map<int, int> cnt;
rep(i, k) a = sum[i], cnt[a]++;
ll ans = 0;
rep(i, n) {
a = sum[i];
cnt[a]--;
ans += (cnt[a]);
if (i + k <= n)
a = sum[i + k], cnt[a]++;
}
llout(ans);
}
| #include <bits/stdc++.h>
using namespace std;
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define F first
#define S second
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define PI 3.141592653589
// Input
#define in(a) scanf("%d", &a)
#define in2(a, b) scanf("%d%d", &a, &b)
#define in3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld", &a)
#define read(v, i, n) \
for (i = 0; i < n; i++) \
in(v[i])
#define twod(mat, i, j, n, m) \
rep(i, n) { rep(j, m) in(mat[i][j]); }
#define sc(ch) scanf("%c", &ch)
#define sstr(str) scanf("%s", str)
// Output
#define pr(a) printf("%d ", a)
#define pr2(a, b) printf("%d %d\n", a, b)
#define pr3(a, b, c) printf("%d %d %d\n", a, b, c)
#define out(a) printf("%d\n", a)
#define outl(a) printf("%lld\n", a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i, a, b) for (i = a; i < b; i++)
#define rep(i, n) for (i = 0; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lower(v, k) lower_bound(v.begin(), v.end(), k) - v.begin()
#define upper(v, k) upper_bound(v.begin(), v.end(), k) - v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v, i, n) \
for (i = 0; i < n; i++) \
pr(v[i]); \
lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) \
{ \
string _s = #args; \
replace(_s.begin(), _s.end(), ',', ' '); \
stringstream _ss(_s); \
istream_iterator<string> _it(_ss); \
err(_it, args); \
}
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << "\n";
err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int, int>
#define pli pair<ll, int>
#define triple tuple<int, int, int>
#define vi vector<int>
#define vii vector<pair<int, int>>
#define vvi vector<vector<int>>
#define viii vector<pair<pair<int, int>, int>>
#define vvii vector<vector<pair<int, int>>>
#define M 1000000000
#define N 200005 // check the limits, man
int main() {
int i, n, k, a;
in2(n, k);
vi v(n);
read(v, i, n);
vi sum(n + 1);
sum[0] = 0;
lp(i, 1, n + 1) {
sum[i] = sum[i - 1] + v[i - 1];
sum[i] %= k;
}
rep(i, n + 1) {
sum[i] -= (i % k);
if (sum[i] < 0)
sum[i] += k;
}
map<int, int> cnt;
rep(i, min(n + 1, k)) a = sum[i], cnt[a]++;
ll ans = 0;
rep(i, n) {
a = sum[i];
cnt[a]--;
ans += (cnt[a]);
if (i + k <= n)
a = sum[i + k], cnt[a]++;
}
llout(ans);
}
| replace | 92 | 93 | 92 | 93 | 0 | |
p02851 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int>> mati;
typedef vector<vector<double>> matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
#define FOR(i, x, y) for (ll i = (ll)x; i < (ll)y; ++i)
#define REP(i, y) FOR(i, 0, y)
#define RFOR(i, x, y) for (ll i = (ll)x; i >= (ll)y; --i)
#define RREP(i, x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_printf(x...) \
cerr << "line " << __LINE__ << " : "; \
debug_printf_in(x);
template <typename First> void debug_printf_in(First first) {
cerr << first << endl;
return;
}
template <typename First, typename... Rest>
void debug_printf_in(First first, Rest... rest) {
cerr << first << " ";
debug_printf_in(rest...);
return;
}
void IN(void) { return; }
template <typename First, typename... Rest>
void IN(First &first, Rest &...rest) {
cin >> first;
IN(rest...);
return;
}
template <typename First> void OUT(First first) {
cout << first << endl;
return;
}
template <typename First, typename... Rest>
void OUT(First first, Rest... rest) {
cout << first << " ";
OUT(rest...);
return;
}
template <class t, class u> void chmax(t &a, u b) {
if (a < b)
a = b;
};
template <class t, class u> void chmin(t &a, u b) {
if (a > b)
a = b;
};
int popcount(int t) { return __builtin_popcount(t); } // GCC
int popcount(ll t) { return __builtin_popcountll(t); } // GCC
template <typename T> void vec_print(vector<T> VEC) {
REP(i, VEC.size()) { cout << VEC[i] << " "; }
cout << "\n";
};
template <typename T>
void mat_print(vector<vector<T>> MAT){
REP(i, MAT.size()){REP(j, MAT[i].size()){cout << MAT[i][j] << " ";
}
cout << "\n";
}
}
;
template <typename CLASS1, typename CLASS2> class HOGE {
public:
CLASS1 key;
CLASS2 value;
HOGE(void) { return; };
HOGE(CLASS1 key, CLASS2 value) {
this->key = key;
this->value = value;
};
~HOGE(void) { return; };
void print(void) {
cout << "key : " << key << ", value : " << value << "\n";
return;
};
bool operator==(const HOGE &obj) { return (this->value == obj.value); };
bool operator<(const HOGE &obj) { return (this->value < obj.value); };
bool operator>(const HOGE &obj) { return (this->value > obj.value); };
};
template <typename CLASS1, typename CLASS2>
bool operator==(const HOGE<CLASS1, CLASS2> &hoge1,
const HOGE<CLASS1, CLASS2> &hoge2) {
return hoge1.value == hoge2.value;
};
template <typename CLASS1, typename CLASS2>
bool operator<(const HOGE<CLASS1, CLASS2> &hoge1,
const HOGE<CLASS1, CLASS2> &hoge2) {
return hoge1.value < hoge2.value;
};
template <typename CLASS1, typename CLASS2>
bool operator>(const HOGE<CLASS1, CLASS2> &hoge1,
const HOGE<CLASS1, CLASS2> &hoge2) {
return hoge1.value > hoge2.value;
};
constexpr int INF = (1 << 30);
constexpr ll INFLL = 1LL << 62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9) + 7);
ll N, K;
vll A;
int main() {
cin.tie(0); // cut the cin and cout (default, std::flush is performed after
// std::cin)
ios::sync_with_stdio(
false); // cut the iostream and stdio (DON'T endl; BUT "\n";)
IN(N, K);
A.resize(N);
REP(i, N) IN(A[i]);
REP(i, N) A[i]--;
REP(i, N) A[i] %= K;
vll L(N + 1, 0);
L[0] = 0;
REP(i, N) L[i + 1] = (L[i] + A[i]) % K;
vll M(K, 0);
ll ans = 0;
//(L[i] - L[j]) = 0
REP(i, N + 1) {
/*
debug_printf(i, L[i]);
REP(j,K){
debug_printf(M[j]);
}
*/
if (i >= K)
M[L[i - K]]--;
ans += M[L[i]];
M[L[i]]++;
// debug_printf(i, ans);
}
OUT(ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int>> mati;
typedef vector<vector<double>> matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
#define FOR(i, x, y) for (ll i = (ll)x; i < (ll)y; ++i)
#define REP(i, y) FOR(i, 0, y)
#define RFOR(i, x, y) for (ll i = (ll)x; i >= (ll)y; --i)
#define RREP(i, x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_printf(x...) \
cerr << "line " << __LINE__ << " : "; \
debug_printf_in(x);
template <typename First> void debug_printf_in(First first) {
cerr << first << endl;
return;
}
template <typename First, typename... Rest>
void debug_printf_in(First first, Rest... rest) {
cerr << first << " ";
debug_printf_in(rest...);
return;
}
void IN(void) { return; }
template <typename First, typename... Rest>
void IN(First &first, Rest &...rest) {
cin >> first;
IN(rest...);
return;
}
template <typename First> void OUT(First first) {
cout << first << endl;
return;
}
template <typename First, typename... Rest>
void OUT(First first, Rest... rest) {
cout << first << " ";
OUT(rest...);
return;
}
template <class t, class u> void chmax(t &a, u b) {
if (a < b)
a = b;
};
template <class t, class u> void chmin(t &a, u b) {
if (a > b)
a = b;
};
int popcount(int t) { return __builtin_popcount(t); } // GCC
int popcount(ll t) { return __builtin_popcountll(t); } // GCC
template <typename T> void vec_print(vector<T> VEC) {
REP(i, VEC.size()) { cout << VEC[i] << " "; }
cout << "\n";
};
template <typename T>
void mat_print(vector<vector<T>> MAT){
REP(i, MAT.size()){REP(j, MAT[i].size()){cout << MAT[i][j] << " ";
}
cout << "\n";
}
}
;
template <typename CLASS1, typename CLASS2> class HOGE {
public:
CLASS1 key;
CLASS2 value;
HOGE(void) { return; };
HOGE(CLASS1 key, CLASS2 value) {
this->key = key;
this->value = value;
};
~HOGE(void) { return; };
void print(void) {
cout << "key : " << key << ", value : " << value << "\n";
return;
};
bool operator==(const HOGE &obj) { return (this->value == obj.value); };
bool operator<(const HOGE &obj) { return (this->value < obj.value); };
bool operator>(const HOGE &obj) { return (this->value > obj.value); };
};
template <typename CLASS1, typename CLASS2>
bool operator==(const HOGE<CLASS1, CLASS2> &hoge1,
const HOGE<CLASS1, CLASS2> &hoge2) {
return hoge1.value == hoge2.value;
};
template <typename CLASS1, typename CLASS2>
bool operator<(const HOGE<CLASS1, CLASS2> &hoge1,
const HOGE<CLASS1, CLASS2> &hoge2) {
return hoge1.value < hoge2.value;
};
template <typename CLASS1, typename CLASS2>
bool operator>(const HOGE<CLASS1, CLASS2> &hoge1,
const HOGE<CLASS1, CLASS2> &hoge2) {
return hoge1.value > hoge2.value;
};
constexpr int INF = (1 << 30);
constexpr ll INFLL = 1LL << 62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9) + 7);
ll N, K;
vll A;
int main() {
cin.tie(0); // cut the cin and cout (default, std::flush is performed after
// std::cin)
ios::sync_with_stdio(
false); // cut the iostream and stdio (DON'T endl; BUT "\n";)
IN(N, K);
A.resize(N);
REP(i, N) IN(A[i]);
REP(i, N) A[i]--;
REP(i, N) A[i] %= K;
vll L(N + 1, 0);
L[0] = 0;
REP(i, N) L[i + 1] = (L[i] + A[i]) % K;
// vll M(K, 0);
map<ll, ll> M;
ll ans = 0;
//(L[i] - L[j]) = 0
REP(i, N + 1) {
/*
debug_printf(i, L[i]);
REP(j,K){
debug_printf(M[j]);
}
*/
if (i >= K)
M[L[i - K]]--;
ans += M[L[i]];
M[L[i]]++;
// debug_printf(i, ans);
}
OUT(ans);
return 0;
} | replace | 152 | 153 | 152 | 154 | 0 | |
p02851 | C++ | Time Limit Exceeded |
#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <vector>
long long mod = 1e9 + 7;
class Mint {
public:
long long x;
Mint(){}; // 引数なしでも定義できるように引数なしコンストラクタも用意しておく
Mint(long long a) {
x = a % mod;
while (x < 0) {
x += mod;
}
};
Mint &operator+=(const Mint &a) {
x += a.x;
x %= mod;
return *this;
}
Mint &operator-=(const Mint &a) {
x += (mod - a.x);
x %= mod;
return *this;
}
Mint &operator*=(const Mint &a) {
x *= a.x;
x %= mod;
return *this;
}
// a^n mod を計算する
// Useaeg: Mint z = Mint(2).pow(n);
Mint pow(long long n) const {
if (n == 0)
return Mint(1);
Mint y = pow(n >> 1); // pow(n/2)を計算する
y *= y;
if (n % 2 == 1)
y *= *this;
return y;
}
// a^{-1} mod を計算する
Mint modinv(const Mint &a) const { return a.pow(mod - 2); }
Mint &operator/=(const Mint &a) {
x *= modinv(a).x;
x %= mod;
return *this;
}
Mint operator+(Mint &a) const {
Mint y(*this);
y += a;
return y;
}
Mint operator-(Mint &a) const {
Mint y(*this);
y -= a;
return y;
}
Mint operator*(Mint &a) const {
Mint y(*this);
y *= a;
return y;
}
Mint operator/(Mint &a) const {
Mint y(*this);
y /= a;
return y.x;
}
// nCk @mod を計算する
Mint nCk(Mint &n, const long long k) const {
Mint y = Mint(1);
Mint one = Mint(1);
for (Mint i(0); (i.x) < k; i.x++) {
y *= (n - i);
y /= (i + one);
}
return y;
}
// nPk @mod を計算する
Mint nPk(Mint &n, long long k) const {
Mint y(1);
for (Mint i(0); (i.x) < k; i.x++) {
y *= (n - i);
}
return y;
}
};
int main() {
int N, K;
std::cin >> N >> K;
std::vector<int> A(N);
for (int i = 0; i < N; i++) {
std::cin >> A[i];
}
std::vector<int> S(N + 4);
S[0] = 0;
for (int i = 0; i < N; i++) {
S[i + 1] = (S[i] + A[i]) % K;
}
for (int i = 0; i <= N; i++) {
S[i] -= i;
while (S[i] < 0)
S[i] += K;
}
std::map<int, long long> mp;
long long ans = 0;
for (int i = 0; i <= N; i++) {
if (i >= K)
mp[S[i - K]]--;
ans += mp[S[i]];
// printf("ans+=mp[%d]=%lld\n", S[i], mp[S[i]]);
mp[S[i]]++;
}
std::cout << ans << std::endl;
return 0;
} |
#include <algorithm>
#include <bitset>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <vector>
long long mod = 1e9 + 7;
class Mint {
public:
long long x;
Mint(){}; // 引数なしでも定義できるように引数なしコンストラクタも用意しておく
Mint(long long a) {
x = a % mod;
while (x < 0) {
x += mod;
}
};
Mint &operator+=(const Mint &a) {
x += a.x;
x %= mod;
return *this;
}
Mint &operator-=(const Mint &a) {
x += (mod - a.x);
x %= mod;
return *this;
}
Mint &operator*=(const Mint &a) {
x *= a.x;
x %= mod;
return *this;
}
// a^n mod を計算する
// Useaeg: Mint z = Mint(2).pow(n);
Mint pow(long long n) const {
if (n == 0)
return Mint(1);
Mint y = pow(n >> 1); // pow(n/2)を計算する
y *= y;
if (n % 2 == 1)
y *= *this;
return y;
}
// a^{-1} mod を計算する
Mint modinv(const Mint &a) const { return a.pow(mod - 2); }
Mint &operator/=(const Mint &a) {
x *= modinv(a).x;
x %= mod;
return *this;
}
Mint operator+(Mint &a) const {
Mint y(*this);
y += a;
return y;
}
Mint operator-(Mint &a) const {
Mint y(*this);
y -= a;
return y;
}
Mint operator*(Mint &a) const {
Mint y(*this);
y *= a;
return y;
}
Mint operator/(Mint &a) const {
Mint y(*this);
y /= a;
return y.x;
}
// nCk @mod を計算する
Mint nCk(Mint &n, const long long k) const {
Mint y = Mint(1);
Mint one = Mint(1);
for (Mint i(0); (i.x) < k; i.x++) {
y *= (n - i);
y /= (i + one);
}
return y;
}
// nPk @mod を計算する
Mint nPk(Mint &n, long long k) const {
Mint y(1);
for (Mint i(0); (i.x) < k; i.x++) {
y *= (n - i);
}
return y;
}
};
int main() {
int N, K;
std::cin >> N >> K;
std::vector<int> A(N);
for (int i = 0; i < N; i++) {
std::cin >> A[i];
}
std::vector<int> S(N + 4);
S[0] = 0;
for (int i = 0; i < N; i++) {
S[i + 1] = (S[i] + A[i]) % K;
}
for (int i = 0; i <= N; i++) {
S[i] -= i % K;
while (S[i] < 0)
S[i] += K;
}
std::map<int, long long> mp;
long long ans = 0;
for (int i = 0; i <= N; i++) {
if (i >= K)
mp[S[i - K]]--;
ans += mp[S[i]];
// printf("ans+=mp[%d]=%lld\n", S[i], mp[S[i]]);
mp[S[i]]++;
}
std::cout << ans << std::endl;
return 0;
} | replace | 122 | 123 | 122 | 123 | TLE | |
p02851 | C++ | Runtime Error | #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
int a[114514], sum[114514];
signed main() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i]--;
}
map<int, int> mope;
int ans = 0;
mope[0] = 1;
for (int i = 1; i <= n; i++) {
sum[i] = sum[i - 1] + a[i];
if (i >= k)
mope[sum[i - k] % k]--;
ans += mope[sum[i] % k];
// cout << mope[ sum[i] % k ] <<endl;
mope[sum[i] % k]++;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
int a[214514], sum[214514];
signed main() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i]--;
}
map<int, int> mope;
int ans = 0;
mope[0] = 1;
for (int i = 1; i <= n; i++) {
sum[i] = sum[i - 1] + a[i];
if (i >= k)
mope[sum[i - k] % k]--;
ans += mope[sum[i] % k];
// cout << mope[ sum[i] % k ] <<endl;
mope[sum[i] % k]++;
}
cout << ans << endl;
return 0;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p02851 | C++ | Runtime Error | #include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e5 + 7;
int n, k, sum[maxn], val[maxn], ans;
map<int, int> mp;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
if (fopen("test.inp", "r"))
freopen("test.inp", "r", stdin);
cin >> n >> k;
mp[0] = 1;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
sum[i] = (sum[i - 1] + x) % k;
val[i] = ((sum[i] - i) % k + k) % k;
if (i - k >= 0) {
mp[val[i - k]]--;
}
ans += mp[val[i]];
mp[val[i]]++;
}
cout << ans;
} | #include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 2e5 + 7;
int n, k, sum[maxn], val[maxn], ans;
map<int, int> mp;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
if (fopen("test.inp", "r"))
freopen("test.inp", "r", stdin);
cin >> n >> k;
mp[0] = 1;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
sum[i] = (sum[i - 1] + x) % k;
val[i] = ((sum[i] - i) % k + k) % k;
if (i - k >= 0) {
mp[val[i - k]]--;
}
ans += mp[val[i]];
mp[val[i]]++;
}
cout << ans;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02851 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define me BOSS
#define bug() cout << "AIkahne aise" << endl
#define PI acos(-1)
ll A[5000001], bin[5000001];
vector<ll> v;
map<int, int> myMap;
set<int> mySet;
vector<pair<ll, ll>> vp;
/* Precode Start Here *\
power of 2 less than or equal to N
ll largest_power(ll N)
{
//changing all right side bits to 1.
N = N (N>>1);
N = N| (N>>2);
N = N| (N>>4);
N = N| (N>>8);
//as now the number is 2 * x-1, where x is required answer, so adding 1 and
dividing it by 2. return (N+1)>>1;
}
Sieve
void sieve()
{
for(ll i=3; i<=2000; i+=2)
{
for(ll j=i*i; j<=4000000; j+=i)
A[j]=1;
}
v.push_back(2);
for(ll i=3; i<=4000000; i+=2)
if(A[i]==0)
v.push_back(i);
}
Power Function Modulo P
ll modPow(ll a, ll x, ll p) {
//calculates a^x mod p in logarithmic time.
long res = 1;
while(x > 0) {
if( x % 2 != 0) {
res = (res * a) % p;
}
a = (a * a) % p;
x /= 2;
}
return res;
}
factorial
ll fact(ll n)
{
ll ans=1;
for(ll i=1;i<=n;i++)
{
ans=(ans*i)%mod;
}
return ans;
}
Calculating nCr using Fermats law Theorem
ll modInverse(ll a, ll p) {
//calculates the modular multiplicative of a mod m.
//(assuming p is prime).
return modPow(a, p-2, p);
}
ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).
ll numerator = 1; // n * (n-1) * ... * (n-k+1)
for (ll i=0; i<k; i++) {
numerator = (numerator * (n-i) ) % p;
}
ll denominator = 1; // k!
for (ll i=1; i<=k; i++) {
denominator = (denominator * i) % p;
}
// numerator / denominator mod p.
return ( numerator* modInverse(denominator,p) ) % p;
}
num of divisor and euler totient
ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
for(int i=1;i<=n;i++)
phi[i]=i;
for(int i=2;i<=n;i++)
{
if(!mark[i])
{
for(int j=i;j<=n;j+=i)
{
mark[j]=1;
phi[j]*=(1-1/(double)i);
}
}
}
for(ll i=1;i<=n;i++)
{
for(ll j=i;j<=n;j+=i)
divi[j]++;
}
}
/* Precode Ends */
ll sum[100001];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n, k, ans = 0, a;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> A[i];
sum[i] = (A[i] + sum[i - 1]) % k;
}
for (int i = 1; i <= n; i++) {
sum[i] = (sum[i] - i) % k;
sum[i] += k;
sum[i] %= k;
// cout<<sum[i]<<" ";
}
// myMap[0]=1;
for (int i = 0; i <= n; i++) {
ans += myMap[sum[i]];
// cout<<ans<<" "<<myMap[sum[i]]<<" "<<sum[i]<<endl;
myMap[sum[i]]++;
if (i >= k - 1) {
myMap[sum[i - k + 1]]--;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define me BOSS
#define bug() cout << "AIkahne aise" << endl
#define PI acos(-1)
ll A[5000001], bin[5000001];
vector<ll> v;
map<int, int> myMap;
set<int> mySet;
vector<pair<ll, ll>> vp;
/* Precode Start Here *\
power of 2 less than or equal to N
ll largest_power(ll N)
{
//changing all right side bits to 1.
N = N (N>>1);
N = N| (N>>2);
N = N| (N>>4);
N = N| (N>>8);
//as now the number is 2 * x-1, where x is required answer, so adding 1 and
dividing it by 2. return (N+1)>>1;
}
Sieve
void sieve()
{
for(ll i=3; i<=2000; i+=2)
{
for(ll j=i*i; j<=4000000; j+=i)
A[j]=1;
}
v.push_back(2);
for(ll i=3; i<=4000000; i+=2)
if(A[i]==0)
v.push_back(i);
}
Power Function Modulo P
ll modPow(ll a, ll x, ll p) {
//calculates a^x mod p in logarithmic time.
long res = 1;
while(x > 0) {
if( x % 2 != 0) {
res = (res * a) % p;
}
a = (a * a) % p;
x /= 2;
}
return res;
}
factorial
ll fact(ll n)
{
ll ans=1;
for(ll i=1;i<=n;i++)
{
ans=(ans*i)%mod;
}
return ans;
}
Calculating nCr using Fermats law Theorem
ll modInverse(ll a, ll p) {
//calculates the modular multiplicative of a mod m.
//(assuming p is prime).
return modPow(a, p-2, p);
}
ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).
ll numerator = 1; // n * (n-1) * ... * (n-k+1)
for (ll i=0; i<k; i++) {
numerator = (numerator * (n-i) ) % p;
}
ll denominator = 1; // k!
for (ll i=1; i<=k; i++) {
denominator = (denominator * i) % p;
}
// numerator / denominator mod p.
return ( numerator* modInverse(denominator,p) ) % p;
}
num of divisor and euler totient
ll phi[1000001],mark[1000001],divi[1000001];;
void divisorPhi(ll n)
{
for(int i=1;i<=n;i++)
phi[i]=i;
for(int i=2;i<=n;i++)
{
if(!mark[i])
{
for(int j=i;j<=n;j+=i)
{
mark[j]=1;
phi[j]*=(1-1/(double)i);
}
}
}
for(ll i=1;i<=n;i++)
{
for(ll j=i;j<=n;j+=i)
divi[j]++;
}
}
/* Precode Ends */
ll sum[300001];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n, k, ans = 0, a;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> A[i];
sum[i] = (A[i] + sum[i - 1]) % k;
}
for (int i = 1; i <= n; i++) {
sum[i] = (sum[i] - i) % k;
sum[i] += k;
sum[i] %= k;
// cout<<sum[i]<<" ";
}
// myMap[0]=1;
for (int i = 0; i <= n; i++) {
ans += myMap[sum[i]];
// cout<<ans<<" "<<myMap[sum[i]]<<" "<<sum[i]<<endl;
myMap[sum[i]]++;
if (i >= k - 1) {
myMap[sum[i - k + 1]]--;
}
}
cout << ans << endl;
return 0;
}
| replace | 126 | 127 | 126 | 127 | 0 | |
p02851 | C++ | Runtime Error | // finish date: 2019/11/24
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int(i) = a; (i) < (b); (i)++)
#define rep(i, n) FOR(i, 0, n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1000000007;
const long long INFll = 100000000000000000;
int main() {
int N, K;
cin >> N >> K;
vi A(N);
rep(i, N) {
cin >> A[i];
A[i] -= 1;
A[i] %= K;
}
vi cum(N, 0);
rep(i, N) {
cum[i] = A[i] % K;
if (i != 0)
cum[i] = (cum[i] + cum[i - 1]) % K;
}
ll ans = 0;
map<int, int> cnt;
rep(i, K - 1) {
// cum[i] = (K - cum[i]) % K;
cnt[cum[i]]++;
}
ans += cnt[0];
// int focus = 0;
FOR(i, K - 1, N + K - 1) {
cnt[cum[i - K + 1]]--;
if (i < N)
cnt[cum[i]]++;
ans += cnt[(cum[i - K + 1]) % K];
}
cout << ans << endl;
return 0;
}
| // finish date: 2019/11/24
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int(i) = a; (i) < (b); (i)++)
#define rep(i, n) FOR(i, 0, n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1000000007;
const long long INFll = 100000000000000000;
int main() {
int N, K;
cin >> N >> K;
vi A(N);
rep(i, N) {
cin >> A[i];
A[i] -= 1;
A[i] %= K;
}
vi cum(N, 0);
rep(i, N) {
cum[i] = A[i] % K;
if (i != 0)
cum[i] = (cum[i] + cum[i - 1]) % K;
}
ll ans = 0;
map<int, int> cnt;
rep(i, min(K - 1, N)) {
// cum[i] = (K - cum[i]) % K;
cnt[cum[i]]++;
}
ans += cnt[0];
// int focus = 0;
FOR(i, K - 1, N + K - 1) {
cnt[cum[i - K + 1]]--;
if (i < N)
cnt[cum[i]]++;
ans += cnt[(cum[i - K + 1]) % K];
}
cout << ans << endl;
return 0;
}
| replace | 47 | 48 | 47 | 48 | 0 | |
p02851 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define ALL(x) x.begin(), x.end()
#define ll long long
typedef pair<int, int> P;
const int inf = 1000000007;
const int MOD = 1000000007;
signed main() {
int n, k;
cin >> n >> k;
vector<int> a(n + 1, 0);
rep1(i, n) cin >> a[i];
vector<int> sum(n + 1, 0);
rep1(i, n) { sum[i] = sum[i - 1] + a[i]; }
map<int, int> memo;
if (k > n) {
rep(i, k) {
int buf = (sum[i] - i + n * k) % k;
int hoge = memo[buf];
memo[buf] += 1;
}
int res = 0;
auto it = memo.begin();
while (it != memo.end()) {
int buf = it->second;
res += buf * (buf - 1) / 2;
// printf("%lld %lld\n",it->first,it->second);
++it;
}
cout << res << "\n";
} else {
rep(i, k) {
int buf = (sum[i] - i + n * k) % k;
int hoge = memo[buf];
memo[buf] += 1;
}
int res = 0;
auto it = memo.begin();
while (it != memo.end()) {
int buf = it->second;
res += buf * (buf - 1) / 2;
// printf("%lld %lld\n",it->first,it->second);
++it;
}
for (int i = k; i <= n; i++) {
int buf = sum[i - k] - (i - k) + n * k;
buf %= k;
memo[buf]--;
buf = sum[i] - i + k * n;
buf %= k;
res += memo[buf];
memo[buf] += 1;
}
cout << res << "\n";
}
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define ALL(x) x.begin(), x.end()
#define ll long long
typedef pair<int, int> P;
const int inf = 1000000007;
const int MOD = 1000000007;
signed main() {
int n, k;
cin >> n >> k;
vector<int> a(n + 1, 0);
rep1(i, n) cin >> a[i];
vector<int> sum(n + 1, 0);
rep1(i, n) { sum[i] = sum[i - 1] + a[i]; }
map<int, int> memo;
if (k > n) {
rep(i, n + 1) {
int buf = (sum[i] - i + n * k) % k;
int hoge = memo[buf];
memo[buf] += 1;
}
int res = 0;
auto it = memo.begin();
while (it != memo.end()) {
int buf = it->second;
res += buf * (buf - 1) / 2;
// printf("%lld %lld\n",it->first,it->second);
++it;
}
cout << res << "\n";
} else {
rep(i, k) {
int buf = (sum[i] - i + n * k) % k;
int hoge = memo[buf];
memo[buf] += 1;
}
int res = 0;
auto it = memo.begin();
while (it != memo.end()) {
int buf = it->second;
res += buf * (buf - 1) / 2;
// printf("%lld %lld\n",it->first,it->second);
++it;
}
for (int i = k; i <= n; i++) {
int buf = sum[i - k] - (i - k) + n * k;
buf %= k;
memo[buf]--;
buf = sum[i] - i + k * n;
buf %= k;
res += memo[buf];
memo[buf] += 1;
}
cout << res << "\n";
}
return 0;
}
| replace | 29 | 30 | 29 | 30 | 0 | |
p02851 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <deque>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, char> pic;
#define bit(x, v) ((ll)x << v)
const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int pr[100010];
int lank[100010];
void uini(int n) {
for (size_t i = 0; i <= n; i++) {
pr[i] = i;
}
}
int parent(int x) {
if (x == pr[x])
return x;
return pr[x] = parent(pr[x]);
}
int same(int x, int y) { return parent(x) == parent(y); }
bool unit(int x, int y) {
int px = parent(x);
int py = parent(y);
if (px == py)
return false;
if (lank[px] < lank[py]) {
pr[py] = px;
lank[px] += lank[py] + 1;
} else {
pr[px] = py;
lank[py] += lank[px] + 1;
}
return true;
}
ll bit[200010];
int max_n = 200000;
int pm = 0;
void add(int x) {
while (max_n >= x) {
bit[x]++;
x += x & -x;
}
}
void sub(int x) {
while (max_n >= x) {
bit[x]--;
x += x & -x;
}
}
ll merge(ll *a, int left, int mid, int right) {
ll n1 = mid - left;
ll n2 = right - mid;
vector<int> L(n1 + 1);
vector<int> R(n2 + 1);
for (size_t i = 0; i < n1; i++) {
L[i] = a[left + i];
}
for (size_t i = 0; i < n2; i++) {
R[i] = a[mid + i];
}
L[n1] = INF;
R[n2] = INF;
ll i = 0;
ll j = 0;
ll r = 0;
for (size_t k = left; k < right; k++) {
if (L[i] <= R[j]) {
a[k] = L[i];
i++;
} else {
a[k] = R[j];
r += n1 - i;
j++;
}
}
return r;
}
ll merge2(pair<int, char> *a, int left, int mid, int right) {
ll n1 = mid - left;
ll n2 = right - mid;
vector<pair<int, char>> L(n1 + 1);
vector<pair<int, char>> R(n2 + 1);
for (size_t i = 0; i < n1; i++) {
L[i] = a[left + i];
}
for (size_t i = 0; i < n2; i++) {
R[i] = a[mid + i];
}
L[n1] = make_pair(INF, ' ');
R[n2] = make_pair(INF, ' ');
ll i = 0;
ll j = 0;
ll r = 0;
for (size_t k = left; k < right; k++) {
if (L[i].first <= R[j].first) {
a[k] = L[i];
i++;
} else {
a[k] = R[j];
r += n1 - i;
j++;
}
}
return r;
}
ll mergeSort2(pair<int, char> *a, int left, int right) {
ll res = 0;
if (left + 1 < right) {
int mid = (left + right) / 2;
res = mergeSort2(a, left, mid);
res += mergeSort2(a, mid, right);
res += merge2(a, left, mid, right);
}
return res;
}
ll mergeSort(ll *a, int left, int right) {
ll res = 0;
if (left + 1 < right) {
int mid = (left + right) / 2;
res = mergeSort(a, left, mid);
res += mergeSort(a, mid, right);
res += merge(a, left, mid, right);
}
return res;
}
int partition(pair<int, char> *a, int p, int r) {
pair<int, char> x = a[r];
int i = p - 1;
for (size_t j = p; j < r; j++) {
if (a[j].first <= x.first) {
i++;
swap(a[i], a[j]);
}
}
swap(a[i + 1], a[r]);
return i + 1;
}
void quick(pair<int, char> *a, int p, int r) {
if (p < r) {
int q = partition(a, p, r);
quick(a, p, q - 1);
quick(a, q + 1, r);
}
}
ll n;
int ci = 0;
ll P[1000010];
struct Node {
int key;
int priority;
Node *parent, *left, *right;
Node(int key, int priority);
Node() {}
};
Node NIL;
Node::Node(int key, int priority) : key(key), priority(priority) {
left = &NIL;
right = &NIL;
}
Node *root = new Node();
void cenrec(Node *k) {
if (k->key == NIL.key)
return;
cenrec(k->left);
cout << " " << k->key;
cenrec(k->right);
}
void fastrec(Node *k) {
if (k->key == NIL.key)
return;
cout << " " << k->key;
fastrec(k->left);
fastrec(k->right);
}
void insert(Node *v) {
Node *y = &NIL;
Node *x = root;
while (x->key != NIL.key) {
y = x;
if (v->key < x->key) {
x = x->left;
} else {
x = x->right;
}
}
v->parent = y;
if (y->key == NIL.key) {
root = v;
} else if (v->key < y->key) {
y->left = v;
} else {
y->right = v;
}
}
Node *find(Node *k, ll v) {
if (k->key == NIL.key)
return &NIL;
if (k->key == v)
return k;
if (v < k->key)
return find(k->left, v);
return find(k->right, v);
}
void delp12(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key == NIL.key && r->key == NIL.key) {
if (pr->left == x) {
pr->left = &NIL;
} else
pr->right = &NIL;
} else if (l->key != NIL.key) {
if (pr->left == x) {
pr->left = l;
} else
pr->right = l;
l->parent = pr;
} else if (r->key != NIL.key) {
if (pr->left == x) {
pr->left = r;
} else
pr->right = r;
r->parent = pr;
}
}
Node *get_next(Node *k) {
if (k->key == NIL.key)
return &NIL;
Node *res = get_next(k->left);
if (res->key != NIL.key)
return res;
return k;
}
void del(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key != NIL.key && r->key != NIL.key) {
Node *nex = get_next(r);
x->key = nex->key;
delp12(nex);
} else {
delp12(x);
}
}
Node *rightRotate(Node *t) {
Node *s = t->left;
t->left = s->right;
s->right = t;
return s;
}
Node *leftRotate(Node *t) {
Node *s = t->right;
t->right = s->left;
s->left = t;
return s;
}
Node *_insert(Node *t, int key, int priority) {
if (t->key == NIL.key) {
return new Node(key, priority);
}
if (key == t->key) {
return t;
}
if (key < t->key) {
t->left = _insert(t->left, key, priority);
if (t->priority < t->left->priority) {
t = rightRotate(t);
}
} else {
t->right = _insert(t->right, key, priority);
if (t->priority < t->right->priority) {
t = leftRotate(t);
}
}
return t;
}
Node *delete1(Node *t, int key);
Node *_delete(Node *t, int key) {
if (t->left->key == NIL.key && t->right->key == NIL.key) {
return &NIL;
} else if (t->left->key == NIL.key) {
t = leftRotate(t);
} else if (t->right->key == NIL.key) {
t = rightRotate(t);
} else {
if (t->left->priority > t->right->priority) {
t = rightRotate(t);
} else
t = leftRotate(t);
}
return delete1(t, key);
}
Node *delete1(Node *t, int key) {
if (t->key == NIL.key) {
return &NIL;
}
if (key < t->key) {
t->left = delete1(t->left, key);
} else if (key > t->key) {
t->right = delete1(t->right, key);
} else
return _delete(t, key);
return t;
}
int H;
int left(int i) { return i * 2 + 1; }
int right(int i) { return i * 2 + 2; }
ll heap[2000010];
void maxHeapify(int i) {
int l = left(i);
int r = right(i);
int largest = 0;
if (l < H && heap[l] > heap[i])
largest = l;
else
largest = i;
if (r < H && heap[r] > heap[largest])
largest = r;
if (largest != i) {
swap(heap[i], heap[largest]);
maxHeapify(largest);
}
}
int pare(int i) { return (i - 1) / 2; }
void raise(int i) {
int l = pare(i);
if (l < 0)
return;
if (heap[l] < heap[i]) {
swap(heap[i], heap[l]);
raise(l);
}
}
void minHeapify(int i) {
int l = left(i);
int r = right(i);
int minimam = 0;
if (l < H && heap[l] < heap[i])
minimam = l;
else
minimam = i;
if (r < H && heap[r] < heap[minimam])
minimam = r;
if (minimam != i) {
swap(heap[i], heap[minimam]);
minHeapify(minimam);
}
}
void buildMaxHeap() {
for (int i = H / 2; i >= 0; i--) {
maxHeapify(i);
}
}
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
std::vector<int> find_all(const std::string str, const std::string subStr) {
std::vector<int> result;
int subStrSize = subStr.size();
int pos = str.find(subStr);
while (pos != std::string::npos) {
result.push_back(pos);
pos = str.find(subStr, pos + 1);
}
return result;
}
// ll memo[100010];
// ll next[100010];
// ll dm[100010];
// int f[100010];
// ll rec(int x) {
//
// if (~memo[x]) return memo[x];
// if (x == n) {
// dm[n] = 1;
// return 1;
// }
// ll *res = &memo[x];
// *res = 0;
// set<int> st;
// st.insert(f[x]);
// for (int i = x + 1; i <= n; i++)
// {
// if (~memo[i]) {
// *res += memo[i] + 1;
// *res %= INF;
// break;
// }
//
// *res += rec(i);
// *res %= INF;
// if (st.find(f[i]) != st.end()) {break; }
// st.insert(f[i]);
// }
//
// return *res;
// }
#define bit(x, v) ((ll)x << v)
class BIT {
static const int MAX_N = 100010;
public:
BIT() { memset(bit, 0, sizeof(bit)); }
int bit[MAX_N + 1], n;
int sum(int i) {
int s = 0;
while (i > 0) {
s += bit[i];
i -= i & -i;
}
return s;
}
void add(int i, int x) {
while (i <= n) {
bit[i] += x;
i += i & -i;
}
}
void clear() { memset(bit, 0, sizeof(bit)); }
int a[MAX_N];
void bable_swap_count() {
ll ans = 0;
for (size_t j = 0; j < n; j++) {
ans += j - sum(a[j]);
add(a[j], 1);
}
printf("%lld\n", ans);
}
int search(int s, int x) {
ll half = (s + x) / 2;
ll sh = sum(x);
ll sl = sum(half);
ll st = sum(s);
if (sh - sl == 0) {
return x;
}
if (sh - sl < x - half) {
return search(half, x);
}
if (sl - st == 0) {
return half;
}
if (sl - st < half - s) {
return search(s, half);
}
return -1;
}
};
vector<int> es[100010];
ll memo[2][100010];
ll rec(int x, int color, int frm) {
if (~memo[color][x])
return memo[color][x];
ll res = 1;
for (auto v : es[x]) {
if (v == frm)
continue;
if (color == 1) {
res *= rec(v, 0, x);
} else {
res *= rec(v, 0, x) + rec(v, 1, x);
}
res %= INF;
}
return memo[color][x] = res;
}
int ex[110];
vector<int> edg[110];
bool vis[110];
ll rec(int x) {
vis[x] = true;
ll r = 0;
for (auto v : edg[x]) {
if (vis[v])
continue;
r += rec(v);
}
if (r > 0) {
r++;
} else {
r = ex[x];
}
return r;
}
int tb[110][110];
int visit[110];
bool check(int x, int fr) {
visit[x] = true;
for (size_t i = 1; i <= n; i++) {
if (tb[x][i] == 1) {
if (i == fr)
continue;
if (visit[i])
return false;
if (!check(i, x))
return false;
}
}
return true;
}
void solv() {
ll k;
cin >> n >> k;
ll a[200010];
ll s[200010];
for (size_t i = 0; i < n; i++) {
cin >> a[i];
}
s[0] = 0;
for (size_t i = 1; i <= n; i++) {
s[i] = s[i - 1] + a[i - 1];
}
map<ll, queue<int>> mp;
mp[0].push(0);
ll res = 0;
for (ll j = 1; j <= n; j++) {
ll v = (s[j] - j) % k;
auto q = mp[v];
while (!q.empty() && q.front() <= max(-1LL, j - k)) {
q.pop();
}
res += q.size();
q.push(j);
mp[v] = q;
}
cout << res << endl;
}
int main() {
// COMinit();
solv();
return 0;
} | #include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <deque>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, char> pic;
#define bit(x, v) ((ll)x << v)
const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; i++) {
fac[i] = fac[i - 1] * i % MOD;
inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
finv[i] = finv[i - 1] * inv[i] % MOD;
}
}
// 二項係数計算
long long COM(int n, int k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int pr[100010];
int lank[100010];
void uini(int n) {
for (size_t i = 0; i <= n; i++) {
pr[i] = i;
}
}
int parent(int x) {
if (x == pr[x])
return x;
return pr[x] = parent(pr[x]);
}
int same(int x, int y) { return parent(x) == parent(y); }
bool unit(int x, int y) {
int px = parent(x);
int py = parent(y);
if (px == py)
return false;
if (lank[px] < lank[py]) {
pr[py] = px;
lank[px] += lank[py] + 1;
} else {
pr[px] = py;
lank[py] += lank[px] + 1;
}
return true;
}
ll bit[200010];
int max_n = 200000;
int pm = 0;
void add(int x) {
while (max_n >= x) {
bit[x]++;
x += x & -x;
}
}
void sub(int x) {
while (max_n >= x) {
bit[x]--;
x += x & -x;
}
}
ll merge(ll *a, int left, int mid, int right) {
ll n1 = mid - left;
ll n2 = right - mid;
vector<int> L(n1 + 1);
vector<int> R(n2 + 1);
for (size_t i = 0; i < n1; i++) {
L[i] = a[left + i];
}
for (size_t i = 0; i < n2; i++) {
R[i] = a[mid + i];
}
L[n1] = INF;
R[n2] = INF;
ll i = 0;
ll j = 0;
ll r = 0;
for (size_t k = left; k < right; k++) {
if (L[i] <= R[j]) {
a[k] = L[i];
i++;
} else {
a[k] = R[j];
r += n1 - i;
j++;
}
}
return r;
}
ll merge2(pair<int, char> *a, int left, int mid, int right) {
ll n1 = mid - left;
ll n2 = right - mid;
vector<pair<int, char>> L(n1 + 1);
vector<pair<int, char>> R(n2 + 1);
for (size_t i = 0; i < n1; i++) {
L[i] = a[left + i];
}
for (size_t i = 0; i < n2; i++) {
R[i] = a[mid + i];
}
L[n1] = make_pair(INF, ' ');
R[n2] = make_pair(INF, ' ');
ll i = 0;
ll j = 0;
ll r = 0;
for (size_t k = left; k < right; k++) {
if (L[i].first <= R[j].first) {
a[k] = L[i];
i++;
} else {
a[k] = R[j];
r += n1 - i;
j++;
}
}
return r;
}
ll mergeSort2(pair<int, char> *a, int left, int right) {
ll res = 0;
if (left + 1 < right) {
int mid = (left + right) / 2;
res = mergeSort2(a, left, mid);
res += mergeSort2(a, mid, right);
res += merge2(a, left, mid, right);
}
return res;
}
ll mergeSort(ll *a, int left, int right) {
ll res = 0;
if (left + 1 < right) {
int mid = (left + right) / 2;
res = mergeSort(a, left, mid);
res += mergeSort(a, mid, right);
res += merge(a, left, mid, right);
}
return res;
}
int partition(pair<int, char> *a, int p, int r) {
pair<int, char> x = a[r];
int i = p - 1;
for (size_t j = p; j < r; j++) {
if (a[j].first <= x.first) {
i++;
swap(a[i], a[j]);
}
}
swap(a[i + 1], a[r]);
return i + 1;
}
void quick(pair<int, char> *a, int p, int r) {
if (p < r) {
int q = partition(a, p, r);
quick(a, p, q - 1);
quick(a, q + 1, r);
}
}
ll n;
int ci = 0;
ll P[1000010];
struct Node {
int key;
int priority;
Node *parent, *left, *right;
Node(int key, int priority);
Node() {}
};
Node NIL;
Node::Node(int key, int priority) : key(key), priority(priority) {
left = &NIL;
right = &NIL;
}
Node *root = new Node();
void cenrec(Node *k) {
if (k->key == NIL.key)
return;
cenrec(k->left);
cout << " " << k->key;
cenrec(k->right);
}
void fastrec(Node *k) {
if (k->key == NIL.key)
return;
cout << " " << k->key;
fastrec(k->left);
fastrec(k->right);
}
void insert(Node *v) {
Node *y = &NIL;
Node *x = root;
while (x->key != NIL.key) {
y = x;
if (v->key < x->key) {
x = x->left;
} else {
x = x->right;
}
}
v->parent = y;
if (y->key == NIL.key) {
root = v;
} else if (v->key < y->key) {
y->left = v;
} else {
y->right = v;
}
}
Node *find(Node *k, ll v) {
if (k->key == NIL.key)
return &NIL;
if (k->key == v)
return k;
if (v < k->key)
return find(k->left, v);
return find(k->right, v);
}
void delp12(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key == NIL.key && r->key == NIL.key) {
if (pr->left == x) {
pr->left = &NIL;
} else
pr->right = &NIL;
} else if (l->key != NIL.key) {
if (pr->left == x) {
pr->left = l;
} else
pr->right = l;
l->parent = pr;
} else if (r->key != NIL.key) {
if (pr->left == x) {
pr->left = r;
} else
pr->right = r;
r->parent = pr;
}
}
Node *get_next(Node *k) {
if (k->key == NIL.key)
return &NIL;
Node *res = get_next(k->left);
if (res->key != NIL.key)
return res;
return k;
}
void del(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key != NIL.key && r->key != NIL.key) {
Node *nex = get_next(r);
x->key = nex->key;
delp12(nex);
} else {
delp12(x);
}
}
Node *rightRotate(Node *t) {
Node *s = t->left;
t->left = s->right;
s->right = t;
return s;
}
Node *leftRotate(Node *t) {
Node *s = t->right;
t->right = s->left;
s->left = t;
return s;
}
Node *_insert(Node *t, int key, int priority) {
if (t->key == NIL.key) {
return new Node(key, priority);
}
if (key == t->key) {
return t;
}
if (key < t->key) {
t->left = _insert(t->left, key, priority);
if (t->priority < t->left->priority) {
t = rightRotate(t);
}
} else {
t->right = _insert(t->right, key, priority);
if (t->priority < t->right->priority) {
t = leftRotate(t);
}
}
return t;
}
Node *delete1(Node *t, int key);
Node *_delete(Node *t, int key) {
if (t->left->key == NIL.key && t->right->key == NIL.key) {
return &NIL;
} else if (t->left->key == NIL.key) {
t = leftRotate(t);
} else if (t->right->key == NIL.key) {
t = rightRotate(t);
} else {
if (t->left->priority > t->right->priority) {
t = rightRotate(t);
} else
t = leftRotate(t);
}
return delete1(t, key);
}
Node *delete1(Node *t, int key) {
if (t->key == NIL.key) {
return &NIL;
}
if (key < t->key) {
t->left = delete1(t->left, key);
} else if (key > t->key) {
t->right = delete1(t->right, key);
} else
return _delete(t, key);
return t;
}
int H;
int left(int i) { return i * 2 + 1; }
int right(int i) { return i * 2 + 2; }
ll heap[2000010];
void maxHeapify(int i) {
int l = left(i);
int r = right(i);
int largest = 0;
if (l < H && heap[l] > heap[i])
largest = l;
else
largest = i;
if (r < H && heap[r] > heap[largest])
largest = r;
if (largest != i) {
swap(heap[i], heap[largest]);
maxHeapify(largest);
}
}
int pare(int i) { return (i - 1) / 2; }
void raise(int i) {
int l = pare(i);
if (l < 0)
return;
if (heap[l] < heap[i]) {
swap(heap[i], heap[l]);
raise(l);
}
}
void minHeapify(int i) {
int l = left(i);
int r = right(i);
int minimam = 0;
if (l < H && heap[l] < heap[i])
minimam = l;
else
minimam = i;
if (r < H && heap[r] < heap[minimam])
minimam = r;
if (minimam != i) {
swap(heap[i], heap[minimam]);
minHeapify(minimam);
}
}
void buildMaxHeap() {
for (int i = H / 2; i >= 0; i--) {
maxHeapify(i);
}
}
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
std::vector<int> find_all(const std::string str, const std::string subStr) {
std::vector<int> result;
int subStrSize = subStr.size();
int pos = str.find(subStr);
while (pos != std::string::npos) {
result.push_back(pos);
pos = str.find(subStr, pos + 1);
}
return result;
}
// ll memo[100010];
// ll next[100010];
// ll dm[100010];
// int f[100010];
// ll rec(int x) {
//
// if (~memo[x]) return memo[x];
// if (x == n) {
// dm[n] = 1;
// return 1;
// }
// ll *res = &memo[x];
// *res = 0;
// set<int> st;
// st.insert(f[x]);
// for (int i = x + 1; i <= n; i++)
// {
// if (~memo[i]) {
// *res += memo[i] + 1;
// *res %= INF;
// break;
// }
//
// *res += rec(i);
// *res %= INF;
// if (st.find(f[i]) != st.end()) {break; }
// st.insert(f[i]);
// }
//
// return *res;
// }
#define bit(x, v) ((ll)x << v)
class BIT {
static const int MAX_N = 100010;
public:
BIT() { memset(bit, 0, sizeof(bit)); }
int bit[MAX_N + 1], n;
int sum(int i) {
int s = 0;
while (i > 0) {
s += bit[i];
i -= i & -i;
}
return s;
}
void add(int i, int x) {
while (i <= n) {
bit[i] += x;
i += i & -i;
}
}
void clear() { memset(bit, 0, sizeof(bit)); }
int a[MAX_N];
void bable_swap_count() {
ll ans = 0;
for (size_t j = 0; j < n; j++) {
ans += j - sum(a[j]);
add(a[j], 1);
}
printf("%lld\n", ans);
}
int search(int s, int x) {
ll half = (s + x) / 2;
ll sh = sum(x);
ll sl = sum(half);
ll st = sum(s);
if (sh - sl == 0) {
return x;
}
if (sh - sl < x - half) {
return search(half, x);
}
if (sl - st == 0) {
return half;
}
if (sl - st < half - s) {
return search(s, half);
}
return -1;
}
};
vector<int> es[100010];
ll memo[2][100010];
ll rec(int x, int color, int frm) {
if (~memo[color][x])
return memo[color][x];
ll res = 1;
for (auto v : es[x]) {
if (v == frm)
continue;
if (color == 1) {
res *= rec(v, 0, x);
} else {
res *= rec(v, 0, x) + rec(v, 1, x);
}
res %= INF;
}
return memo[color][x] = res;
}
int ex[110];
vector<int> edg[110];
bool vis[110];
ll rec(int x) {
vis[x] = true;
ll r = 0;
for (auto v : edg[x]) {
if (vis[v])
continue;
r += rec(v);
}
if (r > 0) {
r++;
} else {
r = ex[x];
}
return r;
}
int tb[110][110];
int visit[110];
bool check(int x, int fr) {
visit[x] = true;
for (size_t i = 1; i <= n; i++) {
if (tb[x][i] == 1) {
if (i == fr)
continue;
if (visit[i])
return false;
if (!check(i, x))
return false;
}
}
return true;
}
void solv() {
ll k;
cin >> n >> k;
ll a[200010];
ll s[200010];
for (size_t i = 0; i < n; i++) {
cin >> a[i];
}
s[0] = 0;
for (size_t i = 1; i <= n; i++) {
s[i] = s[i - 1] + a[i - 1];
}
map<ll, queue<int>> mp;
mp[0].push(0);
ll res = 0;
for (ll j = 1; j <= n; j++) {
ll v = (s[j] - j) % k;
auto q = &mp[v];
while (!q->empty() && q->front() <= max(-1LL, j - k)) {
q->pop();
}
res += q->size();
q->push(j);
}
cout << res << endl;
}
int main() {
// COMinit();
solv();
return 0;
} | replace | 612 | 619 | 612 | 618 | TLE | |
p02851 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
Int N, K;
vector<Int> A(200010, 0), S(200010, 0);
Int id(Int i) {
Int res = S[i] - i;
while (res < 0)
res += K;
res %= K;
return res;
}
int main() {
cin >> N >> K;
rep1(i, N) {
cin >> A[i];
S[i] = S[i - 1] + A[i];
S[i] %= K;
}
map<Int, Int> M;
Int ans = 0;
rep1(j, N) {
Int R = j - 1, L = j - K;
M[id(R)]++;
if (L >= 0) {
M[id(L)]--;
}
ans += M[id(j)];
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;
Int N, K;
vector<Int> A(200010, 0), S(200010, 0);
Int id(Int i) {
Int res = S[i] - i;
if (res >= 0) {
res %= K;
} else {
res = (K - (-res) % K) % K;
}
return res;
}
int main() {
cin >> N >> K;
rep1(i, N) {
cin >> A[i];
S[i] = S[i - 1] + A[i];
S[i] %= K;
}
map<Int, Int> M;
Int ans = 0;
rep1(j, N) {
Int R = j - 1, L = j - K;
M[id(R)]++;
if (L >= 0) {
M[id(L)]--;
}
ans += M[id(j)];
}
cout << ans << endl;
} | replace | 11 | 14 | 11 | 16 | TLE | |
p02851 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rint register int
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
// until dimension reduction.
using namespace std;
typedef long long LL;
#define LOG(...) fprintf(stderr, __VA_ARGS__)
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
const int INF = 0x3f3f3f3f, N = 200010;
const LL INFL = 0x3f3f3f3f3f3f3f3fll;
int n, k, b[N << 1], cc, sum[N], a[N], ps1[N], ps2[N];
int rt[N << 1], nd;
int ss[N * 31], ls[N * 31], rs[N * 31];
void upd(int &p, int l, int r, int v) {
if (!p)
p = ++nd;
if (l == r) {
++ss[p];
return;
}
int mid = (l + r) >> 1;
(v <= mid) ? upd(ls[p], l, mid, v) : upd(rs[p], mid + 1, r, v);
ss[p] = ss[ls[p]] + ss[rs[p]];
}
int qrange(int p, int l, int r, int ql, int qr) {
if (!p || l > r)
return 0;
if (ql <= l && r <= qr)
return ss[p];
int mid = (l + r) >> 1, res = 0;
if (ql <= mid)
res += qrange(ls[p], l, mid, ql, qr);
if (qr > mid)
res += qrange(rs[p], mid + 1, r, ql, qr);
return res;
}
signed main() {
freopen("test.in", "r", stdin);
scanf("%d%d", &n, &k);
for (rint i = 1; i <= n; i++)
scanf("%d", &a[i]), sum[i] = (sum[i - 1] + a[i]) % k;
for (rint r = 0; r <= n; r++) {
b[++cc] = sum[r] - r;
b[++cc] = sum[r] - r + k;
}
sort(b + 1, b + cc + 1);
int m = unique(b + 1, b + cc + 1) - (b + 1);
for (rint i = 0; i <= n; i++) {
ps1[i] = lower_bound(b + 1, b + m + 1, sum[i] - i) - b;
ps2[i] = lower_bound(b + 1, b + m + 1, sum[i] - i + k) - b;
}
upd(rt[ps1[0]], 1, k, sum[0] + 1);
LL ans = 0;
for (rint r = 1; r <= n; r++) {
ans += qrange(rt[ps1[r]], 1, k, 1, sum[r] + 1) +
qrange(rt[ps2[r]], 1, k, sum[r] + 2, k);
upd(rt[ps1[r]], 1, k, sum[r] + 1);
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rint register int
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
// until dimension reduction.
using namespace std;
typedef long long LL;
#define LOG(...) fprintf(stderr, __VA_ARGS__)
#define pb push_back
#define mp make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
const int INF = 0x3f3f3f3f, N = 200010;
const LL INFL = 0x3f3f3f3f3f3f3f3fll;
int n, k, b[N << 1], cc, sum[N], a[N], ps1[N], ps2[N];
int rt[N << 1], nd;
int ss[N * 31], ls[N * 31], rs[N * 31];
void upd(int &p, int l, int r, int v) {
if (!p)
p = ++nd;
if (l == r) {
++ss[p];
return;
}
int mid = (l + r) >> 1;
(v <= mid) ? upd(ls[p], l, mid, v) : upd(rs[p], mid + 1, r, v);
ss[p] = ss[ls[p]] + ss[rs[p]];
}
int qrange(int p, int l, int r, int ql, int qr) {
if (!p || l > r)
return 0;
if (ql <= l && r <= qr)
return ss[p];
int mid = (l + r) >> 1, res = 0;
if (ql <= mid)
res += qrange(ls[p], l, mid, ql, qr);
if (qr > mid)
res += qrange(rs[p], mid + 1, r, ql, qr);
return res;
}
signed main() {
// freopen ("test.in", "r", stdin);
scanf("%d%d", &n, &k);
for (rint i = 1; i <= n; i++)
scanf("%d", &a[i]), sum[i] = (sum[i - 1] + a[i]) % k;
for (rint r = 0; r <= n; r++) {
b[++cc] = sum[r] - r;
b[++cc] = sum[r] - r + k;
}
sort(b + 1, b + cc + 1);
int m = unique(b + 1, b + cc + 1) - (b + 1);
for (rint i = 0; i <= n; i++) {
ps1[i] = lower_bound(b + 1, b + m + 1, sum[i] - i) - b;
ps2[i] = lower_bound(b + 1, b + m + 1, sum[i] - i + k) - b;
}
upd(rt[ps1[0]], 1, k, sum[0] + 1);
LL ans = 0;
for (rint r = 1; r <= n; r++) {
ans += qrange(rt[ps1[r]], 1, k, 1, sum[r] + 1) +
qrange(rt[ps2[r]], 1, k, sum[r] + 2, k);
upd(rt[ps1[r]], 1, k, sum[r] + 1);
}
cout << ans << endl;
return 0;
}
| replace | 87 | 88 | 87 | 88 | -11 | |
p02851 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 100;
ll s[maxn];
ll a[maxn];
int main() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
s[i] = (s[i - 1] + a[i]);
}
for (int i = 1; i <= n; i++) {
s[i] = (s[i] - i) % k;
}
map<ll, ll> cnt;
ll ans = 0;
for (int i = 0; i <= n; i++) {
ans += cnt[s[i]];
cnt[s[i]]++;
if (i - k + 1 >= 0)
cnt[s[i - k + 1]]--;
}
printf("%lld\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 100;
ll s[maxn];
ll a[maxn];
int main() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
s[i] = (s[i - 1] + a[i]);
}
for (int i = 1; i <= n; i++) {
s[i] = (s[i] - i) % k;
}
map<ll, ll> cnt;
ll ans = 0;
for (int i = 0; i <= n; i++) {
ans += cnt[s[i]];
cnt[s[i]]++;
if (i - k + 1 >= 0)
cnt[s[i - k + 1]]--;
}
printf("%lld\n", ans);
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02851 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll) v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
ll N, K;
cin >> N >> K;
vector<ll> A(N);
rep(i, N) cin >> A[i];
vector<ll> S(N + 1);
S[0] = 0;
rep(i, N) S[i + 1] = S[i] + A[i];
rep(i, N + 1) S[i] = (S[i] - i + K) % K;
map<ll, ll> mp;
ll ans = 0;
rep(i, K) mp[S[i]]++;
ans += mp[S[0]] - 1;
for (ll i = 1; i <= N; ++i) {
mp[S[i - 1]]--;
if (i + K - 1 <= N)
mp[S[i + K - 1]]++;
ans += mp[S[i]] - 1;
}
print(ans);
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll) v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
ll N, K;
cin >> N >> K;
vector<ll> A(N);
rep(i, N) cin >> A[i];
vector<ll> S(N + 1);
S[0] = 0;
rep(i, N) S[i + 1] = S[i] + A[i];
rep(i, N + 1) S[i] = (S[i] - i + K) % K;
map<ll, ll> mp;
ll ans = 0;
rep(i, min(K, N + 1)) mp[S[i]]++;
ans += mp[S[0]] - 1;
for (ll i = 1; i <= N; ++i) {
mp[S[i - 1]]--;
if (i + K - 1 <= N)
mp[S[i + K - 1]]++;
ans += mp[S[i]] - 1;
}
print(ans);
return 0;
} | replace | 36 | 37 | 36 | 37 | 0 | |
p02851 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
template <class T> void corner(bool flg, T hoge) {
if (flg) {
cout << hoge << endl;
exit(0);
}
}
#define all(v) v.begin(), v.end()
#define inputv(v, n) \
vl v; \
rep(i, n) { \
ll x; \
cin >> x; \
v.push_back(x); \
}
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
vl A, B(MAX_N, 0), dp(MOD, 0);
int main() {
cin >> n >> k;
rep(i, n) {
cin >> a;
a--;
A.push_back(a);
}
rep(i, n) {
B[i + 1] = B[i];
B[i + 1] += A[i];
}
ans = 0;
auto ite1 = A.begin(), ite2 = A.begin();
while (ite2 != A.end()) {
dp[B[ite2 - A.begin()] % k]++;
ite2++;
while (ite2 - ite1 >= k) {
dp[B[ite1 - A.begin()] % k]--;
ite1++;
}
ans += dp[B[ite2 - A.begin()] % k];
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for (ll i = 0; i < ll(n); i++)
template <class T> void corner(bool flg, T hoge) {
if (flg) {
cout << hoge << endl;
exit(0);
}
}
#define all(v) v.begin(), v.end()
#define inputv(v, n) \
vl v; \
rep(i, n) { \
ll x; \
cin >> x; \
v.push_back(x); \
}
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
vl A, B(MAX_N, 0);
map<ll, ll> dp;
int main() {
cin >> n >> k;
rep(i, n) {
cin >> a;
a--;
A.push_back(a);
}
rep(i, n) {
B[i + 1] = B[i];
B[i + 1] += A[i];
}
ans = 0;
auto ite1 = A.begin(), ite2 = A.begin();
while (ite2 != A.end()) {
dp[B[ite2 - A.begin()] % k]++;
ite2++;
while (ite2 - ite1 >= k) {
dp[B[ite1 - A.begin()] % k]--;
ite1++;
}
ans += dp[B[ite2 - A.begin()] % k];
}
cout << ans << endl;
}
| replace | 24 | 25 | 24 | 26 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p02852 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, m, n) for (ll i = m; i < (ll)(n); i++)
#define rrep(i, n, m) for (ll i = n; i >= (ll)(m); i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG
/**
* For DEBUG
* https://github.com/ta7uw/cpp-pyprint
*/
#include "cpp-pyprint/pyprint.h"
#endif
void Main() {
ll N, M;
cin >> N >> M;
string S;
cin >> S;
vector<ll> ans;
ll now = N;
while (now != 0) {
ll t = -1;
rrep(i, now - 1, now - M) {
if (S[i] == '0') {
t = i;
}
}
if (t == -1) {
cout << -1 << '\n';
return;
} else {
ans.push_back(now - t);
now = t;
}
}
reverse(ans.begin(), ans.end());
rep(i, ans.size()) { cout << ans[i] << ' '; }
cout << '\n';
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, m, n) for (ll i = m; i < (ll)(n); i++)
#define rrep(i, n, m) for (ll i = n; i >= (ll)(m); i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG
/**
* For DEBUG
* https://github.com/ta7uw/cpp-pyprint
*/
#include "cpp-pyprint/pyprint.h"
#endif
void Main() {
ll N, M;
cin >> N >> M;
string S;
cin >> S;
vector<ll> ans;
ll now = N;
while (now != 0) {
ll t = -1;
rrep(i, now - 1, max(0LL, now - M)) {
if (S[i] == '0') {
t = i;
}
}
if (t == -1) {
cout << -1 << '\n';
return;
} else {
ans.push_back(now - t);
now = t;
}
}
reverse(ans.begin(), ans.end());
rep(i, ans.size()) { cout << ans[i] << ' '; }
cout << '\n';
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
Main();
return 0;
}
| replace | 35 | 36 | 35 | 36 | 0 | |
p02852 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep2(i, s, n) for (int i = (s); i < (int)n; i++)
int INF = 1e9 + 7;
int main() {
int N, M;
string S, T;
cin >> N >> M >> T;
rep(i, N + 1) S[i] = T[N - i];
vi s(N + 2);
rep(i, N + 1) s[i + 1] = s[i] + (int)(S[i] - '0');
int now = 0;
vi ans;
bool flag = true;
while (now < N) {
if (now + M >= N) {
ans.push_back(N - now);
break;
}
if (S[now + M] == 0) {
ans.push_back(M);
continue;
}
int l = now - 1, r = now + M;
while (r - l > 1) {
int m = (l + r) / 2;
if (s[now + M + 1] - s[m + 1] == now + M - m)
r = m;
else
l = m;
}
if (r == now) {
flag = false;
break;
}
ans.push_back(r - now);
now = r;
}
if (flag) {
reverse(ans.begin(), ans.end());
for (int x : ans)
cout << x << ' ';
cout << endl;
} else
cout << -1 << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vvb = vector<vb>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep2(i, s, n) for (int i = (s); i < (int)n; i++)
int INF = 1e9 + 7;
int main() {
int N, M;
string S;
cin >> N >> M >> S;
reverse(S.begin(), S.end());
vi s(N + 2);
rep(i, N + 1) s[i + 1] = s[i] + (int)(S[i] - '0');
int now = 0;
vi ans;
bool flag = true;
while (now < N) {
if (now + M >= N) {
ans.push_back(N - now);
break;
}
if (S[now + M] == 0) {
ans.push_back(M);
continue;
}
int l = now - 1, r = now + M;
while (r - l > 1) {
int m = (l + r) / 2;
if (s[now + M + 1] - s[m + 1] == now + M - m)
r = m;
else
l = m;
}
if (r == now) {
flag = false;
break;
}
ans.push_back(r - now);
now = r;
}
if (flag) {
reverse(ans.begin(), ans.end());
for (int x : ans)
cout << x << ' ';
cout << endl;
} else
cout << -1 << endl;
} | replace | 22 | 25 | 22 | 25 | 0 | |
p02852 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
int cnt = 0;
for (int i = 0; i < n + 1; i++) {
if (s[i] == '1') {
cnt++;
} else {
cnt = 0;
}
if (cnt > m) {
cout << -1 << endl;
return 0;
}
}
reverse(s.begin(), s.end());
int t = 0;
vector<int> ans;
int r = 0;
while (t < n) {
int num = t;
for (int i = num + 1; i <= num + m; i++) {
if (s[i] == '0') {
t = i;
}
}
ans.push_back(t - num);
}
for (int i = ans.size() - 1; i >= 0; i--) {
cout << ans[i] << " ";
}
cout << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
int cnt = 0;
for (int i = 0; i < n + 1; i++) {
if (s[i] == '1') {
cnt++;
} else {
cnt = 0;
}
if (cnt >= m) {
cout << -1 << endl;
return 0;
}
}
reverse(s.begin(), s.end());
int t = 0;
vector<int> ans;
int r = 0;
while (t < n) {
int num = t;
for (int i = num + 1; i <= num + m; i++) {
if (s[i] == '0') {
t = i;
}
}
ans.push_back(t - num);
}
for (int i = ans.size() - 1; i >= 0; i--) {
cout << ans[i] << " ";
}
cout << endl;
} | replace | 14 | 15 | 14 | 15 | TLE | |
p02852 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
int n;
pair<int, int> seg[maxn], ans[maxn];
void upd(int p, int v) {
for (seg[p += n] = {v, p}; p > 1; p >>= 1)
seg[p >> 1] = min(seg[p], seg[p ^ 1]);
}
pair<int, int> qry(int l, int r) {
pair<int, int> ans = {1 << 30, 1 << 30};
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1)
ans = min(ans, seg[l++]);
if (r & 1)
ans = min(ans, seg[--r]);
}
return ans;
}
int main() {
int m;
cin >> n >> m;
string s;
cin >> s;
n++;
upd(n - 1, 0);
for (int i = n - 2; i >= 0; i--) {
pair<int, int> b = {1 << 30, 1 << 30};
if (s[i] == '0') {
b = qry(i + 1, min(i + m + 1, n));
}
b.first++;
upd(i, b.first);
ans[i] = b;
}
if (ans[0].first >= (1 << 30))
cout << -1 << endl;
else {
int p = 0;
while (p != n - 1) {
cout << ans[p].second - p << " ";
p = ans[p].second;
}
cout << endl;
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int maxn = 300100;
int n;
pair<int, int> seg[maxn], ans[maxn];
void upd(int p, int v) {
for (seg[p += n] = {v, p}; p > 1; p >>= 1)
seg[p >> 1] = min(seg[p], seg[p ^ 1]);
}
pair<int, int> qry(int l, int r) {
pair<int, int> ans = {1 << 30, 1 << 30};
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1)
ans = min(ans, seg[l++]);
if (r & 1)
ans = min(ans, seg[--r]);
}
return ans;
}
int main() {
int m;
cin >> n >> m;
string s;
cin >> s;
n++;
upd(n - 1, 0);
for (int i = n - 2; i >= 0; i--) {
pair<int, int> b = {1 << 30, 1 << 30};
if (s[i] == '0') {
b = qry(i + 1, min(i + m + 1, n));
}
b.first++;
upd(i, b.first);
ans[i] = b;
}
if (ans[0].first >= (1 << 30))
cout << -1 << endl;
else {
int p = 0;
while (p != n - 1) {
cout << ans[p].second - p << " ";
p = ans[p].second;
}
cout << endl;
}
return 0;
}
| replace | 2 | 3 | 2 | 3 | 0 | |
p02852 | C++ | Runtime Error | #include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR \
if (DEBUG) \
cerr
#define MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, NAME, ...) NAME
#define pr(...) \
CERR << MACRO(__VA_ARGS__, pr10, pr9, pr8, pr7, pr6, pr5, pr4, pr3, pr2, \
pr1)(__VA_ARGS__) \
<< endl
#define pr1(a) (#a) << "=" << (a) << " "
#define pr2(a, b) pr1(a) << pr1(b)
#define pr3(a, b, c) pr1(a) << pr2(b, c)
#define pr4(a, b, c, d) pr1(a) << pr3(b, c, d)
#define pr5(a, b, c, d, e) pr1(a) << pr4(b, c, d, e)
#define pr6(a, b, c, d, e, f) pr1(a) << pr5(b, c, d, e, f)
#define pr7(a, b, c, d, e, f, g) pr1(a) << pr6(b, c, d, e, f, g)
#define pr8(a, b, c, d, e, f, g, h) pr1(a) << pr7(b, c, d, e, f, g, h)
#define pr9(a, b, c, d, e, f, g, h, i) pr1(a) << pr8(b, c, d, e, f, g, h, i)
#define pr10(a, b, c, d, e, f, g, h, i, j) \
pr1(a) << pr9(b, c, d, e, f, g, h, i, j)
#define prArr(a) \
{ \
CERR << (#a) << "={"; \
int i = 0; \
for (auto t : (a)) \
CERR << (i++ ? ", " : "") << t; \
CERR << "}" << endl; \
}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL << 60) + 1e9; // ~ 1.15 * 1e18
const Int mod = (1e9) + 7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int, Int>;
template <class T> T Max(T &a, T b) { return a = max(a, b); }
template <class T> T Min(T &a, T b) { return a = min(a, b); }
template <class T1, class T2> ostream &operator<<(ostream &o, pair<T1, T2> p) {
return o << "(" << p.first << "," << p.second << ")";
}
template <class T1, class T2, class T3>
ostream &operator<<(ostream &o, tuple<T1, T2, T3> t) {
return o << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
}
template <class T1, class T2> istream &operator>>(istream &i, pair<T1, T2> &p) {
return i >> p.first >> p.second;
}
template <class T> ostream &operator<<(ostream &o, vector<T> a) {
Int i = 0;
for (T t : a)
o << (i++ ? " " : "") << t;
return o;
}
template <class T> istream &operator>>(istream &i, vector<T> &a) {
for (T &t : a)
i >> t;
return i;
}
// INSERT ABOVE HERE
template <typename D, Int useAssert = 1> class RMQ {
public:
struct T { // 遅延データ
Int type; // 0 - empty, 1 - update, 2 - ifUpdate
D value;
T() {}
T(Int type, D value) : type(type), value(value) {}
};
Int n, n_;
D initValue; // 範囲外の時に返す値
vector<D> dat;
vector<T> td;
Int toMax; // 0 -> RangeMin 1->RangeMax;
RMQ() { n = -1; }
RMQ(Int n_, D initValue, Int toMax = 0)
: n_(n_), initValue(initValue), toMax(toMax) {
n = 1;
while (n < n_)
n *= 2;
td.resize(2 * n - 1, T(0, initValue));
dat.resize(2 * n - 1, initValue);
}
// 目的データのマージ
inline D mergeD(D l, D r) { return toMax ? max(l, r) : min(l, r); }
// 遅延データのマージ
inline T mergeT(const T &from, const T &to) {
if (to.type == 0)
return from;
if (from.type == 0)
return to; // from-empty
if (to.type == 1)
return to; // to-update;
if (to.type == 2)
return T(from.type, mergeD(from.value, to.value)); // to-ifupdate
if (useAssert)
assert(0);
return T();
}
// 目的データに遅延データを反映
inline void apply(D &a, const T &b) {
if (b.type == 0)
return;
if (b.type == 1)
a = b.value; // update
else
a = mergeD(a, b.value); // if-update
}
D dfs(Int a, Int b, const T x, Int k, Int l, Int r) {
if (r <= a || b <= l)
return x.type == 0 ? initValue : dat[k];
if (a <= l && r <= b) {
td[k] = mergeT(td[k], x);
apply(dat[k], x);
return dat[k];
}
Int kl = k * 2 + 1, kr = k * 2 + 2;
{ // 遅延を子に反映
td[kl] = mergeT(td[kl], td[k]);
td[kr] = mergeT(td[kr], td[k]);
apply(dat[kl], td[k]);
apply(dat[kr], td[k]);
td[k] = T(0, initValue);
}
D vl = dfs(a, b, x, kl, l, (l + r) / 2);
D vr = dfs(a, b, x, kr, (l + r) / 2, r);
return x.type == 0 ? mergeD(vl, vr) : (dat[k] = mergeD(vl, vr));
}
//[l,r)の値をxに変更 update(l,r,x)
void update(Int l, Int r, D x) {
if (useAssert)
assert(l <= r), assert(l <= n && r <= n), assert(l >= 0 && r >= 0);
dfs(l, r, T(1, x), 0, 0, n);
}
//[l,r)の値をもしもxの方が小さければ変更 ifupdate(l,r,x)
// toMaxのときは[l,r)の値をもしもxの方が大きければ変更 ifupdate(l,r,x)
void ifupdate(Int l, Int r, D x) {
if (useAssert)
assert(l <= r), assert(l <= n && r <= n), assert(l >= 0 && r >= 0);
dfs(l, r, T(2, x), 0, 0, n);
}
//[l,r)の最小値を得る get(l,r);
D get(Int l, Int r) {
if (useAssert)
assert(l <= r), assert(l <= n && r <= n), assert(l >= 0 && r >= 0);
return dfs(l, r, T(0, initValue), 0, 0, n);
}
};
signed main() {
srand((unsigned)time(NULL));
cin.tie(0);
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(12);
Int N, M;
string S;
cin >> N >> M >> S;
RMQ<P, 1> seg(N + 1, P(INF, INF), 0);
seg.ifupdate(N, N + 1, P(0, INF));
for (Int i = N; i >= 0; i--) {
if (S[i] == '1')
continue;
Int d = seg.get(i, i + 1).first;
seg.ifupdate(i - M, i, P(d + 1, i));
}
if (seg.get(0, 1).first == INF) {
cout << -1 << endl;
return 0;
}
vector<Int> ans;
{
Int pos = 0;
while (pos != N) {
Int from = seg.get(pos, pos + 1).second;
ans.push_back(from - pos);
pos = from;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR \
if (DEBUG) \
cerr
#define MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, NAME, ...) NAME
#define pr(...) \
CERR << MACRO(__VA_ARGS__, pr10, pr9, pr8, pr7, pr6, pr5, pr4, pr3, pr2, \
pr1)(__VA_ARGS__) \
<< endl
#define pr1(a) (#a) << "=" << (a) << " "
#define pr2(a, b) pr1(a) << pr1(b)
#define pr3(a, b, c) pr1(a) << pr2(b, c)
#define pr4(a, b, c, d) pr1(a) << pr3(b, c, d)
#define pr5(a, b, c, d, e) pr1(a) << pr4(b, c, d, e)
#define pr6(a, b, c, d, e, f) pr1(a) << pr5(b, c, d, e, f)
#define pr7(a, b, c, d, e, f, g) pr1(a) << pr6(b, c, d, e, f, g)
#define pr8(a, b, c, d, e, f, g, h) pr1(a) << pr7(b, c, d, e, f, g, h)
#define pr9(a, b, c, d, e, f, g, h, i) pr1(a) << pr8(b, c, d, e, f, g, h, i)
#define pr10(a, b, c, d, e, f, g, h, i, j) \
pr1(a) << pr9(b, c, d, e, f, g, h, i, j)
#define prArr(a) \
{ \
CERR << (#a) << "={"; \
int i = 0; \
for (auto t : (a)) \
CERR << (i++ ? ", " : "") << t; \
CERR << "}" << endl; \
}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL << 60) + 1e9; // ~ 1.15 * 1e18
const Int mod = (1e9) + 7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int, Int>;
template <class T> T Max(T &a, T b) { return a = max(a, b); }
template <class T> T Min(T &a, T b) { return a = min(a, b); }
template <class T1, class T2> ostream &operator<<(ostream &o, pair<T1, T2> p) {
return o << "(" << p.first << "," << p.second << ")";
}
template <class T1, class T2, class T3>
ostream &operator<<(ostream &o, tuple<T1, T2, T3> t) {
return o << "(" << get<0>(t) << "," << get<1>(t) << "," << get<2>(t) << ")";
}
template <class T1, class T2> istream &operator>>(istream &i, pair<T1, T2> &p) {
return i >> p.first >> p.second;
}
template <class T> ostream &operator<<(ostream &o, vector<T> a) {
Int i = 0;
for (T t : a)
o << (i++ ? " " : "") << t;
return o;
}
template <class T> istream &operator>>(istream &i, vector<T> &a) {
for (T &t : a)
i >> t;
return i;
}
// INSERT ABOVE HERE
template <typename D, Int useAssert = 1> class RMQ {
public:
struct T { // 遅延データ
Int type; // 0 - empty, 1 - update, 2 - ifUpdate
D value;
T() {}
T(Int type, D value) : type(type), value(value) {}
};
Int n, n_;
D initValue; // 範囲外の時に返す値
vector<D> dat;
vector<T> td;
Int toMax; // 0 -> RangeMin 1->RangeMax;
RMQ() { n = -1; }
RMQ(Int n_, D initValue, Int toMax = 0)
: n_(n_), initValue(initValue), toMax(toMax) {
n = 1;
while (n < n_)
n *= 2;
td.resize(2 * n - 1, T(0, initValue));
dat.resize(2 * n - 1, initValue);
}
// 目的データのマージ
inline D mergeD(D l, D r) { return toMax ? max(l, r) : min(l, r); }
// 遅延データのマージ
inline T mergeT(const T &from, const T &to) {
if (to.type == 0)
return from;
if (from.type == 0)
return to; // from-empty
if (to.type == 1)
return to; // to-update;
if (to.type == 2)
return T(from.type, mergeD(from.value, to.value)); // to-ifupdate
if (useAssert)
assert(0);
return T();
}
// 目的データに遅延データを反映
inline void apply(D &a, const T &b) {
if (b.type == 0)
return;
if (b.type == 1)
a = b.value; // update
else
a = mergeD(a, b.value); // if-update
}
D dfs(Int a, Int b, const T x, Int k, Int l, Int r) {
if (r <= a || b <= l)
return x.type == 0 ? initValue : dat[k];
if (a <= l && r <= b) {
td[k] = mergeT(td[k], x);
apply(dat[k], x);
return dat[k];
}
Int kl = k * 2 + 1, kr = k * 2 + 2;
{ // 遅延を子に反映
td[kl] = mergeT(td[kl], td[k]);
td[kr] = mergeT(td[kr], td[k]);
apply(dat[kl], td[k]);
apply(dat[kr], td[k]);
td[k] = T(0, initValue);
}
D vl = dfs(a, b, x, kl, l, (l + r) / 2);
D vr = dfs(a, b, x, kr, (l + r) / 2, r);
return x.type == 0 ? mergeD(vl, vr) : (dat[k] = mergeD(vl, vr));
}
//[l,r)の値をxに変更 update(l,r,x)
void update(Int l, Int r, D x) {
if (useAssert)
assert(l <= r), assert(l <= n && r <= n), assert(l >= 0 && r >= 0);
dfs(l, r, T(1, x), 0, 0, n);
}
//[l,r)の値をもしもxの方が小さければ変更 ifupdate(l,r,x)
// toMaxのときは[l,r)の値をもしもxの方が大きければ変更 ifupdate(l,r,x)
void ifupdate(Int l, Int r, D x) {
if (useAssert)
assert(l <= r), assert(l <= n && r <= n), assert(l >= 0 && r >= 0);
dfs(l, r, T(2, x), 0, 0, n);
}
//[l,r)の最小値を得る get(l,r);
D get(Int l, Int r) {
if (useAssert)
assert(l <= r), assert(l <= n && r <= n), assert(l >= 0 && r >= 0);
return dfs(l, r, T(0, initValue), 0, 0, n);
}
};
signed main() {
srand((unsigned)time(NULL));
cin.tie(0);
ios_base::sync_with_stdio(0);
cout << fixed << setprecision(12);
Int N, M;
string S;
cin >> N >> M >> S;
RMQ<P, 1> seg(N + 1, P(INF, INF), 0);
seg.ifupdate(N, N + 1, P(0, INF));
for (Int i = N; i >= 0; i--) {
if (S[i] == '1')
continue;
Int d = seg.get(i, i + 1).first;
seg.ifupdate(max(0LL, i - M), i, P(d + 1, i));
}
if (seg.get(0, 1).first == INF) {
cout << -1 << endl;
return 0;
}
vector<Int> ans;
{
Int pos = 0;
while (pos != N) {
Int from = seg.get(pos, pos + 1).second;
ans.push_back(from - pos);
pos = from;
}
}
cout << ans << endl;
return 0;
}
| replace | 183 | 184 | 183 | 184 | -6 | f41276d7-cb6b-413b-9666-5830930401c0.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02852/C++/s677913078.cpp:115: void RMQ<D, useAssert>::ifupdate(Int, Int, D) [with D = std::pair<long long int, long long int>; long long int useAssert = 1; Int = long long int]: Assertion `l >= 0 && r >= 0' failed.
|
p02852 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
// #define int long long
#define endl '\n'
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define bug1(x) \
{ cerr << (#x) << "=" << x << endl; }
#define bug2(x, y) \
{ cerr << (#x) << "=" << (x) << " " << (#y) << "=" << (y) << endl; }
#define bug3(x, y, z) \
{ \
cerr << (#x) << "=" << (x) << " " << (#y) << "=" << (y) << " " \
<< (#z) << "=" << (z) << endl; \
}
#define bug4(x, y, z, w) \
{ \
cerr << (#x) << "=" << (x) << " " << (#y) << "=" << (y) << " " \
<< (#z) << "=" << (z) << " " << (#w) << "=" << w << endl; \
}
#define bug5(x, y, z, w, p) \
{ \
cerr << (#x) << "=" << (x) << " " << (#y) << "=" << (y) << " " \
<< (#z) << "=" << (z) << " " << (#w) << "=" << w << " " << (#p) \
<< "=" << p << endl; \
}
#define bug6(x, y, z, w, p, q) \
{ \
cerr << (#x) << "=" << (x) << " " << (#y) << "=" << (y) << " " \
<< (#z) << "=" << (z) << " " << (#w) << "=" << w << " " << (#p) \
<< "=" << p << " " << (#q) << "=" << q << endl; \
}
#define bugn(x, n) \
{ \
cerr << (#x) << ":"; \
for (int i = 0; i < n; i++) \
cerr << x[i] << " "; \
cerr << endl; \
}
#define bugnm(x, n, m) \
{ \
cerr << (#x) << endl; \
for (int i = 0; i < n; i++) { \
cerr << "Row #" << i << ":"; \
for (int j = 0; j < m; j++) \
cerr << x[i][j] << " "; \
cerr << endl; \
} \
}
typedef long long ll;
typedef long double ld;
using namespace std;
int n, m;
string s;
vector<int> path;
vector<int> vis(100000 + 5);
void dfs(int n) {
// if( vis[n] )return;
// vis[n]=1;
if (n == 0) {
reverse(path.begin(), path.end());
for (auto p : path) {
cout << p << " ";
}
exit(0);
}
for (int k = min(n, m); k >= 1; k--) {
if (s[n - k] == '0') {
path.push_back(k);
dfs(n - k);
path.pop_back();
}
}
}
int32_t main() {
IOS cin >> n >> m >> s;
dfs(n);
cout << -1 << endl;
}
/*
* long long or int?
* index out of bound?
* Tested on own test case?corner?
* Make more general solution.
* Read Read Read Read ....
*/
| #include <bits/stdc++.h>
// #define int long long
#define endl '\n'
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define bug1(x) \
{ cerr << (#x) << "=" << x << endl; }
#define bug2(x, y) \
{ cerr << (#x) << "=" << (x) << " " << (#y) << "=" << (y) << endl; }
#define bug3(x, y, z) \
{ \
cerr << (#x) << "=" << (x) << " " << (#y) << "=" << (y) << " " \
<< (#z) << "=" << (z) << endl; \
}
#define bug4(x, y, z, w) \
{ \
cerr << (#x) << "=" << (x) << " " << (#y) << "=" << (y) << " " \
<< (#z) << "=" << (z) << " " << (#w) << "=" << w << endl; \
}
#define bug5(x, y, z, w, p) \
{ \
cerr << (#x) << "=" << (x) << " " << (#y) << "=" << (y) << " " \
<< (#z) << "=" << (z) << " " << (#w) << "=" << w << " " << (#p) \
<< "=" << p << endl; \
}
#define bug6(x, y, z, w, p, q) \
{ \
cerr << (#x) << "=" << (x) << " " << (#y) << "=" << (y) << " " \
<< (#z) << "=" << (z) << " " << (#w) << "=" << w << " " << (#p) \
<< "=" << p << " " << (#q) << "=" << q << endl; \
}
#define bugn(x, n) \
{ \
cerr << (#x) << ":"; \
for (int i = 0; i < n; i++) \
cerr << x[i] << " "; \
cerr << endl; \
}
#define bugnm(x, n, m) \
{ \
cerr << (#x) << endl; \
for (int i = 0; i < n; i++) { \
cerr << "Row #" << i << ":"; \
for (int j = 0; j < m; j++) \
cerr << x[i][j] << " "; \
cerr << endl; \
} \
}
typedef long long ll;
typedef long double ld;
using namespace std;
int n, m;
string s;
vector<int> path;
vector<int> vis(100000 + 5);
void dfs(int n) {
if (vis[n])
return;
vis[n] = 1;
if (n == 0) {
reverse(path.begin(), path.end());
for (auto p : path) {
cout << p << " ";
}
exit(0);
}
for (int k = min(n, m); k >= 1; k--) {
if (s[n - k] == '0') {
path.push_back(k);
dfs(n - k);
path.pop_back();
}
}
}
int32_t main() {
IOS cin >> n >> m >> s;
dfs(n);
cout << -1 << endl;
}
/*
* long long or int?
* index out of bound?
* Tested on own test case?corner?
* Make more general solution.
* Read Read Read Read ....
*/
| replace | 59 | 61 | 59 | 62 | TLE | |
p02852 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
priority_queue<pii> Q;
int ans[100010];
int main() {
int n, m;
string s;
cin >> n >> m;
cin >> s;
// cout << n << ' ' << m << ' ' << s << endl;
fill(ans, ans + n + 1, -1);
for (int i = n - 1, j = 1; i >= n - m; i--, j++) {
if (s[i] == '1')
continue;
Q.push({-1, -i});
ans[i] = j;
}
for (int i = n - m - 1; i >= 0; i--) {
if (s[i] == '1')
continue;
while (!Q.empty()) {
pii u = Q.top();
// cout << i << ' ' << u.ff << ' ' << u.ss << endl;
if (i + m < -u.ss) {
Q.pop();
continue;
} else {
Q.push({u.ff - 1, -i});
ans[i] = -u.ss - i;
break;
}
}
}
if (ans[0] == -1) {
cout << -1 << endl;
return 0;
}
for (int i = 0; i < n; i += ans[i]) {
cout << ans[i] << ' ';
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
priority_queue<pii> Q;
int ans[100010];
int main() {
int n, m;
string s;
cin >> n >> m;
cin >> s;
// cout << n << ' ' << m << ' ' << s << endl;
fill(ans, ans + n + 1, -1);
for (int i = n - 1, j = 1; i >= n - m; i--, j++) {
if (i < 0)
break;
if (s[i] == '1')
continue;
Q.push({-1, -i});
ans[i] = j;
}
for (int i = n - m - 1; i >= 0; i--) {
if (s[i] == '1')
continue;
while (!Q.empty()) {
pii u = Q.top();
// cout << i << ' ' << u.ff << ' ' << u.ss << endl;
if (i + m < -u.ss) {
Q.pop();
continue;
} else {
Q.push({u.ff - 1, -i});
ans[i] = -u.ss - i;
break;
}
}
}
if (ans[0] == -1) {
cout << -1 << endl;
return 0;
}
for (int i = 0; i < n; i += ans[i]) {
cout << ans[i] << ' ';
}
return 0;
} | insert | 24 | 24 | 24 | 26 | 0 | |
p02852 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
/*
* coder :: ATUL_PANDEY_2608
* >>> INDIA <<<
*/
using namespace std;
using namespace __gnu_pbds;
// #define part ..
#define pb(a) push_back(a)
#define all(a) a.begin(), a.end()
#define mod 1000000007
// #define maxx 200006
#define ll long long
#define quick ios_base::sync_with_stdio(NULL), cin.tie(0);
#define listll vector<long long>
#define listi vector<int>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define minheap priority_queue<long long, vector<long long>, greater<long long>>
#define rep(i, a, b) for (int i = a; i < b; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
template <class T>
using oset =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// end of #define
// define globals ...
const int maxx = 2e5 + 26;
// write function from here ...
int Main() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
vector<int> arr;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '0')
arr.pb(i);
}
reverse(all(arr));
if (s[0] == '1' || s[s.length() - 1] == '1') {
cout << -1;
return 0;
}
int sz = arr.size();
for (int i = 0; i < sz - 1; i++) {
if (arr[i] - arr[i + 1] > m) {
cout << -1 << endl;
return 0;
}
}
int r = n;
vector<int> ans;
for (int i = 0; i < sz; i++) {
while (r - arr[i] <= m) {
i++;
}
i--;
ans.pb(r - arr[i]);
r = arr[i];
}
reverse(all(ans));
for (auto it : ans)
cout << it << " ";
return 0;
}
int main() {
quick;
int t = 1;
// cin>>t;
while (t--)
Main();
return 0;
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
/*
* coder :: ATUL_PANDEY_2608
* >>> INDIA <<<
*/
using namespace std;
using namespace __gnu_pbds;
// #define part ..
#define pb(a) push_back(a)
#define all(a) a.begin(), a.end()
#define mod 1000000007
// #define maxx 200006
#define ll long long
#define quick ios_base::sync_with_stdio(NULL), cin.tie(0);
#define listll vector<long long>
#define listi vector<int>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define minheap priority_queue<long long, vector<long long>, greater<long long>>
#define rep(i, a, b) for (int i = a; i < b; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
template <class T>
using oset =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// end of #define
// define globals ...
const int maxx = 2e5 + 26;
// write function from here ...
int Main() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
vector<int> arr;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '0')
arr.pb(i);
}
reverse(all(arr));
if (s[0] == '1' || s[s.length() - 1] == '1') {
cout << -1;
return 0;
}
int sz = arr.size();
for (int i = 0; i < sz - 1; i++) {
if (arr[i] - arr[i + 1] > m) {
cout << -1 << endl;
return 0;
}
}
int r = n;
vector<int> ans;
for (int i = 0; i < sz; i++) {
while (r - arr[i] <= m && i < sz) {
i++;
}
i--;
ans.pb(r - arr[i]);
r = arr[i];
}
reverse(all(ans));
for (auto it : ans)
cout << it << " ";
return 0;
}
int main() {
quick;
int t = 1;
// cin>>t;
while (t--)
Main();
return 0;
}
| replace | 72 | 73 | 72 | 73 | -11 | |
p02852 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int n, m;
string s;
vector<int> v;
bool func(int now) {
if (now == 0) {
return true;
}
if (now < 0) {
return false;
}
for (int i = m; i >= 1; i--) {
int next = now - i;
if (s[next] == '0') {
v.push_back(next);
if (func(next))
return true;
v.pop_back();
}
}
return false;
}
int main() {
cin >> n >> m;
cin >> s;
if (!func(n)) {
cout << -1 << endl;
return 0;
}
reverse(v.begin(), v.end());
for (int i = 1; i <= v.size(); i++) {
if (i == v.size())
cout << n - v[i - 1] << " ";
else
cout << v[i] - v[i - 1] << " ";
}
cout << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int n, m;
string s;
vector<int> v;
bool func(int now) {
if (now == 0) {
return true;
}
if (now < 0) {
return false;
}
for (int i = m; i >= 1; i--) {
int next = now - i;
if (s[next] == '0') {
v.push_back(next);
if (func(next))
return true;
v.pop_back();
}
}
return false;
}
int main() {
cin >> n >> m;
cin >> s;
int now = n;
while (now > 0) {
bool ok = false;
for (int i = m; i >= 1; i--) {
int next = now - i;
if (next < 0)
continue;
if (s[next] == '1')
continue;
v.push_back(next);
now = next;
ok = true;
break;
}
if (!ok) {
cout << -1 << endl;
return 0;
}
}
reverse(v.begin(), v.end());
for (int i = 1; i <= v.size(); i++) {
if (i == v.size())
cout << n - v[i - 1] << " ";
else
cout << v[i] - v[i - 1] << " ";
}
cout << endl;
return 0;
}
| replace | 31 | 35 | 31 | 49 | TLE | |
p02852 | C++ | Runtime Error | #pragma GCC optimize("O3")
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using QWORD = uint64_t;
using SQWORD = int64_t;
using DWORD = uint32_t;
using SDWORD = int32_t;
using WORD = uint16_t;
using SWORD = int16_t;
using BYTE = uint8_t;
using SBYTE = int8_t;
using DOUBLE = double;
using FLOAT = float;
#define MIN_SDWORD (-2147483648)
#define MAX_SDWORD (2147483647)
#define MIN_SBYTE (-128)
#define MAX_SBYTE (127)
#define MIN_SQWORD (0x8000000000000000)
#define MAX_SQWORD (0x7FFFFFFFFFFFFFFF)
#define MAX_QWORD (0xFFFFFFFFFFFFFFFF)
#define MAX_DWORD (0xFFFFFFFF)
#define MAX_WORD (0xFFFF)
#define MAX_BYTE (0xFF)
#define MAX_DOUBLE (1.0e+308)
#define DOUBLE_EPS (1.0e-12)
#define MIN_DOUBLE_N (-1.0e+308)
#define ArrayLength(a) (sizeof(a) / sizeof(a[0]))
static inline DOUBLE MAX(DOUBLE a, DOUBLE b) { return a > b ? a : b; }
static inline QWORD MAX(QWORD a, QWORD b) { return a > b ? a : b; }
static inline DWORD MAX(DWORD a, DWORD b) { return a > b ? a : b; }
static inline SDWORD MAX(SDWORD a, SDWORD b) { return a > b ? a : b; }
static inline DOUBLE MIN(DOUBLE a, DOUBLE b) { return a < b ? a : b; }
static inline QWORD MIN(QWORD a, QWORD b) { return a < b ? a : b; }
static inline DWORD MIN(DWORD a, DWORD b) { return a < b ? a : b; }
static inline SDWORD MIN(SDWORD a, SDWORD b) { return a < b ? a : b; }
#define BYTE_BITS (8)
#define WORD_BITS (16)
#define DWORD_BITS (32)
#define QWORD_BITS (64)
static inline void inputStringSpSeparated(char *pcStr) {
char *pcCur = pcStr;
for (;;) {
char c = getchar();
if (('\n' == c) || (EOF == c) || (' ' == c)) {
break;
}
*pcCur = c;
pcCur++;
}
*pcCur = '\0';
}
static inline void inputString(char *pcStr) {
char *pcCur = pcStr;
for (;;) {
char c = getchar();
if (('\n' == c) || (EOF == c)) {
break;
}
*pcCur = c;
pcCur++;
}
*pcCur = '\0';
}
static inline SQWORD inputSQWORD(void) {
SQWORD sqNumber = 0;
SQWORD sqMultiplier = 1;
bool bRead = false;
for (;;) {
char c = getchar();
if (!bRead) {
if ('-' == c) {
sqMultiplier = -1;
}
}
if (('0' <= c) && (c <= '9')) {
sqNumber *= 10LL;
sqNumber += (SQWORD)(c - '0');
bRead = true;
} else {
if (bRead) {
return sqNumber * sqMultiplier;
}
}
}
}
static inline SDWORD inputSDWORD(void) {
SDWORD lNumber = 0;
SDWORD lMultiplier = 1;
bool bRead = false;
for (;;) {
char c = getchar();
if (!bRead) {
if ('-' == c) {
lMultiplier = -1;
}
}
if (('0' <= c) && (c <= '9')) {
lNumber *= 10;
lNumber += (c - '0');
bRead = true;
} else {
if (bRead) {
return lNumber * lMultiplier;
}
}
}
}
static inline DOUBLE inputFP(void) {
DOUBLE dInt = 0.0;
DOUBLE dFrac = 0.0;
DOUBLE dMultiplier = 1.0;
DWORD dwFpCnt = 0;
DOUBLE *pdCur = &dInt;
bool bRead = false;
for (;;) {
char c = getchar();
if (!bRead) {
if ('-' == c) {
dMultiplier = -1;
}
}
if ('.' == c) {
pdCur = &dFrac;
} else if (('0' <= c) && (c <= '9')) {
(*pdCur) *= 10;
(*pdCur) += (DOUBLE)(c - '0');
bRead = true;
if (pdCur == &dFrac) {
dwFpCnt++;
}
} else {
if (bRead) {
return dMultiplier *
(dInt + dFrac / (pow((DOUBLE)10.0, (DOUBLE)dwFpCnt)));
}
}
}
}
/*----------------------------------------------*/
/**
* mod による操作ライブラリ
*/
#define ANS_MOD (1000000007)
class MODINT {
static SQWORD MOD;
SQWORD m_x;
public:
MODINT(SQWORD val) { m_x = (val % MOD + MOD) % MOD; };
MODINT() { m_x = 0; }
static void Init(SQWORD sqMod) { MOD = sqMod; }
MODINT &operator+=(const MODINT a) {
m_x = (m_x + a.m_x) % MOD;
return *this;
};
MODINT &operator-=(const MODINT a) {
m_x = (m_x - a.m_x + MOD) % MOD;
return *this;
};
MODINT &operator*=(const MODINT a) {
m_x = (m_x * a.m_x) % MOD;
return *this;
};
MODINT pow(SQWORD t) const {
if (!t)
return 1;
MODINT a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
MODINT operator+(const MODINT a) const {
MODINT res(*this);
return (res += a);
}
MODINT operator-(const MODINT a) const {
MODINT res(*this);
return (res -= a);
}
MODINT operator*(const MODINT a) const {
MODINT res(*this);
return (res *= a);
}
MODINT operator/(const MODINT a) const {
MODINT res(*this);
return (res /= a);
}
/* 逆元 */
MODINT inv() const { return pow(MOD - 2); }
/* 除算 */
MODINT &operator/=(const MODINT a) { return (*this) *= a.inv(); }
/* 整数版 */
MODINT &operator+=(const SQWORD a) {
*this += MODINT(a);
return *this;
};
MODINT &operator-=(const SQWORD a) {
*this -= MODINT(a);
return *this;
};
MODINT &operator*=(const SQWORD a) {
*this *= MODINT(a);
return *this;
};
MODINT &operator/=(const SQWORD a) {
*this /= MODINT(a);
return *this;
};
SQWORD getVal() { return m_x; };
};
SQWORD MODINT::MOD = ANS_MOD;
/*----------------------------------------------*/
/*----------------------------------------------*/
struct DP_ENTRY {
SQWORD sqCnt;
SQWORD sqPrev;
};
int main(void) {
SQWORD sqN = inputSQWORD();
SQWORD sqM = inputSQWORD();
string strS;
cin >> strS;
vector<SQWORD> vsqPtr(sqN - 1, 0);
SQWORD sqNext = sqN;
for (SQWORD sqIdx = sqN; 0 <= sqIdx; sqIdx--) {
if ('0' == strS[sqIdx]) {
sqNext = sqIdx;
}
vsqPtr[sqIdx] = sqNext;
}
SQWORD sqCur = sqN;
vector<SQWORD> vsqAns;
while (1) {
if (sqCur <= sqM) {
vsqAns.emplace_back(sqCur);
break;
}
if (sqCur == vsqPtr[sqCur - sqM]) {
printf("-1\n");
return 0;
}
vsqAns.emplace_back(sqCur - vsqPtr[sqCur - sqM]);
sqCur = vsqPtr[sqCur - sqM];
}
reverse(vsqAns.begin(), vsqAns.end());
for (auto s : vsqAns) {
printf("%lld ", s);
}
printf("\n");
return 0;
} | #pragma GCC optimize("O3")
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using QWORD = uint64_t;
using SQWORD = int64_t;
using DWORD = uint32_t;
using SDWORD = int32_t;
using WORD = uint16_t;
using SWORD = int16_t;
using BYTE = uint8_t;
using SBYTE = int8_t;
using DOUBLE = double;
using FLOAT = float;
#define MIN_SDWORD (-2147483648)
#define MAX_SDWORD (2147483647)
#define MIN_SBYTE (-128)
#define MAX_SBYTE (127)
#define MIN_SQWORD (0x8000000000000000)
#define MAX_SQWORD (0x7FFFFFFFFFFFFFFF)
#define MAX_QWORD (0xFFFFFFFFFFFFFFFF)
#define MAX_DWORD (0xFFFFFFFF)
#define MAX_WORD (0xFFFF)
#define MAX_BYTE (0xFF)
#define MAX_DOUBLE (1.0e+308)
#define DOUBLE_EPS (1.0e-12)
#define MIN_DOUBLE_N (-1.0e+308)
#define ArrayLength(a) (sizeof(a) / sizeof(a[0]))
static inline DOUBLE MAX(DOUBLE a, DOUBLE b) { return a > b ? a : b; }
static inline QWORD MAX(QWORD a, QWORD b) { return a > b ? a : b; }
static inline DWORD MAX(DWORD a, DWORD b) { return a > b ? a : b; }
static inline SDWORD MAX(SDWORD a, SDWORD b) { return a > b ? a : b; }
static inline DOUBLE MIN(DOUBLE a, DOUBLE b) { return a < b ? a : b; }
static inline QWORD MIN(QWORD a, QWORD b) { return a < b ? a : b; }
static inline DWORD MIN(DWORD a, DWORD b) { return a < b ? a : b; }
static inline SDWORD MIN(SDWORD a, SDWORD b) { return a < b ? a : b; }
#define BYTE_BITS (8)
#define WORD_BITS (16)
#define DWORD_BITS (32)
#define QWORD_BITS (64)
static inline void inputStringSpSeparated(char *pcStr) {
char *pcCur = pcStr;
for (;;) {
char c = getchar();
if (('\n' == c) || (EOF == c) || (' ' == c)) {
break;
}
*pcCur = c;
pcCur++;
}
*pcCur = '\0';
}
static inline void inputString(char *pcStr) {
char *pcCur = pcStr;
for (;;) {
char c = getchar();
if (('\n' == c) || (EOF == c)) {
break;
}
*pcCur = c;
pcCur++;
}
*pcCur = '\0';
}
static inline SQWORD inputSQWORD(void) {
SQWORD sqNumber = 0;
SQWORD sqMultiplier = 1;
bool bRead = false;
for (;;) {
char c = getchar();
if (!bRead) {
if ('-' == c) {
sqMultiplier = -1;
}
}
if (('0' <= c) && (c <= '9')) {
sqNumber *= 10LL;
sqNumber += (SQWORD)(c - '0');
bRead = true;
} else {
if (bRead) {
return sqNumber * sqMultiplier;
}
}
}
}
static inline SDWORD inputSDWORD(void) {
SDWORD lNumber = 0;
SDWORD lMultiplier = 1;
bool bRead = false;
for (;;) {
char c = getchar();
if (!bRead) {
if ('-' == c) {
lMultiplier = -1;
}
}
if (('0' <= c) && (c <= '9')) {
lNumber *= 10;
lNumber += (c - '0');
bRead = true;
} else {
if (bRead) {
return lNumber * lMultiplier;
}
}
}
}
static inline DOUBLE inputFP(void) {
DOUBLE dInt = 0.0;
DOUBLE dFrac = 0.0;
DOUBLE dMultiplier = 1.0;
DWORD dwFpCnt = 0;
DOUBLE *pdCur = &dInt;
bool bRead = false;
for (;;) {
char c = getchar();
if (!bRead) {
if ('-' == c) {
dMultiplier = -1;
}
}
if ('.' == c) {
pdCur = &dFrac;
} else if (('0' <= c) && (c <= '9')) {
(*pdCur) *= 10;
(*pdCur) += (DOUBLE)(c - '0');
bRead = true;
if (pdCur == &dFrac) {
dwFpCnt++;
}
} else {
if (bRead) {
return dMultiplier *
(dInt + dFrac / (pow((DOUBLE)10.0, (DOUBLE)dwFpCnt)));
}
}
}
}
/*----------------------------------------------*/
/**
* mod による操作ライブラリ
*/
#define ANS_MOD (1000000007)
class MODINT {
static SQWORD MOD;
SQWORD m_x;
public:
MODINT(SQWORD val) { m_x = (val % MOD + MOD) % MOD; };
MODINT() { m_x = 0; }
static void Init(SQWORD sqMod) { MOD = sqMod; }
MODINT &operator+=(const MODINT a) {
m_x = (m_x + a.m_x) % MOD;
return *this;
};
MODINT &operator-=(const MODINT a) {
m_x = (m_x - a.m_x + MOD) % MOD;
return *this;
};
MODINT &operator*=(const MODINT a) {
m_x = (m_x * a.m_x) % MOD;
return *this;
};
MODINT pow(SQWORD t) const {
if (!t)
return 1;
MODINT a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
MODINT operator+(const MODINT a) const {
MODINT res(*this);
return (res += a);
}
MODINT operator-(const MODINT a) const {
MODINT res(*this);
return (res -= a);
}
MODINT operator*(const MODINT a) const {
MODINT res(*this);
return (res *= a);
}
MODINT operator/(const MODINT a) const {
MODINT res(*this);
return (res /= a);
}
/* 逆元 */
MODINT inv() const { return pow(MOD - 2); }
/* 除算 */
MODINT &operator/=(const MODINT a) { return (*this) *= a.inv(); }
/* 整数版 */
MODINT &operator+=(const SQWORD a) {
*this += MODINT(a);
return *this;
};
MODINT &operator-=(const SQWORD a) {
*this -= MODINT(a);
return *this;
};
MODINT &operator*=(const SQWORD a) {
*this *= MODINT(a);
return *this;
};
MODINT &operator/=(const SQWORD a) {
*this /= MODINT(a);
return *this;
};
SQWORD getVal() { return m_x; };
};
SQWORD MODINT::MOD = ANS_MOD;
/*----------------------------------------------*/
/*----------------------------------------------*/
struct DP_ENTRY {
SQWORD sqCnt;
SQWORD sqPrev;
};
int main(void) {
SQWORD sqN = inputSQWORD();
SQWORD sqM = inputSQWORD();
string strS;
cin >> strS;
vector<SQWORD> vsqPtr(sqN + 1, 0);
SQWORD sqNext = sqN;
for (SQWORD sqIdx = sqN; 0 <= sqIdx; sqIdx--) {
if ('0' == strS[sqIdx]) {
sqNext = sqIdx;
}
vsqPtr[sqIdx] = sqNext;
}
SQWORD sqCur = sqN;
vector<SQWORD> vsqAns;
while (1) {
if (sqCur <= sqM) {
vsqAns.emplace_back(sqCur);
break;
}
if (sqCur == vsqPtr[sqCur - sqM]) {
printf("-1\n");
return 0;
}
vsqAns.emplace_back(sqCur - vsqPtr[sqCur - sqM]);
sqCur = vsqPtr[sqCur - sqM];
}
reverse(vsqAns.begin(), vsqAns.end());
for (auto s : vsqAns) {
printf("%lld ", s);
}
printf("\n");
return 0;
} | replace | 262 | 263 | 262 | 263 | -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)
|
p02852 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
int main() {
int n, m;
string s;
cin >> n >> m >> s;
vector<int> dp(n + 1, INF);
dp[n] = 0;
queue<int> q;
q.push(0);
for (int i = n - 1; i >= 0; --i) {
while (1) {
if (q.size() == 0) {
puts("-1");
return 0;
}
if (q.front() != INF && q.size() <= m)
break;
q.pop();
}
if (s[i] == '0')
dp[i] = q.front() + 1;
q.push(dp[i]);
}
vector<int> ans;
int x = 0;
int rest = dp[0];
while (x < n) {
--rest;
int i = 1;
while (dp[x + i] != rest)
++i;
ans.push_back(i);
x += i;
}
rep(i, n) { printf("%d%c", ans[i], i == n - 1 ? '\n' : ' '); }
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
int main() {
int n, m;
string s;
cin >> n >> m >> s;
vector<int> dp(n + 1, INF);
dp[n] = 0;
queue<int> q;
q.push(0);
for (int i = n - 1; i >= 0; --i) {
while (1) {
if (q.size() == 0) {
puts("-1");
return 0;
}
if (q.front() != INF && q.size() <= m)
break;
q.pop();
}
if (s[i] == '0')
dp[i] = q.front() + 1;
q.push(dp[i]);
}
vector<int> ans;
int x = 0;
int rest = dp[0];
while (x < n) {
--rest;
int i = 1;
while (dp[x + i] != rest)
++i;
ans.push_back(i);
x += i;
}
rep(i, ans.size()) {
printf("%d%c", ans[i], i == int(ans.size()) - 1 ? '\n' : ' ');
}
return 0;
} | replace | 41 | 42 | 41 | 44 | 0 | |
p02852 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag,
tree_order_statistics_node_update>; template<typename T, typename L> using
gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>,
rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios {
fast_ios() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
};
} fast_ios_;
#define FOR(i, begin, end) for (int i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define IFOR(i, begin, end) for (int i = (end)-1; i >= (begin); i--)
#define IREP(i, n) IFOR(i, 0, n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(), v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) \
distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL << (n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) \
cout << #v << "=" << endl; \
REP(i_debug, v.size()) { cout << v[i_debug] << ","; } \
cout << endl;
#define mdebug(m) \
cout << #m << "=" << endl; \
REP(i_debug, m.size()) { \
REP(j_debug, m[i_debug].size()) { cout << m[i_debug][j_debug] << ","; } \
cout << endl; \
}
#define Return(ans) \
{ \
cout << (ans) << endl; \
return 0; \
}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &x : v)
is >> x;
return is;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
for (int i = 0; i < v.size(); i++) {
cout << v[i];
if (i != v.size() - 1)
cout << endl;
};
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
cout << '(' << p.first << ',' << p.second << ')';
return os;
}
template <typename T> void Out(T x) { cout << x << endl; }
template <typename T1, typename T2> void Ans(bool f, T1 y, T2 n) {
if (f)
Out(y);
else
Out(n);
}
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
// int dx[4] = {1,0,-1,0};
// int dy[4] = {0,1,0,-1};
// char d[4] = {'D','R','U','L'};
const int mod = 1000000007;
// const int mod = 998244353;
// #define Add(x, y) x = (x + (y)) % mod
// #define Mult(x, y) x = (x * (y)) % mod
struct SegmentTree {
using T = int;
int N;
vector<T> dat;
T id = INF;
T F(T &a, T &b) { return min(a, b); }
SegmentTree(int n) {
N = 1;
while (n > N)
N = N << 1;
dat = vector<T>(2 * N - 1, id);
}
SegmentTree(int n, vector<T> &v) {
N = 1;
while (n > N)
N = N << 1;
dat = vector<T>(2 * N - 1, id);
for (int i = 0; i < n; i++)
dat[i + N - 1] = v[i];
for (int i = N - 2; i >= 0; i--)
dat[i] = F(dat[i * 2 + 1], dat[i * 2 + 2]);
}
SegmentTree() {}
void update(int k, T a) {
k += N - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = F(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
void reset() { fill(dat.begin(), dat.end(), id); }
T get(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return id;
if (a <= l && r <= b)
return dat[k];
else {
T vl = get(a, b, k * 2 + 1, l, (l + r) / 2);
T vr = get(a, b, k * 2 + 2, (l + r) / 2, r);
return F(vl, vr);
}
}
T get(int a, int b) { return get(a, b, 0, 0, N); }
T val(int k) { return dat[k + N - 1]; }
};
signed main() {
int N, M;
cin >> N >> M;
string S;
cin >> S;
SegmentTree ST(N + 1);
vec dp(N + 1, INF);
dp[0] = 0;
ST.update(0, 0);
FOR(i, 1, N + 1) if (S[i] == '0') {
int m = ST.get(max(0LL, i - M), i);
if (m < INF) {
dp[i] = m + 1;
ST.update(i, m + 1);
}
}
// debug(dp[N]);
if (dp[N] >= INF)
Return(-1);
int now = N;
vec ans;
while (now) {
IFOR(i, 1, M + 1) {
if (dp[now] == dp[now - i] + 1) {
ans.pb(i);
now -= i;
break;
}
}
}
Reverse(ans);
for (int x : ans)
cout << x << " ";
cout << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag,
tree_order_statistics_node_update>; template<typename T, typename L> using
gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>,
rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios {
fast_ios() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
};
} fast_ios_;
#define FOR(i, begin, end) for (int i = (begin); i < (end); i++)
#define REP(i, n) FOR(i, 0, n)
#define IFOR(i, begin, end) for (int i = (end)-1; i >= (begin); i--)
#define IREP(i, n) IFOR(i, 0, n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(), v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) \
distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL << (n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) \
cout << #v << "=" << endl; \
REP(i_debug, v.size()) { cout << v[i_debug] << ","; } \
cout << endl;
#define mdebug(m) \
cout << #m << "=" << endl; \
REP(i_debug, m.size()) { \
REP(j_debug, m[i_debug].size()) { cout << m[i_debug][j_debug] << ","; } \
cout << endl; \
}
#define Return(ans) \
{ \
cout << (ans) << endl; \
return 0; \
}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &x : v)
is >> x;
return is;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
for (int i = 0; i < v.size(); i++) {
cout << v[i];
if (i != v.size() - 1)
cout << endl;
};
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
cout << '(' << p.first << ',' << p.second << ')';
return os;
}
template <typename T> void Out(T x) { cout << x << endl; }
template <typename T1, typename T2> void Ans(bool f, T1 y, T2 n) {
if (f)
Out(y);
else
Out(n);
}
using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;
// int dx[4] = {1,0,-1,0};
// int dy[4] = {0,1,0,-1};
// char d[4] = {'D','R','U','L'};
const int mod = 1000000007;
// const int mod = 998244353;
// #define Add(x, y) x = (x + (y)) % mod
// #define Mult(x, y) x = (x * (y)) % mod
struct SegmentTree {
using T = int;
int N;
vector<T> dat;
T id = INF;
T F(T &a, T &b) { return min(a, b); }
SegmentTree(int n) {
N = 1;
while (n > N)
N = N << 1;
dat = vector<T>(2 * N - 1, id);
}
SegmentTree(int n, vector<T> &v) {
N = 1;
while (n > N)
N = N << 1;
dat = vector<T>(2 * N - 1, id);
for (int i = 0; i < n; i++)
dat[i + N - 1] = v[i];
for (int i = N - 2; i >= 0; i--)
dat[i] = F(dat[i * 2 + 1], dat[i * 2 + 2]);
}
SegmentTree() {}
void update(int k, T a) {
k += N - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = F(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
void reset() { fill(dat.begin(), dat.end(), id); }
T get(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return id;
if (a <= l && r <= b)
return dat[k];
else {
T vl = get(a, b, k * 2 + 1, l, (l + r) / 2);
T vr = get(a, b, k * 2 + 2, (l + r) / 2, r);
return F(vl, vr);
}
}
T get(int a, int b) { return get(a, b, 0, 0, N); }
T val(int k) { return dat[k + N - 1]; }
};
signed main() {
int N, M;
cin >> N >> M;
string S;
cin >> S;
SegmentTree ST(N + 1);
vec dp(N + 1, INF);
dp[0] = 0;
ST.update(0, 0);
FOR(i, 1, N + 1) if (S[i] == '0') {
int m = ST.get(max(0LL, i - M), i);
if (m < INF) {
dp[i] = m + 1;
ST.update(i, m + 1);
}
}
// debug(dp[N]);
if (dp[N] >= INF)
Return(-1);
int now = N;
vec ans;
while (now) {
IFOR(i, 1, M + 1) if (now - i >= 0) {
if (dp[now] == dp[now - i] + 1) {
ans.pb(i);
now -= i;
break;
}
}
}
Reverse(ans);
for (int x : ans)
cout << x << " ";
cout << endl;
return 0;
}
| replace | 179 | 180 | 179 | 180 | 0 | |
p02852 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define ALL(x) x.begin(), x.end()
#define ll long long
typedef pair<int, int> P;
const int inf = 1000000007;
const int MOD = 1000000007;
signed main() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
reverse(ALL(s));
vector<bool> dp(n + m + 10, false);
dp[n] = true;
for (int i = n - 1; i >= 0; i--) {
if (s[i] == '1') {
dp[i] = false;
continue;
} else {
int sup = min(n - i, m);
rep1(j, sup) { dp[i] = dp[i] || dp[i + j]; }
}
}
if (!dp[0]) {
cout << -1 << "\n";
} else {
vector<int> res;
rep(i, n) {
for (int j = m; j > 0; --j) {
if (dp[i + j]) {
i += j - 1;
res.push_back(j);
break;
}
}
}
int num = res.size();
rep(i, num) { cout << res[num - i - 1] << " "; }
cout << endl;
}
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i <= n; ++i)
#define ALL(x) x.begin(), x.end()
#define ll long long
typedef pair<int, int> P;
const int inf = 1000000007;
const int MOD = 1000000007;
signed main() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
reverse(ALL(s));
vector<bool> dp(n + m + 10, false);
dp[n] = true;
for (int i = n - 1; i >= 0; i--) {
if (s[i] == '1') {
dp[i] = false;
continue;
} else {
int sup = min(n - i, m);
rep1(j, sup) {
dp[i] = dp[i] || dp[i + j];
if (dp[i])
break;
}
}
}
if (!dp[0]) {
cout << -1 << "\n";
} else {
vector<int> res;
rep(i, n) {
for (int j = m; j > 0; --j) {
if (dp[i + j]) {
i += j - 1;
res.push_back(j);
break;
}
}
}
int num = res.size();
rep(i, num) { cout << res[num - i - 1] << " "; }
cout << endl;
}
return 0;
}
| replace | 33 | 34 | 33 | 38 | TLE | |
p02852 | C++ | Time Limit Exceeded | // |. . . . . . . . . .| NEXT
// |. . . . . . . . . .| ______
// |. . . . . . . . . .| | |
// |. . . . . . . . . .| | OO |
// |. . . . . . . . . .| | OO |
// |. . . . . . . . . .| |______|
// |. . . . I . . . . .|
// |. . . . I . . . . .|
// |. . . . I . . . . .| PLAYER
// |. . . . I . . . . .| STYXCEL
// |. . . . . . . . . .|
// |I J J J . T T T S S| LINES
// |I J O O . L T S S T| 0
// |I L O O . L Z Z T T| SCORE
// |I L L L . L L Z Z T| 00021
#include <bits/stdc++.h>
using namespace std;
// #pragma GCC optimize ("O2,unroll-loops")
// #pragma GCC target ("tune=native")
#define ll long long
#define ull unsigned long long
#define ld long double
#define vi vector<ll>
#define vii vector<vector<ll>>
#define fr() front()
#define bc() back()
#define pushb push_back
#define popb pop_backtop
#define pii pair<ll, ll>
#define piii pair<pair<ll, ll>, ll>
#define fi first
#define se second
#define ff fi.fi
#define fs fi.se
#define sf se.fi
#define ss se.se
#define psplit(pp, a, b) (a = pp.fi, b = pp.se);
#define ppsplit(ppp, a, b, c) (a = ppp.fi.fi, b = ppp.fi.se, c = ppp.se);
#define endl ("\n")
const ll INF = 1 << 30;
const ll LINF = 1 << 62;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;
int main() {
// freopen("inp.txt","r",stdin);
// freopen("out.txt","w",stdout);
// ios::sync_with_stdio(false);
// cin.tie(0);
// cout.tie(0);
int n = 0, m = 0;
string s;
cin >> n >> m;
cin >> s;
int ye = 0;
stack<int> jumps;
int cur = n;
while (cur > 0) {
for (int i = m; i > 0; i--) {
if (cur - i >= 0 && s[cur - i] == '0') {
jumps.push(i);
cur -= i;
ye = 1;
break;
}
}
if (!ye) {
cout << -1 << endl;
return 0;
}
}
cout << jumps.top();
jumps.pop();
while (!jumps.empty()) {
cout << " " << jumps.top();
jumps.pop();
}
cout << endl;
return 0;
} | // |. . . . . . . . . .| NEXT
// |. . . . . . . . . .| ______
// |. . . . . . . . . .| | |
// |. . . . . . . . . .| | OO |
// |. . . . . . . . . .| | OO |
// |. . . . . . . . . .| |______|
// |. . . . I . . . . .|
// |. . . . I . . . . .|
// |. . . . I . . . . .| PLAYER
// |. . . . I . . . . .| STYXCEL
// |. . . . . . . . . .|
// |I J J J . T T T S S| LINES
// |I J O O . L T S S T| 0
// |I L O O . L Z Z T T| SCORE
// |I L L L . L L Z Z T| 00021
#include <bits/stdc++.h>
using namespace std;
// #pragma GCC optimize ("O2,unroll-loops")
// #pragma GCC target ("tune=native")
#define ll long long
#define ull unsigned long long
#define ld long double
#define vi vector<ll>
#define vii vector<vector<ll>>
#define fr() front()
#define bc() back()
#define pushb push_back
#define popb pop_backtop
#define pii pair<ll, ll>
#define piii pair<pair<ll, ll>, ll>
#define fi first
#define se second
#define ff fi.fi
#define fs fi.se
#define sf se.fi
#define ss se.se
#define psplit(pp, a, b) (a = pp.fi, b = pp.se);
#define ppsplit(ppp, a, b, c) (a = ppp.fi.fi, b = ppp.fi.se, c = ppp.se);
#define endl ("\n")
const ll INF = 1 << 30;
const ll LINF = 1 << 62;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;
int main() {
// freopen("inp.txt","r",stdin);
// freopen("out.txt","w",stdout);
// ios::sync_with_stdio(false);
// cin.tie(0);
// cout.tie(0);
int n = 0, m = 0;
string s;
cin >> n >> m;
cin >> s;
int ye = 0;
stack<int> jumps;
int cur = n;
while (cur > 0) {
ye = 0;
for (int i = m; i > 0; i--) {
if (cur - i >= 0 && s[cur - i] == '0') {
jumps.push(i);
cur -= i;
ye = 1;
break;
}
}
if (!ye) {
cout << -1 << endl;
return 0;
}
}
cout << jumps.top();
jumps.pop();
while (!jumps.empty()) {
cout << " " << jumps.top();
jumps.pop();
}
cout << endl;
return 0;
} | insert | 66 | 66 | 66 | 67 | TLE | |
p02852 | C++ | Time Limit Exceeded | #include "bits/stdc++.h"
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define FOR(i, n, m) for (int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 1e18 + 1;
template <class Monoid> struct SegmentTree {
private:
using Func = std::function<Monoid(Monoid, Monoid)>;
Func F;
Monoid UNITY;
int n;
std::vector<Monoid> node;
public:
SegmentTree() {}
// m=size, f=[](M a,M b){return ;}
// size : m
SegmentTree(int m, const Func f, const Monoid &unity) { build(m, f, unity); }
SegmentTree(const std::vector<Monoid> &v, const Func f, const Monoid &unity) {
build(v, f, unity);
}
void build(int m, const Func f, const Monoid &unity) {
F = f;
UNITY = unity;
n = 1;
while (n < m)
n <<= 1;
node.resize(n * 2 - 1, UNITY);
}
void build(const std::vector<Monoid> &v, const Func f, const Monoid &unity) {
F = f;
UNITY = unity;
int sz = v.size();
n = 1;
while (n < sz)
n <<= 1;
node.resize(n * 2 - 1, UNITY);
REP(i, sz) node[i + n - 1] = v[i];
for (int i = n - 2; i >= 0; i--)
node[i] = F(node[2 * i + 1], node[2 * i + 2]);
}
void update(int x, Monoid val) {
if (x >= n || x < 0)
return;
x += n - 1;
node[x] = val;
while (x > 0) {
x = (x - 1) >> 1;
node[x] = F(node[2 * x + 1], node[2 * x + 2]);
}
}
// [a,b)
Monoid get(int a, int b, int k = 0, int l = 0, int r = -1) {
if (r < 0)
r = n;
if (r <= a || b <= l)
return UNITY;
if (a <= l && r <= b)
return node[k];
Monoid vl = get(a, b, 2 * k + 1, l, (r - l) / 2 + l);
Monoid vr = get(a, b, 2 * k + 2, (r - l) / 2 + l, r);
return F(vl, vr);
}
Monoid operator[](int x) const { return node[n + x - 1]; }
int size() { return n; }
void print() {
REP(i, n) { std::cout << i << "\t: " << node[n + i - 1] << std::endl; }
}
};
int main() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
const int inf = 1e9 + 1;
SegmentTree<int> seg(
n + 1, [](int a, int b) { return min(a, b); }, inf);
seg.update(n, 0);
for (int i = n - 1; i >= 0; i--) {
if (s[i] == '1')
continue;
int rm = seg.get(i + 1, min(n, i + m) + 1);
if (rm == inf) {
puts("-1");
break;
}
seg.update(i, rm + 1);
}
int now = 0;
while (now < n) {
FOR(i, 1, m + 1) {
if (seg[now] - 1 == seg[now + i]) {
now += i;
cout << i << " ";
break;
}
}
}
cout << endl;
return 0;
} | #include "bits/stdc++.h"
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define FOR(i, n, m) for (int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 1e18 + 1;
template <class Monoid> struct SegmentTree {
private:
using Func = std::function<Monoid(Monoid, Monoid)>;
Func F;
Monoid UNITY;
int n;
std::vector<Monoid> node;
public:
SegmentTree() {}
// m=size, f=[](M a,M b){return ;}
// size : m
SegmentTree(int m, const Func f, const Monoid &unity) { build(m, f, unity); }
SegmentTree(const std::vector<Monoid> &v, const Func f, const Monoid &unity) {
build(v, f, unity);
}
void build(int m, const Func f, const Monoid &unity) {
F = f;
UNITY = unity;
n = 1;
while (n < m)
n <<= 1;
node.resize(n * 2 - 1, UNITY);
}
void build(const std::vector<Monoid> &v, const Func f, const Monoid &unity) {
F = f;
UNITY = unity;
int sz = v.size();
n = 1;
while (n < sz)
n <<= 1;
node.resize(n * 2 - 1, UNITY);
REP(i, sz) node[i + n - 1] = v[i];
for (int i = n - 2; i >= 0; i--)
node[i] = F(node[2 * i + 1], node[2 * i + 2]);
}
void update(int x, Monoid val) {
if (x >= n || x < 0)
return;
x += n - 1;
node[x] = val;
while (x > 0) {
x = (x - 1) >> 1;
node[x] = F(node[2 * x + 1], node[2 * x + 2]);
}
}
// [a,b)
Monoid get(int a, int b, int k = 0, int l = 0, int r = -1) {
if (r < 0)
r = n;
if (r <= a || b <= l)
return UNITY;
if (a <= l && r <= b)
return node[k];
Monoid vl = get(a, b, 2 * k + 1, l, (r - l) / 2 + l);
Monoid vr = get(a, b, 2 * k + 2, (r - l) / 2 + l, r);
return F(vl, vr);
}
Monoid operator[](int x) const { return node[n + x - 1]; }
int size() { return n; }
void print() {
REP(i, n) { std::cout << i << "\t: " << node[n + i - 1] << std::endl; }
}
};
int main() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
const int inf = 1e9 + 1;
SegmentTree<int> seg(
n + 1, [](int a, int b) { return min(a, b); }, inf);
seg.update(n, 0);
for (int i = n - 1; i >= 0; i--) {
if (s[i] == '1')
continue;
int rm = seg.get(i + 1, min(n, i + m) + 1);
if (rm == inf) {
puts("-1");
return 0;
}
seg.update(i, rm + 1);
}
int now = 0;
while (now < n) {
FOR(i, 1, m + 1) {
if (seg[now] - 1 == seg[now + i]) {
now += i;
cout << i << " ";
break;
}
}
}
cout << endl;
return 0;
} | replace | 97 | 98 | 97 | 98 | TLE | |
p02852 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9 + 7;
int main() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
int now = n;
vector<int> ans;
while (now != 0) {
bool end = true;
for (int j = m; j >= 1; j--) {
if (s[now - j] == '0') {
now -= j;
end = false;
ans.push_back(j);
break;
}
}
if (end) {
cout << -1 << endl;
return 0;
}
}
reverse(ans.begin(), ans.end());
for (auto p : ans)
cout << p << " ";
cout << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9 + 7;
int main() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
int now = n;
vector<int> ans;
while (now != 0) {
bool end = true;
for (int j = m; j >= 1; j--) {
if (now < j)
continue;
if (s[now - j] == '0') {
now -= j;
end = false;
ans.push_back(j);
break;
}
}
if (end) {
cout << -1 << endl;
return 0;
}
}
reverse(ans.begin(), ans.end());
for (auto p : ans)
cout << p << " ";
cout << endl;
return 0;
} | insert | 15 | 15 | 15 | 17 | 0 | |
p02852 | C++ | Time Limit Exceeded | // x<<y=x*2^y,x>>y=x/2^y
// 1<<31 gives overflow
// while using ?: in add/subt use bracket
// use ll() for using an integer in self-built fn
//(x&-x) bitwise and of (x and its 2's complement) returns (last set bit)
// eg if x=1010 then it will return 0010
// careful dont print empty container(run time error)
// v.erase O(n)
// use ("\n") instead of endl as endl flushes the output buffer
// every time so takes more time than \n (TLE)
// stoll() and to_string()
// INT_MAX is approx 3e10
// iterate over multiples for(ll j=i;j<=n;j+=i)
// For sets use set_name.lower_bound(x)(strictly O(logn))
// NOT lb(all(s),x)(O(logn) for random access (eg vector) but for sets it is
// O(n));
#include <bits/stdc++.h>
typedef long long int ll;
#define ull unsigned long long int
#define lld long double
#define endl "\n"
#define fi first
#define sec second
#define setprecision sp
#define lb lower_bound
#define ub upper_bound
#define For(i, a, b) for (long long int i = (a); i <= (b); i++)
#define Forr(i, a, b) for (long long int i = (a); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define vll vector<ll>
#define vlld vector<lld>
#define vi vector<int>
#define vch vector<char>
#define sll set<ll>
#define sch set<ch>
#define vpll vector<pair<ll, ll>>
#define vpii vector<pair<int, int>>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define mll map<ll, ll>
#define mcll map<char, ll>
#define sz(container) ll((container).size())
#define fill(a, b) memset(a, b, sizeof(a))
#define fast_io ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
using namespace std;
lld pi = 3.1415926535897932;
const ll MOD = 1e9 + 7;
const ll dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const ll dxx[8] = {-1, -1, 0, 1, 1, 1, 0, -1},
dyy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
/**************************************************
//FENWICK TREE
ll bit[100005];
void update(ll idx, ll val, ll n)
{
for (; idx <= n; idx += idx&-idx)
bit[idx] += val;
}
ll query(ll idx)
{
ll sum = 0;
for (; idx>0; idx-=idx&-idx)
sum += bit[idx];
return sum;
}
*****************************************************/
ll lcm(ll a, ll b) {
ll g = __gcd(a, b);
return a / g * b;
}
ll binpow(ll a, ll b, ll m) {
a %= m;
ll res = 1;
while (b > 0) {
if (b & 1)
res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
bool isPrime(ll n) {
// Corner cases
if (n <= 1)
return false;
if (n <= 3)
return true;
// This is checked so that we can skip
// middle five numbers in below loop
if (n % 2 == 0 || n % 3 == 0)
return false;
for (ll i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
/******************************************
ll phi(ll n)
{
ll result = n;
For(i,0,sqrt(n))
{
if (n % i == 0)
{
while (n % i == 0)
n /= i;
result -= result / i;
}
}
if (n > 1)
result -= result / n;
return result;
}
************************************/
/***************************************
//to check whether a string is whole number(without leading 0s)
bool isNumber(string s)
{
if(s=="0") return true;
if(s[0]=='0') return false;
For(i,0,sz(s)-1)
{
if (isdigit(s[i]) == false) return false;
}
return true;
}
******************************/
/******************************
queue<ll> q;
//p:parent d:depth
vll used(200002),p(200002),d(200002);
vector<vll>adj(200002);
void bfs(ll s)
{
q.push(s);
p[s] = -1;
used[s] = 1;
while (!q.empty())
{
ll v = q.front();
q.pop();
for (ll u : adj[v])
{
if (!used[u])
{
used[u] = 1;
q.push(u);
d[u] = d[v] + 1;
p[u] = v;
}
}
}
}
*****************************/
/***********************************
vector<vll >adj(100005);
vll subsz(100005);
void dfs(ll v,ll x)
{
subsz[v]=1;
for(ll u : adj[v])
{
if (u!=x) dfs(u,v),subsz[v]+=subsz[u];
}
}
************************************/
/**********************************
ll used[1005][1005];
char s[1005][1005];
void dfs(ll x,ll y)
{
used[x][y]=1;
For(i,0,3)
{
ll nx=x+dx[i],ny=y+dy[i];
if(used[nx][ny]==0&&s[nx][ny]!='#') dfs(nx,ny);
}
}
*********/
unordered_map<ll, ll> cnt;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fast_io;
ll T = 1; // cin>>T;
For(i, 1, T) {
ll n, m;
cin >> n >> m;
string s;
cin >> s;
reverse(all(s));
if (s[0] == '1' || s[n] == '1') {
cout << "-1";
return 0;
}
if (m >= n) {
cout << n;
return 0;
}
vll temp, ans;
For(j, 0, n) {
if (s[j] == '0')
temp.pb(j);
}
ll low = 0, prev = 0;
while (low < n) {
low = *(--ub(all(temp), m + prev));
if (low == 0) {
cout << "-1";
return 0;
}
ans.pb(low);
prev = low;
}
vll step;
step.pb(ans[0]);
For(j, 1, sz(ans) - 1) step.pb(ans[j] - ans[j - 1]);
reverse(all(step));
for (auto j : step)
cout << j << " ";
}
} | // x<<y=x*2^y,x>>y=x/2^y
// 1<<31 gives overflow
// while using ?: in add/subt use bracket
// use ll() for using an integer in self-built fn
//(x&-x) bitwise and of (x and its 2's complement) returns (last set bit)
// eg if x=1010 then it will return 0010
// careful dont print empty container(run time error)
// v.erase O(n)
// use ("\n") instead of endl as endl flushes the output buffer
// every time so takes more time than \n (TLE)
// stoll() and to_string()
// INT_MAX is approx 3e10
// iterate over multiples for(ll j=i;j<=n;j+=i)
// For sets use set_name.lower_bound(x)(strictly O(logn))
// NOT lb(all(s),x)(O(logn) for random access (eg vector) but for sets it is
// O(n));
#include <bits/stdc++.h>
typedef long long int ll;
#define ull unsigned long long int
#define lld long double
#define endl "\n"
#define fi first
#define sec second
#define setprecision sp
#define lb lower_bound
#define ub upper_bound
#define For(i, a, b) for (long long int i = (a); i <= (b); i++)
#define Forr(i, a, b) for (long long int i = (a); i >= (b); i--)
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define vll vector<ll>
#define vlld vector<lld>
#define vi vector<int>
#define vch vector<char>
#define sll set<ll>
#define sch set<ch>
#define vpll vector<pair<ll, ll>>
#define vpii vector<pair<int, int>>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define mll map<ll, ll>
#define mcll map<char, ll>
#define sz(container) ll((container).size())
#define fill(a, b) memset(a, b, sizeof(a))
#define fast_io ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
using namespace std;
lld pi = 3.1415926535897932;
const ll MOD = 1e9 + 7;
const ll dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const ll dxx[8] = {-1, -1, 0, 1, 1, 1, 0, -1},
dyy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
/**************************************************
//FENWICK TREE
ll bit[100005];
void update(ll idx, ll val, ll n)
{
for (; idx <= n; idx += idx&-idx)
bit[idx] += val;
}
ll query(ll idx)
{
ll sum = 0;
for (; idx>0; idx-=idx&-idx)
sum += bit[idx];
return sum;
}
*****************************************************/
ll lcm(ll a, ll b) {
ll g = __gcd(a, b);
return a / g * b;
}
ll binpow(ll a, ll b, ll m) {
a %= m;
ll res = 1;
while (b > 0) {
if (b & 1)
res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
bool isPrime(ll n) {
// Corner cases
if (n <= 1)
return false;
if (n <= 3)
return true;
// This is checked so that we can skip
// middle five numbers in below loop
if (n % 2 == 0 || n % 3 == 0)
return false;
for (ll i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
/******************************************
ll phi(ll n)
{
ll result = n;
For(i,0,sqrt(n))
{
if (n % i == 0)
{
while (n % i == 0)
n /= i;
result -= result / i;
}
}
if (n > 1)
result -= result / n;
return result;
}
************************************/
/***************************************
//to check whether a string is whole number(without leading 0s)
bool isNumber(string s)
{
if(s=="0") return true;
if(s[0]=='0') return false;
For(i,0,sz(s)-1)
{
if (isdigit(s[i]) == false) return false;
}
return true;
}
******************************/
/******************************
queue<ll> q;
//p:parent d:depth
vll used(200002),p(200002),d(200002);
vector<vll>adj(200002);
void bfs(ll s)
{
q.push(s);
p[s] = -1;
used[s] = 1;
while (!q.empty())
{
ll v = q.front();
q.pop();
for (ll u : adj[v])
{
if (!used[u])
{
used[u] = 1;
q.push(u);
d[u] = d[v] + 1;
p[u] = v;
}
}
}
}
*****************************/
/***********************************
vector<vll >adj(100005);
vll subsz(100005);
void dfs(ll v,ll x)
{
subsz[v]=1;
for(ll u : adj[v])
{
if (u!=x) dfs(u,v),subsz[v]+=subsz[u];
}
}
************************************/
/**********************************
ll used[1005][1005];
char s[1005][1005];
void dfs(ll x,ll y)
{
used[x][y]=1;
For(i,0,3)
{
ll nx=x+dx[i],ny=y+dy[i];
if(used[nx][ny]==0&&s[nx][ny]!='#') dfs(nx,ny);
}
}
*********/
unordered_map<ll, ll> cnt;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fast_io;
ll T = 1; // cin>>T;
For(i, 1, T) {
ll n, m;
cin >> n >> m;
string s;
cin >> s;
reverse(all(s));
if (s[0] == '1' || s[n] == '1') {
cout << "-1";
return 0;
}
if (m >= n) {
cout << n;
return 0;
}
vll temp, ans;
For(j, 0, n) {
if (s[j] == '0')
temp.pb(j);
}
ll low = 0, prev = 0;
while (low < n) {
low = *(--ub(all(temp), m + prev));
if (low == prev) {
cout << "-1";
return 0;
}
ans.pb(low);
prev = low;
}
vll step;
step.pb(ans[0]);
For(j, 1, sz(ans) - 1) step.pb(ans[j] - ans[j - 1]);
reverse(all(step));
for (auto j : step)
cout << j << " ";
}
} | replace | 219 | 220 | 219 | 220 | TLE | |
p02852 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define fix20 cout << fixed << setprecision(20);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007
int main() {
int n, m;
string s;
cin >> n >> m >> s;
vector<int> step(n + 1, 1e9);
step.at(n) = 0;
int pos = n;
int d = 1;
while (pos > 0) {
int tmp = pos;
rep(i, m) {
tmp--;
if (s.at(tmp) == '1')
continue;
step.at(tmp) = d;
pos = tmp;
if (tmp == 0) {
pos = 0;
break;
}
}
d++;
}
// vector<int> path(1,0);
int p = step.at(0);
int id = 0;
for (int i = 1; i <= n; i++) {
if (s.at(i) == '1')
continue;
if (step.at(i) == p)
continue;
cout << i - id << " ";
p = step.at(i);
id = i;
}
cout << endl;
// rep(i,n+1) cout << step.at(i) << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define fix20 cout << fixed << setprecision(20);
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000007
int main() {
int n, m;
string s;
cin >> n >> m >> s;
int cnt = 0;
rep(i, n + 1) {
if (s.at(i) == '1')
cnt++;
else
cnt = 0;
if (cnt == m) {
cout << -1 << endl;
return 0;
}
}
vector<int> step(n + 1, 1e9);
step.at(n) = 0;
int pos = n;
int d = 1;
while (pos > 0) {
int tmp = pos;
rep(i, m) {
tmp--;
if (s.at(tmp) == '1')
continue;
step.at(tmp) = d;
pos = tmp;
if (tmp == 0) {
pos = 0;
break;
}
}
d++;
}
// vector<int> path(1,0);
int p = step.at(0);
int id = 0;
for (int i = 1; i <= n; i++) {
if (s.at(i) == '1')
continue;
if (step.at(i) == p)
continue;
cout << i - id << " ";
p = step.at(i);
id = i;
}
cout << endl;
// rep(i,n+1) cout << step.at(i) << endl;
} | insert | 10 | 10 | 10 | 21 | TLE | |
p02852 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#define INF 1000000009
#define LINF 1000000000000000009
#define double long double
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
ll gcd(ll n, ll m) { return (m ? gcd(m, n % m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
template <class T> class segtree {
int n;
vector<T> data;
T def;
function<T(T, T)> operation;
function<T(T, T)> update;
T _query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return def;
if (a <= l && r <= b)
return data[k];
T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2);
T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r);
return operation(c1, c2);
}
public:
segtree(size_t _n, T _def, function<T(T, T)> _operation,
function<T(T, T)> _update)
: def(_def), operation(_operation), update(_update) {
n = 1;
while (n < _n) {
n *= 2;
}
data = vector<T>(2 * n - 1, def);
}
void change(int i, T x) {
i += n - 1;
data[i] = update(data[i], x);
while (i > 0) {
i = (i - 1) / 2;
data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
}
}
T query(int a, int b) { return _query(a, b, 0, 0, n); }
T operator[](int i) { return data[i + n - 1]; }
};
int main() {
int n, m;
string s;
cin >> n >> m >> s;
segtree<int> seg(
n + 2, INF, [](int a, int b) { return min(a, b); },
[](int a, int b) { return b; });
vector<int> ans(n + 1);
seg.change(n, 0);
ans[0] = n;
for (int i = n - 1; i >= 0; i--) {
if (s[i] == '0') {
int c = seg.query(i + 1, min(i + m + 1, n + 1));
seg.change(i, c + 1);
ans[c + 1] = i;
}
}
if (seg[0] >= INF) {
cout << -1 << endl;
return 0;
}
for (int i = seg[0] - 1; i >= 0; i--) {
cout << ans[i] - ans[i + 1] << ' ';
}
cout << endl;
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#define INF 1000000009
#define LINF 1000000000000000009
#define double long double
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
ll gcd(ll n, ll m) { return (m ? gcd(m, n % m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
template <class T> class segtree {
int n;
vector<T> data;
T def;
function<T(T, T)> operation;
function<T(T, T)> update;
T _query(int a, int b, int k, int l, int r) {
if (r <= a || b <= l)
return def;
if (a <= l && r <= b)
return data[k];
T c1 = _query(a, b, 2 * k + 1, l, (l + r) / 2);
T c2 = _query(a, b, 2 * k + 2, (l + r) / 2, r);
return operation(c1, c2);
}
public:
segtree(size_t _n, T _def, function<T(T, T)> _operation,
function<T(T, T)> _update)
: def(_def), operation(_operation), update(_update) {
n = 1;
while (n < _n) {
n *= 2;
}
data = vector<T>(2 * n - 1, def);
}
void change(int i, T x) {
i += n - 1;
data[i] = update(data[i], x);
while (i > 0) {
i = (i - 1) / 2;
data[i] = operation(data[i * 2 + 1], data[i * 2 + 2]);
}
}
T query(int a, int b) { return _query(a, b, 0, 0, n); }
T operator[](int i) { return data[i + n - 1]; }
};
int main() {
int n, m;
string s;
cin >> n >> m >> s;
segtree<int> seg(
n + 2, INF, [](int a, int b) { return min(a, b); },
[](int a, int b) { return b; });
vector<int> ans(n + 1);
seg.change(n, 0);
ans[0] = n;
for (int i = n - 1; i >= 0; i--) {
if (s[i] == '0') {
int c = seg.query(i + 1, min(i + m + 1, n + 1));
seg.change(i, c + 1);
if (c < INF)
ans[c + 1] = i;
}
}
if (seg[0] >= INF) {
cout << -1 << endl;
return 0;
}
for (int i = seg[0] - 1; i >= 0; i--) {
cout << ans[i] - ans[i + 1] << ' ';
}
cout << endl;
} | replace | 89 | 90 | 89 | 91 | 0 | |
p02852 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
#define INF (1ll << 60)
int main(int argc, char const *argv[]) {
int n, m;
string s;
cin >> n >> m >> s;
vector<ll> dp(n + 1, INF);
vector<int> diff(n + 1, -1);
dp[0] = 0;
int mmove = 0;
rep(i, n) {
if (mmove < i) {
break;
}
if (dp[i] == INF || s[i] == '1') {
continue;
}
// auto newdp = dp;
rep(j, 1, m + 1) {
if (i + j > n)
break;
if (s[i + j] == '1' || dp[i + j] != INF) {
continue;
}
if (dp[i] + 1 < dp[i + j]) {
dp[i + j] = dp[i] + 1;
diff[i + j] = j;
mmove = max(mmove, (int)(i + j));
}
}
// dp = newdp;
if (dp[n] != INF) {
break;
}
}
if (dp[n] == INF) {
cout << -1 << endl;
return 0;
} else {
int cur = n;
vector<int> ans(dp[n], 0);
rep(i, dp[n]) {
// cerr << cur << endl;
ans[i] = diff[cur];
cur -= diff[cur];
}
// rep(i, dp[n]) cerr << ans[i] << endl;
for (int i = ans.size() - 1; i >= 0; i--) {
cout << ans[i] << " ";
}
cout << endl;
return 0;
}
return 0;
}
| #include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
#define INF (1ll << 60)
int main(int argc, char const *argv[]) {
int n, m;
string s;
cin >> n >> m >> s;
vector<ll> dp(n + 1, INF);
vector<int> diff(n + 1, -1);
dp[0] = 0;
int mmove = 0;
rep(i, n) {
if (mmove < i) {
break;
}
if (dp[i] == INF || s[i] == '1') {
continue;
}
// auto newdp = dp;
rep(j, mmove - i, m + 1) {
if (i + j > n)
break;
if (s[i + j] == '1' || dp[i + j] != INF) {
continue;
}
if (dp[i] + 1 < dp[i + j]) {
dp[i + j] = dp[i] + 1;
diff[i + j] = j;
mmove = max(mmove, (int)(i + j));
}
}
// dp = newdp;
if (dp[n] != INF) {
break;
}
}
if (dp[n] == INF) {
cout << -1 << endl;
return 0;
} else {
int cur = n;
vector<int> ans(dp[n], 0);
rep(i, dp[n]) {
// cerr << cur << endl;
ans[i] = diff[cur];
cur -= diff[cur];
}
// rep(i, dp[n]) cerr << ans[i] << endl;
for (int i = ans.size() - 1; i >= 0; i--) {
cout << ans[i] << " ";
}
cout << endl;
return 0;
}
return 0;
}
| replace | 38 | 39 | 38 | 39 | TLE | |
p02852 | C++ | Runtime Error | #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <bitset>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (auto i = a; i < b; i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) {
ll a = 1;
while (p > 0) {
if (p % 2 == 0) {
x *= x;
p /= 2;
} else {
a *= x;
p--;
}
}
return a;
}
ll mpower(ll x, ll p) {
ll a = 1;
while (p > 0) {
if (p % 2 == 0) {
x = x * x % mod;
p /= 2;
} else {
a = a * x % mod;
p--;
}
}
return a;
}
ll ac(ll n, ll k) {
ll a = 1;
rep(i, 1, k) {
a *= n - i + 1;
a /= i;
}
return a;
}
ll mc(ll n, ll m) {
ll k = 1, l = 1;
rep(i, n - m + 1, n + 1) k = k * i % mod;
rep(i, 1, m + 1) l = l * i % mod;
l = mpower(l, mod - 2);
return k * l % mod;
}
int main() {
int n, m;
string s;
cin >> n >> m >> s;
reverse(all(s));
vector<int> ans;
int c = 0;
bool ok;
while (c != n) {
ok = false;
rep(i, 0, m) {
if (m - i + c <= n && s[m - i + c] == '0') {
c += m - i;
ans.push_back(m - i);
ok = true;
break;
}
}
if (!ok) {
puts("-1");
return 1;
}
}
reverse(all(ans));
rep(i, 0, ans.size()) {
printf(i != ans.size() - 1 ? "%d " : "%d\n", ans[i]);
}
return 0;
} | #define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <bitset>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (auto i = a; i < b; i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) {
ll a = 1;
while (p > 0) {
if (p % 2 == 0) {
x *= x;
p /= 2;
} else {
a *= x;
p--;
}
}
return a;
}
ll mpower(ll x, ll p) {
ll a = 1;
while (p > 0) {
if (p % 2 == 0) {
x = x * x % mod;
p /= 2;
} else {
a = a * x % mod;
p--;
}
}
return a;
}
ll ac(ll n, ll k) {
ll a = 1;
rep(i, 1, k) {
a *= n - i + 1;
a /= i;
}
return a;
}
ll mc(ll n, ll m) {
ll k = 1, l = 1;
rep(i, n - m + 1, n + 1) k = k * i % mod;
rep(i, 1, m + 1) l = l * i % mod;
l = mpower(l, mod - 2);
return k * l % mod;
}
int main() {
int n, m;
string s;
cin >> n >> m >> s;
reverse(all(s));
vector<int> ans;
int c = 0;
bool ok;
while (c != n) {
ok = false;
rep(i, 0, m) {
if (m - i + c <= n && s[m - i + c] == '0') {
c += m - i;
ans.push_back(m - i);
ok = true;
break;
}
}
if (!ok) {
puts("-1");
return 0;
}
}
reverse(all(ans));
rep(i, 0, ans.size()) {
printf(i != ans.size() - 1 ? "%d " : "%d\n", ans[i]);
}
return 0;
} | replace | 91 | 92 | 91 | 92 | 0 | |
p02852 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mid (l + r) / 2
#define L (x << 1)
#define R (L + 1)
pair<int, int> tree[1000000];
string s;
void build(int x, int l, int r) {
if (l == r) {
tree[x] = {1e9, l};
} else {
build(L, l, mid);
build(R, mid + 1, r);
tree[x] = min(tree[L], tree[R]);
}
}
void upd(int x, int l, int r, int v, int val) {
if (v > r || v < l)
return;
if (l == r) {
tree[x] = {val, l};
} else {
upd(L, l, mid, v, val);
upd(R, mid + 1, r, v, val);
tree[x] = min(tree[L], tree[R]);
}
}
pair<int, int> query(int x, int l, int r, int s, int e) {
if (l > e || r < s)
return {1e9, 0};
if (l >= s && r <= e)
return tree[x];
return min(query(L, l, mid, s, e), query(R, mid + 1, r, s, e));
}
int dp[1000000];
int back[1000000];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
cin >> s;
if (s[n] == '1') {
cout << -1 << endl;
return 0;
}
build(1, 0, n);
dp[n] = 0;
upd(1, 0, n, n, 0);
for (int i = n - 1; i >= 0; i--) {
dp[i] = 1e9;
if (s[i] == '1')
continue;
int r = min(n, i + m);
auto q = query(1, 0, n, i + 1, r);
dp[i] = q.first + 1;
back[i] = q.second;
upd(1, 0, n, i, dp[i]);
}
if (dp[0] == 1e9) {
cout << -1 << endl;
} else {
int v = 0;
vector<int> path;
while (v != n) {
path.push_back(back[v] - v);
v = back[v];
}
for (auto x : path)
cout << x << ' ';
cout << endl;
}
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mid (l + r) / 2
#define L (x << 1)
#define R (L + 1)
pair<int, int> tree[1000000];
string s;
void build(int x, int l, int r) {
if (l == r) {
tree[x] = {1e9, l};
} else {
build(L, l, mid);
build(R, mid + 1, r);
tree[x] = min(tree[L], tree[R]);
}
}
void upd(int x, int l, int r, int v, int val) {
if (v > r || v < l)
return;
if (l == r) {
tree[x] = {val, l};
} else {
upd(L, l, mid, v, val);
upd(R, mid + 1, r, v, val);
tree[x] = min(tree[L], tree[R]);
}
}
pair<int, int> query(int x, int l, int r, int s, int e) {
if (l > e || r < s)
return {1e9, 0};
if (l >= s && r <= e)
return tree[x];
return min(query(L, l, mid, s, e), query(R, mid + 1, r, s, e));
}
int dp[1000000];
int back[1000000];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
cin >> s;
if (s[n] == '1') {
cout << -1 << endl;
return 0;
}
build(1, 0, n);
dp[n] = 0;
upd(1, 0, n, n, 0);
for (int i = n - 1; i >= 0; i--) {
dp[i] = 1e9;
if (s[i] == '1')
continue;
int r = min(n, i + m);
auto q = query(1, 0, n, i + 1, r);
dp[i] = q.first + 1;
back[i] = q.second;
upd(1, 0, n, i, dp[i]);
}
if (dp[0] >= 1e9) {
cout << -1 << endl;
} else {
int v = 0;
vector<int> path;
while (v != n) {
path.push_back(back[v] - v);
v = back[v];
}
for (auto x : path)
cout << x << ' ';
cout << endl;
}
} | replace | 61 | 62 | 61 | 62 | TLE | |
p02852 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
// template {{{ 0
// using {{{ 1
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x, y) scanf("%d%d", &x, &y)
#define Scd3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x, y) scanf("%lld%lld", &x, &y)
#define Scll3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x, y, z) for (ll x = z; x < y; x++)
#define Rep(x, y) Repe(x, y, 0)
#define RRepe(x, y, z) for (ll x = y - z - 1; x >= 0; x--)
#define RRep(x, y) RRepe(x, y, 0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a) ? printf("Yes\n") : printf("No\n")
#define YESNO(a) (a) ? printf("YES\n") : printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0
const long long int mod = 1000000007;
// PowMod( base, index, modulo) return base ** index % modulo {{{
// PowMod = base ** index % mod ( natural numbers )
inline constexpr long long int PowMod(long long int base, long long int index,
long long int modulo = mod) {
if (index == 0)
return 1;
// O( log(index) )
if (index % 2) {
return base * PowMod(base, index - 1, modulo) % modulo;
} else {
long long int Phalf = index / 2;
long long int half = PowMod(base, Phalf, modulo);
return half * half % modulo;
}
}
// }}}
// CombMod( n, r, modulo ) return nCr % modulo {{{
// CombMod(ination) = nCr % mod ( natural number )
inline constexpr long long int CombMod(long long int n, long long int r,
long long int modulo = mod) {
if (n < r)
return CombMod(r, n, modulo);
long long int Upper = 1;
long long int Lower = 1;
for (long long int i = 0; i < r; i++) {
Upper = Upper * (n - i) % modulo;
Lower = Lower * (i + 1) % modulo;
}
// Return (Upper / Lower)
long long int ret = Upper * PowMod(Lower, modulo - 2, modulo) % modulo;
return ret;
}
// }}}
// FactMod( n, modulo ) return n! % modulo {{{
// Fact(orial) = n! % mod ( natural number )
inline constexpr long long int Fact(long long int n,
long long int modulo = mod) {
long long int Upper = 1;
for (long long int i = 0; i < n; i++) {
Upper = Upper * (n - i) % modulo;
}
return Upper;
}
// }}}
// modint {{{
struct modint {
long long int a;
inline constexpr modint(long long int x = 0) noexcept : a(x % mod) {}
inline constexpr long long int &value() noexcept { return a; }
inline constexpr const long long int &value() const noexcept { return a; }
inline constexpr modint operator+(const modint rhs) const noexcept {
return modint(*this) += rhs;
}
inline constexpr modint operator+(const int rhs) const noexcept {
return modint(*this) += rhs;
}
inline constexpr modint operator+(const long long int rhs) const noexcept {
return modint(*this) += rhs;
}
inline constexpr modint operator-(const modint rhs) const noexcept {
return modint(*this) -= rhs;
}
inline constexpr modint operator-(const int rhs) const noexcept {
return modint(*this) -= rhs;
}
inline constexpr modint operator-(const long long int rhs) const noexcept {
return modint(*this) -= rhs;
}
inline constexpr modint operator*(const modint rhs) const noexcept {
return modint(*this) *= rhs;
}
inline constexpr modint operator*(const int rhs) const noexcept {
return modint(*this) *= rhs;
}
inline constexpr modint operator*(const long long int rhs) const noexcept {
return modint(*this) *= rhs;
}
inline constexpr modint operator/(const modint rhs) const noexcept {
return modint(*this) /= rhs;
}
inline constexpr modint operator/(const int rhs) const noexcept {
return modint(*this) /= rhs;
}
inline constexpr modint operator/(const long long int rhs) const noexcept {
return modint(*this) /= rhs;
}
inline constexpr modint operator+=(const modint rhs) noexcept {
a += rhs.a;
if (a >= mod)
a -= mod;
return *this;
}
inline constexpr modint operator-=(const modint rhs) noexcept {
a -= rhs.a;
if (a < 0)
a += mod;
return *this;
}
inline constexpr modint operator*=(const modint rhs) noexcept {
a = a * rhs.a % mod;
return *this;
}
inline constexpr modint operator/=(const modint rhs) noexcept {
a = a * PowMod(rhs.a, mod - 2) % mod;
return *this;
}
};
// }}}
int main() {
int N, M;
Scd2(N, M);
char s[123123];
Scs(s);
int ni = N;
stack<int> ans;
bool ng = false;
while (ni) {
int from = max(0, ni - M);
Repe(i, ni + 1, ni - M) {
if (i == ni) {
ng = true;
break;
}
if (s[i] == '0') {
ans.push(ni - i);
ni = i;
break;
}
}
if (ng)
break;
}
if (ng)
printf("%d\n", -1);
else
while (ans.size()) {
printf("%d", ans.top());
ans.pop();
printf("%c", ans.empty() ? '\n' : ' ');
}
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
// template {{{ 0
// using {{{ 1
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x, y) scanf("%d%d", &x, &y)
#define Scd3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x, y) scanf("%lld%lld", &x, &y)
#define Scll3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x, y, z) for (ll x = z; x < y; x++)
#define Rep(x, y) Repe(x, y, 0)
#define RRepe(x, y, z) for (ll x = y - z - 1; x >= 0; x--)
#define RRep(x, y) RRepe(x, y, 0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a) ? printf("Yes\n") : printf("No\n")
#define YESNO(a) (a) ? printf("YES\n") : printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0
const long long int mod = 1000000007;
// PowMod( base, index, modulo) return base ** index % modulo {{{
// PowMod = base ** index % mod ( natural numbers )
inline constexpr long long int PowMod(long long int base, long long int index,
long long int modulo = mod) {
if (index == 0)
return 1;
// O( log(index) )
if (index % 2) {
return base * PowMod(base, index - 1, modulo) % modulo;
} else {
long long int Phalf = index / 2;
long long int half = PowMod(base, Phalf, modulo);
return half * half % modulo;
}
}
// }}}
// CombMod( n, r, modulo ) return nCr % modulo {{{
// CombMod(ination) = nCr % mod ( natural number )
inline constexpr long long int CombMod(long long int n, long long int r,
long long int modulo = mod) {
if (n < r)
return CombMod(r, n, modulo);
long long int Upper = 1;
long long int Lower = 1;
for (long long int i = 0; i < r; i++) {
Upper = Upper * (n - i) % modulo;
Lower = Lower * (i + 1) % modulo;
}
// Return (Upper / Lower)
long long int ret = Upper * PowMod(Lower, modulo - 2, modulo) % modulo;
return ret;
}
// }}}
// FactMod( n, modulo ) return n! % modulo {{{
// Fact(orial) = n! % mod ( natural number )
inline constexpr long long int Fact(long long int n,
long long int modulo = mod) {
long long int Upper = 1;
for (long long int i = 0; i < n; i++) {
Upper = Upper * (n - i) % modulo;
}
return Upper;
}
// }}}
// modint {{{
struct modint {
long long int a;
inline constexpr modint(long long int x = 0) noexcept : a(x % mod) {}
inline constexpr long long int &value() noexcept { return a; }
inline constexpr const long long int &value() const noexcept { return a; }
inline constexpr modint operator+(const modint rhs) const noexcept {
return modint(*this) += rhs;
}
inline constexpr modint operator+(const int rhs) const noexcept {
return modint(*this) += rhs;
}
inline constexpr modint operator+(const long long int rhs) const noexcept {
return modint(*this) += rhs;
}
inline constexpr modint operator-(const modint rhs) const noexcept {
return modint(*this) -= rhs;
}
inline constexpr modint operator-(const int rhs) const noexcept {
return modint(*this) -= rhs;
}
inline constexpr modint operator-(const long long int rhs) const noexcept {
return modint(*this) -= rhs;
}
inline constexpr modint operator*(const modint rhs) const noexcept {
return modint(*this) *= rhs;
}
inline constexpr modint operator*(const int rhs) const noexcept {
return modint(*this) *= rhs;
}
inline constexpr modint operator*(const long long int rhs) const noexcept {
return modint(*this) *= rhs;
}
inline constexpr modint operator/(const modint rhs) const noexcept {
return modint(*this) /= rhs;
}
inline constexpr modint operator/(const int rhs) const noexcept {
return modint(*this) /= rhs;
}
inline constexpr modint operator/(const long long int rhs) const noexcept {
return modint(*this) /= rhs;
}
inline constexpr modint operator+=(const modint rhs) noexcept {
a += rhs.a;
if (a >= mod)
a -= mod;
return *this;
}
inline constexpr modint operator-=(const modint rhs) noexcept {
a -= rhs.a;
if (a < 0)
a += mod;
return *this;
}
inline constexpr modint operator*=(const modint rhs) noexcept {
a = a * rhs.a % mod;
return *this;
}
inline constexpr modint operator/=(const modint rhs) noexcept {
a = a * PowMod(rhs.a, mod - 2) % mod;
return *this;
}
};
// }}}
int main() {
int N, M;
Scd2(N, M);
char s[123123];
Scs(s);
int ni = N;
stack<int> ans;
bool ng = false;
while (ni) {
int from = max(0, ni - M);
Repe(i, ni + 1, from) {
if (i == ni) {
ng = true;
break;
}
if (s[i] == '0') {
ans.push(ni - i);
ni = i;
break;
}
}
if (ng)
break;
}
if (ng)
printf("%d\n", -1);
else
while (ans.size()) {
printf("%d", ans.top());
ans.pop();
printf("%c", ans.empty() ? '\n' : ' ');
}
}
| replace | 172 | 173 | 172 | 173 | 0 | |
p02852 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second
/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */
template <typename ValueMonoid, typename OperatorMonoid> class LazySegmentTree {
public:
using value_type = ValueMonoid;
using reference = value_type &;
using const_reference = const value_type &;
using operator_type = OperatorMonoid;
private:
using operator_constref = const operator_type &;
using container_type = std::vector<std::pair<value_type, operator_type>>;
public:
using size_type = typename container_type::size_type;
private:
using F = std::function<value_type(const_reference, const_reference)>;
using G = std::function<operator_type(operator_constref, operator_constref)>;
using H = std::function<value_type(const_reference, operator_constref)>;
const F f;
const G g;
const H h;
const value_type v_neutral;
const operator_type o_neutral;
size_type height, size_;
container_type tree;
static size_type getheight(const size_type size) {
size_type ret = 0;
while ((size_type)1 << ret < size)
++ret;
return ret;
}
value_type reflect(const size_type index) {
return h(tree[index].first, tree[index].second);
}
void recalc(const size_type index) {
tree[index].first = f(reflect(index << 1), reflect(index << 1 | 1));
}
void assign(const size_type index, operator_constref data) {
tree[index].second = g(tree[index].second, data);
}
void push(const size_type index) {
assign(index << 1, tree[index].second);
assign(index << 1 | 1, tree[index].second);
tree[index].second = o_neutral;
}
void propagate(const size_type index) {
for (size_type i = height; i; --i)
push(index >> i);
}
void thrust(const size_type index) {
tree[index].first = reflect(index);
push(index);
}
void evaluate(const size_type index) {
for (size_type i = height; i; --i)
thrust(index >> i);
}
void build(size_type index) {
while (index >>= 1)
recalc(index);
}
public:
LazySegmentTree(
const size_type size, const F &value_addition = std::plus<value_type>(),
const_reference value_neutral = value_type(),
const G &operator_multiplication = std::multiplies<operator_type>(),
operator_constref operator_neutral = operator_type(),
const H &mutual_multiplication =
[](const_reference l, operator_constref r) { return l * r; })
: f(value_addition), v_neutral(value_neutral), g(operator_multiplication),
o_neutral(operator_neutral), h(mutual_multiplication),
height(getheight(size)), size_((size_type)1 << height),
tree(size_ << 1, std::make_pair(v_neutral, o_neutral)) {}
void update(size_type begin, size_type end, operator_constref data) {
assert(begin <= end);
assert(begin <= size_);
assert(end <= size_);
begin += size_;
end += size_;
propagate(begin);
propagate(end - 1);
for (size_type left = begin, right = end; left < right;
left >>= 1, right >>= 1) {
if (left & 1)
assign(left++, data);
if (right & 1)
assign(right - 1, data);
}
build(begin);
build(end - 1);
}
void update(size_type index,
const std::function<value_type(const_reference)> &e) {
assert(index < size_);
index += size_;
propagate(index);
tree[index].first = e(reflect(index));
tree[index].second = o_neutral;
build(index);
}
void update(const size_type index, const_reference data) {
assert(index < size_);
update(index, [&data](const_reference d) { return data; });
}
value_type range(size_type begin, size_type end) {
assert(begin <= end);
assert(begin <= size_);
assert(end <= size_);
begin += size_;
end += size_;
evaluate(begin);
evaluate(end - 1);
value_type retL = v_neutral, retR = v_neutral;
for (; begin < end; begin >>= 1, end >>= 1) {
if (begin & 1)
retL = f(retL, reflect(begin++));
if (end & 1)
retR = f(reflect(end - 1), retR);
}
return f(retL, retR);
}
size_type search(const std::function<bool(const_reference)> &b) {
if (!b(reflect(1)))
return size_;
value_type acc = v_neutral;
size_type i = 1;
while (i < size_) {
thrust(i);
if (!b(f(acc, reflect(i <<= 1))))
acc = f(acc, reflect(i++));
}
return i - size_;
}
const_reference operator[](const size_type index) {
assert(index < size_);
index += size_;
evaluate(index);
tree[index].first = reflect(index);
tree[index].second = o_neutral;
return tree[index].first;
}
size_type size() const { return size_; }
};
using value_t = pair<int, int>;
const value_t inf = {1 << 25, -1};
int main() {
#ifdef DEBUG
ifstream ifs("in.txt");
cin.rdbuf(ifs.rdbuf());
#endif
int N, M;
string S;
while (cin >> N >> M >> S) {
LazySegmentTree<value_t, value_t> seg(
N, [&](const value_t &a, const value_t &b) { return min(a, b); }, inf,
[&](const value_t &a, const value_t &b) { return min(a, b); }, inf,
[&](const value_t &a, const value_t &b) { return min(a, b); });
seg.update(N, {0, -1});
for (int i = N; i >= 1; i--) {
if (S[i] == '1')
continue;
auto v = seg.range(i, i + 1);
auto nv = value_t{v.fst + 1, i};
seg.update(max(i - M, 0), i, nv);
}
auto v = seg.range(0, 1);
if (v >= inf) {
cout << -1 << endl;
break;
}
int i = 0;
vector<int> res;
while (i < N) {
auto v = seg.range(i, i + 1);
int jump = (v.snd - i);
res.push_back(jump);
i = v.snd;
}
for (int x : res)
cout << x << " ";
cout << endl;
}
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second
/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */
template <typename ValueMonoid, typename OperatorMonoid> class LazySegmentTree {
public:
using value_type = ValueMonoid;
using reference = value_type &;
using const_reference = const value_type &;
using operator_type = OperatorMonoid;
private:
using operator_constref = const operator_type &;
using container_type = std::vector<std::pair<value_type, operator_type>>;
public:
using size_type = typename container_type::size_type;
private:
using F = std::function<value_type(const_reference, const_reference)>;
using G = std::function<operator_type(operator_constref, operator_constref)>;
using H = std::function<value_type(const_reference, operator_constref)>;
const F f;
const G g;
const H h;
const value_type v_neutral;
const operator_type o_neutral;
size_type height, size_;
container_type tree;
static size_type getheight(const size_type size) {
size_type ret = 0;
while ((size_type)1 << ret < size)
++ret;
return ret;
}
value_type reflect(const size_type index) {
return h(tree[index].first, tree[index].second);
}
void recalc(const size_type index) {
tree[index].first = f(reflect(index << 1), reflect(index << 1 | 1));
}
void assign(const size_type index, operator_constref data) {
tree[index].second = g(tree[index].second, data);
}
void push(const size_type index) {
assign(index << 1, tree[index].second);
assign(index << 1 | 1, tree[index].second);
tree[index].second = o_neutral;
}
void propagate(const size_type index) {
for (size_type i = height; i; --i)
push(index >> i);
}
void thrust(const size_type index) {
tree[index].first = reflect(index);
push(index);
}
void evaluate(const size_type index) {
for (size_type i = height; i; --i)
thrust(index >> i);
}
void build(size_type index) {
while (index >>= 1)
recalc(index);
}
public:
LazySegmentTree(
const size_type size, const F &value_addition = std::plus<value_type>(),
const_reference value_neutral = value_type(),
const G &operator_multiplication = std::multiplies<operator_type>(),
operator_constref operator_neutral = operator_type(),
const H &mutual_multiplication =
[](const_reference l, operator_constref r) { return l * r; })
: f(value_addition), v_neutral(value_neutral), g(operator_multiplication),
o_neutral(operator_neutral), h(mutual_multiplication),
height(getheight(size)), size_((size_type)1 << height),
tree(size_ << 1, std::make_pair(v_neutral, o_neutral)) {}
void update(size_type begin, size_type end, operator_constref data) {
assert(begin <= end);
assert(begin <= size_);
assert(end <= size_);
begin += size_;
end += size_;
propagate(begin);
propagate(end - 1);
for (size_type left = begin, right = end; left < right;
left >>= 1, right >>= 1) {
if (left & 1)
assign(left++, data);
if (right & 1)
assign(right - 1, data);
}
build(begin);
build(end - 1);
}
void update(size_type index,
const std::function<value_type(const_reference)> &e) {
assert(index < size_);
index += size_;
propagate(index);
tree[index].first = e(reflect(index));
tree[index].second = o_neutral;
build(index);
}
void update(const size_type index, const_reference data) {
assert(index < size_);
update(index, [&data](const_reference d) { return data; });
}
value_type range(size_type begin, size_type end) {
assert(begin <= end);
assert(begin <= size_);
assert(end <= size_);
begin += size_;
end += size_;
evaluate(begin);
evaluate(end - 1);
value_type retL = v_neutral, retR = v_neutral;
for (; begin < end; begin >>= 1, end >>= 1) {
if (begin & 1)
retL = f(retL, reflect(begin++));
if (end & 1)
retR = f(reflect(end - 1), retR);
}
return f(retL, retR);
}
size_type search(const std::function<bool(const_reference)> &b) {
if (!b(reflect(1)))
return size_;
value_type acc = v_neutral;
size_type i = 1;
while (i < size_) {
thrust(i);
if (!b(f(acc, reflect(i <<= 1))))
acc = f(acc, reflect(i++));
}
return i - size_;
}
const_reference operator[](const size_type index) {
assert(index < size_);
index += size_;
evaluate(index);
tree[index].first = reflect(index);
tree[index].second = o_neutral;
return tree[index].first;
}
size_type size() const { return size_; }
};
using value_t = pair<int, int>;
const value_t inf = {1 << 25, -1};
int main() {
#ifdef DEBUG
ifstream ifs("in.txt");
cin.rdbuf(ifs.rdbuf());
#endif
int N, M;
string S;
while (cin >> N >> M >> S) {
LazySegmentTree<value_t, value_t> seg(
N + 1, [&](const value_t &a, const value_t &b) { return min(a, b); },
inf, [&](const value_t &a, const value_t &b) { return min(a, b); }, inf,
[&](const value_t &a, const value_t &b) { return min(a, b); });
seg.update(N, {0, -1});
for (int i = N; i >= 1; i--) {
if (S[i] == '1')
continue;
auto v = seg.range(i, i + 1);
auto nv = value_t{v.fst + 1, i};
seg.update(max(i - M, 0), i, nv);
}
auto v = seg.range(0, 1);
if (v >= inf) {
cout << -1 << endl;
break;
}
int i = 0;
vector<int> res;
while (i < N) {
auto v = seg.range(i, i + 1);
int jump = (v.snd - i);
res.push_back(jump);
i = v.snd;
}
for (int x : res)
cout << x << " ";
cout << endl;
}
return 0;
}
| replace | 191 | 193 | 191 | 193 | 0 | |
p02852 | C++ | Runtime Error | #pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
int main() {
// cin.tie(0);
// ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
string S;
cin >> S;
int dp[100002] = {};
int mae = 0;
int kazu = 0;
while (mae <= N) {
int tugi = mae + M;
chmin(tugi, N);
kazu++;
int saigo = mae;
for (int i = mae + 1; i <= tugi; i++) {
if (S[i] == '0') {
dp[i] = kazu;
saigo = i;
}
}
if (mae == saigo)
break;
mae = saigo;
}
if (dp[N] == 0) {
co(-1);
return 0;
}
vector<int> kotae;
for (int i = N; i > 0;) {
int k = dp[i];
for (int j = i - M; j <= i; j++) {
if (dp[j] == k - 1) {
kotae.pb(i - j);
i = j;
break;
}
}
}
for (auto itr = kotae.rbegin(); itr != kotae.rend(); itr++) {
cosp(*itr);
}
Would you please return 0;
} | #pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please
int main() {
// cin.tie(0);
// ios::sync_with_stdio(false);
int N, M;
cin >> N >> M;
string S;
cin >> S;
int dp[100002] = {};
int mae = 0;
int kazu = 0;
while (mae <= N) {
int tugi = mae + M;
chmin(tugi, N);
kazu++;
int saigo = mae;
for (int i = mae + 1; i <= tugi; i++) {
if (S[i] == '0') {
dp[i] = kazu;
saigo = i;
}
}
if (mae == saigo)
break;
mae = saigo;
}
if (dp[N] == 0) {
co(-1);
return 0;
}
vector<int> kotae;
for (int i = N; i > 0;) {
int k = dp[i];
for (int j = max(0, i - M); j <= i; j++) {
if (dp[j] == k - 1) {
kotae.pb(i - j);
i = j;
break;
}
}
}
for (auto itr = kotae.rbegin(); itr != kotae.rend(); itr++) {
cosp(*itr);
}
Would you please return 0;
} | replace | 54 | 55 | 54 | 55 | 0 | |
p02852 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#define rep(i, a, b) for (long long(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) \
std::cerr << "debug " \
<< "LINE:" << __LINE__ << " " << #i << ":" << i << std::endl
template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &os, std::pair<T1, T2> pa) {
return os << pa.first << " " << pa.second;
}
template <typename T>
std::ostream &operator<<(std::ostream &os, std::vector<T> vec) {
for (int i = 0; i < vec.size(); i++)
os << vec[i] << (i + 1 == vec.size() ? "" : " ");
return os;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
long long pow_mod(long long a, long long b, long long mod = -1) {
if ((a == 0) || (mod != -1 && a % mod == 0)) {
return 0;
}
long long x = 1;
while (b > 0) {
if (b & 1) {
x = (mod != -1) ? (x * a) % mod : x * a;
}
a = (mod != -1) ? (a * a) % mod : a * a;
b >>= 1;
}
return x;
}
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;
using ll = long long;
using P = std::pair<ll, ll>;
template <typename T> class SWAG {
private:
std::function<T(T, T)> fn;
std::stack<T> front, back;
std::vector<T> front_fold, back_fold;
T id;
public:
SWAG(T id_, std::function<T(T, T)> fn_)
: id(id_), fn(fn_), front_fold(1, id_), back_fold(1, id_) {}
void push(T val) {
back.push(val);
back_fold.push_back(fn(back_fold.back(), val));
}
void pop() {
if (front.empty()) {
assert(front_fold.size() == 1);
while (!back.empty()) {
T temp = back.top();
back.pop();
back_fold.pop_back();
front.push(temp);
front_fold.push_back(fn(temp, front_fold.back()));
}
}
assert(!front.empty());
front.pop();
front_fold.pop_back();
}
T fold_all() { return fn(front_fold.back(), back_fold.back()); }
};
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
ll n, m;
std::cin >> n >> m;
std::string s;
std::cin >> s;
SWAG<P> swag({MOD, MOD}, [](P a, P b) { return std::min<P>(a, b); });
std::vector<P> dp(n + 1, {MOD, MOD});
dp[n] = {0, 0};
swag.push({0, n});
for (ll i = n - 1; i >= 0; i--) {
if (s[i] == '0') {
P temp = swag.fold_all();
dp[i] = {temp.first + 1, temp.second - i};
}
swag.push({dp[i].first, i});
if (i <= n - m)
swag.pop();
}
if (dp[0].first == MOD) {
std::cout << -1 << "\n";
return 0;
}
ll now = 0;
while (now != n) {
std::cout << dp[now].second;
now += dp[now].second;
if (now != n)
std::cout << " ";
}
std::cout << "\n";
return 0;
} | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
#define rep(i, a, b) for (long long(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) \
std::cerr << "debug " \
<< "LINE:" << __LINE__ << " " << #i << ":" << i << std::endl
template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &os, std::pair<T1, T2> pa) {
return os << pa.first << " " << pa.second;
}
template <typename T>
std::ostream &operator<<(std::ostream &os, std::vector<T> vec) {
for (int i = 0; i < vec.size(); i++)
os << vec[i] << (i + 1 == vec.size() ? "" : " ");
return os;
}
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
return a > b && (a = b, true);
}
long long pow_mod(long long a, long long b, long long mod = -1) {
if ((a == 0) || (mod != -1 && a % mod == 0)) {
return 0;
}
long long x = 1;
while (b > 0) {
if (b & 1) {
x = (mod != -1) ? (x * a) % mod : x * a;
}
a = (mod != -1) ? (a * a) % mod : a * a;
b >>= 1;
}
return x;
}
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;
using ll = long long;
using P = std::pair<ll, ll>;
template <typename T> class SWAG {
private:
std::function<T(T, T)> fn;
std::stack<T> front, back;
std::vector<T> front_fold, back_fold;
T id;
public:
SWAG(T id_, std::function<T(T, T)> fn_)
: id(id_), fn(fn_), front_fold(1, id_), back_fold(1, id_) {}
void push(T val) {
back.push(val);
back_fold.push_back(fn(back_fold.back(), val));
}
void pop() {
if (front.empty()) {
assert(front_fold.size() == 1);
while (!back.empty()) {
T temp = back.top();
back.pop();
back_fold.pop_back();
front.push(temp);
front_fold.push_back(fn(temp, front_fold.back()));
}
}
assert(!front.empty());
front.pop();
front_fold.pop_back();
}
T fold_all() { return fn(front_fold.back(), back_fold.back()); }
};
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
ll n, m;
std::cin >> n >> m;
std::string s;
std::cin >> s;
SWAG<P> swag({MOD, MOD}, [](P a, P b) { return std::min<P>(a, b); });
std::vector<P> dp(n + 1, {MOD, MOD});
dp[n] = {0, 0};
swag.push({0, n});
for (ll i = n - 1; i >= 0; i--) {
if (s[i] == '0') {
P temp = swag.fold_all();
dp[i] = {temp.first + 1, temp.second - i};
}
swag.push({dp[i].first, i});
if (i <= n - m)
swag.pop();
}
if (dp[0].first >= MOD) {
std::cout << -1 << "\n";
return 0;
}
ll now = 0;
while (now != n) {
std::cout << dp[now].second;
now += dp[now].second;
if (now != n)
std::cout << " ";
}
std::cout << "\n";
return 0;
} | replace | 140 | 141 | 140 | 141 | 0 | |
p02852 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()
int N, M;
string S;
int main() {
cin >> N >> M >> S;
stack<int> m;
int i = N;
while (i != 0) {
bool found = false;
for (int j = i - M; j < i; ++j) {
if (S[j] == '0') {
m.push(i - j);
i = j;
found = true;
break;
}
}
if (!found)
break;
}
if (i != 0) {
cout << -1 << endl;
return 0;
}
cout << m.top();
m.pop();
while (!m.empty()) {
cout << " " << m.top();
m.pop();
}
cout << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()
int N, M;
string S;
int main() {
cin >> N >> M >> S;
stack<int> m;
int i = N;
while (i != 0) {
bool found = false;
for (int j = i - M; j < i; ++j) {
if (j >= 0 && S[j] == '0') {
m.push(i - j);
i = j;
found = true;
break;
}
}
if (!found)
break;
}
if (i != 0) {
cout << -1 << endl;
return 0;
}
cout << m.top();
m.pop();
while (!m.empty()) {
cout << " " << m.top();
m.pop();
}
cout << endl;
return 0;
}
| replace | 17 | 18 | 17 | 18 | 0 | |
p02852 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int, int>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define all(v) v.begin(), v.end()
#define pb push_back
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int kaijo[2000010];
struct edge {
int to, cost;
};
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
bool prime(int a) {
if (a == 1)
return false;
for (int i = 2; i * i <= a; i++) {
if (a % i == 0)
return false;
}
return true;
}
void init_fact() {
kaijo[0] = 1;
for (int i = 1; i <= 2000000; i++) {
kaijo[i] = kaijo[i - 1] * i;
kaijo[i] %= MOD;
}
}
int modpow(int a, int b) {
if (b == 0)
return 1;
if (b % 2)
return modpow(a, b - 1) * a % MOD;
int memo = modpow(a, b / 2);
return memo * memo % MOD;
}
int comb(int a, int b) {
if (!kaijo[0])
init_fact();
return kaijo[a] * modpow(kaijo[a - b], MOD - 2) % MOD *
modpow(kaijo[b], MOD - 2) % MOD;
}
int inv(int x) {
x = modpow(x, MOD - 2);
return x;
}
bool kosa(double ax, double ay, double bx, double by, double cx, double cy,
double dx, double dy) {
double ta = (cx - dx) * (ay - cy) + (cy - dy) * (cx - ax);
double tb = (cx - dx) * (by - cy) + (cy - dy) * (cx - bx);
double tc = (ax - bx) * (cy - ay) + (ay - by) * (ax - cx);
double td = (ax - bx) * (dy - ay) + (ay - by) * (ax - dx);
return tc * td < 0 && ta * tb < 0;
}
double dist(double ax, double ay, double bx, double by) {
return sqrt((bx - ax) * (bx - ax) + (ay - by) * (ay - by));
}
int n, m, now;
string s;
vector<int> ans;
signed main() {
cin >> n >> m >> s;
now = n;
while (now) {
for (int i = now - m; i < now; i++) {
if (s[i] == '0') {
ans.pb(now - i);
now = i;
goto ok;
}
}
puts("-1");
return 0;
ok:;
}
reverse(all(ans));
for (int i : ans) {
cout << i << " ";
}
cout << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int, int>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define all(v) v.begin(), v.end()
#define pb push_back
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
int kaijo[2000010];
struct edge {
int to, cost;
};
int gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
bool prime(int a) {
if (a == 1)
return false;
for (int i = 2; i * i <= a; i++) {
if (a % i == 0)
return false;
}
return true;
}
void init_fact() {
kaijo[0] = 1;
for (int i = 1; i <= 2000000; i++) {
kaijo[i] = kaijo[i - 1] * i;
kaijo[i] %= MOD;
}
}
int modpow(int a, int b) {
if (b == 0)
return 1;
if (b % 2)
return modpow(a, b - 1) * a % MOD;
int memo = modpow(a, b / 2);
return memo * memo % MOD;
}
int comb(int a, int b) {
if (!kaijo[0])
init_fact();
return kaijo[a] * modpow(kaijo[a - b], MOD - 2) % MOD *
modpow(kaijo[b], MOD - 2) % MOD;
}
int inv(int x) {
x = modpow(x, MOD - 2);
return x;
}
bool kosa(double ax, double ay, double bx, double by, double cx, double cy,
double dx, double dy) {
double ta = (cx - dx) * (ay - cy) + (cy - dy) * (cx - ax);
double tb = (cx - dx) * (by - cy) + (cy - dy) * (cx - bx);
double tc = (ax - bx) * (cy - ay) + (ay - by) * (ax - cx);
double td = (ax - bx) * (dy - ay) + (ay - by) * (ax - dx);
return tc * td < 0 && ta * tb < 0;
}
double dist(double ax, double ay, double bx, double by) {
return sqrt((bx - ax) * (bx - ax) + (ay - by) * (ay - by));
}
int n, m, now;
string s;
vector<int> ans;
signed main() {
cin >> n >> m >> s;
now = n;
while (now) {
for (int i = max(0ll, now - m); i < now; i++) {
if (s[i] == '0') {
ans.pb(now - i);
now = i;
goto ok;
}
}
puts("-1");
return 0;
ok:;
}
reverse(all(ans));
for (int i : ans) {
cout << i << " ";
}
cout << endl;
return 0;
}
| replace | 75 | 76 | 75 | 76 | 0 | |
p02852 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define int long long
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
typedef pair<int, int> pint;
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define MOD (1000 * 1000 * 1000 + 7)
signed main() {
int n, m;
string s;
cin >> n >> m;
cin >> s;
vector<int> ok_list;
{
int one_max = 0;
int now = 0;
REP(i, n + 1) {
if (s[i] == '1') {
now++;
one_max = max(one_max, now);
} else {
now = 0;
ok_list.pb(i);
}
}
if (one_max >= m) {
cout << -1 << endl;
return -1;
}
}
int now = n;
vector<int> pos;
pos.pb(now);
while (now != 0) {
decltype(ok_list)::iterator it =
std::upper_bound(ok_list.begin(), ok_list.end(), now - m - 1);
now = *it;
pos.pb(now);
}
int _size = SZ(pos);
RREP(i, _size - 1) {
cout << (pos[i] - pos[i + 1]);
if (i != 0)
cout << " ";
}
cout << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// #define int long long
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
typedef pair<int, int> pint;
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define MOD (1000 * 1000 * 1000 + 7)
signed main() {
int n, m;
string s;
cin >> n >> m;
cin >> s;
vector<int> ok_list;
{
int one_max = 0;
int now = 0;
REP(i, n + 1) {
if (s[i] == '1') {
now++;
one_max = max(one_max, now);
} else {
now = 0;
ok_list.pb(i);
}
}
if (one_max >= m) {
cout << -1 << endl;
return 0;
}
}
int now = n;
vector<int> pos;
pos.pb(now);
while (now != 0) {
decltype(ok_list)::iterator it =
std::upper_bound(ok_list.begin(), ok_list.end(), now - m - 1);
now = *it;
pos.pb(now);
}
int _size = SZ(pos);
RREP(i, _size - 1) {
cout << (pos[i] - pos[i + 1]);
if (i != 0)
cout << " ";
}
cout << endl;
return 0;
} | replace | 46 | 47 | 46 | 47 | 0 | |
p02852 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;
template <class M> class segment_tree {
public:
typedef typename M::value_type value_type;
size_t n;
vector<value_type> v;
value_type e = M::unit();
segment_tree(size_t size) {
n = 1;
while (n < size)
n <<= 1;
v.resize(2 * n, e);
for (size_t i = 1; i < n + size; ++i)
v[i] = e;
}
segment_tree(vector<value_type> a) {
size_t size = a.size();
n = 1;
while (n < size)
n <<= 1;
v.resize(2 * n, e);
for (size_t i = 0; i < size; ++i)
v[n + i] = a[i];
for (size_t i = n - 1; i > 0; --i)
v[i] = M::operate(v[2 * i], v[2 * i + 1]);
}
void point_update(size_t k, value_type val) {
k += n;
v[k] = val;
k >>= 1;
while (k > 0) {
v[k] = M::operate(v[2 * k], v[2 * k + 1]);
k >>= 1;
}
}
void point_operate(size_t k, value_type lval) {
k += n;
v[k] = M::operate(lval, v[k]);
k >>= 1;
while (k > 0) {
v[k] = M::operate(v[2 * k], v[2 * k + 1]);
k >>= 1;
}
}
value_type range_get(size_t l, size_t r) { // [l, r)
value_type lres = e;
value_type rres = e;
l += n;
r += n;
while (l < r) {
if (l & 1) {
lres = M::operate(lres, v[l]);
++l;
}
if (r & 1) {
--r;
rres = M::operate(v[r], rres);
}
l >>= 1;
r >>= 1;
}
return M::operate(lres, rres);
}
value_type operator[](size_t k) { return v[k + n]; }
};
struct plus_monoid {
using value_type = Int;
static value_type unit() { return 0; }
static value_type operate(value_type l, value_type r) { return l + r; }
};
struct min_monoid {
using value_type = Int;
static value_type unit() { return 1e9; }
static value_type operate(value_type l, value_type r) { return min(l, r); }
};
int main() {
// cin.tie(0);
// ios::sync_with_stdio(false);
Int n, m;
cin >> n >> m;
string s;
cin >> s;
vector<Int> a(n + 1, 1e9);
a[n] = 0;
segment_tree<min_monoid> st(a);
for (Int i = n - 1; i >= 0; --i)
if (s[i] == '0') {
a[i] = st.range_get(i + 1, min(i + m + 1, n + 1)) + 1;
st.point_update(i, a[i]);
}
if (a[0] > 1e8) {
cout << -1 << "\n";
return 0;
}
// for(Int i=0; i<=n; ++i)
// cout << i << " " << a[i] << "\n";
vector<Int> ans;
for (Int i = 0; i <= n; ++i) {
for (Int j = 1; j <= m; ++j) {
if (a[i] - 1 == a[i + j]) {
ans.push_back(j);
i = i + j - 1;
break;
}
}
}
for (size_t i = 0; i < ans.size(); ++i)
cout << ans[i] << " \n"[i + 1 == ans.size()];
} | #include <bits/stdc++.h>
using namespace std;
using Int = int_fast64_t;
template <class M> class segment_tree {
public:
typedef typename M::value_type value_type;
size_t n;
vector<value_type> v;
value_type e = M::unit();
segment_tree(size_t size) {
n = 1;
while (n < size)
n <<= 1;
v.resize(2 * n, e);
for (size_t i = 1; i < n + size; ++i)
v[i] = e;
}
segment_tree(vector<value_type> a) {
size_t size = a.size();
n = 1;
while (n < size)
n <<= 1;
v.resize(2 * n, e);
for (size_t i = 0; i < size; ++i)
v[n + i] = a[i];
for (size_t i = n - 1; i > 0; --i)
v[i] = M::operate(v[2 * i], v[2 * i + 1]);
}
void point_update(size_t k, value_type val) {
k += n;
v[k] = val;
k >>= 1;
while (k > 0) {
v[k] = M::operate(v[2 * k], v[2 * k + 1]);
k >>= 1;
}
}
void point_operate(size_t k, value_type lval) {
k += n;
v[k] = M::operate(lval, v[k]);
k >>= 1;
while (k > 0) {
v[k] = M::operate(v[2 * k], v[2 * k + 1]);
k >>= 1;
}
}
value_type range_get(size_t l, size_t r) { // [l, r)
value_type lres = e;
value_type rres = e;
l += n;
r += n;
while (l < r) {
if (l & 1) {
lres = M::operate(lres, v[l]);
++l;
}
if (r & 1) {
--r;
rres = M::operate(v[r], rres);
}
l >>= 1;
r >>= 1;
}
return M::operate(lres, rres);
}
value_type operator[](size_t k) { return v[k + n]; }
};
struct plus_monoid {
using value_type = Int;
static value_type unit() { return 0; }
static value_type operate(value_type l, value_type r) { return l + r; }
};
struct min_monoid {
using value_type = Int;
static value_type unit() { return 1e9; }
static value_type operate(value_type l, value_type r) { return min(l, r); }
};
int main() {
// cin.tie(0);
// ios::sync_with_stdio(false);
Int n, m;
cin >> n >> m;
string s;
cin >> s;
vector<Int> a(n + 1, 1e9);
a[n] = 0;
segment_tree<min_monoid> st(a);
for (Int i = n - 1; i >= 0; --i)
if (s[i] == '0') {
a[i] = st.range_get(i + 1, min(i + m + 1, n + 1)) + 1;
st.point_update(i, a[i]);
}
if (a[0] > 1e8) {
cout << -1 << "\n";
return 0;
}
// for(Int i=0; i<=n; ++i)
// cout << i << " " << a[i] << "\n";
vector<Int> ans;
for (Int i = 0; i <= n; ++i) {
for (Int j = 1; j <= m && i + j <= n; ++j) {
if (a[i] - 1 == a[i + j]) {
ans.push_back(j);
i = i + j - 1;
break;
}
}
}
for (size_t i = 0; i < ans.size(); ++i)
cout << ans[i] << " \n"[i + 1 == ans.size()];
} | replace | 102 | 103 | 102 | 103 | 0 | |
p02852 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <cmath>
const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
// #define rep(i, n) for (ll i = 0; i < (n); ++i)
// typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;
std::istream &operator>>(std::istream &in, set<int> &o) {
ll a;
in >> a;
o.insert(a);
return in;
}
std::istream &operator>>(std::istream &in, queue<int> &o) {
ll a;
in >> a;
o.push(a);
return in;
}
bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }
// ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
// ofstream outfile("log.txt");
// outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0')
// << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
// const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string>> PQ_ASK;
#include <iostream>
#include <vector>
using namespace std;
struct Food {
ll time, good;
};
struct SegTreeMin {
ll N, dat[4 * 100000];
SegTreeMin() {}
SegTreeMin(ll n) {
N = 1;
while (N < n)
N *= 2;
for (ll i = 0; i < 2 * N - 1; i++)
dat[i] = INF;
}
// update k th element
void update(ll k, ll a) {
k += N - 1; // leaf
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
// min [a, b)
ll query(ll a, ll b) { return query(a, b, 0, 0, N); }
ll query(ll a, ll b, ll k, ll l, ll r) {
if (r <= a or b <= l)
return INF;
if (a <= l and r <= b)
return dat[k];
ll m = (l + r) / 2;
return min(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
}
};
int main() {
int n, m;
string s;
cin >> n >> m >> s;
SegTreeMin st(n + 1);
rep(i, n + 2) st.update(i, INF);
st.update(n, 0);
for (int i = n - 1; i >= 0; i--) {
if (s[i] == '1') {
continue;
}
ll start = i + 1;
ll end = min(i + m + 1, n + 1);
ll mi = st.query(start, end);
if (mi == INF) {
cout << -1 << endl;
ret();
}
st.update(i, mi + 1);
}
ll ma = st.query(0, 1);
vector<ll> shortness(n + 1);
rep(i, n + 2) shortness[i] = st.query(i, i + 1);
vector<ll> points(ma + 1);
for (ll i = n; i >= 0; i--) {
ll p = shortness[i];
if (p == INF)
continue;
points[p] = i;
}
reverse(points.begin(), points.end());
rep(i, ma) { cout << points[i + 1] - points[i] << ' '; }
cout << endl;
} | #include <bits/stdc++.h>
#include <cmath>
const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
// #define rep(i, n) for (ll i = 0; i < (n); ++i)
// typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;
std::istream &operator>>(std::istream &in, set<int> &o) {
ll a;
in >> a;
o.insert(a);
return in;
}
std::istream &operator>>(std::istream &in, queue<int> &o) {
ll a;
in >> a;
o.push(a);
return in;
}
bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }
// ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
// ofstream outfile("log.txt");
// outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0')
// << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
// const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string>> PQ_ASK;
#include <iostream>
#include <vector>
using namespace std;
struct Food {
ll time, good;
};
struct SegTreeMin {
ll N, dat[4 * 100000];
SegTreeMin() {}
SegTreeMin(ll n) {
N = 1;
while (N < n)
N *= 2;
for (ll i = 0; i < 2 * N - 1; i++)
dat[i] = INF;
}
// update k th element
void update(ll k, ll a) {
k += N - 1; // leaf
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
}
}
// min [a, b)
ll query(ll a, ll b) { return query(a, b, 0, 0, N); }
ll query(ll a, ll b, ll k, ll l, ll r) {
if (r <= a or b <= l)
return INF;
if (a <= l and r <= b)
return dat[k];
ll m = (l + r) / 2;
return min(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
}
};
int main() {
int n, m;
string s;
cin >> n >> m >> s;
SegTreeMin st(n + 1);
rep(i, n + 2) st.update(i, INF);
st.update(n, 0);
for (int i = n - 1; i >= 0; i--) {
if (s[i] == '1') {
continue;
}
ll start = i + 1;
ll end = min(i + m + 1, n + 1);
ll mi = st.query(start, end);
if (mi == INF) {
cout << -1 << endl;
ret();
}
st.update(i, mi + 1);
}
ll ma = st.query(0, 1);
vector<ll> shortness(n + 1);
rep(i, n + 1) shortness[i] = st.query(i, i + 1);
vector<ll> points(ma + 1);
for (ll i = n; i >= 0; i--) {
ll p = shortness[i];
if (p == INF)
continue;
points[p] = i;
}
reverse(points.begin(), points.end());
rep(i, ma) { cout << points[i + 1] - points[i] << ' '; }
cout << endl;
} | replace | 110 | 111 | 110 | 111 | 0 | |
p02852 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define MOD 1000000007
#define maxn 100010
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
string s;
cin >> s;
int now = n;
vector<int> ans;
while (now > 0) {
bool fl = false;
for (int i = now - m; i < now; i++) {
if (s[i] == '0') {
ans.push_back(now - i);
now = i;
fl = true;
break;
}
}
if (!fl)
break;
}
if (now)
cout << -1 << endl;
else
for (int i = ans.size() - 1; i >= 0; i--)
cout << ans[i] << " ";
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define MOD 1000000007
#define maxn 100010
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
string s;
cin >> s;
int now = n;
vector<int> ans;
while (now > 0) {
bool fl = false;
for (int i = max(0ll, now - m); i < now; i++) {
if (s[i] == '0') {
ans.push_back(now - i);
now = i;
fl = true;
break;
}
}
if (!fl)
break;
}
if (now)
cout << -1 << endl;
else
for (int i = ans.size() - 1; i >= 0; i--)
cout << ans[i] << " ";
} | replace | 24 | 25 | 24 | 25 | 0 | |
p02852 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using i64 = long long;
template <typename Monoid> struct SegmentTree {
using F = function<Monoid(Monoid, Monoid)>;
int sz;
vector<Monoid> seg;
const F f;
const Monoid M1;
SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
sz = 1;
while (sz < n)
sz <<= 1;
seg.assign(2 * sz, M1);
}
void set(int k, const Monoid &x) { seg[k + sz] = x; }
void build() {
for (int k = sz - 1; k > 0; k--) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
void update(int k, const Monoid &x) {
k += sz;
seg[k] = x;
while (k >>= 1) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
Monoid query(int a, int b) {
Monoid L = M1, R = M1;
for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
if (a & 1)
L = f(L, seg[a++]);
if (b & 1)
R = f(seg[--b], R);
}
return f(L, R);
}
Monoid operator[](const int &k) const { return seg[k + sz]; }
template <typename C>
int find_subtree(int a, const C &check, Monoid &M, bool type) {
while (a < sz) {
Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
if (check(nxt))
a = 2 * a + type;
else
M = nxt, a = 2 * a + 1 - type;
}
return a - sz;
}
template <typename C> int find_first(int a, const C &check) {
Monoid L = M1;
if (a <= 0) {
if (check(f(L, seg[1])))
return find_subtree(1, check, L, false);
return -1;
}
int b = sz;
for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
if (a & 1) {
Monoid nxt = f(L, seg[a]);
if (check(nxt))
return find_subtree(a, check, L, false);
L = nxt;
++a;
}
}
return -1;
}
template <typename C> int find_last(int b, const C &check) {
Monoid R = M1;
if (b >= sz) {
if (check(f(seg[1], R)))
return find_subtree(1, check, R, true);
return -1;
}
int a = sz;
for (b += sz; a < b; a >>= 1, b >>= 1) {
if (b & 1) {
Monoid nxt = f(seg[--b], R);
if (check(nxt))
return find_subtree(b, check, R, true);
R = nxt;
}
}
return -1;
}
};
int main() {
i64 n, m;
string s;
cin >> n >> m >> s;
SegmentTree<pair<i64, i64>> seg(
n, [](pair<i64, i64> a, pair<i64, i64> b) { return min(a, b); },
{1e9, 1e9});
for (i64 i = 0; i < (i64)s.size(); i++)
seg.set(i, {s[i] - '0', i});
seg.build();
vector<i64> ans;
for (i64 i = n; 0 < i;) {
pair<i64, i64> st = seg.query(max(0LL, i - m), i);
if (st.first == 1) {
cout << -1 << endl;
return 0;
}
ans.push_back(i - st.second);
i = st.second;
}
for (i64 i = ans.size() - 1; -1 < i; i--)
cout << ans[i] << (i == 0 ? "\n" : " ");
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using i64 = long long;
template <typename Monoid> struct SegmentTree {
using F = function<Monoid(Monoid, Monoid)>;
int sz;
vector<Monoid> seg;
const F f;
const Monoid M1;
SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
sz = 1;
while (sz < n)
sz <<= 1;
seg.assign(2 * sz, M1);
}
void set(int k, const Monoid &x) { seg[k + sz] = x; }
void build() {
for (int k = sz - 1; k > 0; k--) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
void update(int k, const Monoid &x) {
k += sz;
seg[k] = x;
while (k >>= 1) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
Monoid query(int a, int b) {
Monoid L = M1, R = M1;
for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
if (a & 1)
L = f(L, seg[a++]);
if (b & 1)
R = f(seg[--b], R);
}
return f(L, R);
}
Monoid operator[](const int &k) const { return seg[k + sz]; }
template <typename C>
int find_subtree(int a, const C &check, Monoid &M, bool type) {
while (a < sz) {
Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
if (check(nxt))
a = 2 * a + type;
else
M = nxt, a = 2 * a + 1 - type;
}
return a - sz;
}
template <typename C> int find_first(int a, const C &check) {
Monoid L = M1;
if (a <= 0) {
if (check(f(L, seg[1])))
return find_subtree(1, check, L, false);
return -1;
}
int b = sz;
for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
if (a & 1) {
Monoid nxt = f(L, seg[a]);
if (check(nxt))
return find_subtree(a, check, L, false);
L = nxt;
++a;
}
}
return -1;
}
template <typename C> int find_last(int b, const C &check) {
Monoid R = M1;
if (b >= sz) {
if (check(f(seg[1], R)))
return find_subtree(1, check, R, true);
return -1;
}
int a = sz;
for (b += sz; a < b; a >>= 1, b >>= 1) {
if (b & 1) {
Monoid nxt = f(seg[--b], R);
if (check(nxt))
return find_subtree(b, check, R, true);
R = nxt;
}
}
return -1;
}
};
int main() {
i64 n, m;
string s;
cin >> n >> m >> s;
SegmentTree<pair<i64, i64>> seg(
n + 1, [](pair<i64, i64> a, pair<i64, i64> b) { return min(a, b); },
{1e9, 1e9});
for (i64 i = 0; i < (i64)s.size(); i++)
seg.set(i, {s[i] - '0', i});
seg.build();
vector<i64> ans;
for (i64 i = n; 0 < i;) {
pair<i64, i64> st = seg.query(max(0LL, i - m), i);
if (st.first == 1) {
cout << -1 << endl;
return 0;
}
ans.push_back(i - st.second);
i = st.second;
}
for (i64 i = ans.size() - 1; -1 < i; i--)
cout << ans[i] << (i == 0 ? "\n" : " ");
return 0;
}
| replace | 106 | 107 | 106 | 107 | 0 | |
p02852 | Python | Time Limit Exceeded | n, m = map(int, input().split())
s = input()
s = s[::-1]
if s[0] == "1":
print(-1)
exit()
pre = [-1] * (n + 1)
stack = [0]
while stack:
now = stack.pop()
if now == n:
break
for i in range(1, m + 1):
tsugi = now + i
if tsugi > n:
continue
if s[tsugi] == "1":
continue
pre[tsugi] = now
stack.append(tsugi)
else:
print(-1)
exit()
ato = n
mae = pre[n]
ans = []
while mae >= 0:
ans.append(ato - mae)
ato = mae
mae = pre[ato]
print(*ans, sep=" ")
| n, m = map(int, input().split())
s = input()
out_s = "1" * (m)
if out_s in s:
print(-1)
exit()
s = s[::-1]
if s[0] == "1":
print(-1)
exit()
pre = [-1] * (n + 1)
stack = [0]
while stack:
now = stack.pop()
if now == n:
break
for i in range(1, m + 1):
tsugi = now + i
if tsugi > n:
continue
if s[tsugi] == "1":
continue
pre[tsugi] = now
stack.append(tsugi)
else:
print(-1)
exit()
ato = n
mae = pre[n]
ans = []
while mae >= 0:
ans.append(ato - mae)
ato = mae
mae = pre[ato]
print(*ans, sep=" ")
| insert | 2 | 2 | 2 | 6 | TLE | |
p02852 | Python | Time Limit Exceeded | import sys
sys.setrecursionlimit(10**9)
n, m = map(int, input().split())
s = input()
def solve(t):
if len(t) <= m + 1:
return [len(t) - 1]
for i in reversed(range(1, m + 1)):
if t[len(t) - 1 - i] == "0":
cand = solve(t[:-i])
if len(cand) != 0:
cand.append(i)
return cand
return []
cnt1_continuous = 0
cnt = 0
for i in range(n + 1):
if s[i] == "1":
cnt += 1
if i == n:
cnt1_continuous = max(cnt1_continuous, cnt)
else:
cnt1_continuous = max(cnt1_continuous, cnt)
cnt = 0
if cnt1_continuous >= m:
print(-1)
else:
print(*solve(s))
| import sys
sys.setrecursionlimit(10**9)
n, m = map(int, input().split())
s = input()
def solve(t):
if len(t) <= m + 1:
return [len(t) - 1]
for i in reversed(range(1, m + 1)):
if t[len(t) - 1 - i] == "0":
cand = solve(t[:-i])
if len(cand) != 0:
cand.append(i)
return cand
return []
cnt1_continuous = 0
cnt = 0
for i in range(n + 1):
if s[i] == "1":
cnt += 1
if i == n:
cnt1_continuous = max(cnt1_continuous, cnt)
else:
cnt1_continuous = max(cnt1_continuous, cnt)
cnt = 0
if cnt1_continuous >= m:
print(-1)
else:
if m == 1:
ans = [1] * n
else:
ans = solve(s)
print(*ans)
| replace | 35 | 36 | 35 | 40 | TLE | |
p02852 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;
#define sz(a) int((a).size())
#define all(x) x.begin(), x.end()
#define pb push_back
#define endl '\n'
#define watch(x) cout << #x << " : " << x << endl;
#define FastIO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
const int N = int(1e5) + 10;
const int K = int(1e6) + 10;
// const int MOD = int(1e9)+7;
const int INF = int(1e9) + 5;
const ll INF64 = 2e18;
const ll MOD = 998244353;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
int dp[N], parent[N];
vi ans;
void solve() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
deque<ii> q;
if (s[0] == '1' || s[n] == '1') {
cout << -1 << endl;
return;
}
// Base Case.
for (int i = 1; i <= n; i++)
dp[i] = INF;
dp[0] = 0;
q.pb({0, 0});
int l = 0;
for (int i = 1; i <= n; i++) {
// Whether to kick out or not.
if (i >= m + 1) {
if (q.front().first == dp[l])
q.pop_front();
l++;
}
if (s[i] == '1')
continue;
if (!q.empty()) {
dp[i] = q.front().first + 1;
parent[i] = q.front().second;
}
while (!q.empty() && dp[i] < q.back().first)
q.pop_back();
q.push_back({dp[i], i});
}
if (dp[n] == INF) {
cout << -1 << endl;
return;
}
int curr = n;
while (curr != 0) {
ans.pb(curr);
curr = parent[curr];
}
reverse(all(ans));
int si = sz(ans);
for (int i = 0; i < si; i++) {
if (i == 0)
cout << ans[i] - 0 << " ";
else
cout << ans[i] - ans[i - 1] << " ";
}
}
int main() {
FastIO
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
int t;
// cin>>t;
t = 1;
while (t--) {
solve();
}
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;
#define sz(a) int((a).size())
#define all(x) x.begin(), x.end()
#define pb push_back
#define endl '\n'
#define watch(x) cout << #x << " : " << x << endl;
#define FastIO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
const int N = int(1e5) + 10;
const int K = int(1e6) + 10;
// const int MOD = int(1e9)+7;
const int INF = int(1e9) + 5;
const ll INF64 = 2e18;
const ll MOD = 998244353;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
int dp[N], parent[N];
vi ans;
void solve() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
deque<ii> q;
if (s[0] == '1' || s[n] == '1') {
cout << -1 << endl;
return;
}
// Base Case.
for (int i = 1; i <= n; i++)
dp[i] = INF;
dp[0] = 0;
q.pb({0, 0});
int l = 0;
for (int i = 1; i <= n; i++) {
// Whether to kick out or not.
if (!q.empty() && i >= m + 1) {
if (q.front().first == dp[l])
q.pop_front();
l++;
}
if (s[i] == '1')
continue;
if (!q.empty()) {
dp[i] = q.front().first + 1;
parent[i] = q.front().second;
}
while (!q.empty() && dp[i] < q.back().first)
q.pop_back();
q.push_back({dp[i], i});
}
if (dp[n] == INF) {
cout << -1 << endl;
return;
}
int curr = n;
while (curr != 0) {
ans.pb(curr);
curr = parent[curr];
}
reverse(all(ans));
int si = sz(ans);
for (int i = 0; i < si; i++) {
if (i == 0)
cout << ans[i] - 0 << " ";
else
cout << ans[i] - ans[i - 1] << " ";
}
}
int main() {
FastIO
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
int t;
// cin>>t;
t = 1;
while (t--) {
solve();
}
return 0;
} | replace | 64 | 65 | 64 | 65 | 0 | |
p02852 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, x, y) for (int i = x; i < y; i++)
#define range(a) (a).begin(), (a).end()
#define print(A, n) \
rep(i, 0, n) { cout << (i ? " " : "") << A[i]; } \
cout << endl;
#define pprint(A, m, n) \
rep(j, 0, m) { print(A[j], n); }
const long mod = 1e9 + 7;
const int size = 1e5;
const long inf = 1e9;
int main() {
int N, M;
cin >> N >> M;
string s;
cin >> s;
int t[N + 1];
t[0] = 1;
for (int i = N - 1; i >= 0; i--) {
t[N - i] = t[N - i - 1] + (s[i] == '1' ? 0 : 1);
}
// print(t,N+1);
deque<int> dq;
int i = 0;
int j;
while (i < N) {
if (t[i + M] == t[i]) {
cout << -1 << endl;
return 0;
}
j = upper_bound(t + i + 1, t + min(i + M + 1, N + 1),
t[min(i + M, N)] - 1) -
t;
dq.push_back(j - i);
i = j;
}
reverse(dq.begin(), dq.end());
print(dq, dq.size());
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, x, y) for (int i = x; i < y; i++)
#define range(a) (a).begin(), (a).end()
#define print(A, n) \
rep(i, 0, n) { cout << (i ? " " : "") << A[i]; } \
cout << endl;
#define pprint(A, m, n) \
rep(j, 0, m) { print(A[j], n); }
const long mod = 1e9 + 7;
const int size = 1e5;
const long inf = 1e9;
int main() {
int N, M;
cin >> N >> M;
string s;
cin >> s;
int t[N + 1];
t[0] = 1;
for (int i = N - 1; i >= 0; i--) {
t[N - i] = t[N - i - 1] + (s[i] == '1' ? 0 : 1);
}
// print(t,N+1);
deque<int> dq;
int i = 0;
int j;
while (i < N) {
if (t[min(i + M, N)] == t[i]) {
cout << -1 << endl;
return 0;
}
j = upper_bound(t + i + 1, t + min(i + M + 1, N + 1),
t[min(i + M, N)] - 1) -
t;
dq.push_back(j - i);
i = j;
}
reverse(dq.begin(), dq.end());
print(dq, dq.size());
} | replace | 27 | 28 | 27 | 28 | 0 | |
p02852 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)
#define pb push_back
#define sz(v) ((li)(v).size())
#define bgn(v) ((v).begin())
#define eend(v) ((v).end())
#define allof(v) (v).begin(), (v).end()
#define dodp(v, n) memset(v, (li)n, sizeof(v))
#define bit(n) (1ll << (li)(n))
#define mp(a, b) make_pair(a, b)
#define rin rep(i, n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;
#define INF bit(60)
#define DBGP 1
#define idp if (DBGP)
#define F first
#define S second
#define p2(a, b) idp cout << a << "\t" << b << endl
#define p3(a, b, c) idp cout << a << "\t" << b << "\t" << c << endl
#define p4(a, b, c, d) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << endl
#define p5(a, b, c, d, e) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << endl
#define p6(a, b, c, d, e, f) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << endl
#define p7(a, b, c, d, e, f, g) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << endl
#define p8(a, b, c, d, e, f, g, h) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << "\t" << h << endl
#define p9(a, b, c, d, e, f, g, h, i) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << "\t" << h << "\t" << i << endl
#define p10(a, b, c, d, e, f, g, h, i, j) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << "\t" << h << "\t" << i << "\t" << j << endl
#define foreach(it, v) \
for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)
#define p2p(x) idp p2((x).F, (x).S)
#define dump(x, n) \
idp { \
rep(i, n) { cout << x[i] << " "; } \
puts(""); \
}
#define dump2(x, n) \
idp { \
rep(i, n) { cout << "[" << x[i].F << " , " << x[i].S << "] "; } \
puts(""); \
}
#define dumpi(x) \
idp { \
foreach (it, x) { \
cout << (*it) << " "; \
} \
puts(""); \
}
#define dumpi2(x) \
idp { \
foreach (it, x) { \
cout << "[" << (it)->F << " , " << (it)->S << "] "; \
} \
puts(""); \
}
#define read2d(a, w, h) rep(i, h) rep(j, w) cin >> a[i][j]
#define dump2d(a, w, h) \
rep(i, h) { \
rep(j, w) cout << a[i][j] << " "; \
puts(""); \
}
// segtree ----------------------------------
// verified: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_A
template <typename T> class Segtree {
public:
Segtree(li n, T default_value, T invalid_value_, std::function<T(T, T)> func_)
: invalid_value(invalid_value_), func(func_) {
nn = 1;
while (nn < n) {
nn *= 2;
}
data.resize(nn * 2 - 1);
for (auto &&item : data) {
item = default_value;
}
}
inline void update(li i, T x) {
i += nn - 1;
data[i] = x;
while (i > 0) {
i = (i - 1) / 2;
data[i] = func(data[i * 2 + 1], data[i * 2 + 2]);
}
}
inline T query_(li a, li b, li k, li l, li r) {
if (r <= a || b <= l)
return invalid_value;
if (a <= l && r <= b)
return data[k];
li mid = (l + r) / 2;
T vl = query_(a, b, k * 2 + 1, l, mid);
T vr = query_(a, b, k * 2 + 2, mid, r);
return func(vl, vr);
}
inline T query(li a, li b) {
li l = 0;
li r = nn;
li k = 0;
if (r <= a || b <= l)
return invalid_value;
if (a <= l && r <= b)
return data[k];
li mid = (l + r) / 2;
T vl = query_(a, b, k * 2 + 1, l, mid);
T vr = query_(a, b, k * 2 + 2, mid, r);
return func(vl, vr);
}
li nn;
vector<T> data;
T invalid_value;
function<T(T, T)> func;
};
// segtree --------------------------------//
li n, m;
string s;
li prev_[100200];
int main() {
cin >> n >> m;
cin >> s;
Segtree<PI> segtree(n, {bit(31) - 1, 0}, {INF, -1},
[](PI a, PI b) { return min(a, b); });
segtree.update(0, {0, 0});
rep(i, n + 1) { prev_[i] = -1; }
repp(i, 1, n + 1) {
if (s[i] == '1') {
segtree.update(i, {INF, i});
continue;
}
PI opt = segtree.query(max(0ll, i - m), i);
segtree.update(i, {opt.F + 1, i});
prev_[i] = opt.S;
}
vector<li> res;
li now = n;
while (now > 0) {
res.pb(now);
now = prev_[now];
}
if (now == -1) {
puts("-1");
return 0;
}
res.pb(0);
reverse(allof(res));
rep(i, sz(res) - 1) { cout << res[i + 1] - res[i] << " "; }
cout << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)
#define pb push_back
#define sz(v) ((li)(v).size())
#define bgn(v) ((v).begin())
#define eend(v) ((v).end())
#define allof(v) (v).begin(), (v).end()
#define dodp(v, n) memset(v, (li)n, sizeof(v))
#define bit(n) (1ll << (li)(n))
#define mp(a, b) make_pair(a, b)
#define rin rep(i, n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;
#define INF bit(60)
#define DBGP 1
#define idp if (DBGP)
#define F first
#define S second
#define p2(a, b) idp cout << a << "\t" << b << endl
#define p3(a, b, c) idp cout << a << "\t" << b << "\t" << c << endl
#define p4(a, b, c, d) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << endl
#define p5(a, b, c, d, e) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << endl
#define p6(a, b, c, d, e, f) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << endl
#define p7(a, b, c, d, e, f, g) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << endl
#define p8(a, b, c, d, e, f, g, h) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << "\t" << h << endl
#define p9(a, b, c, d, e, f, g, h, i) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << "\t" << h << "\t" << i << endl
#define p10(a, b, c, d, e, f, g, h, i, j) \
idp cout << a << "\t" << b << "\t" << c << "\t" << d << "\t" << e << "\t" \
<< f << "\t" << g << "\t" << h << "\t" << i << "\t" << j << endl
#define foreach(it, v) \
for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)
#define p2p(x) idp p2((x).F, (x).S)
#define dump(x, n) \
idp { \
rep(i, n) { cout << x[i] << " "; } \
puts(""); \
}
#define dump2(x, n) \
idp { \
rep(i, n) { cout << "[" << x[i].F << " , " << x[i].S << "] "; } \
puts(""); \
}
#define dumpi(x) \
idp { \
foreach (it, x) { \
cout << (*it) << " "; \
} \
puts(""); \
}
#define dumpi2(x) \
idp { \
foreach (it, x) { \
cout << "[" << (it)->F << " , " << (it)->S << "] "; \
} \
puts(""); \
}
#define read2d(a, w, h) rep(i, h) rep(j, w) cin >> a[i][j]
#define dump2d(a, w, h) \
rep(i, h) { \
rep(j, w) cout << a[i][j] << " "; \
puts(""); \
}
// segtree ----------------------------------
// verified: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_A
template <typename T> class Segtree {
public:
Segtree(li n, T default_value, T invalid_value_, std::function<T(T, T)> func_)
: invalid_value(invalid_value_), func(func_) {
nn = 1;
while (nn < n) {
nn *= 2;
}
data.resize(nn * 2 - 1);
for (auto &&item : data) {
item = default_value;
}
}
inline void update(li i, T x) {
i += nn - 1;
data[i] = x;
while (i > 0) {
i = (i - 1) / 2;
data[i] = func(data[i * 2 + 1], data[i * 2 + 2]);
}
}
inline T query_(li a, li b, li k, li l, li r) {
if (r <= a || b <= l)
return invalid_value;
if (a <= l && r <= b)
return data[k];
li mid = (l + r) / 2;
T vl = query_(a, b, k * 2 + 1, l, mid);
T vr = query_(a, b, k * 2 + 2, mid, r);
return func(vl, vr);
}
inline T query(li a, li b) {
li l = 0;
li r = nn;
li k = 0;
if (r <= a || b <= l)
return invalid_value;
if (a <= l && r <= b)
return data[k];
li mid = (l + r) / 2;
T vl = query_(a, b, k * 2 + 1, l, mid);
T vr = query_(a, b, k * 2 + 2, mid, r);
return func(vl, vr);
}
li nn;
vector<T> data;
T invalid_value;
function<T(T, T)> func;
};
// segtree --------------------------------//
li n, m;
string s;
li prev_[100200];
int main() {
cin >> n >> m;
cin >> s;
Segtree<PI> segtree(n + 2, {bit(31) - 1, 0}, {INF, -1},
[](PI a, PI b) { return min(a, b); });
segtree.update(0, {0, 0});
rep(i, n + 1) { prev_[i] = -1; }
repp(i, 1, n + 1) {
if (s[i] == '1') {
segtree.update(i, {INF, i});
continue;
}
PI opt = segtree.query(max(0ll, i - m), i);
segtree.update(i, {opt.F + 1, i});
prev_[i] = opt.S;
}
vector<li> res;
li now = n;
while (now > 0) {
res.pb(now);
now = prev_[now];
}
if (now == -1) {
puts("-1");
return 0;
}
res.pb(0);
reverse(allof(res));
rep(i, sz(res) - 1) { cout << res[i + 1] - res[i] << " "; }
cout << endl;
return 0;
} | replace | 149 | 150 | 149 | 150 | 0 | |
p02852 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
long long N, M;
string S;
cin >> N >> M >> S;
if (S.front() != '0') {
cout << -1 << endl;
}
if (S.back() != '0') {
cout << -1 << endl;
}
reverse(S.begin(), S.end());
vector<bool> over(S.size());
for (int i = 0; i < over.size(); i++) {
over[i] = S[i] == '0';
}
bool now = true;
long long count = 0;
vector<pair<bool, long long>> comp;
for (int i = 0; i < over.size(); i++) {
if (now != over[i]) {
comp.push_back(make_pair(now, count));
now = over[i];
count = 1;
} else {
count++;
}
}
if (count > 0) {
comp.push_back(make_pair(now, count));
}
vector<long long> ans;
long long current = 0;
long long idx = 0;
long long remain = comp[0].second - 1;
while (N > 0) {
long long m = M;
long long sum = 0;
while (m > 0) {
if (remain == 0) {
if (comp[idx + 1].second < m) {
m -= comp[idx + 1].second + 1;
sum += comp[idx + 1].second + 1;
idx += 2;
remain = comp[idx].second - 1;
} else {
m = 0;
}
} else {
long long d = min(remain, m);
sum += d;
m -= d;
remain -= d;
}
}
if (sum == 0) {
cout << -1 << endl;
return 0;
}
ans.push_back(min(N, sum));
N -= sum;
}
reverse(ans.begin(), ans.end());
for (long long a : ans) {
cout << a << " ";
}
cout << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long long N, M;
string S;
cin >> N >> M >> S;
if (S.front() != '0') {
cout << -1 << endl;
}
if (S.back() != '0') {
cout << -1 << endl;
}
reverse(S.begin(), S.end());
vector<bool> over(S.size());
for (int i = 0; i < over.size(); i++) {
over[i] = S[i] == '0';
}
bool now = true;
long long count = 0;
vector<pair<bool, long long>> comp;
for (int i = 0; i < over.size(); i++) {
if (now != over[i]) {
comp.push_back(make_pair(now, count));
now = over[i];
count = 1;
} else {
count++;
}
}
if (count > 0) {
comp.push_back(make_pair(now, count));
}
vector<long long> ans;
long long current = 0;
long long idx = 0;
long long remain = comp[0].second - 1;
while (N > 0) {
long long m = M;
long long sum = 0;
while (m > 0) {
if (remain == 0) {
if ((idx + 1) < comp.size() && comp[idx + 1].second < m) {
m -= comp[idx + 1].second + 1;
sum += comp[idx + 1].second + 1;
idx += 2;
remain = comp[idx].second - 1;
} else {
m = 0;
}
} else {
long long d = min(remain, m);
sum += d;
m -= d;
remain -= d;
}
}
if (sum == 0) {
cout << -1 << endl;
return 0;
}
ans.push_back(min(N, sum));
N -= sum;
}
reverse(ans.begin(), ans.end());
for (long long a : ans) {
cout << a << " ";
}
cout << endl;
}
| replace | 46 | 47 | 46 | 47 | 0 | |
p02852 | C++ | Runtime Error | #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int n, m;
cin >> n >> m;
char s[100010];
cin >> s;
int r = 0, idx = 0;
while (idx < n) {
for (int i = m; i >= 0; i--) {
if (i == 0) {
cout << -1 << endl;
return 0;
}
if (s[idx + i] == '0') {
idx += i;
r++;
break;
}
}
}
int ans[100010] = {};
int r2 = 0;
idx = n;
while (idx > 0) {
for (int i = m; i >= 0; i--) {
if (idx - i >= 0 && s[idx - i] == '0') {
idx -= i;
ans[r2++] = i;
break;
}
}
}
for (int i = r2 - 1; i >= 0; i--) {
if (i != r2 - 1)
cout << " ";
cout << ans[i];
}
cout << endl;
}
| #include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int n, m;
cin >> n >> m;
char s[100010];
cin >> s;
int r = 0, idx = 0;
while (idx < n) {
for (int i = m; i >= 0; i--) {
if (i == 0) {
cout << -1 << endl;
return 0;
}
if (idx + i <= n && s[idx + i] == '0') {
idx += i;
r++;
break;
}
}
}
int ans[100010] = {};
int r2 = 0;
idx = n;
while (idx > 0) {
for (int i = m; i >= 0; i--) {
if (idx - i >= 0 && s[idx - i] == '0') {
idx -= i;
ans[r2++] = i;
break;
}
}
}
for (int i = r2 - 1; i >= 0; i--) {
if (i != r2 - 1)
cout << " ";
cout << ans[i];
}
cout << endl;
}
| replace | 25 | 26 | 25 | 26 | 0 | |
p02852 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << endl
#define STI(s) atoi(s.c_str())
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
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;
}
struct io {
io() {
ios::sync_with_stdio(false);
cin.tie(0);
};
};
const ll MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL << 62;
bool isgoal(vi &v, vi &w, int m) {
for (int i = 0; i < v.size(); i++) {
if (w[i] - v[i] + 1 >= m) {
return false;
}
}
return true;
}
int main(void) {
int n, m;
cin >> n >> m;
string s;
vi v, w;
cin >> s;
reverse(all(s));
for (int i = 0; i < s.size(); i++) {
if (s[i] == '1') {
int maxpos = i;
v.push_back(i);
while (s[i + 1] == '1') {
maxpos = i + 1;
i++;
}
w.push_back(maxpos);
}
}
if (!isgoal(v, w, m)) {
fin(-1);
return 0;
}
int pos = 0;
vi pass;
while (pos != n) {
auto nextpos = lower_bound(all(v), pos + m);
if (nextpos == v.end()) {
} else if (*nextpos != pos + m && nextpos != v.begin()) {
nextpos--;
}
// cout<<m+pos<<" "<<*nextpos<<"
// "<<*(abs(distance(nextpos,v.begin()))+w.begin())<<endl;
// cout<<distance(nextpos,v.begin())<<endl;
if (m + pos >= n) {
// cout<<"A"<<endl;
pass.push_back(n - pos);
pos = n;
} else if (m + pos >= *nextpos &&
*(abs(distance(nextpos, v.begin())) + w.begin()) >= m + pos) {
// cout<<"B"<<endl;
pass.push_back(*nextpos - 1 - pos);
pos = *nextpos - 1;
} else {
// cout<<"C"<<endl;
pass.push_back(m);
pos += m;
}
}
reverse(all(pass));
rep(i, pass.size()) {
if (i == 0)
cout << pass[i];
else
cout << " " << pass[i];
}
cout << endl;
}
| #include <algorithm>
#include <bitset>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << endl
#define STI(s) atoi(s.c_str())
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
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;
}
struct io {
io() {
ios::sync_with_stdio(false);
cin.tie(0);
};
};
const ll MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL << 62;
bool isgoal(vi &v, vi &w, int m) {
for (int i = 0; i < v.size(); i++) {
if (w[i] - v[i] + 1 >= m) {
return false;
}
}
return true;
}
int main(void) {
int n, m;
cin >> n >> m;
string s;
vi v, w;
cin >> s;
reverse(all(s));
for (int i = 0; i < s.size(); i++) {
if (s[i] == '1') {
int maxpos = i;
v.push_back(i);
while (s[i + 1] == '1') {
maxpos = i + 1;
i++;
}
w.push_back(maxpos);
}
}
if (!isgoal(v, w, m)) {
fin(-1);
return 0;
}
int pos = 0;
vi pass;
while (pos != n) {
auto nextpos = lower_bound(all(v), pos + m);
if (nextpos == v.end()) {
} else if (*nextpos != pos + m && nextpos != v.begin()) {
nextpos--;
}
// cout<<m+pos<<" "<<*nextpos<<"
// "<<*(abs(distance(nextpos,v.begin()))+w.begin())<<endl;
// cout<<distance(nextpos,v.begin())<<endl;
if (m + pos >= n) {
// cout<<"A"<<endl;
pass.push_back(n - pos);
pos = n;
} else if (nextpos != v.end() && m + pos >= *nextpos &&
*(abs(distance(nextpos, v.begin())) + w.begin()) >= m + pos) {
// cout<<"B"<<endl;
pass.push_back(*nextpos - 1 - pos);
pos = *nextpos - 1;
} else {
// cout<<"C"<<endl;
pass.push_back(m);
pos += m;
}
}
reverse(all(pass));
rep(i, pass.size()) {
if (i == 0)
cout << pass[i];
else
cout << " " << pass[i];
}
cout << endl;
}
| replace | 116 | 117 | 116 | 117 | 0 | |
p02852 | C++ | Runtime Error | // includes {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;
// SegmentTree( size [, initial] )
// SegmentTree( <data> )
/// --- SegmentTree {{{ ///
#include <cassert>
#include <initializer_list>
#include <iostream>
#include <iterator>
#include <vector>
template <class Monoid> struct SegmentTree {
private:
using T = typename Monoid::T;
using size_type = std::size_t;
size_type n;
std::vector<T> data;
// call after touch data[i]
void prop(int i) { data[i] = Monoid::op(data[2 * i], data[2 * i + 1]); }
public:
SegmentTree() : n(0) {}
SegmentTree(int n, T initial = Monoid::identity()) : n(n) {
data.resize(n * 2, initial);
for (int i = n - 1; i > 0; i--)
data[i] = Monoid::op(data[i * 2], data[i * 2 + 1]);
}
template <class InputIter,
class = typename std::iterator_traits<InputIter>::value_type>
SegmentTree(InputIter first, InputIter last)
: SegmentTree(distance(first, last)) {
copy(first, last, data.begin() + n);
// fill from deep
for (int i = n - 1; i > 0; i--)
prop(i);
}
SegmentTree(std::vector<T> v) : SegmentTree(v.begin(), v.end()) {}
SegmentTree(std::initializer_list<T> v) : SegmentTree(v.begin(), v.end()) {}
void set(size_t i, const T &v) {
assert(i < n);
data[i += n] = v;
while (i >>= 1)
prop(i); // propUp
}
T get(size_t i) {
assert(i < n);
return data[i + n];
}
T fold(int l, int r) {
if (l < 0)
l = 0;
if (l >= r)
return Monoid::identity();
if (r > static_cast<int>(n))
r = n;
T tmpL = Monoid::identity(), tmpR = Monoid::identity();
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1)
tmpL = Monoid::op(tmpL, data[l++]);
if (r & 1)
tmpR = Monoid::op(data[--r], tmpR);
}
return Monoid::op(tmpL, tmpR);
}
size_type size() { return n; }
inline void dum(int r = -1) {
#ifdef DEBUG
if (r < 0)
r = n;
DEBUG_OUT << "{";
for (int i = 0; i < std::min<int>(r, n); i++)
DEBUG_OUT << (i ? ", " : "") << get(i);
DEBUG_OUT << "}" << std::endl;
#endif
}
};
/// }}}--- ///
/// --- Monoid examples {{{ ///
constexpr int inf_monoid = 1e9;
#include <algorithm>
struct Nothing {
using T = char;
using Monoid = Nothing;
using M = T;
static constexpr T op(const T &, const T &) { return T(); }
static constexpr T identity() { return T(); }
template <class X>
static constexpr X actInto(const M &, long long, const X &x) {
return x;
}
};
template <class U = long long> struct RangeMin {
using T = U;
static T op(const T &a, const T &b) { return std::min<T>(a, b); }
static constexpr T identity() { return T(inf_monoid, inf_monoid); }
};
template <class U = long long> struct RangeMax {
using T = U;
static T op(const T &a, const T &b) { return std::max<T>(a, b); }
static constexpr T identity() { return T(-inf_monoid); }
};
template <class U = long long> struct RangeSum {
using T = U;
static T op(const T &a, const T &b) { return a + b; }
static constexpr T identity() { return T(0); }
};
template <class U> struct RangeProd {
using T = U;
static T op(const T &a, const T &b) { return a * b; }
static constexpr T identity() { return T(1); }
};
template <class U = long long> struct RangeOr {
using T = U;
static T op(const T &a, const T &b) { return a | b; }
static constexpr T identity() { return T(0); }
};
#include <bitset>
template <class U = long long> struct RangeAnd {
using T = U;
static T op(const T &a, const T &b) { return a & b; }
static constexpr T identity() { return T(-1); }
};
template <size_t N> struct RangeAnd<std::bitset<N>> {
using T = std::bitset<N>;
static T op(const T &a, const T &b) { return a & b; }
static constexpr T identity() { return std::bitset<N>().set(); }
};
/// }}}--- ///
using Seg = SegmentTree<RangeMin<pair<int, int>>>;
int main() {
std::ios::sync_with_stdio(false), std::cin.tie(0);
int n, m;
string s;
cin >> n >> m;
cin >> s;
Seg seg(n + 1);
seg.set(n, pair<int, int>(0, n));
vector<int> nxt(n + 1, -1);
for (int i = n - 1; i >= 0; i--)
if (s[i] == '0') {
int d, j;
tie(d, j) = seg.fold(i + 1, min(n + 1, i + m + 1));
nxt[i] = j;
seg.set(i, pair<int, int>(d + 1, i));
}
if (nxt[0] == -1)
return cout << -1 << endl, 0;
int now = 0;
while (now != n) {
cout << nxt[now] - now << " ";
now = nxt[now];
}
return 0;
}
| // includes {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;
// SegmentTree( size [, initial] )
// SegmentTree( <data> )
/// --- SegmentTree {{{ ///
#include <cassert>
#include <initializer_list>
#include <iostream>
#include <iterator>
#include <vector>
template <class Monoid> struct SegmentTree {
private:
using T = typename Monoid::T;
using size_type = std::size_t;
size_type n;
std::vector<T> data;
// call after touch data[i]
void prop(int i) { data[i] = Monoid::op(data[2 * i], data[2 * i + 1]); }
public:
SegmentTree() : n(0) {}
SegmentTree(int n, T initial = Monoid::identity()) : n(n) {
data.resize(n * 2, initial);
for (int i = n - 1; i > 0; i--)
data[i] = Monoid::op(data[i * 2], data[i * 2 + 1]);
}
template <class InputIter,
class = typename std::iterator_traits<InputIter>::value_type>
SegmentTree(InputIter first, InputIter last)
: SegmentTree(distance(first, last)) {
copy(first, last, data.begin() + n);
// fill from deep
for (int i = n - 1; i > 0; i--)
prop(i);
}
SegmentTree(std::vector<T> v) : SegmentTree(v.begin(), v.end()) {}
SegmentTree(std::initializer_list<T> v) : SegmentTree(v.begin(), v.end()) {}
void set(size_t i, const T &v) {
assert(i < n);
data[i += n] = v;
while (i >>= 1)
prop(i); // propUp
}
T get(size_t i) {
assert(i < n);
return data[i + n];
}
T fold(int l, int r) {
if (l < 0)
l = 0;
if (l >= r)
return Monoid::identity();
if (r > static_cast<int>(n))
r = n;
T tmpL = Monoid::identity(), tmpR = Monoid::identity();
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1)
tmpL = Monoid::op(tmpL, data[l++]);
if (r & 1)
tmpR = Monoid::op(data[--r], tmpR);
}
return Monoid::op(tmpL, tmpR);
}
size_type size() { return n; }
inline void dum(int r = -1) {
#ifdef DEBUG
if (r < 0)
r = n;
DEBUG_OUT << "{";
for (int i = 0; i < std::min<int>(r, n); i++)
DEBUG_OUT << (i ? ", " : "") << get(i);
DEBUG_OUT << "}" << std::endl;
#endif
}
};
/// }}}--- ///
/// --- Monoid examples {{{ ///
constexpr int inf_monoid = 1e9;
#include <algorithm>
struct Nothing {
using T = char;
using Monoid = Nothing;
using M = T;
static constexpr T op(const T &, const T &) { return T(); }
static constexpr T identity() { return T(); }
template <class X>
static constexpr X actInto(const M &, long long, const X &x) {
return x;
}
};
template <class U = long long> struct RangeMin {
using T = U;
static T op(const T &a, const T &b) { return std::min<T>(a, b); }
static constexpr T identity() { return T(inf_monoid, inf_monoid); }
};
template <class U = long long> struct RangeMax {
using T = U;
static T op(const T &a, const T &b) { return std::max<T>(a, b); }
static constexpr T identity() { return T(-inf_monoid); }
};
template <class U = long long> struct RangeSum {
using T = U;
static T op(const T &a, const T &b) { return a + b; }
static constexpr T identity() { return T(0); }
};
template <class U> struct RangeProd {
using T = U;
static T op(const T &a, const T &b) { return a * b; }
static constexpr T identity() { return T(1); }
};
template <class U = long long> struct RangeOr {
using T = U;
static T op(const T &a, const T &b) { return a | b; }
static constexpr T identity() { return T(0); }
};
#include <bitset>
template <class U = long long> struct RangeAnd {
using T = U;
static T op(const T &a, const T &b) { return a & b; }
static constexpr T identity() { return T(-1); }
};
template <size_t N> struct RangeAnd<std::bitset<N>> {
using T = std::bitset<N>;
static T op(const T &a, const T &b) { return a & b; }
static constexpr T identity() { return std::bitset<N>().set(); }
};
/// }}}--- ///
using Seg = SegmentTree<RangeMin<pair<int, int>>>;
int main() {
std::ios::sync_with_stdio(false), std::cin.tie(0);
int n, m;
string s;
cin >> n >> m;
cin >> s;
Seg seg(n + 1);
seg.set(n, pair<int, int>(0, n));
vector<int> nxt(n + 1, -1);
for (int i = n - 1; i >= 0; i--)
if (s[i] == '0') {
int d, j;
tie(d, j) = seg.fold(i + 1, min(n + 1, i + m + 1));
if (j > n)
continue;
nxt[i] = j;
seg.set(i, pair<int, int>(d + 1, i));
}
if (nxt[0] == -1)
return cout << -1 << endl, 0;
int now = 0;
while (now != n) {
cout << nxt[now] - now << " ";
now = nxt[now];
}
return 0;
}
| insert | 174 | 174 | 174 | 176 | 0 | |
p02852 | C++ | Time Limit Exceeded | #pragma target("avx")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;
#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
//------ Believe yourself as a genius!!!!!! ------
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;
V ans;
int main(void) {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
cin >> n >> m >> s;
ll now = n;
while (1) {
if (now - m <= 0) {
ans.p_b(abs(now));
break;
} else {
int ok = 0;
ll dis = m;
rrep(i, now - m, n) {
if (s[i] == '0') {
now = i;
ans.p_b(dis);
ok = 1;
break;
} else
dis--;
}
if (!ok) {
Cout(-1);
return 0;
}
}
}
reverse(all(ans));
rep(i, Size(ans)) cout << ans[i] << " ";
cout << "\n";
return 0;
} | #pragma target("avx")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;
#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
//------ Believe yourself as a genius!!!!!! ------
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;
V ans;
int main(void) {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
cin >> n >> m >> s;
ll now = n;
while (1) {
if (now - m <= 0) {
ans.p_b(abs(now));
break;
} else {
int ok = 0;
ll dis = m;
rrep(i, now - m, now) {
if (s[i] == '0') {
now = i;
ans.p_b(dis);
ok = 1;
break;
} else
dis--;
}
if (!ok) {
Cout(-1);
return 0;
}
}
}
reverse(all(ans));
rep(i, Size(ans)) cout << ans[i] << " ";
cout << "\n";
return 0;
} | replace | 50 | 51 | 50 | 51 | TLE | |
p02852 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
// #pragma optimization_level 3
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define f0r(a, b) for (long long a = 0; a < (b); a++)
#define f1r(a, b, c) for (long long a = (b); a < (c); a++)
#define f0rd(a, b) for (long long a = (b); a >= 0; a--)
#define f1rd(a, b, c) for (long long a = (b); a >= (c); a--)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define pb push_back
#define io \
{ \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL); \
}
#define fix(prec) \
{ cout << setprecision(prec) << fixed; }
#define mp make_pair
#define f first
#define s second
#define presum(p, a, n) \
{ \
p[0] = a[0]; \
for (int i = 1; i < (n); i++) \
p[i] = a[i] + p[i - 1]; \
}
#define all(v) v.begin(), v.end()
#define getunique(v) \
{ \
sort(all(v)); \
v.erase(unique(all(v)), v.end()); \
}
#define readgraph(list, edges) \
for (int i = 0; i < edges; i++) { \
int a, b; \
cin >> a >> b; \
a--; \
b--; \
list[a].pb(b); \
list[b].pb(a); \
}
#define ai(a, n) \
for (int ele = 0; ele < n; ele++) \
cin >> a[ele];
#define ain(a, lb, rb) \
for (int ele = lb; ele <= rb; ele++) \
cin >> a[ele];
#define ao(a, n) \
{ \
for (int ele = 0; ele < n; ele++) { \
if (ele) \
cout << " "; \
cout << a[ele]; \
} \
cout << '\n'; \
}
#define aout(a, lb, rb) \
{ \
for (int ele = lb; ele <= rb; ele++) { \
if (ele > lb) \
cout << " "; \
cout << a[ele]; \
} \
cout << '\n'; \
}
typedef long long ll;
typedef double ld;
typedef long double lld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
template <typename A> ostream &operator<<(ostream &cout, vector<A> const &v);
template <typename A, typename B>
ostream &operator<<(ostream &cout, pair<A, B> const &p) {
return cout << "(" << p.f << ", " << p.s << ")";
}
template <typename A> ostream &operator<<(ostream &cout, vector<A> const &v) {
cout << "[";
for (int i = 0; i < v.size(); i++) {
if (i)
cout << ", ";
cout << v[i];
}
return cout << "]";
}
template <typename A, typename B>
istream &operator>>(istream &cin, pair<A, B> &p) {
cin >> p.first;
return cin >> p.second;
}
// template<typename A, typename B> ll max(A x, B y) {
// return x > y ? x : y;
// }
// template<typename A, typename B> ll min(A x, B y) {
// return x < y ? x : y;
// }
mt19937 rng(steady_clock::now().time_since_epoch().count());
/* usage - just do rng() */
void usaco(string filename) {
// #pragma message("be careful, freopen may be wrong")
freopen((filename + ".in").c_str(), "r", stdin);
freopen((filename + ".out").c_str(), "w", stdout);
}
const lld pi = 3.14159265358979323846;
const ll mod = 1000000007;
// const ll mod = 998244353;
ll n, m, k, q, Q, T, l, r, x, y, z;
ll a[1000005];
ll b[1000005];
ll c[1000005];
string s, t;
ll ans = 0;
ll dp[100005];
bool pos[100005];
int main() {
io;
// freopen("case", "r", stdin);
// freopen("test.txt", "r", stdin);
// freopen("case", "w", stdout);
// freopen("file.in", "r", stdin);
// usaco("file");
cin >> n >> k;
cin >> s;
f0r(i, n + 1) pos[i] = (s[i] == '0');
ms(dp, 0);
bool f = 1;
f0rd(i, n) {
if (i == 0)
break;
bool found = 0;
int best = i;
f1rd(j, i - 1, i - k) {
if (pos[j]) {
best = j;
found = 1;
dp[j] = dp[i] + 1;
}
}
if (!found) {
f = 0;
break;
}
i = best + 1;
}
if (!f) {
cout << -1 << endl;
} else {
int pt = 0;
while (pt < n) {
f1r(j, pt + 1, pt + k + 1) {
if (pos[j] && dp[j] < dp[pt]) {
cout << j - pt << " ";
pt = j;
break;
}
}
}
}
} | #include <bits/stdc++.h>
#include <chrono>
using namespace std;
using namespace std::chrono;
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
// #pragma optimization_level 3
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define f0r(a, b) for (long long a = 0; a < (b); a++)
#define f1r(a, b, c) for (long long a = (b); a < (c); a++)
#define f0rd(a, b) for (long long a = (b); a >= 0; a--)
#define f1rd(a, b, c) for (long long a = (b); a >= (c); a--)
#define ms(arr, v) memset(arr, v, sizeof(arr))
#define pb push_back
#define io \
{ \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL); \
}
#define fix(prec) \
{ cout << setprecision(prec) << fixed; }
#define mp make_pair
#define f first
#define s second
#define presum(p, a, n) \
{ \
p[0] = a[0]; \
for (int i = 1; i < (n); i++) \
p[i] = a[i] + p[i - 1]; \
}
#define all(v) v.begin(), v.end()
#define getunique(v) \
{ \
sort(all(v)); \
v.erase(unique(all(v)), v.end()); \
}
#define readgraph(list, edges) \
for (int i = 0; i < edges; i++) { \
int a, b; \
cin >> a >> b; \
a--; \
b--; \
list[a].pb(b); \
list[b].pb(a); \
}
#define ai(a, n) \
for (int ele = 0; ele < n; ele++) \
cin >> a[ele];
#define ain(a, lb, rb) \
for (int ele = lb; ele <= rb; ele++) \
cin >> a[ele];
#define ao(a, n) \
{ \
for (int ele = 0; ele < n; ele++) { \
if (ele) \
cout << " "; \
cout << a[ele]; \
} \
cout << '\n'; \
}
#define aout(a, lb, rb) \
{ \
for (int ele = lb; ele <= rb; ele++) { \
if (ele > lb) \
cout << " "; \
cout << a[ele]; \
} \
cout << '\n'; \
}
typedef long long ll;
typedef double ld;
typedef long double lld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
template <typename A> ostream &operator<<(ostream &cout, vector<A> const &v);
template <typename A, typename B>
ostream &operator<<(ostream &cout, pair<A, B> const &p) {
return cout << "(" << p.f << ", " << p.s << ")";
}
template <typename A> ostream &operator<<(ostream &cout, vector<A> const &v) {
cout << "[";
for (int i = 0; i < v.size(); i++) {
if (i)
cout << ", ";
cout << v[i];
}
return cout << "]";
}
template <typename A, typename B>
istream &operator>>(istream &cin, pair<A, B> &p) {
cin >> p.first;
return cin >> p.second;
}
// template<typename A, typename B> ll max(A x, B y) {
// return x > y ? x : y;
// }
// template<typename A, typename B> ll min(A x, B y) {
// return x < y ? x : y;
// }
mt19937 rng(steady_clock::now().time_since_epoch().count());
/* usage - just do rng() */
void usaco(string filename) {
// #pragma message("be careful, freopen may be wrong")
freopen((filename + ".in").c_str(), "r", stdin);
freopen((filename + ".out").c_str(), "w", stdout);
}
const lld pi = 3.14159265358979323846;
const ll mod = 1000000007;
// const ll mod = 998244353;
ll n, m, k, q, Q, T, l, r, x, y, z;
ll a[1000005];
ll b[1000005];
ll c[1000005];
string s, t;
ll ans = 0;
ll dp[100005];
bool pos[100005];
int main() {
io;
// freopen("case", "r", stdin);
// freopen("test.txt", "r", stdin);
// freopen("case", "w", stdout);
// freopen("file.in", "r", stdin);
// usaco("file");
cin >> n >> k;
cin >> s;
f0r(i, n + 1) pos[i] = (s[i] == '0');
ms(dp, 0);
bool f = 1;
f0rd(i, n) {
if (i == 0)
break;
bool found = 0;
int best = i;
f1rd(j, i - 1, max(0LL, i - k)) {
if (pos[j]) {
best = j;
found = 1;
dp[j] = dp[i] + 1;
}
}
if (!found) {
f = 0;
break;
}
i = best + 1;
}
if (!f) {
cout << -1 << endl;
} else {
int pt = 0;
while (pt < n) {
f1r(j, pt + 1, pt + k + 1) {
if (pos[j] && dp[j] < dp[pt]) {
cout << j - pt << " ";
pt = j;
break;
}
}
}
}
} | replace | 156 | 157 | 156 | 157 | 0 | |
p02852 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long int ll;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, k;
cin >> n >> k;
string s;
cin >> s;
int now = n;
vector<int> ans;
while (now) {
for (int i = k; i >= 0; i--) {
if (now - i >= 0 && s[now - i] == '0') {
ans.push_back(i);
now -= i;
break;
}
if (i == 0) {
cout << -1 << endl;
return 0;
}
}
}
reverse(ans.begin(), ans.end());
for (int p : ans) {
cout << p << endl;
}
} | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long int ll;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n, k;
cin >> n >> k;
string s;
cin >> s;
int now = n;
vector<int> ans;
while (now) {
for (int i = k; i >= 0; i--) {
if (now - i >= 0 && s[now - i] == '0' && i) {
ans.push_back(i);
now -= i;
break;
}
if (i == 0) {
cout << -1 << endl;
return 0;
}
}
}
reverse(ans.begin(), ans.end());
for (int p : ans) {
cout << p << endl;
}
} | replace | 21 | 22 | 21 | 22 | TLE | |
p02852 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
vector<int> ans;
int t = n;
while (t != 0) {
int i = m;
for (i = m; i >= 0; i--) {
if (s[t - i] == '0') {
ans.push_back(i);
t -= i;
break;
}
}
if (i == 0) {
cout << -1 << endl;
return 0;
}
}
for (int i = ans.size() - 1; i >= 0; i--) {
cout << ans[i] << " ";
}
cout << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
string s;
cin >> s;
vector<int> ans;
int t = n;
while (t != 0) {
int i = m;
for (i = min(t, m); i >= 0; i--) {
if (s[t - i] == '0') {
ans.push_back(i);
t -= i;
break;
}
}
if (i == 0) {
cout << -1 << endl;
return 0;
}
}
for (int i = ans.size() - 1; i >= 0; i--) {
cout << ans[i] << " ";
}
cout << endl;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p02852 | C++ | Runtime Error | #include <deque>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
int n, m;
string s;
cin >> n >> m >> s;
vector<int> ans(n);
deque<pair<int, int>> d;
for (int i = 0; i < n; i++) {
ans[i] = -1;
}
ans[n] = 0;
d.push_back({0, n});
for (int i = n - 1; i >= 0; i--) {
if (!d.empty() && d[0].second > i + m) {
d.pop_front();
}
if (!d.empty() && s[i] == '0') {
ans[i] = d[0].first + 1;
d.push_back({ans[i], i});
}
}
if (ans[0] == -1) {
cout << -1 << endl;
} else {
int p = 0;
for (int i = 0; i <= n; i++) {
if (ans[i] == ans[p] - 1) {
cout << i - p << " ";
p = i;
}
}
cout << endl;
}
} | #include <deque>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
int n, m;
string s;
cin >> n >> m >> s;
vector<int> ans(n + 1);
deque<pair<int, int>> d;
for (int i = 0; i < n; i++) {
ans[i] = -1;
}
ans[n] = 0;
d.push_back({0, n});
for (int i = n - 1; i >= 0; i--) {
if (!d.empty() && d[0].second > i + m) {
d.pop_front();
}
if (!d.empty() && s[i] == '0') {
ans[i] = d[0].first + 1;
d.push_back({ans[i], i});
}
}
if (ans[0] == -1) {
cout << -1 << endl;
} else {
int p = 0;
for (int i = 0; i <= n; i++) {
if (ans[i] == ans[p] - 1) {
cout << i - p << " ";
p = i;
}
}
cout << endl;
}
} | replace | 11 | 12 | 11 | 12 | 0 | |
p02852 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(name) name.begin(), name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif
const ll LLINF = (1LL << 60);
const int INF = (1LL << 30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010
int N, M;
string S;
vector<int> l_zero,
r_zero; // i からみて 1 がないすぐ左/右の場所(自分が 0 なら自分)
signed main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
cin >> N >> M >> S;
// -1 チェック
int cnt = 0;
REP(i, N + 1) {
if (S[i] == '1') {
cnt++;
if (cnt >= M) {
printf("-1\n");
return 0;
}
} else {
cnt = 0;
}
}
// l_zero, r_zero の作成
l_zero.assign(N + 1, -1);
r_zero.assign(N + 1, -1);
int cur = 0;
REP(i, N + 1) {
if (S[i] == '0') {
cur = i;
}
l_zero[i] = cur;
}
cur = N;
for (int i = N; i >= 0; --i) {
if (S[i] == '0') {
cur = i;
}
r_zero[i] = cur;
}
// まず最短距離を出す
int ans_dist = 0;
vector<int> ans_pos;
cur = 0;
ans_pos.push_back(0);
while (cur < N) {
// 行けそうなら行く
if (cur + M >= N) {
cur = N;
ans_dist++;
break;
}
int next_cur = cur + M;
if (S[next_cur] == '1') {
next_cur = l_zero[next_cur];
}
cur = next_cur;
ans_pos.push_back(cur);
ans_dist++;
}
ans_pos.push_back(N);
// ans_pos を左に寄せられないか調整
reverse(ans_pos.begin(), ans_pos.end());
vector<int> ans_r;
REP(i, ans_pos.size() - 1) {
// 現在の移動距離
int cur_dist = ans_pos[i] - ans_pos[i + 1];
// まだいける移動距離
int sub_dist = M - cur_dist;
int new_pos = ans_pos[i + 1] - sub_dist;
new_pos = r_zero[new_pos];
int new_dist = ans_pos[i] - new_pos;
ans_r.push_back(new_dist);
ans_pos[i + 1] = new_pos;
}
reverse(ans_r.begin(), ans_r.end());
REP(i, ans_r.size()) {
printf("%lld%c", ans_r[i], (i == ans_r.size() - 1) ? '\n' : ' ');
}
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(name) name.begin(), name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#define DBG(fmt, ...)
#endif
const ll LLINF = (1LL << 60);
const int INF = (1LL << 30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010
int N, M;
string S;
vector<int> l_zero,
r_zero; // i からみて 1 がないすぐ左/右の場所(自分が 0 なら自分)
signed main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
cin >> N >> M >> S;
// -1 チェック
int cnt = 0;
REP(i, N + 1) {
if (S[i] == '1') {
cnt++;
if (cnt >= M) {
printf("-1\n");
return 0;
}
} else {
cnt = 0;
}
}
// l_zero, r_zero の作成
l_zero.assign(N + 1, -1);
r_zero.assign(N + 1, -1);
int cur = 0;
REP(i, N + 1) {
if (S[i] == '0') {
cur = i;
}
l_zero[i] = cur;
}
cur = N;
for (int i = N; i >= 0; --i) {
if (S[i] == '0') {
cur = i;
}
r_zero[i] = cur;
}
// まず最短距離を出す
int ans_dist = 0;
vector<int> ans_pos;
cur = 0;
ans_pos.push_back(0);
while (cur < N) {
// 行けそうなら行く
if (cur + M >= N) {
cur = N;
ans_dist++;
break;
}
int next_cur = cur + M;
if (S[next_cur] == '1') {
next_cur = l_zero[next_cur];
}
cur = next_cur;
ans_pos.push_back(cur);
ans_dist++;
}
ans_pos.push_back(N);
// ans_pos を左に寄せられないか調整
reverse(ans_pos.begin(), ans_pos.end());
vector<int> ans_r;
REP(i, ans_pos.size() - 1) {
// 現在の移動距離
int cur_dist = ans_pos[i] - ans_pos[i + 1];
// まだいける移動距離
int sub_dist = M - cur_dist;
int new_pos = ans_pos[i + 1] - sub_dist;
if (new_pos < 0) {
new_pos = 0;
}
new_pos = r_zero[new_pos];
int new_dist = ans_pos[i] - new_pos;
ans_r.push_back(new_dist);
ans_pos[i + 1] = new_pos;
}
reverse(ans_r.begin(), ans_r.end());
REP(i, ans_r.size()) {
printf("%lld%c", ans_r[i], (i == ans_r.size() - 1) ? '\n' : ' ');
}
return 0;
}
| insert | 101 | 101 | 101 | 104 | 0 | |
p02852 | C++ | Runtime Error | // May this submission get accepted!
#pragma GCC optimize("O3")
#pragma GCC target("tune=native")
#pragma GCC target("avx")
#include <bits/stdc++.h>
// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i, n) for (long long i = 0, i##_len = (n); i < i##_len; i++)
#define RANGE(i, is, ie) \
for (long long i = (is), i##_end = (ie); i <= i##_end; i++)
#define DSRNG(i, is, ie) \
for (long long i = (is), i##_end = (ie); i >= i##_end; i--)
#define STEP(i, is, ie, step) \
for (long long i = (is), i##_end = (ie), i##_step = (step); i <= i##_end; \
i += i##_step)
#define UNIQUE(v) \
do { \
sort((v).begin(), (v).end()); \
(v).erase(unique((v).begin(), (v).end()), (v).end()); \
} while (false)
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) \
cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) \
do { \
cerr << "[DEBUG] " #q ": ["; \
REP(DUMPALL_ITR, (q).size()) { \
cerr << (q)[DUMPALL_ITR] \
<< (DUMPALL_ITR == DUMPALL_ITR_len - 1 ? "" : ", "); \
} \
cerr << "] at " __FILE__ ":" << __LINE__ << endl; \
} while (false)
template <class T> T gcd(T a, T b) {
if (a < b)
std::swap(a, b);
while (b)
std::swap(a %= b, b);
return a;
}
template <class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }
// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using ld = long double;
using namespace std;
// モジュール
bool found = false;
// ランレングス圧縮 O(N)
template <class RandomAccessIterator>
vector<ll> run_length(RandomAccessIterator first, RandomAccessIterator last) {
vector<ll> rl;
for (RandomAccessIterator itr = first; itr != last;) {
RandomAccessIterator jtr = itr++;
while ((itr != last && *itr == *(itr - 1)))
itr++;
rl.push_back(itr - jtr);
}
return rl;
}
void dfs(ll i, ll &n, ll &m, vector<ll> &from, string &s) {
if (i == 0) {
found = true;
return;
}
RANGE(di, -m, -1) {
if (i + di < 0)
continue;
if (s[i + di] == '0') {
from[i + di] = i;
dfs(i + di, n, m, from, s);
if (found)
return;
}
}
}
// 処理内容
int main() {
// インタラクティブ問題では除去した方がいいかも
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n, m;
cin >> n >> m;
string s;
cin >> s;
auto rl = run_length(ALL_OF(s));
REP(i, n) {
if (i % 2 == 0)
continue;
if (rl[i] >= m) {
cout << -1 << endl;
return 0;
}
}
vector<ll> from(n + 1, -1);
dfs(n, n, m, from, s);
if (from[0] == -1) {
cout << -1 << endl;
return 0;
}
vector<ll> ans;
ans.reserve(n + 1);
ll b = 0;
while (b < n) {
ll pb = b;
b = from[b];
ans.push_back(b - pb);
}
REP(i, ans.size()) { cout << ans[i] << " \n"[i == i_len - 1]; }
} | // May this submission get accepted!
#pragma GCC optimize("O3")
#pragma GCC target("tune=native")
#pragma GCC target("avx")
#include <bits/stdc++.h>
// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i, n) for (long long i = 0, i##_len = (n); i < i##_len; i++)
#define RANGE(i, is, ie) \
for (long long i = (is), i##_end = (ie); i <= i##_end; i++)
#define DSRNG(i, is, ie) \
for (long long i = (is), i##_end = (ie); i >= i##_end; i--)
#define STEP(i, is, ie, step) \
for (long long i = (is), i##_end = (ie), i##_step = (step); i <= i##_end; \
i += i##_step)
#define UNIQUE(v) \
do { \
sort((v).begin(), (v).end()); \
(v).erase(unique((v).begin(), (v).end()), (v).end()); \
} while (false)
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) \
cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) \
do { \
cerr << "[DEBUG] " #q ": ["; \
REP(DUMPALL_ITR, (q).size()) { \
cerr << (q)[DUMPALL_ITR] \
<< (DUMPALL_ITR == DUMPALL_ITR_len - 1 ? "" : ", "); \
} \
cerr << "] at " __FILE__ ":" << __LINE__ << endl; \
} while (false)
template <class T> T gcd(T a, T b) {
if (a < b)
std::swap(a, b);
while (b)
std::swap(a %= b, b);
return a;
}
template <class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }
// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using ld = long double;
using namespace std;
// モジュール
bool found = false;
// ランレングス圧縮 O(N)
template <class RandomAccessIterator>
vector<ll> run_length(RandomAccessIterator first, RandomAccessIterator last) {
vector<ll> rl;
for (RandomAccessIterator itr = first; itr != last;) {
RandomAccessIterator jtr = itr++;
while ((itr != last && *itr == *(itr - 1)))
itr++;
rl.push_back(itr - jtr);
}
return rl;
}
void dfs(ll i, ll &n, ll &m, vector<ll> &from, string &s) {
if (i == 0) {
found = true;
return;
}
RANGE(di, -m, -1) {
if (i + di < 0)
continue;
if (s[i + di] == '0') {
from[i + di] = i;
dfs(i + di, n, m, from, s);
if (found)
return;
}
}
}
// 処理内容
int main() {
// インタラクティブ問題では除去した方がいいかも
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n, m;
cin >> n >> m;
string s;
cin >> s;
auto rl = run_length(ALL_OF(s));
REP(i, rl.size()) {
if (i % 2 == 0)
continue;
if (rl[i] >= m) {
cout << -1 << endl;
return 0;
}
}
vector<ll> from(n + 1, -1);
dfs(n, n, m, from, s);
if (from[0] == -1) {
cout << -1 << endl;
return 0;
}
vector<ll> ans;
ans.reserve(n + 1);
ll b = 0;
while (b < n) {
ll pb = b;
b = from[b];
ans.push_back(b - pb);
}
REP(i, ans.size()) { cout << ans[i] << " \n"[i == i_len - 1]; }
}
| replace | 123 | 124 | 123 | 124 | 0 | |
p02852 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = s; i < (int)n; i++)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; i--)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
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;
}
constexpr long long INF = 1e18;
signed main() {
int N, M;
cin >> N >> M;
string s;
cin >> s;
vector<int> ans;
int now = N;
while (now != 0) {
int flg = 1;
FOR(j, now - M, now) {
if (s[j] == '0') {
ans.push_back(now - j);
now = j;
flg = 0;
break;
}
if (j == now - 1) {
cout << -1 << endl;
return 0;
}
}
}
RREP(i, ans.size()) {
if (i + 1 != ans.size())
cout << " ";
cout << ans[i];
}
cout << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = s; i < (int)n; i++)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; i--)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
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;
}
constexpr long long INF = 1e18;
signed main() {
int N, M;
cin >> N >> M;
string s;
cin >> s;
vector<int> ans;
int now = N;
while (now != 0) {
int flg = 1;
FOR(j, now - M, now) {
if (j < 0)
continue;
if (s[j] == '0') {
ans.push_back(now - j);
now = j;
flg = 0;
break;
}
if (j == now - 1) {
cout << -1 << endl;
return 0;
}
}
}
RREP(i, ans.size()) {
if (i + 1 != ans.size())
cout << " ";
cout << ans[i];
}
cout << endl;
} | insert | 35 | 35 | 35 | 37 | 0 | |
p02852 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, i, j, k, p, last;
string s;
cin >> n >> m >> s;
vector<int> dp(n + 1, -1);
vector<bool> reached(n + 1, false);
last = -1;
p = n - 1;
reached[n] = true;
for (i = n; i >= 1; i--) {
if (s[i] == '1')
continue;
while ((p >= i - m) && (p >= 0)) {
if (s[p] == '0')
last = p;
p--;
}
dp[i] = last;
if (reached[i])
reached[last] = true;
}
if (!reached[0])
cout << "-1\n";
else {
vector<int> ans;
ans.push_back(n);
p = n;
while (dp[p] != -1) {
p = dp[p];
ans.push_back(p);
}
reverse(ans.begin(), ans.end());
for (i = 1; i < ans.size(); i++)
cout << ans[i] - ans[i - 1] << " ";
cout << "\n";
}
return 0;
}
| #include <algorithm>
#include <bitset>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, i, j, k, p, last;
string s;
cin >> n >> m >> s;
vector<int> dp(n + 1, -1);
vector<bool> reached(n + 1, false);
last = -1;
p = n - 1;
reached[n] = true;
for (i = n; i >= 1; i--) {
if (s[i] == '1')
continue;
while ((p >= i - m) && (p >= 0)) {
if (s[p] == '0')
last = p;
p--;
}
dp[i] = last;
if ((last != -1) && (reached[i]))
reached[last] = true;
}
if (!reached[0])
cout << "-1\n";
else {
vector<int> ans;
ans.push_back(n);
p = n;
while (dp[p] != -1) {
p = dp[p];
ans.push_back(p);
}
reverse(ans.begin(), ans.end());
for (i = 1; i < ans.size(); i++)
cout << ans[i] - ans[i - 1] << " ";
cout << "\n";
}
return 0;
}
| replace | 44 | 45 | 44 | 45 | 0 | |
p02852 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, cc, n) for (int i = cc; i <= n; ++i)
#define drep(i, cc, n) for (int i = cc; i >= n; --i)
#define sz(s) (int)(s.size())
#define vecprint(v) \
rep(i, 0, v.size() - 1) cout << v[i] << " "; \
cout << endl;
using namespace std;
const int mod = 1000000007;
typedef long long ll;
typedef pair<int, int> P;
string s;
vector<int> ans;
int m;
bool dfs(int start) {
if (s[start] == '1')
return false;
if (start == 0)
return true;
drep(i, m, 1) {
if (start - i < 0)
continue;
if (dfs(start - i)) {
ans.push_back(i);
return true;
}
}
return false;
}
int main() {
int n;
cin >> n >> m;
cin >> s;
int now = n;
if (dfs(n)) {
vecprint(ans);
return 0;
} else {
puts("-1");
return 0;
}
// cout << ans << endl;
// printf("%.10f\n",ans);
return 0;
} | #include <bits/stdc++.h>
#define rep(i, cc, n) for (int i = cc; i <= n; ++i)
#define drep(i, cc, n) for (int i = cc; i >= n; --i)
#define sz(s) (int)(s.size())
#define vecprint(v) \
rep(i, 0, v.size() - 1) cout << v[i] << " "; \
cout << endl;
using namespace std;
const int mod = 1000000007;
typedef long long ll;
typedef pair<int, int> P;
string s;
vector<int> ans;
int m;
bool dfs(int start) {
if (s[start] == '1')
return false;
if (start == 0)
return true;
drep(i, m, 1) {
if (start - i < 0)
continue;
if (dfs(start - i)) {
ans.push_back(i);
return true;
}
}
return false;
}
int main() {
int n;
cin >> n >> m;
cin >> s;
int now = n;
int cnt = 0;
rep(i, 0, n) {
if (s[i] == '0')
cnt = 0;
else
cnt++;
if (cnt == m) {
puts("-1");
return 0;
}
}
if (dfs(n)) {
vecprint(ans);
return 0;
} else {
puts("-1");
return 0;
}
// cout << ans << endl;
// printf("%.10f\n",ans);
return 0;
} | insert | 37 | 37 | 37 | 48 | TLE | |
p02852 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int n, m, res[100001], cnt = 0;
int book[100001], jud = 1;
string s;
void dfs(int x) {
if (x == 0) {
for (int i = cnt - 1; i >= 0; i--) {
if (i != cnt - 1)
cout << " ";
cout << res[i];
}
jud = 0;
return;
}
for (int i = m; i > 0; i--) {
if (x - i >= 0 && s[x - i] == '0') {
res[cnt++] = i;
dfs(x - i);
if (!jud)
return;
cnt--;
}
}
}
int main() {
cin >> n >> m >> s;
if (s[0] == '1') {
cout << "-1";
return 0;
}
dfs(n);
if (jud)
cout << "-1";
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int n, m, res[100001], cnt = 0;
int book[100001], jud = 1;
string s;
void dfs(int x) {
if (x == 0) {
for (int i = cnt - 1; i >= 0; i--) {
if (i != cnt - 1)
cout << " ";
cout << res[i];
}
jud = 0;
return;
}
for (int i = m; i > 0; i--) {
if (x - i >= 0 && s[x - i] == '0') {
res[cnt++] = i;
dfs(x - i);
return;
}
}
}
int main() {
cin >> n >> m >> s;
if (s[0] == '1') {
cout << "-1";
return 0;
}
dfs(n);
if (jud)
cout << "-1";
return 0;
} | replace | 26 | 29 | 26 | 27 | TLE | |
p02852 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 2e5 + 10, mod = 1e9 + 7;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
string s;
cin >> s;
int cur = n, lst = -1, ch = n - 1;
vector<int> ans;
while (cur != 0) {
for (int i = ch; i >= max(0, cur - m); i--) {
if (s[i] == '0')
lst = i;
ch = i - 1;
}
if (lst == -1)
return cout << -1, 0;
ans.push_back(cur - lst);
cur = lst;
}
reverse(ans.begin(), ans.end());
for (int x : ans)
cout << x << " ";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 2e5 + 10, mod = 1e9 + 7;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
string s;
cin >> s;
int cur = n, lst = -1, ch = n - 1;
vector<int> ans;
while (cur != 0) {
for (int i = ch; i >= max(0, cur - m); i--) {
if (s[i] == '0')
lst = i;
ch = i - 1;
}
if (lst == -1)
return cout << -1, 0;
ans.push_back(cur - lst);
cur = lst;
lst = -1;
}
reverse(ans.begin(), ans.end());
for (int x : ans)
cout << x << " ";
return 0;
}
| insert | 28 | 28 | 28 | 29 | TLE | |
p02852 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <string>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
string str;
set<int> canmove;
cin >> n >> m;
cin >> str;
if (str.find(string(m, '1')) != string::npos) {
cout << "-1\n";
return 0;
}
for (int i = 0; i <= n; i++) {
if (str[i] == '1')
continue;
canmove.insert(i);
}
map<int, int> tomove;
auto ep = end(canmove);
list<int> ans;
int p = n;
while (p > 0) {
auto bp = canmove.lower_bound(p - m);
ans.push_front(p - *bp);
p = *bp;
canmove.erase(bp, canmove.end());
}
while (ans.size() > 1) {
cout << ans.front() << " ";
ans.pop_front();
}
cout << ans.back() << "\n";
} | #include <algorithm>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <string>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
string str;
set<int> canmove;
cin >> n >> m;
cin >> str;
if (str.find(string(m, '1')) != string::npos) {
cout << "-1\n";
return 0;
}
if (m == 1) {
string ans = "1";
for (int i = 1; i < n; i++) {
ans += " 1";
}
cout << ans << "\n";
return 0;
}
for (int i = 0; i <= n; i++) {
if (str[i] == '1')
continue;
canmove.insert(i);
}
map<int, int> tomove;
auto ep = end(canmove);
list<int> ans;
int p = n;
while (p > 0) {
auto bp = canmove.lower_bound(p - m);
ans.push_front(p - *bp);
p = *bp;
canmove.erase(bp, canmove.end());
}
while (ans.size() > 1) {
cout << ans.front() << " ";
ans.pop_front();
}
cout << ans.back() << "\n";
} | insert | 20 | 20 | 20 | 28 | TLE | |
p02852 | C++ | Time Limit Exceeded | #pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define eps 1e-10
using namespace std;
inline int read() {
int x = 0, w = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
w = -1;
c = getchar();
}
while (c <= '9' && c >= '0') {
x = (x << 1) + (x << 3) + c - '0';
c = getchar();
}
return w == 1 ? x : -x;
}
int n, m;
vector<int> ans;
char s[maxn];
int main() {
n = read();
m = read();
scanf("%s", s);
int nw = n;
while (nw != 0) {
int f = 0;
for (int i = max(0, nw - m); i <= nw; i++) {
if (s[i] == '0') {
ans.push_back(nw - i);
nw = i, f = 1;
break;
}
}
if (f == 0) {
puts("-1");
return 0;
}
}
for (int i = ans.size() - 1; i >= 0; i--)
printf("%d ", ans[i]);
return 0;
} | #pragma GCC optimize(2)
#include <bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define eps 1e-10
using namespace std;
inline int read() {
int x = 0, w = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
w = -1;
c = getchar();
}
while (c <= '9' && c >= '0') {
x = (x << 1) + (x << 3) + c - '0';
c = getchar();
}
return w == 1 ? x : -x;
}
int n, m;
vector<int> ans;
char s[maxn];
int main() {
n = read();
m = read();
scanf("%s", s);
int nw = n;
while (nw != 0) {
int f = 0;
for (int i = max(0, nw - m); i < nw; i++) {
if (s[i] == '0') {
ans.push_back(nw - i);
nw = i, f = 1;
break;
}
}
if (f == 0) {
puts("-1");
return 0;
}
}
for (int i = ans.size() - 1; i >= 0; i--)
printf("%d ", ans[i]);
return 0;
} | replace | 34 | 35 | 34 | 35 | TLE | |
p02853 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string, int>;
const double PI = acos(-1);
int main() {
int x, y;
cin >> x >> y;
vector<int> a = {300000, 200000, 100000};
int ans = 0;
ans += a.at(x - 1);
ans += a.at(y - 1);
if (x == 1 && y == 1)
ans += 400000;
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string, int>;
const double PI = acos(-1);
int main() {
int x, y;
cin >> x >> y;
vector<int> a = {300000, 200000, 100000};
int ans = 0;
if (x <= 3)
ans += a.at(x - 1);
if (y <= 3)
ans += a.at(y - 1);
if (x == 1 && y == 1)
ans += 400000;
cout << ans << endl;
}
| replace | 12 | 14 | 12 | 16 | 0 | |
p02853 | C++ | Runtime Error | #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("INPUT.txt", "r", stdin);
freopen("OUTPUT.txt", "w", stdout);
#endif
// -------------------------------------Code starts
// here---------------------------------------------------------------------
int a[400] = {0};
a[1] = 300000;
a[2] = 200000;
a[3] = 100000;
int x, y;
cin >> x >> y;
int s = 0;
s += a[x] + a[y];
if (x == y && x == 1) {
s += 400000;
}
cout << s;
// -------------------------------------Code ends
// here------------------------------------------------------
clock_t clk;
clk = clock();
clk = clock() - clk;
cerr << fixed << setprecision(6) << "Time: " << ((double)clk) / CLOCKS_PER_SEC
<< "\n";
return 0;
} | #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// #ifndef ONLINE_JUDGE
// freopen ("INPUT.txt" , "r" , stdin);
// freopen ("OUTPUT.txt" , "w" , stdout);
// #endif
// -------------------------------------Code starts
// here---------------------------------------------------------------------
int a[400] = {0};
a[1] = 300000;
a[2] = 200000;
a[3] = 100000;
int x, y;
cin >> x >> y;
int s = 0;
s += a[x] + a[y];
if (x == y && x == 1) {
s += 400000;
}
cout << s;
// -------------------------------------Code ends
// here------------------------------------------------------
clock_t clk;
clk = clock();
clk = clock() - clk;
cerr << fixed << setprecision(6) << "Time: " << ((double)clk) / CLOCKS_PER_SEC
<< "\n";
return 0;
} | replace | 10 | 14 | 10 | 14 | -11 | |
p02853 | C++ | Runtime Error | #include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define MAX 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ub upper_bound
#define lb lower_bound
#define zoom \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
zoom;
ll X, Y;
cin >> X >> Y;
ll look[3] = {300000, 200000, 100000};
ll ans = 0;
if (X <= 3)
ans += look[X - 1];
if (Y <= 3)
ans += look[Y - 1];
if (X == 1 && Y == 1)
ans += 400000;
cout << ans;
return 0;
} | #include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MOD 1000000007
#define MAX 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ub upper_bound
#define lb lower_bound
#define zoom \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
using namespace std;
int main() {
zoom;
ll X, Y;
cin >> X >> Y;
ll look[3] = {300000, 200000, 100000};
ll ans = 0;
if (X <= 3)
ans += look[X - 1];
if (Y <= 3)
ans += look[Y - 1];
if (X == 1 && Y == 1)
ans += 400000;
cout << ans;
return 0;
} | delete | 19 | 24 | 19 | 19 | 0 | |
p02853 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int x, y;
cin >> x >> y;
long long ans = 0;
int a[3] = {300000, 200000, 100000};
if (x <= 3)
ans += a[x - 1];
if (y <= 3)
ans += a[y - 1];
if (x == 1 && y == 1)
ans += 400000;
cout << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int x, y;
cin >> x >> y;
long long ans = 0;
int a[3] = {300000, 200000, 100000};
if (x <= 3)
ans += a[x - 1];
if (y <= 3)
ans += a[y - 1];
if (x == 1 && y == 1)
ans += 400000;
cout << ans;
return 0;
} | replace | 4 | 10 | 4 | 5 | 0 | |
p02853 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define oo 0x3f3f3f3fLL
#define sz(s) (int)(s.size())
#define RT(s) return cout << s, 0
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(), v.end()
#define watch(x) cout << (#x) << " = " << x << endl
const int dr[]{-1, -1, 0, 1, 1, 1, 0, -1};
const int dc[]{0, 1, 1, 1, 0, -1, -1, -1};
void run() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.in", "r", stdin);
// freopen("output.out", "w", stdout);
#else
#endif
}
int main() {
run();
int x, y;
cin >> x >> y;
vector<int> v = {300000, 200000, 100000, 0};
ll sum = v[min(x - 1, 3)] + v[min(y - 1, 3)];
if (x == y && x == 1)
sum += 400000;
cout << sum;
} | #include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define endl "\n"
#define ll long long
#define oo 0x3f3f3f3fLL
#define sz(s) (int)(s.size())
#define RT(s) return cout << s, 0
#define INF 0x3f3f3f3f3f3f3f3fLL
#define all(v) v.begin(), v.end()
#define watch(x) cout << (#x) << " = " << x << endl
const int dr[]{-1, -1, 0, 1, 1, 1, 0, -1};
const int dc[]{0, 1, 1, 1, 0, -1, -1, -1};
void run() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int main() {
run();
int x, y;
cin >> x >> y;
vector<int> v = {300000, 200000, 100000, 0};
ll sum = v[min(x - 1, 3)] + v[min(y - 1, 3)];
if (x == y && x == 1)
sum += 400000;
cout << sum;
} | delete | 18 | 23 | 18 | 18 | -11 | |
p02854 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
int main() {
size_t N;
cin >> N;
vector<size_t> A;
for (size_t i = 0; i < N; i++) {
size_t a;
cin >> a;
A.emplace_back(a);
}
size_t sumA = A[0];
size_t idxA = 1;
size_t sumB = 0;
size_t idxB = N - 1;
while (true) {
if (sumA <= sumB) {
sumA += A[idxA];
idxA++;
} else {
sumB += A[idxB];
idxB--;
}
if (idxA == idxB) {
if (sumA <= sumB) {
sumA += A[idxA];
} else {
sumB += A[idxA];
}
break;
}
}
if (sumA <= sumB) {
cout << sumB - sumA << endl;
} else {
cout << sumA - sumB << endl;
}
return 0;
}
| #include <iostream>
#include <vector>
using namespace std;
int main() {
size_t N;
cin >> N;
vector<size_t> A;
for (size_t i = 0; i < N; i++) {
size_t a;
cin >> a;
A.emplace_back(a);
}
if (A.size() == 2) {
if (A[0] < A[1]) {
cout << A[1] - A[0] << endl;
} else {
cout << A[0] - A[1] << endl;
}
return 0;
}
size_t sumA = A[0];
size_t idxA = 1;
size_t sumB = 0;
size_t idxB = N - 1;
while (true) {
if (sumA <= sumB) {
sumA += A[idxA];
idxA++;
} else {
sumB += A[idxB];
idxB--;
}
if (idxA == idxB) {
if (sumA <= sumB) {
sumA += A[idxA];
} else {
sumB += A[idxA];
}
break;
}
}
if (sumA <= sumB) {
cout << sumB - sumA << endl;
} else {
cout << sumA - sumB << endl;
}
return 0;
}
| insert | 14 | 14 | 14 | 23 | 0 | |
p02854 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <chrono>
using namespace std;
using ll = long long;
int main() {
ll N;
cin >> N;
ll L = 0; // 全長
vector<ll> A(N);
for (int i = 0; i < N; i++) {
ll a;
cin >> a;
L += a;
A[i] = a;
}
vector<vector<ll>> B(2, vector<ll>(N - 1));
priority_queue<ll, vector<ll>, greater<ll>> ans;
B[0][0] = A[0];
B[1][0] = L - A[0];
ans.push(abs(B[1][0] - B[0][0]));
for (int i = 1; i <= N - 1; i++) {
B[0][i] = B[0][i - 1] + A[i];
B[1][i] = L - B[0][i];
ans.push(abs(B[1][i] - B[0][i]));
}
cout << ans.top() << endl;
}
| #include <bits/stdc++.h>
#include <chrono>
using namespace std;
using ll = long long;
int main() {
ll N;
cin >> N;
ll L = 0; // 全長
vector<ll> A(N);
for (int i = 0; i < N; i++) {
ll a;
cin >> a;
L += a;
A[i] = a;
}
vector<vector<ll>> B(2, vector<ll>(N - 1));
priority_queue<ll, vector<ll>, greater<ll>> ans;
B[0][0] = A[0];
B[1][0] = L - A[0];
ans.push(abs(B[1][0] - B[0][0]));
for (int i = 1; i <= N - 2; i++) {
B[0][i] = B[0][i - 1] + A[i];
B[1][i] = L - B[0][i];
ans.push(abs(B[1][i] - B[0][i]));
}
cout << ans.top() << endl;
}
| replace | 21 | 22 | 21 | 22 | 0 | |
p02854 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << endl
#define STI(s) atoi(s.c_str())
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
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;
}
struct io {
io() {
ios::sync_with_stdio(false);
cin.tie(0);
};
};
const ll MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL << 62;
int main(void) {
int n;
cin >> n;
vll v(n);
rep(i, n) cin >> v[i];
ll ans = LLINF;
for (int i = 0; i < n - 1; i++) {
ll a = 0, b = 0;
for (int j = 0; j <= i; j++)
a += v[j];
for (int j = i + 1; j < n; j++)
b += v[j];
ans = min(ans, abs(a - b));
}
fin(ans);
}
| #include <algorithm>
#include <bitset>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << endl
#define STI(s) atoi(s.c_str())
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
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;
}
struct io {
io() {
ios::sync_with_stdio(false);
cin.tie(0);
};
};
const ll MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL << 62;
int main(void) {
int n;
cin >> n;
vll v(n);
rep(i, n) cin >> v[i];
ll ans = LLINF;
ll a = v[0];
ll b = 0;
for (int i = 1; i < n; i++)
b += v[i];
ans = min(ans, abs(a - b));
for (int i = 1; i < n - 1; i++) {
a += v[i];
b -= v[i];
ans = min(ans, abs(a - b));
}
fin(ans);
}
| replace | 75 | 81 | 75 | 83 | TLE | |
p02854 | C++ | Runtime Error | /* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>
// algorithm library
#include <algorithm>
#include <cmath>
#include <cstring>
#include <numeric>
#include <random>
// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
// type
#include <cstdint>
/* ---------- Namespace ---------- */
using namespace std;
/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>
/* ---------- Constants */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;
/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
int N;
cin >> N;
vector<int> A(N);
vector<int> S(N, 0);
for (int i = 0; i < N; i++) {
cin >> A[i];
S[i + 1] = S[i] + A[i];
}
int ret = INF;
for (int i = 0; i < N - 1; i++) {
int left = S[i + 1];
int right = S[N] - left;
ret = min(ret, abs(left - right));
}
cout << ret << endl;
return 0;
} | /* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>
// algorithm library
#include <algorithm>
#include <cmath>
#include <cstring>
#include <numeric>
#include <random>
// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
// type
#include <cstdint>
/* ---------- Namespace ---------- */
using namespace std;
/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>
/* ---------- Constants */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;
/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
int N;
cin >> N;
vector<int> A(N);
vector<int> S(N + 1, 0);
for (int i = 0; i < N; i++) {
cin >> A[i];
S[i + 1] = S[i] + A[i];
}
int ret = INF;
for (int i = 0; i < N - 1; i++) {
int left = S[i + 1];
int right = S[N] - left;
ret = min(ret, abs(left - right));
}
cout << ret << endl;
return 0;
} | replace | 51 | 52 | 51 | 52 | -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)
|
p02854 | C++ | Runtime Error | #include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
ll a[100010];
int main() {
int n;
while (cin >> n) {
ll ans = 0, tmp = 0, sm = 0, tmp1;
for (int i = 0; i < n; ++i) {
scanf("%lld", a + i);
sm += a[i];
}
ans = sm;
for (int i = 0; i < n; ++i) {
tmp += a[i];
tmp1 = sm - tmp;
ans = min(ans, abs(tmp1 - tmp));
}
cout << ans << endl;
}
return 0;
}
| #include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
ll a[2020010];
int main() {
int n;
while (cin >> n) {
ll ans = 0, tmp = 0, sm = 0, tmp1;
for (int i = 0; i < n; ++i) {
scanf("%lld", a + i);
sm += a[i];
}
ans = sm;
for (int i = 0; i < n; ++i) {
tmp += a[i];
tmp1 = sm - tmp;
ans = min(ans, abs(tmp1 - tmp));
}
cout << ans << endl;
}
return 0;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p02854 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, n) for (int i = 1; i <= n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rreps(i, n) for (int i = n; i >= 1; i--)
#define mrep(i, from, n) for (int i = from; i < n; i++)
#define mreps(i, from, n) for (int i = from; i <= n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x, val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
ll mod = 1000000007;
void solve() {
int n;
cin >> n;
vector<ll> a(n), s(n + 1, 0);
rep(i, n) cin >> a[i];
rep(i, n + 1) s[i + 1] = s[i] + a[i];
ll ans = 2e15;
rep(i, n + 1) {
ll x = s[i];
ll y = s[n] - x;
chmin(ans, abs(x - y));
}
cout << ans << endl;
return;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define reps(i, n) for (int i = 1; i <= n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
#define rreps(i, n) for (int i = n; i >= 1; i--)
#define mrep(i, from, n) for (int i = from; i < n; i++)
#define mreps(i, from, n) for (int i = from; i <= n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x, val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
ll mod = 1000000007;
void solve() {
int n;
cin >> n;
vector<ll> a(n), s(n + 1, 0);
rep(i, n) cin >> a[i];
rep(i, n) s[i + 1] = s[i] + a[i];
ll ans = 2e16;
rep(i, n + 1) {
ll x = s[i];
ll y = s[n] - x;
chmin(ans, abs(x - y));
}
cout << ans << endl;
return;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
solve();
return 0;
}
| replace | 34 | 36 | 34 | 36 | 0 | |
p02854 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define endl "\n"
typedef long long ll;
typedef string str;
const double pi = 3.14159265358979323846;
const long long inf = 1LL << 60;
int ctoi(const char c) {
if ('0' <= c && c <= '9')
return (c - '0');
return -1;
}
vector<int> input(int n) {
vector<int> vec(n);
for (int i = 0; i < n; i++) {
cin >> vec.at(i);
}
return vec;
}
vector<vector<int>> matinput(int n, int m) {
vector<vector<int>> table(n, vector<int>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> table.at(i).at(j);
}
}
return table;
}
void matoutput(vector<vector<int>> table) {
for (int i = 0; i < int(table.size()); i++) {
for (int j = 0; j < int(table.at(0).size()); j++) {
cout << table.at(i).at(j) << " ";
}
cout << endl;
}
}
long long perm(int n, int r) {
if (n < r) {
cout << "error" << endl;
return 0;
}
long long perm = 1;
for (int i = n; i > n - r; i--) {
perm *= i;
}
return perm;
}
long long comb(int n, int r) {
if (n < r) {
cout << "error" << endl;
return 0;
}
long long comb = perm(n, r);
for (int i = r; i > 0; i--) {
comb /= i;
}
return comb;
}
long long fact(int n) {
long long fact = 1;
for (int i = n; i > 0; i--) {
fact *= i;
}
return fact;
}
int gcd(int a, int b) {
if (a % b == 0) {
return (b);
} else {
return (gcd(b, a % b));
}
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool isprime(int n) {
if (n < 2)
return false;
else if (n == 2)
return true;
else if (n % 2 == 0)
return false;
for (int i = 3; i <= sqrt(n); i += 2) {
if (n % i == 0) {
return false;
}
}
return true;
}
vector<long long> divisors(long long N) {
vector<long long> res;
for (long long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
res.push_back(i);
// 重複しないならば i の相方である N/i も push
if (N / i != i)
res.push_back(N / i);
}
}
// 小さい順に並び替える
sort(res.begin(), res.end());
return res;
/*long long N;
cin >> N;
vector<long long> res = divisors(N);
for (int i = 0; i < res.size(); ++i) {
cout << res[i] << " ";
}
cout << endl;*/
}
vector<pair<long long, long long>> prime_factorize(long long N) {
vector<pair<long long, long long>> res;
for (long long a = 2; a * a <= N; ++a) {
if (N % a != 0)
continue;
long long ex = 0;
while (N % a == 0) {
++ex;
N /= a;
}
res.push_back({a, ex});
}
if (N != 1)
res.push_back({N, 1});
return res;
}
void Yes(bool f) {
if (f) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
void YES(bool f) {
if (f) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
bool leapyear(int y) {
// 閏年かどうかを判定
if (y % 4 == 0) {
if (y % 100 == 0) {
if (y % 400 == 0) {
return true;
} else {
return false;
}
} else {
return true;
}
} else {
return false;
}
}
tuple<int, int, int> dayplus(int y, int m, int d) {
// 次の日を返す
// 31日まである月
if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) {
if (d != 31) {
d++;
return make_tuple(y, m, d);
} else {
d = 1;
if (m == 12) {
m = 1;
y++;
return make_tuple(y, m, d);
} else {
m++;
return make_tuple(y, m, d);
}
}
}
// 30日まである月
else if (m == 4 || m == 6 || m == 9 || m == 11) {
if (d != 30) {
d++;
return make_tuple(y, m, d);
} else {
d = 1;
m++;
return make_tuple(y, m, d);
}
}
// 2月
else {
// 閏年の場合
if (leapyear(y)) {
if (d != 29) {
d++;
return make_tuple(y, m, d);
} else {
d = 1;
m++;
return make_tuple(y, m, d);
}
}
// 閏年ではない場合
else {
if (d != 28) {
d++;
return make_tuple(y, m, d);
} else {
d = 1;
m++;
return make_tuple(y, m, d);
}
}
}
}
tuple<int, int, int> monplus(int y, int m, int d) {
// 月を一つ先に、日を一日にする
d = 1;
if (m == 12) {
m = 1;
y++;
return make_tuple(y, m, d);
} else {
m++;
return make_tuple(y, m, d);
}
}
bool in(vector<int> a, int x) {
if (find(a.begin(), a.end(), x) != a.end()) {
return true;
} else {
return false;
}
}
int count_bool(vector<bool> flag) {
int count = 0;
for (int i = 0; i < int(flag.size()); i++) {
if (flag[i]) {
count++;
}
}
return count;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
ll sumvec(vector<ll> vec) {
ll ret = 0;
for (int i = 0; i < vec.size(); i++) {
ret += vec[i];
}
return ret;
}
int main() {
int n;
cin >> n;
vector<ll> a(n);
rep(i, 0, n) { cin >> a[i]; }
vector<ll> accsum(n);
accsum[0] = a[0];
rep(i, 1, n) { accsum[i] = accsum[i - 1] + a[i]; }
ll ans = inf;
rep(i, 0, n) { chmin(ans, abs(2 * accsum[i] - sumvec(a))); }
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define endl "\n"
typedef long long ll;
typedef string str;
const double pi = 3.14159265358979323846;
const long long inf = 1LL << 60;
int ctoi(const char c) {
if ('0' <= c && c <= '9')
return (c - '0');
return -1;
}
vector<int> input(int n) {
vector<int> vec(n);
for (int i = 0; i < n; i++) {
cin >> vec.at(i);
}
return vec;
}
vector<vector<int>> matinput(int n, int m) {
vector<vector<int>> table(n, vector<int>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> table.at(i).at(j);
}
}
return table;
}
void matoutput(vector<vector<int>> table) {
for (int i = 0; i < int(table.size()); i++) {
for (int j = 0; j < int(table.at(0).size()); j++) {
cout << table.at(i).at(j) << " ";
}
cout << endl;
}
}
long long perm(int n, int r) {
if (n < r) {
cout << "error" << endl;
return 0;
}
long long perm = 1;
for (int i = n; i > n - r; i--) {
perm *= i;
}
return perm;
}
long long comb(int n, int r) {
if (n < r) {
cout << "error" << endl;
return 0;
}
long long comb = perm(n, r);
for (int i = r; i > 0; i--) {
comb /= i;
}
return comb;
}
long long fact(int n) {
long long fact = 1;
for (int i = n; i > 0; i--) {
fact *= i;
}
return fact;
}
int gcd(int a, int b) {
if (a % b == 0) {
return (b);
} else {
return (gcd(b, a % b));
}
}
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool isprime(int n) {
if (n < 2)
return false;
else if (n == 2)
return true;
else if (n % 2 == 0)
return false;
for (int i = 3; i <= sqrt(n); i += 2) {
if (n % i == 0) {
return false;
}
}
return true;
}
vector<long long> divisors(long long N) {
vector<long long> res;
for (long long i = 1; i * i <= N; ++i) {
if (N % i == 0) {
res.push_back(i);
// 重複しないならば i の相方である N/i も push
if (N / i != i)
res.push_back(N / i);
}
}
// 小さい順に並び替える
sort(res.begin(), res.end());
return res;
/*long long N;
cin >> N;
vector<long long> res = divisors(N);
for (int i = 0; i < res.size(); ++i) {
cout << res[i] << " ";
}
cout << endl;*/
}
vector<pair<long long, long long>> prime_factorize(long long N) {
vector<pair<long long, long long>> res;
for (long long a = 2; a * a <= N; ++a) {
if (N % a != 0)
continue;
long long ex = 0;
while (N % a == 0) {
++ex;
N /= a;
}
res.push_back({a, ex});
}
if (N != 1)
res.push_back({N, 1});
return res;
}
void Yes(bool f) {
if (f) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
void YES(bool f) {
if (f) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
bool leapyear(int y) {
// 閏年かどうかを判定
if (y % 4 == 0) {
if (y % 100 == 0) {
if (y % 400 == 0) {
return true;
} else {
return false;
}
} else {
return true;
}
} else {
return false;
}
}
tuple<int, int, int> dayplus(int y, int m, int d) {
// 次の日を返す
// 31日まである月
if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12) {
if (d != 31) {
d++;
return make_tuple(y, m, d);
} else {
d = 1;
if (m == 12) {
m = 1;
y++;
return make_tuple(y, m, d);
} else {
m++;
return make_tuple(y, m, d);
}
}
}
// 30日まである月
else if (m == 4 || m == 6 || m == 9 || m == 11) {
if (d != 30) {
d++;
return make_tuple(y, m, d);
} else {
d = 1;
m++;
return make_tuple(y, m, d);
}
}
// 2月
else {
// 閏年の場合
if (leapyear(y)) {
if (d != 29) {
d++;
return make_tuple(y, m, d);
} else {
d = 1;
m++;
return make_tuple(y, m, d);
}
}
// 閏年ではない場合
else {
if (d != 28) {
d++;
return make_tuple(y, m, d);
} else {
d = 1;
m++;
return make_tuple(y, m, d);
}
}
}
}
tuple<int, int, int> monplus(int y, int m, int d) {
// 月を一つ先に、日を一日にする
d = 1;
if (m == 12) {
m = 1;
y++;
return make_tuple(y, m, d);
} else {
m++;
return make_tuple(y, m, d);
}
}
bool in(vector<int> a, int x) {
if (find(a.begin(), a.end(), x) != a.end()) {
return true;
} else {
return false;
}
}
int count_bool(vector<bool> flag) {
int count = 0;
for (int i = 0; i < int(flag.size()); i++) {
if (flag[i]) {
count++;
}
}
return count;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
ll sumvec(vector<ll> vec) {
ll ret = 0;
for (int i = 0; i < vec.size(); i++) {
ret += vec[i];
}
return ret;
}
int main() {
int n;
cin >> n;
vector<ll> a(n);
rep(i, 0, n) { cin >> a[i]; }
vector<ll> accsum(n);
accsum[0] = a[0];
rep(i, 1, n) { accsum[i] = accsum[i - 1] + a[i]; }
ll ans = inf, vecsum = sumvec(a);
rep(i, 0, n) { chmin(ans, abs(2 * accsum[i] - vecsum)); }
cout << ans << endl;
}
| replace | 271 | 273 | 271 | 273 | TLE | |
p02854 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;
int main() {
int N;
cin >> N;
ll A[100010];
ll sum1 = 0, sum2 = 0;
for (int i = 0; i < N; i++) {
cin >> A[i];
sum2 += A[i];
}
ll ans = INF;
for (int i = 0; i < N; i++) {
sum1 += A[i];
sum2 -= A[i];
// cout << sum1 << " " << sum2 << endl;
ans = min(ans, abs(sum1 - sum2));
}
cout << ans << endl;
}
| #include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;
int main() {
int N;
cin >> N;
ll A[200010];
ll sum1 = 0, sum2 = 0;
for (int i = 0; i < N; i++) {
cin >> A[i];
sum2 += A[i];
}
ll ans = INF;
for (int i = 0; i < N; i++) {
sum1 += A[i];
sum2 -= A[i];
// cout << sum1 << " " << sum2 << endl;
ans = min(ans, abs(sum1 - sum2));
}
cout << ans << endl;
}
| replace | 19 | 20 | 19 | 20 | 0 | |
p02854 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
int main() {
// 制約見て!!!デカかったらlong longにすること!
int n;
cin >> n;
vector<long> a(n);
rep(i, n) cin >> a[i];
long m = INT64_MAX;
rep(i, n) {
long left = 0;
rep(j, i + 1) { left += a[j]; }
long right = 0;
for (int j = i + 1; j < n; j++) {
right += a[j];
}
m = min(m, abs(right - left));
}
cout << m << 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() {
// 制約見て!!!デカかったらlong longにすること!
int n;
cin >> n;
vector<long> a(n);
rep(i, n) cin >> a[i];
long m = INT64_MAX;
long sum = 0;
rep(i, n) sum += a[i];
long left = a[0];
long right = sum - left;
m = abs(right - left);
for (int i = 1; i < n; i++) {
left += a[i];
right -= a[i];
m = min(m, abs(left - right));
}
cout << m << endl;
} | replace | 12 | 20 | 12 | 21 | TLE | |
p02854 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int test[123456];
int main() {
long long n, k, sum = 0, num = 1234567891230, a = 0;
cin >> n;
for (int h = 0; h < n; h++) {
cin >> k;
sum += k;
test[h] = k;
}
for (int h = 0; h < n; h++) {
num = min(abs(a - (sum - a)), num);
a += test[h];
}
cout << num << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int test[213456];
int main() {
long long n, k, sum = 0, num = 1234567891230, a = 0;
cin >> n;
for (int h = 0; h < n; h++) {
cin >> k;
sum += k;
test[h] = k;
}
for (int h = 0; h < n; h++) {
num = min(abs(a - (sum - a)), num);
a += test[h];
}
cout << num << endl;
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02854 | Python | Time Limit Exceeded | N = int(input())
arr = list(map(int, input().split()))
min_delta = sum(arr)
for i in range(1, N):
min_delta = min(abs(sum(arr[:i]) - sum(arr[i:])), min_delta)
print(min_delta)
| N = int(input())
arr = list(map(int, input().split()))
first = 0
second = sum(arr)
min_delta = second - first
for i in range(N):
first += arr[i]
second -= arr[i]
min_delta = min(abs(second - first), min_delta)
print(min_delta)
| replace | 2 | 5 | 2 | 9 | TLE | |
p02854 | Python | Runtime Error | N = int(input())
A = list(map(int, input().split()))
L, R, df = 0, N - 1, A[0] - A[N - 1]
while R - L > 1:
if df < 0:
L += (1,)
df += A[L]
else:
R -= 1
df -= A[R]
print(abs(df))
| N = int(input())
A = list(map(int, input().split()))
L, R, df = 0, N - 1, A[0] - A[N - 1]
while R - L > 1:
if df < 0:
L += 1
df += A[L]
else:
R -= 1
df -= A[R]
print(abs(df))
| replace | 6 | 7 | 6 | 7 | TypeError: unsupported operand type(s) for +=: 'int' and 'tuple' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02854/Python/s340152642.py", line 7, in <module>
L += 1,
TypeError: unsupported operand type(s) for +=: 'int' and 'tuple'
|
p02854 | Python | Time Limit Exceeded | n = int(input())
a = list(map(int, input().split()))
ans = 10**10
for i in range(1, len(a)):
ans = min(ans, abs(sum(a[:i]) - sum(a[i:])))
print(ans)
| n = int(input())
a = list(map(int, input().split()))
L = sum(a)
l = 0
i = 0
while l < L / 2:
l += a[i]
i += 1
print(min(abs(sum(a[: i - 1]) - sum(a[i - 1 :])), abs(sum(a[:i]) - sum(a[i:]))))
| replace | 2 | 6 | 2 | 9 | TLE | |
p02854 | Python | Time Limit Exceeded | #!/usr/bin/env python3
n, *a = map(int, open(0).read().split())
s = sum(a)
r = [sum(a[: i + 1]) for i in range(n)]
print(min(abs(2 * i - s) for i in r))
| #!/usr/bin/env python3
n, *a = map(int, open(0).read().split())
s = sum(a)
r = [a[0]]
for i in range(1, n):
r.append(r[i - 1] + a[i])
print(min(abs(2 * i - s) for i in r))
| replace | 3 | 4 | 3 | 6 | TLE | |
p02854 | Python | Time Limit Exceeded | n = int(input())
a = list(map(int, input().split()))
x = 2020202020
for i in range(1, n):
x = min(x, abs(sum(a[:i]) - sum(a[i:])))
print(x)
| n = int(input())
a = list(map(int, input().split()))
x = 0
y = sum(a)
ans = 2020202020
for i in range(n - 1):
x += a[i]
y -= a[i]
ans = min(ans, abs(x - y))
print(ans)
| replace | 2 | 6 | 2 | 10 | TLE | |
p02854 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, mid, i, a[100], sum = 0, l = 0, ta, ans;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
ans = sum;
for (i = 0; i < n; i++) {
l += a[i];
sum -= a[i];
ta = abs(sum - l);
if (ta < ans)
ans = ta;
}
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, mid, i, a[500000], sum = 0, l = 0, ta, ans;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
ans = sum;
for (i = 0; i < n; i++) {
l += a[i];
sum -= a[i];
ta = abs(sum - l);
if (ta < ans)
ans = ta;
}
cout << ans;
} | replace | 12 | 13 | 12 | 13 | 0 | |
p02854 | C++ | Runtime Error | #include <cmath>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
int main() {
int N;
cin >> N;
vec<ll> A(N), S(N, 0);
for (int i = 0; i < N; i++) {
cin >> A[i];
S[i + 1] = S[i] + A[i];
}
ll ans = 1e18;
for (int i = 0; i < N - 1; i++) {
ll l = S[i + 1], r = S[N] - S[i + 1];
ans = min(ans, abs(l - r));
}
cout << ans << endl;
} | #include <cmath>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
int main() {
int N;
cin >> N;
vec<ll> A(N), S(N + 1, 0);
for (int i = 0; i < N; i++) {
cin >> A[i];
S[i + 1] = S[i] + A[i];
}
ll ans = 1e18;
for (int i = 0; i < N - 1; i++) {
ll l = S[i + 1], r = S[N] - S[i + 1];
ans = min(ans, abs(l - r));
}
cout << ans << endl;
} | 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)
|
p02854 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
#define INF (1e9)
ll N;
int main() {
cin >> N;
vi A(N - 1);
ll S = 0;
for (int i = 0; i < N; i++) {
cin >> A[i];
S += A[i];
}
ll ans = 1e11, R = 0;
for (int i = 0; i < N - 1; i++) {
R += A[i];
ans = min(ans, abs(S - R * 2));
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
#define INF (1e9)
ll N;
int main() {
cin >> N;
vi A(N);
ll S = 0;
for (int i = 0; i < N; i++) {
cin >> A[i];
S += A[i];
}
ll ans = 1e11, R = 0;
for (int i = 0; i < N - 1; i++) {
R += A[i];
ans = min(ans, abs(S - R * 2));
}
cout << ans << endl;
return 0;
}
| replace | 19 | 20 | 19 | 20 | 0 | |
p02854 | C++ | Runtime Error | #include <bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 1000000007
#define lol long long
#define abs(x, y) (max(x, y) - min(x, y))
#define mp make_pair
#define fi first
#define se second
using namespace std;
int i[100005];
lol sum[100005];
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
lol a, b, c = 0, d = 0;
lol ans = INF;
cin >> a;
cin >> b, sum[0] = b;
for (int n = 1; n < a; n++) {
cin >> b;
sum[n] = sum[n - 1] + b;
}
c = sum[a - 1];
for (int n = 0; n < a - 1; n++) {
ans = min(ans, abs(c - sum[n], sum[n]));
}
cout << ans << '\n';
return 0;
}
| #include <bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 1000000007
#define lol long long
#define abs(x, y) (max(x, y) - min(x, y))
#define mp make_pair
#define fi first
#define se second
using namespace std;
int i[100005];
lol sum[200005];
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
lol a, b, c = 0, d = 0;
lol ans = INF;
cin >> a;
cin >> b, sum[0] = b;
for (int n = 1; n < a; n++) {
cin >> b;
sum[n] = sum[n - 1] + b;
}
c = sum[a - 1];
for (int n = 0; n < a - 1; n++) {
ans = min(ans, abs(c - sum[n], sum[n]));
}
cout << ans << '\n';
return 0;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p02854 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
long long int a[20005], sum = 0;
int main(void) {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
long long b = sum / 2, c = 0, ans = 1e18;
for (int i = 0; i < n; i++) {
c += a[i];
ans = min(ans, abs(b - c) + abs(sum - c - b));
}
cout << ans << endl;
}
| #include <algorithm>
#include <iostream>
#include <math.h>
#include <vector>
using namespace std;
long long int a[200005], sum = 0;
int main(void) {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
}
long long b = sum / 2, c = 0, ans = 1e18;
for (int i = 0; i < n; i++) {
c += a[i];
ans = min(ans, abs(b - c) + abs(sum - c - b));
}
cout << ans << endl;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p02854 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
int n;
ll ans = 404040404000000, dif;
ll sum = 0;
cin >> n;
vector<int> a(n);
rep(i, n) {
cin >> a.at(i);
sum += a.at(i);
}
for (int i = 1; i < n; ++i) {
ll left = 0, right = 0;
for (int j = 0; j < i; ++j) {
if (j < i)
left += a.at(j);
}
right = sum - left;
dif = left - right;
if (dif < 0)
dif *= -1;
ans = min(dif, ans);
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
int n;
ll ans = 404040404000000, dif;
ll sum = 0;
cin >> n;
vector<int> a(n);
rep(i, n) {
cin >> a.at(i);
sum += a.at(i);
}
ll left = 0, right;
for (int i = 0; i < n; ++i) {
left += a.at(i);
right = sum - left;
dif = left - right;
if (dif < 0)
dif *= -1;
ans = min(dif, ans);
}
cout << ans << endl;
return 0;
}
| replace | 15 | 21 | 15 | 18 | TLE | |
p02854 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define Rep(i, n) for (ll i = 1; i <= n; ++i)
#define loop(i, m, n) for (ll i = m; i < n; ++i)
#define ggr \
getchar(); \
getchar(); \
return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll, ll>
#define prique priority_queue<ll>
#define ALL(a) (a).begin(), (a).end()
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
int ans = 0;
for (int i = 0; bina > 0; i++) {
ans = ans + (bina % 2) * pow(10, i);
bina = bina / 2;
}
return ans;
}
bool prime(int n) {
for (ll i = 2; i <= sqrt(n); i++) {
if (n % i == 0)
return false;
}
return n != 1;
}
int gcd(int x, int y) {
if (y == 0)
return x;
return gcd(y, x % y);
}
int lcm(int x, int y) { return x * y / gcd(x, y); }
int kai(int x) {
if (x == 0)
return 1;
return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int m) {
int res = 1;
while (y) {
if (y & 1) {
res = res * x % m;
}
x = x * x % m;
y >>= 1;
}
return res;
}
int comb(int n, int r) {
int ans = 1;
for (ll i = n; i > n - r; --i) {
ans = ans * i;
}
for (ll i = 1; i < r + 1; ++i) {
ans = ans / i;
}
return ans;
}
int per(int n, int r) {
r = n - r;
int sum = 1;
int i;
for (i = n; i >= r + 1; i--)
sum *= i;
return sum;
}
struct union_find {
int par[200010], size_[200010];
void init(int x) {
rep(i, x) {
par[i] = i;
size_[i] = 1;
}
}
int find(int x) {
if (par[x] == x)
return x;
return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)
return;
if (size_[x] < size_[y]) {
par[x] = y;
size_[y] += size_[x];
} else {
par[y] = x;
size_[x] += size_[y];
}
}
};
int ctoi(const char c) { return c - '0'; }
int keta(int a) { return to_string(a).size(); }
int a[100010];
signed main() {
int n;
cin >> n;
int cnt = 0;
Rep(i, n) {
cin >> a[i];
cnt += a[i];
}
int ans = cnt, sum = 0;
Rep(i, n) {
sum += a[i];
ans = min(ans, abs(sum - (cnt - sum)));
}
cout << ans << endl;
}
| #include <algorithm>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define Rep(i, n) for (ll i = 1; i <= n; ++i)
#define loop(i, m, n) for (ll i = m; i < n; ++i)
#define ggr \
getchar(); \
getchar(); \
return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll, ll>
#define prique priority_queue<ll>
#define ALL(a) (a).begin(), (a).end()
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
int ans = 0;
for (int i = 0; bina > 0; i++) {
ans = ans + (bina % 2) * pow(10, i);
bina = bina / 2;
}
return ans;
}
bool prime(int n) {
for (ll i = 2; i <= sqrt(n); i++) {
if (n % i == 0)
return false;
}
return n != 1;
}
int gcd(int x, int y) {
if (y == 0)
return x;
return gcd(y, x % y);
}
int lcm(int x, int y) { return x * y / gcd(x, y); }
int kai(int x) {
if (x == 0)
return 1;
return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int m) {
int res = 1;
while (y) {
if (y & 1) {
res = res * x % m;
}
x = x * x % m;
y >>= 1;
}
return res;
}
int comb(int n, int r) {
int ans = 1;
for (ll i = n; i > n - r; --i) {
ans = ans * i;
}
for (ll i = 1; i < r + 1; ++i) {
ans = ans / i;
}
return ans;
}
int per(int n, int r) {
r = n - r;
int sum = 1;
int i;
for (i = n; i >= r + 1; i--)
sum *= i;
return sum;
}
struct union_find {
int par[200010], size_[200010];
void init(int x) {
rep(i, x) {
par[i] = i;
size_[i] = 1;
}
}
int find(int x) {
if (par[x] == x)
return x;
return par[x] = find(par[x]);
}
void unite(int x, int y) {
x = find(x);
y = find(y);
if (x == y)
return;
if (size_[x] < size_[y]) {
par[x] = y;
size_[y] += size_[x];
} else {
par[y] = x;
size_[x] += size_[y];
}
}
};
int ctoi(const char c) { return c - '0'; }
int keta(int a) { return to_string(a).size(); }
int a[200010];
signed main() {
int n;
cin >> n;
int cnt = 0;
Rep(i, n) {
cin >> a[i];
cnt += a[i];
}
int ans = cnt, sum = 0;
Rep(i, n) {
sum += a[i];
ans = min(ans, abs(sum - (cnt - sum)));
}
cout << ans << endl;
}
| replace | 115 | 116 | 115 | 116 | 0 | |
p02854 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < ((ll)(n)); i++)
#define reg(i, a, b) for (ll i = ((ll)(a)); i <= ((ll)(b)); i++)
#define irep(i, n) for (ll i = ((ll)(n)-1); i >= 0; i--)
#define ireg(i, a, b) for (ll i = ((ll)(b)); i >= ((ll)(a)); i--)
template <class T = int> using V = vector<T>;
template <class T = int> using VV = V<V<T>>;
/*
*/
ll n, m;
ll a[100010], b[100010], c[100010];
ll dp[100010];
ll sum = 0, tmp = 0, ans = 1e18;
int main(void) {
cin >> n;
reg(i, 1, n) cin >> a[i];
reg(i, 1, n) sum += a[i];
reg(i, 1, n) {
ans = min(ans, abs(sum - 2 * tmp));
tmp += a[i];
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < ((ll)(n)); i++)
#define reg(i, a, b) for (ll i = ((ll)(a)); i <= ((ll)(b)); i++)
#define irep(i, n) for (ll i = ((ll)(n)-1); i >= 0; i--)
#define ireg(i, a, b) for (ll i = ((ll)(b)); i >= ((ll)(a)); i--)
template <class T = int> using V = vector<T>;
template <class T = int> using VV = V<V<T>>;
/*
*/
ll n, m;
ll a[200010];
ll sum = 0, tmp = 0, ans = 1e18;
int main(void) {
cin >> n;
reg(i, 1, n) cin >> a[i];
reg(i, 1, n) sum += a[i];
reg(i, 1, n) {
ans = min(ans, abs(sum - 2 * tmp));
tmp += a[i];
}
cout << ans << endl;
return 0;
} | replace | 14 | 16 | 14 | 15 | 0 | |
p02854 | C++ | Time Limit Exceeded | #include <iostream>
#include <math.h>
#include <stdlib.h>
#include <vector>
using namespace std;
long long int Sum(vector<int> A, int i, int j) {
long long int sum = 0;
for (int k = i; k < j; k++) {
sum += A[k];
}
return sum;
}
long long int FIND(vector<int> A, long long int sum) {
double inf = INFINITY;
long long int left = 0;
long long int min = inf;
for (int i = 1; i < A.size(); i++) {
left = Sum(A, 0, i);
if (min >= llabs(sum - 2 * left)) {
min = llabs(sum - 2 * left);
} else {
break;
}
}
return min;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
long long int sum = 0;
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < A.size(); i++) {
cin >> A[i];
sum += A[i];
}
cout << FIND(A, sum) << endl;
return 0;
} | #include <iostream>
#include <math.h>
#include <stdlib.h>
#include <vector>
using namespace std;
long long int Sum(vector<int> A, int i, int j) {
long long int sum = 0;
for (int k = i; k < j; k++) {
sum += A[k];
}
return sum;
}
long long int FIND(vector<int> A, long long int sum) {
double inf = INFINITY;
long long int left = 0;
long long int min = inf;
for (int i = 0; i < A.size(); i++) {
left += A[i];
if (min >= llabs(sum - 2 * left)) {
min = llabs(sum - 2 * left);
} else {
break;
}
}
return min;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
long long int sum = 0;
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < A.size(); i++) {
cin >> A[i];
sum += A[i];
}
cout << FIND(A, sum) << endl;
return 0;
}
| replace | 18 | 20 | 18 | 20 | TLE | |
p02854 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; (i) < (n); i++)
#define rep1(i, n) for (int i = 1; (i) <= (n); i++)
#define mst(a, b) memset(a, b, sizeof(a))
#define scd(a) scanf("%d", &a)
#define scdd(a, b) scanf("%d%d", &a, &b)
#define scddd(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define dbg(a) cout << "* " << #a << " : " << a << endl
#define fr first
#define se second
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define lowbit(x) x & (-x)
#define ac cout << ans << endl
// #define DEBUG 0
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-6;
const ull hashp = 1e7 + 19;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 100;
ll a[maxn];
void solve() {
int n;
scd(n);
ll ans = INF;
ll sum = 0;
rep1(i, n) {
scanf("%lld", &a[i]);
sum += a[i];
}
ll now = 0;
rep1(i, n - 1) {
now += a[i];
ans = min(ans, abs(sum - 2 * now));
}
ac;
}
int main() {
// IOS;
// freopen("D://data.txt","r",stdin);
solve();
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; (i) < (n); i++)
#define rep1(i, n) for (int i = 1; (i) <= (n); i++)
#define mst(a, b) memset(a, b, sizeof(a))
#define scd(a) scanf("%d", &a)
#define scdd(a, b) scanf("%d%d", &a, &b)
#define scddd(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define dbg(a) cout << "* " << #a << " : " << a << endl
#define fr first
#define se second
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define lowbit(x) x & (-x)
#define ac cout << ans << endl
// #define DEBUG 0
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-6;
const ull hashp = 1e7 + 19;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 100;
ll a[maxn];
void solve() {
int n;
scd(n);
ll ans = INF;
ll sum = 0;
rep1(i, n) {
scanf("%lld", &a[i]);
sum += a[i];
}
ll now = 0;
rep1(i, n - 1) {
now += a[i];
ans = min(ans, abs(sum - 2 * now));
}
ac;
}
int main() {
// IOS;
// freopen("D://data.txt","r",stdin);
solve();
return 0;
}
| replace | 38 | 39 | 38 | 39 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.