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
|
---|---|---|---|---|---|---|---|---|---|---|---|
p01865
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int L, N, W[100] = {};
cin >> L >> N;
for (int i = 0; i < N; i++) {
int x, w;
cin >> x >> w;
W[x + 50] += w;
}
vector<pair<int, int>> ret;
for (int i = -2 * L; i < 0; i++) {
int P = W[50 + i];
int Q = W[50 - i];
int R = max(W[50 + i], W[50 - i]);
for (int j = W[50 + i]; j < R; j++) {
ret.push_back({i, 1});
}
for (int j = W[50 - i]; j < R; j++) {
ret.push_back({-i, 1});
}
}
cout << ret.size() << endl;
for (auto k : ret) {
cout << k.first << " " << k.second << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int L, N, W[100] = {};
cin >> L >> N;
for (int i = 0; i < N; i++) {
int x, w;
cin >> x >> w;
W[x + 50] += w;
}
vector<pair<int, int>> ret;
for (int i = -L; i < 0; i++) {
int P = W[50 + i];
int Q = W[50 - i];
int R = max(W[50 + i], W[50 - i]);
for (int j = W[50 + i]; j < R; j++) {
ret.push_back({i, 1});
}
for (int j = W[50 - i]; j < R; j++) {
ret.push_back({-i, 1});
}
}
cout << ret.size() << endl;
for (auto k : ret) {
cout << k.first << " " << k.second << endl;
}
}
|
replace
| 13 | 14 | 13 | 14 |
0
| |
p01866
|
C++
|
Runtime Error
|
#include <cassert>
#include <cstdio>
#include <vector>
using namespace std;
int n;
int d;
char S[1001];
vector<int> ones;
int main() {
scanf("%d", &n);
scanf("%s", S);
scanf("%d", &d);
for (int i = 0; i < n && d > 0; i++) {
if (S[i] == '1')
ones.push_back(i);
else if (S[i] == '0') {
S[i] = '1';
--d;
}
}
while (d > 0) {
int idx = ones.back();
assert(S[idx] == '1');
S[idx] = '0';
d--;
}
puts(S);
}
|
#include <cassert>
#include <cstdio>
#include <vector>
using namespace std;
int n;
int d;
char S[1001];
vector<int> ones;
int main() {
scanf("%d", &n);
scanf("%s", S);
scanf("%d", &d);
for (int i = 0; i < n && d > 0; i++) {
if (S[i] == '1')
ones.push_back(i);
else if (S[i] == '0') {
S[i] = '1';
--d;
}
}
while (d > 0) {
int idx = ones.back();
assert(S[idx] == '1');
S[idx] = '0';
d--;
ones.pop_back();
}
puts(S);
}
|
insert
| 29 | 29 | 29 | 30 |
0
| |
p01868
|
C++
|
Memory Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;
int main() {
int N, sum = 0;
cin >> N;
vector<int> T(N);
for (auto &i : T)
cin >> i, sum += i;
vector<vector<vector<int>>> dp(
55, vector<vector<int>>(1111, vector<int>(1111, INF)));
dp[0][0][0] = 0;
int res = INF;
for (int i = 0; i < N; i++) {
for (int j = 0; j < 1000; j++) {
for (int k = 0; k < 1000; k++) {
if (!dp[i][j][k]) {
if (j + T[i] < 1000)
dp[i + 1][j + T[i]][k] = 0;
if (k + T[i] < 1000)
dp[i + 1][j][k + T[i]] = 0;
res = min(res, max(j + T[i], max(k, sum - (j + k + T[i]))));
res = min(res, max(j, max(k + T[i], sum - (j + k + T[i]))));
dp[i + 1][j][k] = 0;
}
}
}
}
cout << res << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;
int main() {
int N, sum = 0;
cin >> N;
vector<int> T(N);
for (auto &i : T)
cin >> i, sum += i;
vector<vector<vector<int>>> dp(
51, vector<vector<int>>(1000, vector<int>(1000, INF)));
dp[0][0][0] = 0;
int res = INF;
for (int i = 0; i < N; i++) {
for (int j = 0; j < 1000; j++) {
for (int k = 0; k < 1000; k++) {
if (!dp[i][j][k]) {
if (j + T[i] < 1000)
dp[i + 1][j + T[i]][k] = 0;
if (k + T[i] < 1000)
dp[i + 1][j][k + T[i]] = 0;
res = min(res, max(j + T[i], max(k, sum - (j + k + T[i]))));
res = min(res, max(j, max(k + T[i], sum - (j + k + T[i]))));
dp[i + 1][j][k] = 0;
}
}
}
}
cout << res << endl;
return 0;
}
|
replace
| 13 | 14 | 13 | 14 |
MLE
| |
p01869
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int ans = -1;
ll n;
vector<ll> a;
void mk28(ll div) {
if (n < div)
return;
if (div)
a.push_back(div);
mk28(div * 10 + 2);
mk28(div * 10 + 8);
}
void saiki(ll num, int idx, int sum) {
if (num == 1)
ans = max(sum, ans);
if (num < idx || idx == a.size())
return;
if (num % a[idx] == 0)
saiki(num / a[idx], idx, sum + 1);
saiki(num, idx + 1, sum);
}
int main() {
cin >> n;
mk28(0);
sort(a.begin(), a.end());
if (n > 1)
saiki(n, 0, 0);
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int ans = -1;
ll n;
vector<ll> a;
void mk28(ll div) {
if (n < div)
return;
if (div)
a.push_back(div);
mk28(div * 10 + 2);
mk28(div * 10 + 8);
}
void saiki(ll num, int idx, int sum) {
if (num == 1)
ans = max(sum, ans);
if (num < a[idx] || idx == a.size())
return;
if (num % a[idx] == 0)
saiki(num / a[idx], idx, sum + 1);
saiki(num, idx + 1, sum);
}
int main() {
cin >> n;
mk28(0);
sort(a.begin(), a.end());
if (n > 1)
saiki(n, 0, 0);
cout << ans << endl;
return 0;
}
|
replace
| 21 | 22 | 21 | 22 |
TLE
| |
p01869
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
vector<ll> V;
int ans = -1;
void recursive(ll N, int index, int count) {
if (N == 1) {
ans = max(ans, count);
return;
}
if (N < V[index] || index == (int)V.size())
return;
recursive(N, index + 1, count);
while (N % V[index] == 0) {
N /= V[index];
recursive(N, index + 1, ++count);
}
}
int main() {
ll POW[18];
for (int i = 0; i <= 17; i++) {
POW[i] = pow(10, i);
}
ll tmp;
int limit;
ll N;
scanf("%lld", &N);
if (N == 1) {
printf("-1\n");
return 0;
}
for (int length = 1; length <= 18; length++) {
limit = pow(2, length);
for (int state = 0; state < limit; state++) {
tmp = 0;
for (int loop = 0; loop < length; loop++) {
if (state & (1 << loop)) {
tmp += 8 * POW[loop];
} else {
tmp += 2 * POW[loop];
}
}
if (N % tmp == 0) { //?????????????????°????????§??????!!!
V.push_back(tmp);
}
}
}
sort(V.begin(), V.end());
recursive(N, 0, 0);
printf("%d\n", ans);
return 0;
}
|
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
vector<ll> V;
int ans = -1;
void recursive(ll N, int index, int count) {
if (N == 1) {
ans = max(ans, count);
return;
}
if (N < V[index] || index == (int)V.size())
return;
recursive(N, index + 1, count);
while (N % V[index] == 0) {
N /= V[index];
recursive(N, index + 1, ++count);
}
}
int main() {
ll POW[18];
for (int i = 0; i <= 17; i++) {
POW[i] = pow(10, i);
}
ll tmp;
int limit;
ll N;
scanf("%lld", &N);
if (N == 1) {
printf("-1\n");
return 0;
}
for (int length = 1; length <= 18; length++) {
limit = pow(2, length);
for (int state = 0; state < limit; state++) {
tmp = 0;
for (int loop = 0; loop < length; loop++) {
if (state & (1 << loop)) {
tmp += 8 * POW[loop];
} else {
tmp += 2 * POW[loop];
}
}
if (N % tmp == 0) { //?????????????????°????????§??????!!!
V.push_back(tmp);
}
}
}
sort(V.begin(), V.end());
if (V.size() == 0) {
printf("-1\n");
return 0;
}
recursive(N, 0, 0);
printf("%d\n", ans);
return 0;
}
|
insert
| 78 | 78 | 78 | 83 |
0
| |
p01869
|
C++
|
Runtime Error
|
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
//// < "d:\d_download\visual studio
///2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual
///studio 2015\projects\programing_contest_c++\debug\b.txt"
vector<long long int> v;
map<pair<long long int, long long int>, int> mp;
int solve(long long int n, long long int from) {
if (mp.find(make_pair(from, n)) == mp.end()) {
{
int ans = -1000;
for (int i = 0; i <= from; ++i) {
long long int a = v[i];
if (n % a == 0) {
if (a == n)
ans = max(1, ans);
else {
ans = max(ans, 1 + solve(n / a, a));
}
}
}
mp[make_pair(from, n)] = ans;
}
}
return mp[make_pair(from, n)];
}
int main() {
long long int N;
cin >> N;
for (int i = 1; i <= 18; ++i) {
for (int j = 0; j < (1 << i); ++j) {
bitset<18> bs(j);
long long int n = 0;
for (int k = 0; k < i; ++k) {
n *= 10;
n += bs[i - k - 1] ? 8 : 2;
}
v.emplace_back(n);
}
}
int ans = solve(N, v.size() - 1);
if (ans < 0)
ans = -1;
cout << ans << endl;
return 0;
}
|
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
//// < "d:\d_download\visual studio
///2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual
///studio 2015\projects\programing_contest_c++\debug\b.txt"
vector<long long int> v;
map<pair<long long int, long long int>, int> mp;
int solve(long long int n, long long int from) {
if (mp.find(make_pair(from, n)) == mp.end()) {
{
int ans = -1000;
for (int i = 0; i <= from; ++i) {
long long int a = v[i];
if (n % a == 0) {
if (a == n)
ans = max(1, ans);
else {
ans = max(ans, 1 + solve(n / a, i));
}
}
}
mp[make_pair(from, n)] = ans;
}
}
return mp[make_pair(from, n)];
}
int main() {
long long int N;
cin >> N;
for (int i = 1; i <= 18; ++i) {
for (int j = 0; j < (1 << i); ++j) {
bitset<18> bs(j);
long long int n = 0;
for (int k = 0; k < i; ++k) {
n *= 10;
n += bs[i - k - 1] ? 8 : 2;
}
v.emplace_back(n);
}
}
int ans = solve(N, v.size() - 1);
if (ans < 0)
ans = -1;
cout << ans << endl;
return 0;
}
|
replace
| 26 | 27 | 26 | 27 |
0
| |
p01869
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int d[2] = {2, 8}, ans = -1;
vector<ll> v;
void func(int x, ll k) {
if (x)
v.push_back(k);
if (x == 18)
return;
for (int i = 0; i < 2; i++)
func(x + 1, k * 10 + d[i]);
}
void func2(int x, ll k, int sum) {
if (k == 1 && sum)
ans = max(ans, sum);
if (v[x] > k)
return;
if (k % !v[x])
func2(x, k / v[x], sum + 1);
if (x + 1 != v.size())
func2(x + 1, k, sum);
}
int main() {
ll n;
cin >> n;
func(0, 0);
sort(v.begin(), v.end());
func2(0, n, 0);
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int d[2] = {2, 8}, ans = -1;
vector<ll> v;
void func(int x, ll k) {
if (x)
v.push_back(k);
if (x == 18)
return;
for (int i = 0; i < 2; i++)
func(x + 1, k * 10 + d[i]);
}
void func2(int x, ll k, int sum) {
if (k == 1 && sum)
ans = max(ans, sum);
if (v[x] > k)
return;
if (!(k % v[x]))
func2(x, k / v[x], sum + 1);
if (x + 1 != v.size())
func2(x + 1, k, sum);
}
int main() {
ll n;
cin >> n;
func(0, 0);
sort(v.begin(), v.end());
func2(0, n, 0);
cout << ans << endl;
return 0;
}
|
replace
| 22 | 23 | 22 | 23 |
0
| |
p01869
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll INF = 1LL << 28;
ll N;
vector<ll> num;
map<ll, ll> memo;
queue<ll> q;
function<ll(ll)> seki;
int main() {
cin >> N;
q.push(2LL);
q.push(8LL);
while (q.size()) {
ll n = q.front();
q.pop();
if (n <= 1000000000000000000) {
num.push_back(n);
q.push(n * 10LL + 8LL);
q.push(n * 10LL + 2LL);
}
}
sort(num.begin(), num.end());
seki = [&](ll n) -> ll {
if (memo.find(n) != memo.end())
return memo[n];
int i = (int)(lower_bound(num.begin(), num.end(), n) - num.begin());
memo[n] = -INF;
if (num[i] == n)
memo[n] = 1;
for (; i > -1; i--) {
if (n % num[i] == 0) {
memo[n] = max(memo[n], seki(n / num[i]) + seki(num[i]));
}
}
return memo[n];
};
int ans = seki(N);
if (ans > 0)
cout << ans << endl;
else
cout << -1 << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll INF = 1LL << 28;
ll N;
vector<ll> num;
map<ll, ll> memo;
queue<ll> q;
function<ll(ll)> seki;
int main() {
cin >> N;
q.push(2LL);
q.push(8LL);
while (q.size()) {
ll n = q.front();
q.pop();
num.push_back(n);
if (n <= 1e18) {
q.push(n * 10LL + 8LL);
q.push(n * 10LL + 2LL);
}
}
sort(num.begin(), num.end());
seki = [&](ll n) -> ll {
if (memo.find(n) != memo.end())
return memo[n];
int i = (int)(lower_bound(num.begin(), num.end(), n) - num.begin());
memo[n] = -INF;
if (num[i] == n)
memo[n] = 1;
for (; i > -1; i--) {
if (n % num[i] == 0) {
memo[n] = max(memo[n], seki(n / num[i]) + seki(num[i]));
}
}
return memo[n];
};
int ans = seki(N);
if (ans > 0)
cout << ans << endl;
else
cout << -1 << endl;
return 0;
}
|
replace
| 19 | 21 | 19 | 21 |
0
| |
p01869
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, ll> P;
typedef pair<int, P> iP;
ll n;
vector<ll> a;
queue<iP> Q;
void mk28(ll div) {
if (n < div)
return;
if (div)
a.push_back(div);
mk28(div * 10 + 2);
mk28(div * 10 + 8);
}
int bfs() {
int ans = -1;
Q.push(iP(0, P(0, n)));
while (!Q.empty()) {
iP t = Q.front();
Q.pop();
int idx = t.first, sum = t.second.first;
ll num = t.second.second;
if (num == 1)
ans = max(ans, sum);
if (num < a[idx] || idx == a.size())
continue;
if (num % a[idx] == 0)
Q.push(iP(idx, P(sum + 1, num / a[idx])));
Q.push(iP(idx + 1, P(sum, num)));
}
return ans;
}
int main() {
cin >> n;
mk28(0);
sort(a.begin(), a.end());
cout << bfs() << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, ll> P;
typedef pair<int, P> iP;
ll n;
vector<ll> a;
queue<iP> Q;
void mk28(ll div) {
if (n < div)
return;
if (div)
a.push_back(div);
mk28(div * 10 + 2);
mk28(div * 10 + 8);
}
int bfs() {
if (n == 1)
return -1;
int ans = -1;
Q.push(iP(0, P(0, n)));
while (!Q.empty()) {
iP t = Q.front();
Q.pop();
int idx = t.first, sum = t.second.first;
ll num = t.second.second;
if (num == 1)
ans = max(ans, sum);
if (num < a[idx] || idx == a.size())
continue;
if (num % a[idx] == 0)
Q.push(iP(idx, P(sum + 1, num / a[idx])));
Q.push(iP(idx + 1, P(sum, num)));
}
return ans;
}
int main() {
cin >> n;
mk28(0);
sort(a.begin(), a.end());
cout << bfs() << endl;
return 0;
}
|
insert
| 22 | 22 | 22 | 24 |
-11
| |
p01873
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
int main() {
int N;
scanf("%d", &N);
int *table = new int[N];
for (int i = 0; i < N; i++) {
scanf("%d", &table[i]);
}
bool FLG;
int num;
for (num = 1; num < N; num++) {
FLG = true;
for (int loc = 0; loc + num < N; loc++) {
if (table[loc] != table[loc + num]) {
FLG = false;
break;
}
}
if (FLG)
break;
}
printf("%d\n", N / num);
return 0;
}
|
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <queue>
#include <stack>
#include <stdio.h>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
int main() {
int N;
scanf("%d", &N);
int *table = new int[N];
for (int i = 0; i < N; i++) {
scanf("%d", &table[i]);
}
bool FLG;
int num;
for (num = 1; num < N; num++) {
if (N % num != 0)
continue;
FLG = true;
for (int loc = 0; loc + num < N; loc++) {
if (table[loc] != table[loc + num]) {
FLG = false;
break;
}
}
if (FLG)
break;
}
printf("%d\n", N / num);
return 0;
}
|
insert
| 28 | 28 | 28 | 30 |
TLE
| |
p01873
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1e9;
int main() {
int N;
cin >> N;
vector<int> a(N);
for (int i = 0; i < N; ++i) {
scanf("%d", &a[i]);
}
set<int> s;
for (int i = 1; i * i <= N; ++i) {
if (N % i == 0) {
s.insert(i);
s.insert(N / i);
}
}
int ans = 1;
for (int k : s) {
int t = N / k;
bool f = true;
for (int i = 0; i < t; ++i) {
for (int j = i; j < N; j += k) {
if (a[i] != a[j]) {
f = false;
break;
}
}
if (!f)
break;
}
if (f)
ans = max(ans, t);
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 1e9;
int main() {
int N;
cin >> N;
vector<int> a(N);
for (int i = 0; i < N; ++i) {
scanf("%d", &a[i]);
}
set<int> s;
for (int i = 1; i * i <= N; ++i) {
if (N % i == 0) {
s.insert(i);
s.insert(N / i);
}
}
int ans = 1;
for (int k : s) {
int t = N / k;
bool f = true;
for (int i = 0; i < k; ++i) {
for (int j = i; j < N; j += k) {
if (a[i] != a[j]) {
f = false;
break;
}
}
if (!f)
break;
}
if (f)
ans = max(ans, t);
}
cout << ans << endl;
}
|
replace
| 26 | 27 | 26 | 27 |
TLE
| |
p01874
|
C++
|
Time Limit Exceeded
|
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
/* ??????????????¬ */
#include <complex>
typedef complex<ld> Point;
const ld pi = acos(-1.0);
const ld dtop = pi / 180.;
const ld ptod = 1. / dtop;
namespace std {
bool operator<(const Point &lhs, const Point &rhs) {
if (lhs.real() < rhs.real() - eps)
return true;
if (lhs.real() > rhs.real() + eps)
return false;
return lhs.imag() < rhs.imag();
}
} // namespace std
// ????????\???
Point input_Point() {
ld x, y;
cin >> x >> y;
return Point(x, y);
}
// ????????????????????????
bool eq(const ld a, const ld b) { return (abs(a - b) < eps); }
// ??????
ld dot(const Point &a, const Point &b) { return real(conj(a) * b); }
// ??????
ld cross(const Point &a, const Point &b) { return imag(conj(a) * b); }
// ??´????????????
class Line {
public:
Point a, b;
Line() : a(Point(0, 0)), b(Point(0, 0)) {}
Line(Point a, Point b) : a(a), b(b) {}
Point operator[](const int _num) const {
if (_num == 0)
return a;
else if (_num == 1)
return b;
else {
assert(false);
return Point();
}
}
};
// ?????????????????????
bool isis_sp(const Line &s, const Point &p) {
return (abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps);
}
// ??????????¶?
Point proj(const Line &l, const Point &p) {
ld t = dot(p - l.a, l.b - l.a) / norm(l.a - l.b);
return l.a + t * (l.b - l.a);
}
// ????????¨???????????¢
ld dist_sp(const Line &s, const Point &p) {
Point r = proj(s, p);
return isis_sp(s, r) ? abs(r - p) : min(abs(s.a - p), abs(s.b - p));
}
int main() {
int N, M, X, Y;
cin >> N >> M >> X >> Y;
vector<Line> ls;
vector<Point> ps(1, Point(X, Y));
vector<int> ids(1, -1);
vector<Point> foods;
for (int i = 0; i < N; ++i) {
int px, py;
cin >> px >> py;
foods.push_back(Point(px, py));
}
vector<int> caneats(N, true);
ld sum = 0;
vector<ld> diss(N, 1e18);
for (int i = 0; i < M; ++i) {
pair<ld, int> next(1e18, 0);
for (int j = 0; j < foods.size(); ++j) {
if (caneats[j]) {
auto f(foods[j]);
ld dis = diss[j];
if (ps.size() == 1) {
auto p(ps.back());
dis = min(dis, abs(p - f));
}
if (!ls.empty()) {
auto l(ls.back());
dis = min(dis, dist_sp(l, f));
}
diss[j] = dis;
if (next.first - eps > dis ||
(abs(next.first - dis) < eps && next.second < j)) {
next = make_pair(dis, j);
}
}
}
{
auto f(foods[next.second]);
pair<ld, int> connect(1e18, 0);
for (int j = 0; j < ps.size(); ++j) {
ld dis = abs(f - ps[j]);
if (connect.first - eps > dis ||
(abs(connect.first - dis) < eps && connect.second < ids[j])) {
connect = make_pair(abs(f - ps[j]), j);
}
}
sum += connect.first;
Line l{f, ps[connect.second]};
ls.push_back(l);
ps.push_back(f);
ids.push_back(next.second);
caneats[next.second] = false;
}
}
cout << fixed << setprecision(10) << sum << endl;
return 0;
}
|
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = double;
const ld eps = 1e-6;
/* ??????????????¬ */
#include <complex>
typedef complex<ld> Point;
const ld pi = acos(-1.0);
const ld dtop = pi / 180.;
const ld ptod = 1. / dtop;
namespace std {
bool operator<(const Point &lhs, const Point &rhs) {
if (lhs.real() < rhs.real() - eps)
return true;
if (lhs.real() > rhs.real() + eps)
return false;
return lhs.imag() < rhs.imag();
}
} // namespace std
// ????????\???
Point input_Point() {
ld x, y;
cin >> x >> y;
return Point(x, y);
}
// ????????????????????????
bool eq(const ld a, const ld b) { return (abs(a - b) < eps); }
// ??????
ld dot(const Point &a, const Point &b) { return real(conj(a) * b); }
// ??????
ld cross(const Point &a, const Point &b) { return imag(conj(a) * b); }
// ??´????????????
class Line {
public:
Point a, b;
Line() : a(Point(0, 0)), b(Point(0, 0)) {}
Line(Point a, Point b) : a(a), b(b) {}
Point operator[](const int _num) const {
if (_num == 0)
return a;
else if (_num == 1)
return b;
else {
assert(false);
return Point();
}
}
};
// ?????????????????????
bool isis_sp(const Line &s, const Point &p) {
return (abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps);
}
// ??????????¶?
Point proj(const Line &l, const Point &p) {
ld t = dot(p - l.a, l.b - l.a) / norm(l.a - l.b);
return l.a + t * (l.b - l.a);
}
// ????????¨???????????¢
ld dist_sp(const Line &s, const Point &p) {
Point r = proj(s, p);
return isis_sp(s, r) ? abs(r - p) : min(abs(s.a - p), abs(s.b - p));
}
int main() {
int N, M, X, Y;
cin >> N >> M >> X >> Y;
vector<Line> ls;
vector<Point> ps(1, Point(X, Y));
vector<int> ids(1, -1);
vector<Point> foods;
for (int i = 0; i < N; ++i) {
int px, py;
cin >> px >> py;
foods.push_back(Point(px, py));
}
vector<int> caneats(N, true);
ld sum = 0;
vector<ld> diss(N, 1e18);
for (int i = 0; i < M; ++i) {
pair<ld, int> next(1e18, 0);
for (int j = 0; j < foods.size(); ++j) {
if (caneats[j]) {
auto f(foods[j]);
ld dis = diss[j];
if (ps.size() == 1) {
auto p(ps.back());
dis = min(dis, abs(p - f));
}
if (!ls.empty()) {
auto l(ls.back());
dis = min(dis, dist_sp(l, f));
}
diss[j] = dis;
if (next.first - eps > dis ||
(abs(next.first - dis) < eps && next.second < j)) {
next = make_pair(dis, j);
}
}
}
{
auto f(foods[next.second]);
pair<ld, int> connect(1e18, 0);
for (int j = 0; j < ps.size(); ++j) {
ld dis = abs(f - ps[j]);
if (connect.first - eps > dis ||
(abs(connect.first - dis) < eps && connect.second < ids[j])) {
connect = make_pair(abs(f - ps[j]), j);
}
}
sum += connect.first;
Line l{f, ps[connect.second]};
ls.push_back(l);
ps.push_back(f);
ids.push_back(next.second);
caneats[next.second] = false;
}
}
cout << fixed << setprecision(10) << sum << endl;
return 0;
}
|
replace
| 5 | 7 | 5 | 7 |
TLE
| |
p01877
|
C++
|
Runtime Error
|
/*
_ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/`---'\____
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||- \
| | \\\ - /// | |
| \_| ''\---/'' | |
\ .-\__ `-` ___/-. /
___`. .' /--.--\ `. . __
."" '< `.___\_<|>_/___.' >'"".
| | : `- \`.;`\ _ /`;.`/ - ` : | |
\ \ `-. \_ __\ /__ _/ .-` / /
======`-.____`-.___\_____/___.-`____.-'======
`=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pass System Test!
*/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
if (!v.empty()) {
out << '[';
std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
out << "\b\b]";
}
return out;
}
template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &p) {
out << "[" << p.first << ", " << p.second << "]";
return out;
}
template <class T, class U> void chmin(T &t, U f) {
if (t > f)
t = f;
}
template <class T, class U> void chmax(T &t, U f) {
if (t < f)
t = f;
}
struct StarrySkyTree {
static const int N = 1 << 10;
vector<long long> seg_min, seg_max, seg_add;
StarrySkyTree()
: seg_min(N * 2, (long long)1e18), seg_max(N * 2, -1e18),
seg_add(N * 2, 0) {}
// Add x to [a, b)
void add(int a, int b, int x, int k = 0, int l = 0, int r = N) {
if (r <= a || b <= l)
return;
if (a <= l && r <= b) {
seg_add[k] += x;
while (k) {
k = (k - 1) / 2;
seg_min[k] = min(seg_min[k * 2 + 1] + seg_add[k * 2 + 1],
seg_min[k * 2 + 2] + seg_add[k * 2 + 2]);
seg_max[k] = max(seg_max[k * 2 + 1] + seg_add[k * 2 + 1],
seg_max[k * 2 + 2] + seg_add[k * 2 + 2]);
}
return;
}
add(a, b, x, k * 2 + 1, l, (l + r) / 2);
add(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
void update(int k, long long value) {
k += N - 1;
seg_min[k] = value;
seg_max[k] = value;
while (k > 0) {
k = (k - 1) / 2;
seg_min[k] = min(seg_min[k * 2 + 1], seg_min[k * 2 + 2]);
seg_max[k] = max(seg_max[k * 2 + 1], seg_max[k * 2 + 2]);
}
}
//[a, b)
long long get_min(int a, int b, int k = 0, int l = 0, int r = N) {
if (r <= a || b <= l)
return 1e18;
if (a <= l && r <= b)
return (seg_min[k] + seg_add[k]);
long long x = get_min(a, b, k * 2 + 1, l, (l + r) / 2);
long long y = get_min(a, b, k * 2 + 2, (l + r) / 2, r);
return (min(x, y) + seg_add[k]);
}
//[a, b)
long long get_max(int a, int b, int k = 0, int l = 0, int r = N) {
if (r <= a || b <= l)
return -1e18;
if (a <= l && r <= b)
return (seg_max[k] + seg_add[k]);
long long x = get_max(a, b, k * 2 + 1, l, (l + r) / 2);
long long y = get_max(a, b, k * 2 + 2, (l + r) / 2, r);
return (max(x, y) + seg_add[k]);
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<int> S(N);
for (int i = 0; i < N; ++i)
cin >> S[i];
for (int i = 0; i < N / 2; ++i) {
S[N - 1 - i] -= S[i];
S[i] = 0;
}
StarrySkyTree sst;
for (int i = 0; i < N; ++i)
sst.update(i, S[i]);
int Q;
cin >> Q;
while (Q--) {
int l, r, x;
cin >> l >> r >> x;
if (l <= N / 2 && N / 2 <= r) {
int lw = N / 2 - l + 1;
int rw = r - N / 2;
if (lw > rw) {
r = N / 2 - rw;
} else if (lw < rw) {
l = N / 2 + 1 + lw;
} else {
goto print;
}
}
l--, r--;
if (r < N / 2) {
l = N - 1 - l;
r = N - 1 - r;
swap(l, r);
x = -x;
}
// cout << l << " " << r << " " << x << endl;
sst.add(l, r + 1, x);
print:
// for (int i = 0; i < N; ++i) cout << sst.get_min(i, i + 1) << " ";
// cout << endl;
// cerr << sst.get_max(0, N) << " " << sst.get_min(0, N) << endl;
if (sst.get_max(0, N) == sst.get_min(0, N)) {
cout << 1 << endl;
} else {
cout << 0 << endl;
}
}
}
|
/*
_ooOoo_
o8888888o
88" . "88
(| -_- |)
O\ = /O
____/`---'\____
.' \\| |// `.
/ \\||| : |||// \
/ _||||| -:- |||||- \
| | \\\ - /// | |
| \_| ''\---/'' | |
\ .-\__ `-` ___/-. /
___`. .' /--.--\ `. . __
."" '< `.___\_<|>_/___.' >'"".
| | : `- \`.;`\ _ /`;.`/ - ` : | |
\ \ `-. \_ __\ /__ _/ .-` / /
======`-.____`-.___\_____/___.-`____.-'======
`=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pass System Test!
*/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
if (!v.empty()) {
out << '[';
std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
out << "\b\b]";
}
return out;
}
template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &p) {
out << "[" << p.first << ", " << p.second << "]";
return out;
}
template <class T, class U> void chmin(T &t, U f) {
if (t > f)
t = f;
}
template <class T, class U> void chmax(T &t, U f) {
if (t < f)
t = f;
}
struct StarrySkyTree {
static const int N = 1 << 20;
vector<long long> seg_min, seg_max, seg_add;
StarrySkyTree()
: seg_min(N * 2, (long long)1e18), seg_max(N * 2, -1e18),
seg_add(N * 2, 0) {}
// Add x to [a, b)
void add(int a, int b, int x, int k = 0, int l = 0, int r = N) {
if (r <= a || b <= l)
return;
if (a <= l && r <= b) {
seg_add[k] += x;
while (k) {
k = (k - 1) / 2;
seg_min[k] = min(seg_min[k * 2 + 1] + seg_add[k * 2 + 1],
seg_min[k * 2 + 2] + seg_add[k * 2 + 2]);
seg_max[k] = max(seg_max[k * 2 + 1] + seg_add[k * 2 + 1],
seg_max[k * 2 + 2] + seg_add[k * 2 + 2]);
}
return;
}
add(a, b, x, k * 2 + 1, l, (l + r) / 2);
add(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
void update(int k, long long value) {
k += N - 1;
seg_min[k] = value;
seg_max[k] = value;
while (k > 0) {
k = (k - 1) / 2;
seg_min[k] = min(seg_min[k * 2 + 1], seg_min[k * 2 + 2]);
seg_max[k] = max(seg_max[k * 2 + 1], seg_max[k * 2 + 2]);
}
}
//[a, b)
long long get_min(int a, int b, int k = 0, int l = 0, int r = N) {
if (r <= a || b <= l)
return 1e18;
if (a <= l && r <= b)
return (seg_min[k] + seg_add[k]);
long long x = get_min(a, b, k * 2 + 1, l, (l + r) / 2);
long long y = get_min(a, b, k * 2 + 2, (l + r) / 2, r);
return (min(x, y) + seg_add[k]);
}
//[a, b)
long long get_max(int a, int b, int k = 0, int l = 0, int r = N) {
if (r <= a || b <= l)
return -1e18;
if (a <= l && r <= b)
return (seg_max[k] + seg_add[k]);
long long x = get_max(a, b, k * 2 + 1, l, (l + r) / 2);
long long y = get_max(a, b, k * 2 + 2, (l + r) / 2, r);
return (max(x, y) + seg_add[k]);
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<int> S(N);
for (int i = 0; i < N; ++i)
cin >> S[i];
for (int i = 0; i < N / 2; ++i) {
S[N - 1 - i] -= S[i];
S[i] = 0;
}
StarrySkyTree sst;
for (int i = 0; i < N; ++i)
sst.update(i, S[i]);
int Q;
cin >> Q;
while (Q--) {
int l, r, x;
cin >> l >> r >> x;
if (l <= N / 2 && N / 2 <= r) {
int lw = N / 2 - l + 1;
int rw = r - N / 2;
if (lw > rw) {
r = N / 2 - rw;
} else if (lw < rw) {
l = N / 2 + 1 + lw;
} else {
goto print;
}
}
l--, r--;
if (r < N / 2) {
l = N - 1 - l;
r = N - 1 - r;
swap(l, r);
x = -x;
}
// cout << l << " " << r << " " << x << endl;
sst.add(l, r + 1, x);
print:
// for (int i = 0; i < N; ++i) cout << sst.get_min(i, i + 1) << " ";
// cout << endl;
// cerr << sst.get_max(0, N) << " " << sst.get_min(0, N) << endl;
if (sst.get_max(0, N) == sst.get_min(0, N)) {
cout << 1 << endl;
} else {
cout << 0 << endl;
}
}
}
|
replace
| 50 | 51 | 50 | 51 |
0
| |
p01878
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define each(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define dbg(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;
const int mod = 1e9 + 7;
typedef vector<vi> M;
inline M operator*(const M &a, const M &b) {
M c(a.size(), vi(b[0].size()));
rep(i, c.size()) rep(j, c[0].size()) {
ll s = 0;
rep(k, a[0].size()) s += (ll)a[i][k] * b[k][j] % mod;
c[i][j] = s % mod;
}
return c;
}
inline M pow(M a, ll m) {
M res(a.size(), vi(a.size()));
rep(i, a.size()) res[i][i] = 1;
for (; m; m /= 2) {
if (m & 1)
res = res * a;
a = a * a;
}
return res;
}
int n, K, c, T, a[1000], b[1000], t[1000];
int dp[10][40];
int main() {
cin >> n >> K >> c >> T;
rep(i, K) cin >> a[i] >> b[i] >> t[i], a[i]--;
assert(T < 120);
M A(5 * n, vi(5 * n));
rep(s, 5 * n) {
memset(dp, 0, sizeof(dp));
dp[s / n][s % n] = 1;
rep(i, 5) rep(j, n) if (dp[i][j]) rep(k, K) {
int nj = j >= a[k] + b[k] ? j : j >= a[k] ? j - a[k] : j + b[k];
(dp[i + t[k]][nj] += dp[i][j]) %= mod;
}
for (int i = 5; i < 10; i++)
rep(j, n)(A[(i - 5) * n + j][s] += dp[i][j]) %= mod;
}
A = pow(A, T / 5);
M x(5 * n, vi(1));
x[c - 1][0] = 1;
x = A * x;
memset(dp, 0, sizeof(dp));
rep(i, 5 * n) dp[i / n][i % n] = x[i][0];
rep(i, 5) rep(j, n) if (dp[i][j]) rep(k, K) {
int nj = j >= a[k] + b[k] ? j : j >= a[k] ? j - a[k] : j + b[k];
(dp[i + t[k]][nj] += dp[i][j]) %= mod;
}
cout << dp[T % 5][0] << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define all(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define each(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define dbg(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;
const int mod = 1e9 + 7;
typedef vector<vi> M;
inline M operator*(const M &a, const M &b) {
M c(a.size(), vi(b[0].size()));
rep(i, c.size()) rep(j, c[0].size()) {
ll s = 0;
rep(k, a[0].size()) s += (ll)a[i][k] * b[k][j] % mod;
c[i][j] = s % mod;
}
return c;
}
inline M pow(M a, ll m) {
M res(a.size(), vi(a.size()));
rep(i, a.size()) res[i][i] = 1;
for (; m; m /= 2) {
if (m & 1)
res = res * a;
a = a * a;
}
return res;
}
int n, K, c, T, a[1000], b[1000], t[1000];
int dp[10][40];
int main() {
cin >> n >> K >> c >> T;
rep(i, K) cin >> a[i] >> b[i] >> t[i], a[i]--;
M A(5 * n, vi(5 * n));
rep(s, 5 * n) {
memset(dp, 0, sizeof(dp));
dp[s / n][s % n] = 1;
rep(i, 5) rep(j, n) if (dp[i][j]) rep(k, K) {
int nj = j >= a[k] + b[k] ? j : j >= a[k] ? j - a[k] : j + b[k];
(dp[i + t[k]][nj] += dp[i][j]) %= mod;
}
for (int i = 5; i < 10; i++)
rep(j, n)(A[(i - 5) * n + j][s] += dp[i][j]) %= mod;
}
A = pow(A, T / 5);
M x(5 * n, vi(1));
x[c - 1][0] = 1;
x = A * x;
memset(dp, 0, sizeof(dp));
rep(i, 5 * n) dp[i / n][i % n] = x[i][0];
rep(i, 5) rep(j, n) if (dp[i][j]) rep(k, K) {
int nj = j >= a[k] + b[k] ? j : j >= a[k] ? j - a[k] : j + b[k];
(dp[i + t[k]][nj] += dp[i][j]) %= mod;
}
cout << dp[T % 5][0] << endl;
return 0;
}
|
delete
| 47 | 49 | 47 | 47 |
0
| |
p01878
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
typedef vector<vector<ll>> Matrix;
int N, K, C, T;
vector<int> shuffle(vector<int> &v, int a, int b) {
vector<int> res;
for (int i = 0; i < b; ++i) {
res.push_back(v[a + i]);
}
for (int i = 0; i < a; ++i) {
res.push_back(i);
}
for (int i = a + b; i < N; ++i) {
res.push_back(i);
}
return res;
}
vector<int> make_shuffle(int a, int b) {
vector<int> v(N);
for (int i = 0; i < N; ++i) {
v[i] = i;
}
v = shuffle(v, a, b);
vector<int> res(N);
for (int i = 0; i < N; ++i) {
res[v[i]] = i;
}
return res;
}
vector<vector<ll>> make_E() {
vector<vector<ll>> res(N * 5, vector<ll>(N * 5, 0));
for (int i = 0; i < N * 5; ++i) {
res[i][i] = 1;
}
return res;
}
vector<vector<ll>> mul(Matrix A, Matrix B) {
vector<vector<ll>> res(N * 5, vector<ll>(N * 5, 0));
for (int i = 0; i < N * 5; ++i) {
for (int j = 0; j < N * 5; ++j) {
for (int k = 0; k < N * 5; ++k) {
res[i][j] = (res[i][j] + A[i][k] * B[k][j] % mod) % mod;
}
}
}
return res;
}
vector<vector<ll>> power(Matrix A, int n) {
Matrix res = make_E();
for (int i = 1; i <= n; i <<= 1) {
if (n & i) {
res = mul(res, A);
}
A = mul(A, A);
}
return res;
}
int main() {
cin >> N >> K >> C >> T;
vector<vector<vector<ll>>> pat(5, vector<vector<ll>>(N, vector<ll>(N, 0)));
for (int i = 0; i < K; ++i) {
int a, b, t;
cin >> a >> b >> t;
--a, --t;
vector<int> to = make_shuffle(a, b);
for (int j = 0; j < to.size(); ++j) {
++pat[t][j][to[j]];
}
}
vector<vector<ll>> G(N * 5, vector<ll>(N * 5, 0));
for (int t = 0; t < 5; ++t) {
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
int from = i * 5;
int to = j * 5 + t;
G[from][to] += pat[t][i][j];
}
}
}
for (int i = 0; i < N; ++i) {
for (int t = 1; t < 5; ++t) {
G[i * 5 + t][i * 5 + t - 1] = 1;
}
}
vector<vector<ll>> g = power(G, T);
/* for (int i = 0; i < N*5; ++i) {
for (int j = 0; j < N*5; ++j) {
cout << g[i][j] << " ";
}
cout << endl;
}
*/ cout << g[(C - 1) * 5][0 * 5] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
typedef vector<vector<ll>> Matrix;
int N, K, C, T;
vector<int> shuffle(vector<int> &v, int a, int b) {
vector<int> res;
for (int i = 0; i < b; ++i) {
res.push_back(v[a + i]);
}
for (int i = 0; i < a; ++i) {
res.push_back(i);
}
for (int i = a + b; i < N; ++i) {
res.push_back(i);
}
return res;
}
vector<int> make_shuffle(int a, int b) {
vector<int> v(N);
for (int i = 0; i < N; ++i) {
v[i] = i;
}
v = shuffle(v, a, b);
vector<int> res(N);
for (int i = 0; i < N; ++i) {
res[v[i]] = i;
}
return res;
}
vector<vector<ll>> make_E() {
vector<vector<ll>> res(N * 5, vector<ll>(N * 5, 0));
for (int i = 0; i < N * 5; ++i) {
res[i][i] = 1;
}
return res;
}
vector<vector<ll>> mul(Matrix A, Matrix B) {
vector<vector<ll>> res(N * 5, vector<ll>(N * 5, 0));
for (int i = 0; i < N * 5; ++i) {
for (int j = 0; j < N * 5; ++j) {
for (int k = 0; k < N * 5; ++k) {
res[i][j] = (res[i][j] + A[i][k] * B[k][j] % mod);
if (res[i][j] >= mod)
res[i][j] -= mod;
}
}
}
return res;
}
vector<vector<ll>> power(Matrix A, int n) {
Matrix res = make_E();
for (int i = 1; i <= n; i <<= 1) {
if (n & i) {
res = mul(res, A);
}
A = mul(A, A);
}
return res;
}
int main() {
cin >> N >> K >> C >> T;
vector<vector<vector<ll>>> pat(5, vector<vector<ll>>(N, vector<ll>(N, 0)));
for (int i = 0; i < K; ++i) {
int a, b, t;
cin >> a >> b >> t;
--a, --t;
vector<int> to = make_shuffle(a, b);
for (int j = 0; j < to.size(); ++j) {
++pat[t][j][to[j]];
}
}
vector<vector<ll>> G(N * 5, vector<ll>(N * 5, 0));
for (int t = 0; t < 5; ++t) {
for (int i = 0; i < N; ++i) {
for (int j = 0; j < N; ++j) {
int from = i * 5;
int to = j * 5 + t;
G[from][to] += pat[t][i][j];
}
}
}
for (int i = 0; i < N; ++i) {
for (int t = 1; t < 5; ++t) {
G[i * 5 + t][i * 5 + t - 1] = 1;
}
}
vector<vector<ll>> g = power(G, T);
/* for (int i = 0; i < N*5; ++i) {
for (int j = 0; j < N*5; ++j) {
cout << g[i][j] << " ";
}
cout << endl;
}
*/ cout << g[(C - 1) * 5][0 * 5] << endl;
}
|
replace
| 50 | 51 | 50 | 53 |
TLE
| |
p01879
|
C++
|
Runtime Error
|
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll MOD = 1000000007;
struct bit {
vector<ll> v;
bit(int n) : v(n + 1) {}
ll sum(int i) {
ll res = 0;
for (; i > 0; i -= i & -i)
res += v[i];
return res;
}
void add(int i, ll x) {
for (i++; i < v.size(); i += i & -i)
v[i] += x;
}
};
int B = 800;
int main() {
int N;
cin >> N;
vector<int> p(N);
for (int i = 0; i < N; i++) {
scanf("%d", &p[i]);
p[i]--;
}
vector<vector<int>> num(N / B + 1, vector<int>(N));
for (int i = 0; i < N; i++)
num[p[i] / B][i + 1]++;
for (int j = 0; j <= N / B; j++)
for (int i = 0; i < N; i++)
num[j][i + 1] += num[j][i];
int Q;
cin >> Q;
vector<vector<int>> query(N);
vector<int> l(Q), r(Q);
for (int q = 0; q < Q; q++) {
scanf("%d%d", &l[q], &r[q]);
l[q]--;
r[q]--;
query[r[q]].push_back(q);
}
vector<int> index(N, -1);
bit bt(N);
vector<int> A(N / B + 1);
vector<vector<int>> v(N / B + 1);
vector<vector<ll>> sum(N / B + 1, vector<ll>(1));
ll cur = 0;
vector<ll> ans(Q);
for (int i = 0; i < N; i++) {
for (int x = N - 1; x > p[i];) {
if (x % B == B - 1 && x - B >= p[i]) {
A[x / B]++;
cur += v[x / B].size();
x -= B;
} else {
if (index[x] != -1) {
bt.add(index[x], 1);
cur++;
}
x--;
}
}
int x = p[i];
index[x] = i;
ll prev = sum[x / B].back();
v[x / B].push_back(i);
sum[x / B].push_back(prev + A[x / B]);
for (int k = 0; k < query[i].size(); k++) {
int q = query[i][k];
ans[q] = cur - bt.sum(l[q]);
for (int i = 0; i <= N / B; i++) {
int j = num[i][l[q]];
ans[q] -= (ll)j * A[i] - sum[i][j];
}
}
}
for (int q = 0; q < Q; q++)
printf("%lld\n", ans[q]);
}
|
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll MOD = 1000000007;
struct bit {
vector<ll> v;
bit(int n) : v(n + 1) {}
ll sum(int i) {
ll res = 0;
for (; i > 0; i -= i & -i)
res += v[i];
return res;
}
void add(int i, ll x) {
for (i++; i < v.size(); i += i & -i)
v[i] += x;
}
};
int B = 800;
int main() {
int N;
cin >> N;
vector<int> p(N);
for (int i = 0; i < N; i++) {
scanf("%d", &p[i]);
p[i]--;
}
vector<vector<int>> num(N / B + 1, vector<int>(N + 1));
for (int i = 0; i < N; i++)
num[p[i] / B][i + 1]++;
for (int j = 0; j <= N / B; j++)
for (int i = 0; i < N; i++)
num[j][i + 1] += num[j][i];
int Q;
cin >> Q;
vector<vector<int>> query(N);
vector<int> l(Q), r(Q);
for (int q = 0; q < Q; q++) {
scanf("%d%d", &l[q], &r[q]);
l[q]--;
r[q]--;
query[r[q]].push_back(q);
}
vector<int> index(N, -1);
bit bt(N);
vector<int> A(N / B + 1);
vector<vector<int>> v(N / B + 1);
vector<vector<ll>> sum(N / B + 1, vector<ll>(1));
ll cur = 0;
vector<ll> ans(Q);
for (int i = 0; i < N; i++) {
for (int x = N - 1; x > p[i];) {
if (x % B == B - 1 && x - B >= p[i]) {
A[x / B]++;
cur += v[x / B].size();
x -= B;
} else {
if (index[x] != -1) {
bt.add(index[x], 1);
cur++;
}
x--;
}
}
int x = p[i];
index[x] = i;
ll prev = sum[x / B].back();
v[x / B].push_back(i);
sum[x / B].push_back(prev + A[x / B]);
for (int k = 0; k < query[i].size(); k++) {
int q = query[i][k];
ans[q] = cur - bt.sum(l[q]);
for (int i = 0; i <= N / B; i++) {
int j = num[i][l[q]];
ans[q] -= (ll)j * A[i] - sum[i][j];
}
}
}
for (int q = 0; q < Q; q++)
printf("%lld\n", ans[q]);
}
|
replace
| 34 | 35 | 34 | 35 |
0
| |
p01879
|
C++
|
Memory Limit Exceeded
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
inline int calcIndex(int i, int j) { return j * (j + 1) / 2 + (j - i); }
int main() {
const int BlockSize = 200;
const int MaxN = 100000, MaxNumBlocks = (MaxN + BlockSize - 1) / BlockSize;
static int counts[MaxNumBlocks + 1][MaxN + 1];
static short counts2[BlockSize + 1][BlockSize + 1];
int N;
while (~scanf("%d", &N)) {
int X = N;
vector<int> p(N);
for (int i = 0; i < N; ++i) {
scanf("%d", &p[i]), --p[i];
}
int NumBlocks = (N + BlockSize - 1) / BlockSize;
memset(counts, 0, sizeof counts);
for (int bi = 0; bi < NumBlocks; ++bi) {
int L = bi * BlockSize, R = min((bi + 1) * BlockSize, N);
for (int i = L; i < R; ++i)
++counts[bi + 1][p[i] + 1];
for (int x = 1; x <= X; ++x)
counts[bi + 1][x] +=
counts[bi][x] + counts[bi + 1][x - 1] - counts[bi][x - 1];
}
vector<vector<pair<int, int>>> sortedBlocks(NumBlocks);
vector<vector<int>> inner(NumBlocks);
for (int bi = 0; bi < NumBlocks; ++bi) {
int L = bi * BlockSize, R = min((bi + 1) * BlockSize, N);
int M = R - L, Y = M;
vector<pair<int, int>> &sorted = sortedBlocks[bi];
sorted.resize(M);
for (int i = L; i < R; ++i)
sorted[i - L] = make_pair(p[i], i);
sort(sorted.begin(), sorted.end());
vector<int> rank(M);
for (int i = 0; i < M; ++i)
rank[sorted[i].second - L] = i;
memset(counts2, 0, sizeof counts2);
for (int i = 0; i < M; ++i)
++counts2[i + 1][rank[i] + 1];
for (int i = 0; i < M; ++i)
for (int y = 1; y <= Y; ++y)
counts2[i + 1][y] +=
counts2[i][y] + counts2[i + 1][y - 1] - counts2[i][y - 1];
vector<int> &v = inner[bi];
v.resize((R - L) * (R - L + 1) / 2);
int k = 0;
for (int j = 0; j < M; ++j) {
int sum = 0;
for (int i = j; i >= 0; --i) {
sum += counts2[j + 1][rank[i]] - counts2[i + 1][rank[i]];
v[k++] = sum;
}
}
}
vector<vector<long long>> outer(NumBlocks + 1, vector<long long>(N));
for (int bi = 0; bi <= NumBlocks; ++bi) {
vector<long long> &v = outer[bi];
long long sum;
sum = 0;
for (int bj = bi; bj < NumBlocks; ++bj) {
int L = bj * BlockSize, R = min((bj + 1) * BlockSize, N);
int num = (bj - bi) * BlockSize;
for (int j = L; j < R; ++j) {
sum += num - (counts[bj][p[j] + 1] - counts[bi][p[j] + 1]);
v[j] = sum;
}
sum += inner[bj][calcIndex(0, R - L - 1)];
}
sum = 0;
for (int bj = bi - 1; bj >= 0; --bj) {
int L = bj * BlockSize, R = min((bj + 1) * BlockSize, N);
for (int j = R - 1; j >= L; --j) {
sum += counts[bi][p[j]] - counts[bj + 1][p[j]];
v[j] = sum;
}
sum += inner[bj][calcIndex(0, R - L - 1)];
}
}
int Q;
scanf("%d", &Q);
for (int ii = 0; ii < Q; ++ii) {
int l;
int r;
scanf("%d%d", &l, &r), --l;
int bl = (l + BlockSize - 1) / BlockSize, br = r / BlockSize;
long long ans = 0;
if (l / BlockSize == (r - 1) / BlockSize) {
ans =
inner[l / BlockSize][calcIndex(l % BlockSize, (r - 1) % BlockSize)];
} else {
int L = bl * BlockSize, R = br * BlockSize;
ans += outer[bl][r - 1];
ans += inner[(r - 1) / BlockSize][calcIndex(0, (r - 1) % BlockSize)];
if (l < R) {
ans += outer[br][l];
ans += inner[l / BlockSize][calcIndex(
l % BlockSize,
min(BlockSize, N - l / BlockSize * BlockSize) - 1)];
}
if (bl < br) {
ans -= outer[bl][R - 1];
ans -= inner[(R - 1) / BlockSize][calcIndex(0, BlockSize - 1)];
}
if (l < L && R < r) {
const vector<pair<int, int>> &v = sortedBlocks[bl - 1],
&w = sortedBlocks[br];
int nv = (int)v.size(), nw = (int)w.size();
for (int i = 0, j = 0, cnt = 0; i < nv; ++i) {
for (; j < nw && w[j].first < v[i].first; ++j)
cnt += w[j].second < r;
if (l <= v[i].second)
ans += cnt;
}
}
}
printf("%lld\n", ans);
// fflush(stdout);
}
}
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
inline int calcIndex(int i, int j) { return j * (j + 1) / 2 + (j - i); }
int main() {
const int BlockSize = 250;
const int MaxN = 100000, MaxNumBlocks = (MaxN + BlockSize - 1) / BlockSize;
static int counts[MaxNumBlocks + 1][MaxN + 1];
static short counts2[BlockSize + 1][BlockSize + 1];
int N;
while (~scanf("%d", &N)) {
int X = N;
vector<int> p(N);
for (int i = 0; i < N; ++i) {
scanf("%d", &p[i]), --p[i];
}
int NumBlocks = (N + BlockSize - 1) / BlockSize;
memset(counts, 0, sizeof counts);
for (int bi = 0; bi < NumBlocks; ++bi) {
int L = bi * BlockSize, R = min((bi + 1) * BlockSize, N);
for (int i = L; i < R; ++i)
++counts[bi + 1][p[i] + 1];
for (int x = 1; x <= X; ++x)
counts[bi + 1][x] +=
counts[bi][x] + counts[bi + 1][x - 1] - counts[bi][x - 1];
}
vector<vector<pair<int, int>>> sortedBlocks(NumBlocks);
vector<vector<int>> inner(NumBlocks);
for (int bi = 0; bi < NumBlocks; ++bi) {
int L = bi * BlockSize, R = min((bi + 1) * BlockSize, N);
int M = R - L, Y = M;
vector<pair<int, int>> &sorted = sortedBlocks[bi];
sorted.resize(M);
for (int i = L; i < R; ++i)
sorted[i - L] = make_pair(p[i], i);
sort(sorted.begin(), sorted.end());
vector<int> rank(M);
for (int i = 0; i < M; ++i)
rank[sorted[i].second - L] = i;
memset(counts2, 0, sizeof counts2);
for (int i = 0; i < M; ++i)
++counts2[i + 1][rank[i] + 1];
for (int i = 0; i < M; ++i)
for (int y = 1; y <= Y; ++y)
counts2[i + 1][y] +=
counts2[i][y] + counts2[i + 1][y - 1] - counts2[i][y - 1];
vector<int> &v = inner[bi];
v.resize((R - L) * (R - L + 1) / 2);
int k = 0;
for (int j = 0; j < M; ++j) {
int sum = 0;
for (int i = j; i >= 0; --i) {
sum += counts2[j + 1][rank[i]] - counts2[i + 1][rank[i]];
v[k++] = sum;
}
}
}
vector<vector<long long>> outer(NumBlocks + 1, vector<long long>(N));
for (int bi = 0; bi <= NumBlocks; ++bi) {
vector<long long> &v = outer[bi];
long long sum;
sum = 0;
for (int bj = bi; bj < NumBlocks; ++bj) {
int L = bj * BlockSize, R = min((bj + 1) * BlockSize, N);
int num = (bj - bi) * BlockSize;
for (int j = L; j < R; ++j) {
sum += num - (counts[bj][p[j] + 1] - counts[bi][p[j] + 1]);
v[j] = sum;
}
sum += inner[bj][calcIndex(0, R - L - 1)];
}
sum = 0;
for (int bj = bi - 1; bj >= 0; --bj) {
int L = bj * BlockSize, R = min((bj + 1) * BlockSize, N);
for (int j = R - 1; j >= L; --j) {
sum += counts[bi][p[j]] - counts[bj + 1][p[j]];
v[j] = sum;
}
sum += inner[bj][calcIndex(0, R - L - 1)];
}
}
int Q;
scanf("%d", &Q);
for (int ii = 0; ii < Q; ++ii) {
int l;
int r;
scanf("%d%d", &l, &r), --l;
int bl = (l + BlockSize - 1) / BlockSize, br = r / BlockSize;
long long ans = 0;
if (l / BlockSize == (r - 1) / BlockSize) {
ans =
inner[l / BlockSize][calcIndex(l % BlockSize, (r - 1) % BlockSize)];
} else {
int L = bl * BlockSize, R = br * BlockSize;
ans += outer[bl][r - 1];
ans += inner[(r - 1) / BlockSize][calcIndex(0, (r - 1) % BlockSize)];
if (l < R) {
ans += outer[br][l];
ans += inner[l / BlockSize][calcIndex(
l % BlockSize,
min(BlockSize, N - l / BlockSize * BlockSize) - 1)];
}
if (bl < br) {
ans -= outer[bl][R - 1];
ans -= inner[(R - 1) / BlockSize][calcIndex(0, BlockSize - 1)];
}
if (l < L && R < r) {
const vector<pair<int, int>> &v = sortedBlocks[bl - 1],
&w = sortedBlocks[br];
int nv = (int)v.size(), nw = (int)w.size();
for (int i = 0, j = 0, cnt = 0; i < nv; ++i) {
for (; j < nw && w[j].first < v[i].first; ++j)
cnt += w[j].second < r;
if (l <= v[i].second)
ans += cnt;
}
}
}
printf("%lld\n", ans);
// fflush(stdout);
}
}
return 0;
}
|
replace
| 11 | 12 | 11 | 12 |
MLE
| |
p01880
|
C++
|
Runtime Error
|
//
// main.cpp
// L
//
// Created by LucienShui on 2017/4/20.
// Copyright ? 2017年 LucienShui. All rights reserved.
//
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define mfor(i, n) for (int i = 0; i < n; ++i)
using namespace std;
long long a[1005];
bool panduan(long long a) {
while (a / 10) {
long long t = a % 10;
a /= 10;
if (a % 10 != t - 1)
return false;
}
return true;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
long long n, cnt = 0, result = -1, t;
scanf("%lld", &n);
for (long long i = 0; i < n; i++)
scanf("%lld", a + i);
for (long long i = 0; i < n; i++) {
for (long long j = i + 1; j < n; j++) {
t = a[i] * a[j];
if (panduan(t))
result = max(t, result);
}
}
printf("%lld\n", result);
return 0;
}
|
//
// main.cpp
// L
//
// Created by LucienShui on 2017/4/20.
// Copyright ? 2017年 LucienShui. All rights reserved.
//
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define mfor(i, n) for (int i = 0; i < n; ++i)
using namespace std;
long long a[1005];
bool panduan(long long a) {
while (a / 10) {
long long t = a % 10;
a /= 10;
if (a % 10 != t - 1)
return false;
}
return true;
}
int main() {
long long n, cnt = 0, result = -1, t;
scanf("%lld", &n);
for (long long i = 0; i < n; i++)
scanf("%lld", a + i);
for (long long i = 0; i < n; i++) {
for (long long j = i + 1; j < n; j++) {
t = a[i] * a[j];
if (panduan(t))
result = max(t, result);
}
}
printf("%lld\n", result);
return 0;
}
|
delete
| 35 | 38 | 35 | 35 |
TLE
| |
p01880
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define range(i, s, n) for (int i = s; i < n; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a * b / gcd(a, b); }
int main() {
int n;
cin >> n;
vi v(n);
rep(i, n) { cin >> v[i]; }
vs s;
string t = "123456789";
rep(i, n - 1) range(j, i + 1, n) {
string x = to_string(v[i] * v[j]);
if (t.find(x) != string::npos)
s.push_back(x);
}
sort(all(s), [](string a, string b) {
return a.length() > b.length() || (a.length() == b.length() && a[0] > b[0]);
});
cout << s[0] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define range(i, s, n) for (int i = s; i < n; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a * b / gcd(a, b); }
int main() {
int n;
cin >> n;
vi v(n);
rep(i, n) { cin >> v[i]; }
vs s;
string t = "123456789";
rep(i, n - 1) range(j, i + 1, n) {
string x = to_string(v[i] * v[j]);
if (t.find(x) != string::npos)
s.push_back(x);
}
sort(all(s), [](string a, string b) {
return a.length() > b.length() || (a.length() == b.length() && a[0] > b[0]);
});
if (s.size()) {
cout << s[0] << endl;
} else {
cout << -1 << endl;
}
}
|
replace
| 32 | 33 | 32 | 37 |
0
| |
p01881
|
C++
|
Runtime Error
|
#include "bits/stdc++.h"
using namespace std;
typedef pair<int, int> P;
const int INF = numeric_limits<int>::max() / 2;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int h, w;
vector<string> v(h);
int sx, sy, px, py;
for (int i = 0; i < h; i++) {
cin >> v[i];
for (int j = 0; j < w; j++) {
if (v[i][j] == '%') {
sx = i;
sy = j;
} else if (v[i][j] == '@') {
px = i;
py = j;
}
}
}
vector<vector<int>> dis(300, vector<int>(300, INF));
dis[sx][sy] = 0;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
queue<P> q;
q.push(P(sx, sy));
while (!q.empty()) {
P p = q.front();
q.pop();
int x = p.first, y = p.second;
for (int i = 0; i < 4; i++) {
int nx = x + dx[i], ny = y + dy[i];
if (nx < 0 || h <= nx || ny < 0 || w <= ny)
continue;
if (v[nx][ny] == '#')
continue;
if (dis[nx][ny] != INF)
continue;
dis[nx][ny] = dis[x][y] + 1;
q.push(P(nx, ny));
}
}
int pdis = dis[px][py];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (v[i][j] != '$')
continue;
if (dis[i][j] <= pdis) {
cout << "No" << endl;
return 0;
}
}
}
cout << "Yes" << endl;
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
typedef pair<int, int> P;
const int INF = numeric_limits<int>::max() / 2;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int h, w;
cin >> h >> w;
vector<string> v(h);
int sx, sy, px, py;
for (int i = 0; i < h; i++) {
cin >> v[i];
for (int j = 0; j < w; j++) {
if (v[i][j] == '%') {
sx = i;
sy = j;
} else if (v[i][j] == '@') {
px = i;
py = j;
}
}
}
vector<vector<int>> dis(300, vector<int>(300, INF));
dis[sx][sy] = 0;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
queue<P> q;
q.push(P(sx, sy));
while (!q.empty()) {
P p = q.front();
q.pop();
int x = p.first, y = p.second;
for (int i = 0; i < 4; i++) {
int nx = x + dx[i], ny = y + dy[i];
if (nx < 0 || h <= nx || ny < 0 || w <= ny)
continue;
if (v[nx][ny] == '#')
continue;
if (dis[nx][ny] != INF)
continue;
dis[nx][ny] = dis[x][y] + 1;
q.push(P(nx, ny));
}
}
int pdis = dis[px][py];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (v[i][j] != '$')
continue;
if (dis[i][j] <= pdis) {
cout << "No" << endl;
return 0;
}
}
}
cout << "Yes" << endl;
return 0;
}
|
insert
| 12 | 12 | 12 | 13 |
-11
| |
p01881
|
C++
|
Memory Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) FOR(i, 0, (n))
#define ALL(a) (a.begin(), a.end())
typedef vector<int> vi;
constexpr int INF = 1000000000;
int main() {
int h, w;
cin >> h >> w;
vector<string> t(h);
int pi, pj, hi, hj;
vi si, sj;
REP(i, h) {
cin >> t[i];
REP(j, w) {
switch (t[i][j]) {
case '@':
pi = i;
pj = j;
break;
case '%':
hi = i;
hj = j;
break;
case '$':
si.push_back(i);
sj.push_back(j);
}
}
}
vector<vi> dist(h, vi(w, INF));
dist[hi][hj] = 0;
queue<pair<int, int>> que;
que.push(make_pair(hi, hj));
while (!que.empty()) {
int i, j;
tie(i, j) = que.front();
que.pop();
int di[] = {1, 0, -1, 0};
int dj[] = {0, 1, 0, -1};
REP(k, 4) {
int ni = i + di[k];
int nj = j + dj[k];
if (ni < 0 || nj < 0 || ni >= h || nj >= w)
continue;
if (t[ni][nj] == '#')
continue;
if (dist[ni][nj] <= dist[i][j])
continue;
dist[ni][nj] = dist[i][j] + 1;
que.push(make_pair(ni, nj));
}
}
int pd = dist[pi][pj];
bool valid = true;
REP(i, si.size()) {
if (dist[si[i]][sj[i]] <= pd) {
valid = false;
}
}
if (valid) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) FOR(i, 0, (n))
#define ALL(a) (a.begin(), a.end())
typedef vector<int> vi;
constexpr int INF = 1000000000;
int main() {
int h, w;
cin >> h >> w;
vector<string> t(h);
int pi, pj, hi, hj;
vi si, sj;
REP(i, h) {
cin >> t[i];
REP(j, w) {
switch (t[i][j]) {
case '@':
pi = i;
pj = j;
break;
case '%':
hi = i;
hj = j;
break;
case '$':
si.push_back(i);
sj.push_back(j);
}
}
}
vector<vi> dist(h, vi(w, INF));
dist[hi][hj] = 0;
queue<pair<int, int>> que;
que.push(make_pair(hi, hj));
while (!que.empty()) {
int i, j;
tie(i, j) = que.front();
que.pop();
int di[] = {1, 0, -1, 0};
int dj[] = {0, 1, 0, -1};
REP(k, 4) {
int ni = i + di[k];
int nj = j + dj[k];
if (ni < 0 || nj < 0 || ni >= h || nj >= w)
continue;
if (t[ni][nj] == '#')
continue;
if (dist[ni][nj] <= dist[i][j] + 1)
continue;
dist[ni][nj] = dist[i][j] + 1;
que.push(make_pair(ni, nj));
}
}
int pd = dist[pi][pj];
bool valid = true;
REP(i, si.size()) {
if (dist[si[i]][sj[i]] <= pd) {
valid = false;
}
}
if (valid) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
|
replace
| 51 | 52 | 51 | 52 |
MLE
| |
p01881
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def, Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def, pii> pip;
typedef vector<pip> vip;
#define mt make_tuple
typedef tuple<int, int, int> tp;
typedef vector<tp> vt;
const double PI = acos(-1);
const double EPS = 1e-7;
const int inf = 1e9;
const ll INF = 2e18;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int n, m;
vs in;
vvi d, dp;
bool dfs(int a, int b, int c) {
if (dp[a][b] < c)
return 0;
rep(i, 4) {
int x = a + dx[i];
int y = b + dy[i];
if (x < 0 || y < 0 || x >= n || y >= m || in[x][y] == '#' ||
d[x][y] <= c + 1 || c + 1 >= dp[x][y])
continue;
if (in[x][y] == '%') {
cout << "Yes" << endl;
return 1;
}
if (dfs(x, y, c + 1))
return 1;
}
return 0;
}
int main() {
cin >> n >> m;
in = vs(n);
rep(i, n) cin >> in[i];
dp = vvi(n, vi(m, inf));
priority_queue<tp> que;
rep(i, n) rep(j, m) if (in[i][j] == '$') {
que.push(tp(i, j, 0));
dp[i][j] = 0;
}
while (!que.empty()) {
int x, y, co;
tie(x, y, co) = que.top();
que.pop();
if (dp[x][y] < co)
continue;
rep(i, 4) {
int nx = x + dx[i];
int ny = y + dy[i];
if (nx < 0 || ny < 0 || nx >= n || ny >= m || in[nx][ny] == '#' ||
dp[nx][ny] <= co + 1)
continue;
dp[nx][ny] = co + 1;
que.push(tp(nx, ny, co + 1));
}
}
d = vvi(n, vi(m, inf));
rep(i, n) rep(j, m) if (in[i][j] == '@') {
d[i][j] = 0;
if (!dfs(i, j, 0))
cout << "No" << endl;
}
}
|
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
using namespace std;
// kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def, Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def, pii> pip;
typedef vector<pip> vip;
#define mt make_tuple
typedef tuple<int, int, int> tp;
typedef vector<tp> vt;
const double PI = acos(-1);
const double EPS = 1e-7;
const int inf = 1e9;
const ll INF = 2e18;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int n, m;
vs in;
vvi d, dp;
bool dfs(int a, int b, int c) {
if (dp[a][b] < c)
return 0;
rep(i, 4) {
int x = a + dx[i];
int y = b + dy[i];
if (x < 0 || y < 0 || x >= n || y >= m || in[x][y] == '#' ||
d[x][y] <= c + 1 || c + 1 >= dp[x][y])
continue;
if (in[x][y] == '%') {
cout << "Yes" << endl;
return 1;
}
d[x][y] = c + 1;
if (dfs(x, y, c + 1))
return 1;
}
return 0;
}
int main() {
cin >> n >> m;
in = vs(n);
rep(i, n) cin >> in[i];
dp = vvi(n, vi(m, inf));
priority_queue<tp> que;
rep(i, n) rep(j, m) if (in[i][j] == '$') {
que.push(tp(i, j, 0));
dp[i][j] = 0;
}
while (!que.empty()) {
int x, y, co;
tie(x, y, co) = que.top();
que.pop();
if (dp[x][y] < co)
continue;
rep(i, 4) {
int nx = x + dx[i];
int ny = y + dy[i];
if (nx < 0 || ny < 0 || nx >= n || ny >= m || in[nx][ny] == '#' ||
dp[nx][ny] <= co + 1)
continue;
dp[nx][ny] = co + 1;
que.push(tp(nx, ny, co + 1));
}
}
d = vvi(n, vi(m, inf));
rep(i, n) rep(j, m) if (in[i][j] == '@') {
d[i][j] = 0;
if (!dfs(i, j, 0))
cout << "No" << endl;
}
}
|
insert
| 61 | 61 | 61 | 62 |
TLE
| |
p01881
|
C++
|
Time Limit Exceeded
|
///
// File: 2781.cpp
// Author: ymiyamoto
//
// Created on Fri Dec 29 19:30:51 2017
//
#include <cstdint>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
uint32_t wfs(vector<string> map, int32_t y, int32_t x) {
vector<vector<int32_t>> visited(map.size(),
vector<int32_t>(map[0].size(), -1));
visited[y][x] = 0;
queue<pair<int32_t, int32_t>> q;
q.push({y, x});
while (!q.empty()) {
pair<int32_t, int32_t> p = q.front();
q.pop();
vector<pair<int32_t, int32_t>> ds = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
for (auto d : ds) {
int32_t y2 = p.first + d.first;
int32_t x2 = p.second + d.second;
if (0 <= y2 && y2 < (int32_t)map.size() && 0 <= x2 &&
x2 < (int32_t)map[0].size() && (visited[y2][x2] == -1)) {
if (map[y2][x2] == '#')
continue;
visited[y2][x2] = visited[p.first][p.second] + 1;
q.push({y2, x2});
}
}
}
for (uint32_t i = 0; i < map.size(); i++) {
for (uint32_t j = 0; j < map[0].size(); j++) {
if (map[i][j] == '%') {
return visited[i][j];
}
}
}
}
int32_t main() {
uint32_t H, W;
cin >> H >> W;
vector<string> map;
for (uint32_t i = 0; i < H; i++) {
string line;
cin >> line;
map.push_back(line);
}
uint32_t princess;
uint32_t soldier = UINT32_MAX;
for (uint32_t y = 0; y < H; y++) {
for (uint32_t x = 0; x < W; x++) {
if (map[y][x] == '@') {
princess = wfs(map, y, x);
} else if (map[y][x] == '$') {
soldier = min(soldier, wfs(map, y, x));
}
}
}
if (princess < soldier) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
|
///
// File: 2781.cpp
// Author: ymiyamoto
//
// Created on Fri Dec 29 19:30:51 2017
//
#include <cstdint>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
uint32_t wfs(vector<string> map, int32_t y, int32_t x) {
vector<vector<int32_t>> visited(map.size(),
vector<int32_t>(map[0].size(), -1));
visited[y][x] = 0;
queue<pair<int32_t, int32_t>> q;
q.push({y, x});
while (!q.empty()) {
pair<int32_t, int32_t> p = q.front();
q.pop();
vector<pair<int32_t, int32_t>> ds = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
for (auto d : ds) {
int32_t y2 = p.first + d.first;
int32_t x2 = p.second + d.second;
if (0 <= y2 && y2 < (int32_t)map.size() && 0 <= x2 &&
x2 < (int32_t)map[0].size() && (visited[y2][x2] == -1)) {
if (map[y2][x2] == '#' || map[y2][x2] == '$')
continue;
visited[y2][x2] = visited[p.first][p.second] + 1;
q.push({y2, x2});
}
}
}
for (uint32_t i = 0; i < map.size(); i++) {
for (uint32_t j = 0; j < map[0].size(); j++) {
if (map[i][j] == '%') {
return visited[i][j];
}
}
}
}
int32_t main() {
uint32_t H, W;
cin >> H >> W;
vector<string> map;
for (uint32_t i = 0; i < H; i++) {
string line;
cin >> line;
map.push_back(line);
}
uint32_t princess;
uint32_t soldier = UINT32_MAX;
for (uint32_t y = 0; y < H; y++) {
for (uint32_t x = 0; x < W; x++) {
if (map[y][x] == '@') {
princess = wfs(map, y, x);
} else if (map[y][x] == '$') {
soldier = min(soldier, wfs(map, y, x));
}
}
}
if (princess < soldier) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
}
|
replace
| 32 | 33 | 32 | 33 |
TLE
| |
p01900
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
priority_queue<int> Q[3];
int a[100010];
int F(int bef, int aft) {
int cnt = 0;
while (true) {
int pnt = (3 + aft - bef) % 3;
if (Q[pnt].empty())
break;
cnt++;
Q[pnt].pop();
if (!Q[0].empty()) {
while (!Q[0].empty()) {
cnt++;
Q[0].pop();
}
}
bef = aft;
if (aft == 1)
aft = 2;
else if (aft == 2)
aft = 1;
}
if (!Q[0].empty() || !Q[1].empty() || !Q[2].empty())
cnt++;
return cnt;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++) {
Q[a[i] % 3].push(a[i]);
}
int ans = F(0, 1);
for (int i = 0; i < 3; i++) {
while (!Q[i].empty())
Q[i].pop();
}
for (int i = 0; i < n; i++) {
Q[a[i] % 3].push(a[i]);
}
ans = max(ans, F(0, 2));
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
priority_queue<int> Q[3];
int a[500010];
int F(int bef, int aft) {
int cnt = 0;
while (true) {
int pnt = (3 + aft - bef) % 3;
if (Q[pnt].empty())
break;
cnt++;
Q[pnt].pop();
if (!Q[0].empty()) {
while (!Q[0].empty()) {
cnt++;
Q[0].pop();
}
}
bef = aft;
if (aft == 1)
aft = 2;
else if (aft == 2)
aft = 1;
}
if (!Q[0].empty() || !Q[1].empty() || !Q[2].empty())
cnt++;
return cnt;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int i = 0; i < n; i++) {
Q[a[i] % 3].push(a[i]);
}
int ans = F(0, 1);
for (int i = 0; i < 3; i++) {
while (!Q[i].empty())
Q[i].pop();
}
for (int i = 0; i < n; i++) {
Q[a[i] % 3].push(a[i]);
}
ans = max(ans, F(0, 2));
cout << ans << endl;
return 0;
}
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p01900
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < a; i++)
#define s second
#define f first
using namespace std;
int main(void) {
int n, ary[3] = {0}, in, ret = 0;
cin >> n;
rep(i, n) {
cin >> in;
ary[in % 3]++;
}
if (ary[1] || ary[2])
ret = ary[0];
int h = 1, now = 0;
;
while (true) {
if (h == 2) { // h = 2
int use = min(2, ary[2]);
ret += use;
ary[2] -= use;
if (ary[1] != 0)
h = 1;
now = (use * 2 + now) % 3;
if (now == 0)
break;
} else { // h = 1
int use = min(2, ary[1]);
ret += use;
ary[1] -= use;
if (ary[2] != 0)
h = 2;
now = (now + use) % 3;
if (now == 0)
break;
}
}
cout << (ret == 0 && ary[0] ? 1 : ret) << endl;
}
|
#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < a; i++)
#define s second
#define f first
using namespace std;
int main(void) {
int n, ary[3] = {0}, in, ret = 0;
cin >> n;
rep(i, n) {
cin >> in;
ary[in % 3]++;
}
if (ary[1] || ary[2])
ret = ary[0];
int mi = min(ary[1], ary[2]);
int diff = max(ary[1], ary[2]) - mi;
// cout<<diff<<endl;
ret = ret + mi * 2 + min(3, diff);
// cout<< min(3,diff)<<endl;
cout << (ret == 0 && ary[0] ? 1 : ret) << endl;
}
|
replace
| 15 | 38 | 15 | 21 |
TLE
| |
p01901
|
C++
|
Runtime Error
|
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>
typedef long long ll;
using namespace std;
#define debug(x) cerr << #x << " = " << x << endl;
#define mod 1000000007 // 1e9+7(prime number)
#define INF 1000000000 // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 10000
int main() {
ll t, s[SIZE], e[SIZE], r[SIZE] = {};
int n;
scanf("%lld%d", &t, &n);
for (int i = 0; i < n; i++) {
scanf("%lld%lld", s + i, e + i);
}
for (int i = 1; i < n; i++) {
r[i] = s[i] - e[i - 1] + r[i - 1];
}
ll ans = 0;
for (int i = 0; i < n; i++) {
ll *it = upper_bound(s, s + n, s[i] + t);
if (it == s) {
ans = max(ans, min(t, e[0] - s[0]));
} else {
it--;
if (s[i] + t >= e[it - s])
ans = max(ans, e[it - s] - s[i] - (r[it - s] - r[i]));
else
ans = max(ans, t - (r[it - s] - r[i]));
}
}
printf("%lld\n", ans);
return 0;
}
|
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>
typedef long long ll;
using namespace std;
#define debug(x) cerr << #x << " = " << x << endl;
#define mod 1000000007 // 1e9+7(prime number)
#define INF 1000000000 // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 100010
int main() {
ll t, s[SIZE], e[SIZE], r[SIZE] = {};
int n;
scanf("%lld%d", &t, &n);
for (int i = 0; i < n; i++) {
scanf("%lld%lld", s + i, e + i);
}
for (int i = 1; i < n; i++) {
r[i] = s[i] - e[i - 1] + r[i - 1];
}
ll ans = 0;
for (int i = 0; i < n; i++) {
ll *it = upper_bound(s, s + n, s[i] + t);
if (it == s) {
ans = max(ans, min(t, e[0] - s[0]));
} else {
it--;
if (s[i] + t >= e[it - s])
ans = max(ans, e[it - s] - s[i] - (r[it - s] - r[i]));
else
ans = max(ans, t - (r[it - s] - r[i]));
}
}
printf("%lld\n", ans);
return 0;
}
|
replace
| 25 | 26 | 25 | 26 |
0
| |
p01901
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define MAX_N 111111
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 0;
int n;
ll dat[2 * MAX_N - 1];
void init(int n_) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++)
dat[i] = INF;
}
void update(int k, ll a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = dat[k * 2 + 1] + dat[k * 2 + 2];
}
}
ll query(int a, int b, int k, int l, int r) {
if (b <= a)
return 0;
if (r <= a || b <= l)
return INF;
if (a <= l && r <= b)
return dat[k];
else {
ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return vl + vr;
}
}
int main(void) {
ll T;
int N;
cin >> T >> N;
vector<P> s(N);
vector<P> t;
init(N);
for (int i = 0; i < N; i++) {
cin >> s[i].first >> s[i].second;
update(i, s[i].second - s[i].first);
}
for (int i = 0; i < N; i++) {
t.push_back(P(s[i].first, 0));
t.push_back(P(s[i].second, 1));
}
ll ans = 0;
for (int s_ind = 0; s_ind < N; s_ind++) {
int idx =
upper_bound(t.begin(), t.end(), P(s[s_ind].first + T, 0)) - t.begin();
if (idx == 2 * N)
idx--;
else if (t[idx].second == 1) {
idx -= 2;
} else {
idx -= 1;
}
// idx = max(0, idx+1);
ll r = query(s_ind, (idx + 1) / 2, 0, 0, n);
ans = max(ans, r + (idx + 1 >= 2 * N
? 0
: max(0ll, s[s_ind].first + T - t[idx + 1].first)));
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define MAX_N 1111111
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 0;
int n;
ll dat[2 * MAX_N - 1];
void init(int n_) {
n = 1;
while (n < n_)
n *= 2;
for (int i = 0; i < 2 * n - 1; i++)
dat[i] = INF;
}
void update(int k, ll a) {
k += n - 1;
dat[k] = a;
while (k > 0) {
k = (k - 1) / 2;
dat[k] = dat[k * 2 + 1] + dat[k * 2 + 2];
}
}
ll query(int a, int b, int k, int l, int r) {
if (b <= a)
return 0;
if (r <= a || b <= l)
return INF;
if (a <= l && r <= b)
return dat[k];
else {
ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return vl + vr;
}
}
int main(void) {
ll T;
int N;
cin >> T >> N;
vector<P> s(N);
vector<P> t;
init(N);
for (int i = 0; i < N; i++) {
cin >> s[i].first >> s[i].second;
update(i, s[i].second - s[i].first);
}
for (int i = 0; i < N; i++) {
t.push_back(P(s[i].first, 0));
t.push_back(P(s[i].second, 1));
}
ll ans = 0;
for (int s_ind = 0; s_ind < N; s_ind++) {
int idx =
upper_bound(t.begin(), t.end(), P(s[s_ind].first + T, 0)) - t.begin();
if (idx == 2 * N)
idx--;
else if (t[idx].second == 1) {
idx -= 2;
} else {
idx -= 1;
}
// idx = max(0, idx+1);
ll r = query(s_ind, (idx + 1) / 2, 0, 0, n);
ans = max(ans, r + (idx + 1 >= 2 * N
? 0
: max(0ll, s[s_ind].first + T - t[idx + 1].first)));
}
cout << ans << endl;
return 0;
}
|
replace
| 1 | 2 | 1 | 2 |
0
| |
p01903
|
C++
|
Runtime Error
|
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>
typedef long long ll;
using namespace std;
#define debug(x) cerr << #x << " = " << x << endl;
#define mod 1000000007 // 1e9+7(prime number)
#define INF 10000000 // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 100010
struct Dinic {
struct edge {
int to, cap, rev;
edge(int a, int b, int c) : to(a), cap(b), rev(c) {}
};
vector<vector<edge>> G;
vector<int> level, iter;
int MAX_V;
int last_solve;
Dinic(int max_v) : G(max_v, vector<edge>()), MAX_V(max_v), last_solve(0) {}
int add_edge(int from, int to, int cap) {
int id = G[from].size();
G[from].push_back(edge(to, cap, G[to].size()));
G[to].push_back(edge(from, 0, G[from].size() - 1));
return id;
}
void bfs(int s) {
level.assign(MAX_V, -1);
queue<int> q;
level[s] = 0;
q.push(s);
while (q.size()) {
int v = q.front();
q.pop();
for (int i = 0; i < G[v].size(); i++) {
edge &e = G[v][i];
if (e.cap > 0 && level[e.to] < 0) {
level[e.to] = level[v] + 1;
q.push(e.to);
}
}
}
}
int dfs(int v, int t, int f) {
if (v == t)
return f;
for (int &i = iter[v]; i < G[v].size(); i++) {
edge &e = G[v][i];
if (e.cap > 0 && level[v] < level[e.to]) {
int d = dfs(e.to, t, min(f, e.cap));
if (d > 0) {
e.cap -= d;
G[e.to][e.rev].cap += d;
return d;
}
}
}
return 0;
}
int solve(int s, int t) {
int flow = 0;
while (1) {
bfs(s);
if (level[t] < 0) {
last_solve += flow;
return last_solve;
}
iter.assign(MAX_V, 0);
int f;
while ((f = dfs(s, t, INF)) > 0)
flow += f;
}
}
};
int k, n, m;
int a[SIZE], b[SIZE], c[SIZE];
Dinic calc_first(queue<pair<int, pair<int, int>>> &q) {
Dinic dinic(102);
vector<pair<int, pair<int, int>>> vec;
for (int i = 0; i < m; i++) {
int id = dinic.add_edge(a[i], b[i], c[i]);
int id2 = dinic.add_edge(b[i], a[i], c[i]);
vec.push_back({i, {id, id2}});
}
for (int i = 2; i <= k + 1; i++) {
dinic.add_edge(0, i, INF);
}
debug(dinic.solve(0, 1));
for (int i = 0; i < vec.size(); i++) {
if (dinic.G[a[vec[i].first]][vec[i].second.first].cap == 0 ||
dinic.G[b[vec[i].first]][vec[i].second.second].cap == 0) {
q.push(vec[i]);
}
}
return dinic;
}
int main() {
scanf("%d%d%d", &k, &n, &m);
for (int i = 0; i < m; i++) {
scanf("%d%d%d", a + i, b + i, c + i);
a[i]++;
b[i]++;
}
int ans = 0;
queue<pair<int, pair<int, int>>> q;
Dinic dinic = calc_first(q);
while (q.size()) {
Dinic dinic2 = dinic;
pair<int, pair<int, int>> t = q.front();
q.pop();
dinic2.G[a[t.first]][t.second.first].cap += INF;
dinic2.G[b[t.first]][t.second.second].cap += INF;
ans = max(ans, dinic2.solve(0, 1));
}
if (ans >= INF) {
puts("overfuro");
} else {
printf("%d\n", ans);
}
return 0;
}
|
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>
typedef long long ll;
using namespace std;
#define debug(x) cerr << #x << " = " << x << endl;
#define mod 1000000007 // 1e9+7(prime number)
#define INF 10000000 // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 100010
struct Dinic {
struct edge {
int to, cap, rev;
edge(int a, int b, int c) : to(a), cap(b), rev(c) {}
};
vector<vector<edge>> G;
vector<int> level, iter;
int MAX_V;
int last_solve;
Dinic(int max_v) : G(max_v, vector<edge>()), MAX_V(max_v), last_solve(0) {}
int add_edge(int from, int to, int cap) {
int id = G[from].size();
G[from].push_back(edge(to, cap, G[to].size()));
G[to].push_back(edge(from, 0, G[from].size() - 1));
return id;
}
void bfs(int s) {
level.assign(MAX_V, -1);
queue<int> q;
level[s] = 0;
q.push(s);
while (q.size()) {
int v = q.front();
q.pop();
for (int i = 0; i < G[v].size(); i++) {
edge &e = G[v][i];
if (e.cap > 0 && level[e.to] < 0) {
level[e.to] = level[v] + 1;
q.push(e.to);
}
}
}
}
int dfs(int v, int t, int f) {
if (v == t)
return f;
for (int &i = iter[v]; i < G[v].size(); i++) {
edge &e = G[v][i];
if (e.cap > 0 && level[v] < level[e.to]) {
int d = dfs(e.to, t, min(f, e.cap));
if (d > 0) {
e.cap -= d;
G[e.to][e.rev].cap += d;
return d;
}
}
}
return 0;
}
int solve(int s, int t) {
int flow = 0;
while (1) {
bfs(s);
if (level[t] < 0) {
last_solve += flow;
return last_solve;
}
iter.assign(MAX_V, 0);
int f;
while ((f = dfs(s, t, INF)) > 0)
flow += f;
}
}
};
int k, n, m;
int a[SIZE], b[SIZE], c[SIZE];
Dinic calc_first(queue<pair<int, pair<int, int>>> &q) {
Dinic dinic(102);
vector<pair<int, pair<int, int>>> vec;
for (int i = 0; i < m; i++) {
int id = dinic.add_edge(a[i], b[i], c[i]);
int id2 = dinic.add_edge(b[i], a[i], c[i]);
vec.push_back({i, {id, id2}});
}
for (int i = 2; i <= k + 1; i++) {
dinic.add_edge(0, i, INF);
}
dinic.solve(0, 1);
for (int i = 0; i < vec.size(); i++) {
if (dinic.G[a[vec[i].first]][vec[i].second.first].cap == 0 ||
dinic.G[b[vec[i].first]][vec[i].second.second].cap == 0) {
q.push(vec[i]);
}
}
return dinic;
}
int main() {
scanf("%d%d%d", &k, &n, &m);
for (int i = 0; i < m; i++) {
scanf("%d%d%d", a + i, b + i, c + i);
a[i]++;
b[i]++;
}
int ans = 0;
queue<pair<int, pair<int, int>>> q;
Dinic dinic = calc_first(q);
while (q.size()) {
Dinic dinic2 = dinic;
pair<int, pair<int, int>> t = q.front();
q.pop();
dinic2.G[a[t.first]][t.second.first].cap += INF;
dinic2.G[b[t.first]][t.second.second].cap += INF;
ans = max(ans, dinic2.solve(0, 1));
}
if (ans >= INF) {
puts("overfuro");
} else {
printf("%d\n", ans);
}
return 0;
}
|
replace
| 118 | 119 | 118 | 119 |
0
|
dinic.solve(0,1) = 5
|
p01903
|
C++
|
Runtime Error
|
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define INF (1e9 + 1)
// #define INF (1LL<<59)
#define MAX_V 100
struct edge {
int to, cap, rev;
};
vector<edge> G[MAX_V]; //??°???????????????
int level[MAX_V]; //?§??????????????????¢
int iter[MAX_V]; //???????????§????????????
// from??????to?????????????????????cap???????????°?????????????????????
void add_edge(int from, int to, int cap) {
G[from].push_back((edge){to, cap, (int)G[to].size()});
G[to].push_back((edge){from, 0, (int)G[from].size() - 1});
}
// s????????????????????¢???BFS??§?¨??????????
void bfs(int s) {
rep(i, MAX_V) level[i] = -1;
queue<int> que;
level[s] = 0;
que.push(s);
while (!que.empty()) {
int v = que.front();
que.pop();
rep(i, G[v].size()) {
edge &e = G[v][i];
if (e.cap > 0 && level[e.to] < 0) {
level[e.to] = level[v] + 1;
que.push(e.to);
}
}
}
}
//?¢?????????????DFS??§??¢???
int dfs(int v, int t, int f) {
if (v == t)
return f;
for (int &i = iter[v]; i < G[v].size(); i++) {
edge &e = G[v][i];
if (e.cap > 0 && level[v] < level[e.to]) {
int d = dfs(e.to, t, min(f, e.cap));
if (d > 0) {
e.cap -= d;
G[e.to][e.rev].cap += d;
return d;
}
}
}
return 0;
}
// s??????t???????????§???????±???????
int max_flow(int s, int t) {
if (s == t)
return INF;
int flow = 0;
for (;;) {
bfs(s);
if (level[t] < 0)
return flow;
memset(iter, 0, sizeof(iter));
int f;
while ((f = dfs(s, t, INF)) > 0) {
flow += f;
}
}
}
void isUsedDfs(int s, int t, bool used[MAX_V]) {
if (s == t)
return;
for (auto &e : G[s]) {
if (!used[e.to] && e.cap > 0) {
used[e.to] = true;
isUsedDfs(e.to, t, used);
}
}
}
int main() {
int k, n, m;
cin >> k >> n >> m;
int s = 1 + k + n;
int t = 0;
int v = s + 1;
rep(i, m) {
int a, b, c;
cin >> a >> b >> c;
add_edge(a, b, c);
add_edge(b, a, c);
}
rep(i, k) add_edge(s, i + 1, INF);
int res = max_flow(s, t);
vector<edge> Greg[MAX_V];
rep(i, v) Greg[i] = G[i];
bool used[MAX_V] = {};
used[s] = true;
isUsedDfs(s, t, used);
int ans = 0;
vector<int> sflow(v, -1), tflow(v, -1);
rep(i, v) {
for (auto e : Greg[i]) {
if (used[i] && !used[e.to]) {
rep(i, v) G[i] = Greg[i];
if (sflow[i] == -1)
sflow[i] = max_flow(s, i);
if (tflow[e.to] == -1)
tflow[e.to] = max_flow(e.to, t);
ans = max(ans, res + min(sflow[i], tflow[e.to]));
}
}
}
if (ans >= INF)
cout << "overfuro" << endl;
else
cout << ans << endl;
}
|
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define INF (1e9 + 1)
// #define INF (1LL<<59)
#define MAX_V 110
struct edge {
int to, cap, rev;
};
vector<edge> G[MAX_V]; //??°???????????????
int level[MAX_V]; //?§??????????????????¢
int iter[MAX_V]; //???????????§????????????
// from??????to?????????????????????cap???????????°?????????????????????
void add_edge(int from, int to, int cap) {
G[from].push_back((edge){to, cap, (int)G[to].size()});
G[to].push_back((edge){from, 0, (int)G[from].size() - 1});
}
// s????????????????????¢???BFS??§?¨??????????
void bfs(int s) {
rep(i, MAX_V) level[i] = -1;
queue<int> que;
level[s] = 0;
que.push(s);
while (!que.empty()) {
int v = que.front();
que.pop();
rep(i, G[v].size()) {
edge &e = G[v][i];
if (e.cap > 0 && level[e.to] < 0) {
level[e.to] = level[v] + 1;
que.push(e.to);
}
}
}
}
//?¢?????????????DFS??§??¢???
int dfs(int v, int t, int f) {
if (v == t)
return f;
for (int &i = iter[v]; i < G[v].size(); i++) {
edge &e = G[v][i];
if (e.cap > 0 && level[v] < level[e.to]) {
int d = dfs(e.to, t, min(f, e.cap));
if (d > 0) {
e.cap -= d;
G[e.to][e.rev].cap += d;
return d;
}
}
}
return 0;
}
// s??????t???????????§???????±???????
int max_flow(int s, int t) {
if (s == t)
return INF;
int flow = 0;
for (;;) {
bfs(s);
if (level[t] < 0)
return flow;
memset(iter, 0, sizeof(iter));
int f;
while ((f = dfs(s, t, INF)) > 0) {
flow += f;
}
}
}
void isUsedDfs(int s, int t, bool used[MAX_V]) {
if (s == t)
return;
for (auto &e : G[s]) {
if (!used[e.to] && e.cap > 0) {
used[e.to] = true;
isUsedDfs(e.to, t, used);
}
}
}
int main() {
int k, n, m;
cin >> k >> n >> m;
int s = 1 + k + n;
int t = 0;
int v = s + 1;
rep(i, m) {
int a, b, c;
cin >> a >> b >> c;
add_edge(a, b, c);
add_edge(b, a, c);
}
rep(i, k) add_edge(s, i + 1, INF);
int res = max_flow(s, t);
vector<edge> Greg[MAX_V];
rep(i, v) Greg[i] = G[i];
bool used[MAX_V] = {};
used[s] = true;
isUsedDfs(s, t, used);
int ans = 0;
vector<int> sflow(v, -1), tflow(v, -1);
rep(i, v) {
for (auto e : Greg[i]) {
if (used[i] && !used[e.to]) {
rep(i, v) G[i] = Greg[i];
if (sflow[i] == -1)
sflow[i] = max_flow(s, i);
if (tflow[e.to] == -1)
tflow[e.to] = max_flow(e.to, t);
ans = max(ans, res + min(sflow[i], tflow[e.to]));
}
}
}
if (ans >= INF)
cout << "overfuro" << endl;
else
cout << ans << endl;
}
|
replace
| 10 | 11 | 10 | 11 |
0
| |
p01904
|
C++
|
Time Limit Exceeded
|
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
class Point {
public:
int y, x;
Point() { y = x = 0; }
Point(int y0, int x0) {
y = y0;
x = x0;
}
Point operator+(const Point &p) const { return Point(y + p.y, x + p.x); }
Point operator-(const Point &p) const { return Point(y - p.y, x - p.x); }
Point operator*(int a) const { return Point(y * a, x * a); }
bool operator==(const Point &p) const { return y == p.y && x == p.x; }
bool operator<(const Point &p) const {
return make_pair(y, x) < make_pair(p.y, p.x);
}
long long length2() const { return y * (long long)y + x * (long long)x; }
long long dist2(const Point &p) const {
return (y - p.y) * (long long)(y - p.y) + (x - p.x) * (long long)(x - p.x);
}
long long dot(const Point &p) const {
return y * (long long)p.y + x * (long long)p.x; // |a|*|b|*cos??
}
long long cross(const Point &p) const {
return x * (long long)p.y - y * (long long)p.x; // |a|*|b|*sin??
}
};
void convexHull(const vector<Point> &p0, vector<Point> &ch) {
class Compare {
public:
bool operator()(const Point &a, const Point &b) {
return a.x < b.x || (a.x == b.x && a.y < b.y);
}
};
vector<Point> p = p0;
sort(p.begin(), p.end(), Compare());
int n = p.size();
int j = 0;
ch.clear();
for (int i = 0; i < 2 * n - 1; ++i) {
Point tmp = (i < n ? p[i] : p[2 * (n - 1) - i]);
while (j >= 2 && (tmp - ch[j - 2]).cross(ch[j - 1] - ch[j - 2]) < 0) {
ch.pop_back();
--j;
}
ch.push_back(tmp);
++j;
}
ch.pop_back();
}
const int dy[] = {0, 1, 0, -1};
const int dx[] = {-1, 0, 1, 0};
int main() {
int n;
cin >> n;
vector<int> y(n), x(n);
for (int i = 1; i < n; ++i) {
int a, d;
cin >> a >> d;
y[i] = y[a] + dy[d];
x[i] = x[a] + dx[d];
}
set<Point> s;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < 4; ++j) {
int y2 = y[i] + j / 2;
int x2 = x[i] + j % 2;
s.insert(Point(y2, x2));
}
}
vector<Point> ch;
convexHull(vector<Point>(s.begin(), s.end()), ch);
int m = ch.size();
double ans = DBL_MAX;
for (int i = 0; i < m; ++i) {
Point d = ch[(i + 1) % m] - ch[i];
double theta = atan2((double)d.y, (double)d.x);
double yMin = DBL_MAX;
double yMax = -DBL_MAX;
double xMin = DBL_MAX;
double xMax = -DBL_MAX;
for (int j = 0; j < m; ++j) {
double y2 = ch[j].x * sin(-theta) + ch[j].y * cos(-theta);
double x2 = ch[j].x * cos(-theta) - ch[j].y * sin(-theta);
yMin = min(yMin, y2);
yMax = max(yMax, y2);
xMin = min(xMin, x2);
xMax = max(xMax, x2);
}
ans = min(ans, (yMax - yMin) * (xMax - xMin));
}
printf("%.10f\n", ans);
return 0;
}
|
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
class Point {
public:
int y, x;
Point() { y = x = 0; }
Point(int y0, int x0) {
y = y0;
x = x0;
}
Point operator+(const Point &p) const { return Point(y + p.y, x + p.x); }
Point operator-(const Point &p) const { return Point(y - p.y, x - p.x); }
Point operator*(int a) const { return Point(y * a, x * a); }
bool operator==(const Point &p) const { return y == p.y && x == p.x; }
bool operator<(const Point &p) const {
return make_pair(y, x) < make_pair(p.y, p.x);
}
long long length2() const { return y * (long long)y + x * (long long)x; }
long long dist2(const Point &p) const {
return (y - p.y) * (long long)(y - p.y) + (x - p.x) * (long long)(x - p.x);
}
long long dot(const Point &p) const {
return y * (long long)p.y + x * (long long)p.x; // |a|*|b|*cos??
}
long long cross(const Point &p) const {
return x * (long long)p.y - y * (long long)p.x; // |a|*|b|*sin??
}
};
void convexHull(const vector<Point> &p0, vector<Point> &ch) {
class Compare {
public:
bool operator()(const Point &a, const Point &b) {
return a.x < b.x || (a.x == b.x && a.y < b.y);
}
};
vector<Point> p = p0;
sort(p.begin(), p.end(), Compare());
int n = p.size();
int j = 0;
ch.clear();
for (int i = 0; i < 2 * n - 1; ++i) {
Point tmp = (i < n ? p[i] : p[2 * (n - 1) - i]);
while (j >= 2 && (tmp - ch[j - 2]).cross(ch[j - 1] - ch[j - 2]) <= 0) {
ch.pop_back();
--j;
}
ch.push_back(tmp);
++j;
}
ch.pop_back();
}
const int dy[] = {0, 1, 0, -1};
const int dx[] = {-1, 0, 1, 0};
int main() {
int n;
cin >> n;
vector<int> y(n), x(n);
for (int i = 1; i < n; ++i) {
int a, d;
cin >> a >> d;
y[i] = y[a] + dy[d];
x[i] = x[a] + dx[d];
}
set<Point> s;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < 4; ++j) {
int y2 = y[i] + j / 2;
int x2 = x[i] + j % 2;
s.insert(Point(y2, x2));
}
}
vector<Point> ch;
convexHull(vector<Point>(s.begin(), s.end()), ch);
int m = ch.size();
double ans = DBL_MAX;
for (int i = 0; i < m; ++i) {
Point d = ch[(i + 1) % m] - ch[i];
double theta = atan2((double)d.y, (double)d.x);
double yMin = DBL_MAX;
double yMax = -DBL_MAX;
double xMin = DBL_MAX;
double xMax = -DBL_MAX;
for (int j = 0; j < m; ++j) {
double y2 = ch[j].x * sin(-theta) + ch[j].y * cos(-theta);
double x2 = ch[j].x * cos(-theta) - ch[j].y * sin(-theta);
yMin = min(yMin, y2);
yMax = max(yMax, y2);
xMin = min(xMin, x2);
xMax = max(xMax, x2);
}
ans = min(ans, (yMax - yMin) * (xMax - xMin));
}
printf("%.10f\n", ans);
return 0;
}
|
replace
| 67 | 68 | 67 | 68 |
TLE
| |
p01905
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define mp(a, b) make_pair((a), (b))
#define pb(a) push_back((a))
#define all(x) (x).begin(), (x).end()
#define uniq(x) sort(all(x)), (x).erase(unique(all(x)), end(x))
#define fi first
#define se second
#define dbg(x) cout << #x " = " << ((x)) << endl
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &p) {
o << "(" << p.fi << "," << p.se << ")";
return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
o << "[";
for (T t : v) {
o << t << ",";
}
o << "]";
return o;
}
#define INF 2147483600
int main() {
int n, m;
cin >> n >> m;
vector<int> vec(m);
rep(i, m) cin >> vec[i];
vector<bool> b(n, true);
rep(i, m) b[vec[i] - 1] = false;
int ans = 0;
for (int d = 1; d < n; d *= 2) {
for (int i = 0; i < n; i += d * 2) {
if (b[i] && b[i + d])
ans++;
else if (b[i] || b[i + d])
b[i] = true;
}
// dbg(b);
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define mp(a, b) make_pair((a), (b))
#define pb(a) push_back((a))
#define all(x) (x).begin(), (x).end()
#define uniq(x) sort(all(x)), (x).erase(unique(all(x)), end(x))
#define fi first
#define se second
#define dbg(x) cout << #x " = " << ((x)) << endl
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &p) {
o << "(" << p.fi << "," << p.se << ")";
return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
o << "[";
for (T t : v) {
o << t << ",";
}
o << "]";
return o;
}
#define INF 2147483600
int main() {
int n, m;
cin >> n >> m;
vector<int> vec(m);
rep(i, m) cin >> vec[i];
vector<bool> b(n, true);
rep(i, m) b[vec[i]] = false;
int ans = 0;
for (int d = 1; d < n; d *= 2) {
for (int i = 0; i < n; i += d * 2) {
if (b[i] && b[i + d])
ans++;
else if (b[i] || b[i + d])
b[i] = true;
}
// dbg(b);
}
cout << ans << endl;
return 0;
}
|
replace
| 34 | 35 | 34 | 35 |
0
| |
p01906
|
C++
|
Runtime Error
|
#include <cstdio>
const int MAX_N = 1000;
int N, M;
int A[MAX_N];
int gcf(int a, int b);
int ans = 0;
int main() {
scanf("%d %d", &N, &M);
for (int i = 0; i < N; i++) {
scanf("%d", &A[i]);
}
if (N % M == 0) {
for (int i = 0; i < N; i += M) {
int max = 0, min = 1000;
for (int j = 0; j < M; j++) {
if (A[i + j] < min)
min = A[i + j];
if (A[i + j] > max)
max = A[i + j];
}
ans += max - min;
}
} else {
int gnum = 0;
int gcfn = gcf(N, M);
gnum = N / gcfn;
for (int i = 0; i < gnum; i++) {
int max = 0, min = 1000;
for (int j = 0; j < M; j++) {
int dum = 0;
if (i * M - i * N + j < 0)
dum = M + 1;
if (A[i * M - i * N + j + dum] < min)
min = A[i * M - i * N + j + dum];
if (A[i * M - i * N + j + dum] > max)
max = A[i * M - i * N + j + dum];
}
ans += max - min;
}
}
printf("%d\n", ans);
return 0;
}
int gcf(int a, int b) {
if (a < b) {
int dum = a;
a = b;
b = dum;
}
if (a % b == 1)
return 1;
else if (a % b == 0)
return b;
else
gcf(b, a % b);
}
|
#include <cstdio>
const int MAX_N = 1000;
int N, M;
int A[MAX_N];
int gcf(int a, int b);
int ans = 0;
int main() {
scanf("%d %d", &N, &M);
for (int i = 0; i < N; i++) {
scanf("%d", &A[i]);
}
if (N % M == 0) {
for (int i = 0; i < N; i += M) {
int max = 0, min = 1000;
for (int j = 0; j < M; j++) {
if (A[i + j] < min)
min = A[i + j];
if (A[i + j] > max)
max = A[i + j];
}
ans += max - min;
}
} else {
int gnum = 0;
int gcfn = gcf(N, M);
gnum = N / gcfn;
for (int i = 0; i < gnum; i++) {
int max = 0, min = 1000;
for (int j = 0; j < M; j++) {
int k = (i * M + j) % (N);
if (A[k] < min)
min = A[k];
if (A[k] > max)
max = A[k];
}
ans += max - min;
}
}
printf("%d\n", ans);
return 0;
}
int gcf(int a, int b) {
if (a < b) {
int dum = a;
a = b;
b = dum;
}
if (a % b == 1)
return 1;
else if (a % b == 0)
return b;
else
gcf(b, a % b);
}
|
replace
| 33 | 40 | 33 | 38 |
0
| |
p01906
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#define lol(i, n) for (int i = 0; i < n; i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
int a[110];
pair<int, int> F(int left, int right) {
int p = -1, q = mod;
for (int i = left; i < right; i++) {
p = max(p, a[i]);
q = min(q, a[i]);
}
return make_pair(p, q);
}
int main() {
int n, m;
cin >> n >> m;
lol(i, n) cin >> a[i];
if (n == m) {
pair<int, int> tmp = F(0, n);
cout << tmp.first - tmp.second << endl;
return 0;
}
int left = 0, right = m;
int ans = 0;
while (true) {
int p, q;
if (left < right) {
pair<int, int> tmp = F(left, right);
p = tmp.first, q = tmp.second;
} else {
pair<int, int> tmp = F(0, right);
p = tmp.first, q = tmp.second;
tmp = F(left, n);
p = max(p, tmp.first);
q = min(q, tmp.second);
}
ans += p - q;
left = right % n;
right = (right + m) % n;
if (right <= 0)
right += n;
if (left == 0)
break;
}
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#define lol(i, n) for (int i = 0; i < n; i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
int a[1100];
pair<int, int> F(int left, int right) {
int p = -1, q = mod;
for (int i = left; i < right; i++) {
p = max(p, a[i]);
q = min(q, a[i]);
}
return make_pair(p, q);
}
int main() {
int n, m;
cin >> n >> m;
lol(i, n) cin >> a[i];
if (n == m) {
pair<int, int> tmp = F(0, n);
cout << tmp.first - tmp.second << endl;
return 0;
}
int left = 0, right = m;
int ans = 0;
while (true) {
int p, q;
if (left < right) {
pair<int, int> tmp = F(left, right);
p = tmp.first, q = tmp.second;
} else {
pair<int, int> tmp = F(0, right);
p = tmp.first, q = tmp.second;
tmp = F(left, n);
p = max(p, tmp.first);
q = min(q, tmp.second);
}
ans += p - q;
left = right % n;
right = (right + m) % n;
if (right <= 0)
right += n;
if (left == 0)
break;
}
cout << ans << endl;
return 0;
}
|
replace
| 8 | 9 | 8 | 9 |
0
| |
p01907
|
C++
|
Runtime Error
|
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#include <cstdio>
inline int getInt() {
int s;
scanf("%d", &s);
return s;
}
inline double getDouble() {
double s;
scanf("%lf", &s);
return s;
}
#include <queue>
#include <set>
using namespace std;
vector<pair<int, int>> g[10000];
double pp[100000];
double p;
double dfs(int pos, double prob = 1, int prev = -1) {
::pp[pos] = prob;
double ans = 0;
REP(i, g[pos].size()) {
const int next = g[pos][i].first;
const int c = g[pos][i].second;
if (next != prev) {
ans += p * (c + dfs(next, prob * p, pos));
}
}
return ans;
}
int main() {
::p = getDouble();
const int n = getInt();
REP(i, n - 1) {
const int a = getInt() - 1;
const int b = getInt() - 1;
const int c = getInt();
g[a].push_back(make_pair(b, c));
g[b].push_back(make_pair(a, c));
}
const double t = dfs(0);
double ans = t;
REP(i, n) { ans += pp[i] * t; }
printf("%.10f\n", ans);
}
|
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#include <cstdio>
inline int getInt() {
int s;
scanf("%d", &s);
return s;
}
inline double getDouble() {
double s;
scanf("%lf", &s);
return s;
}
#include <queue>
#include <set>
using namespace std;
vector<pair<int, int>> g[100000];
double pp[100000];
double p;
double dfs(int pos, double prob = 1, int prev = -1) {
::pp[pos] = prob;
double ans = 0;
REP(i, g[pos].size()) {
const int next = g[pos][i].first;
const int c = g[pos][i].second;
if (next != prev) {
ans += p * (c + dfs(next, prob * p, pos));
}
}
return ans;
}
int main() {
::p = getDouble();
const int n = getInt();
REP(i, n - 1) {
const int a = getInt() - 1;
const int b = getInt() - 1;
const int c = getInt();
g[a].push_back(make_pair(b, c));
g[b].push_back(make_pair(a, c));
}
const double t = dfs(0);
double ans = t;
REP(i, n) { ans += pp[i] * t; }
printf("%.10f\n", ans);
}
|
replace
| 19 | 20 | 19 | 20 |
0
| |
p01907
|
C++
|
Runtime Error
|
#include <cstdio>
#include <math.h>
#include <vector>
using namespace std;
const int MAX_N = 10000;
struct edge {
int to, cost;
};
vector<edge> tree[MAX_N];
bool flag[MAX_N] = {false};
int depth[MAX_N];
int s, t, c;
double sum = 0.0;
double ans = 0.0;
double p;
int N;
void dfs(int v, int d) {
flag[v] = true;
depth[v] = d;
for (int i = 0; i < tree[v].size(); i++) {
if (!flag[tree[v][i].to]) {
sum += tree[v][i].cost * pow(p, (d + 1.0));
dfs(tree[v][i].to, d + 1);
}
}
}
int main() {
scanf("%lf %d", &p, &N);
for (int i = 0; i < N - 1; i++) {
scanf("%d %d %d", &s, &t, &c);
s--;
t--;
edge e;
e.to = t;
e.cost = c;
tree[s].push_back(e);
e.to = s;
tree[t].push_back(e);
}
dfs(0, 0);
ans = 2 * sum;
for (int i = 1; i < N; i++) {
ans += sum * pow(p, depth[i]);
}
printf("%.10lf\n", ans);
return 0;
}
|
#include <cstdio>
#include <math.h>
#include <vector>
using namespace std;
const int MAX_N = 100001;
struct edge {
int to, cost;
};
vector<edge> tree[MAX_N];
bool flag[MAX_N] = {false};
int depth[MAX_N];
int s, t, c;
double sum = 0.0;
double ans = 0.0;
double p;
int N;
void dfs(int v, int d) {
flag[v] = true;
depth[v] = d;
for (int i = 0; i < tree[v].size(); i++) {
if (!flag[tree[v][i].to]) {
sum += tree[v][i].cost * pow(p, (d + 1.0));
dfs(tree[v][i].to, d + 1);
}
}
}
int main() {
scanf("%lf %d", &p, &N);
for (int i = 0; i < N - 1; i++) {
scanf("%d %d %d", &s, &t, &c);
s--;
t--;
edge e;
e.to = t;
e.cost = c;
tree[s].push_back(e);
e.to = s;
tree[t].push_back(e);
}
dfs(0, 0);
ans = 2 * sum;
for (int i = 1; i < N; i++) {
ans += sum * pow(p, depth[i]);
}
printf("%.10lf\n", ans);
return 0;
}
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p01908
|
C++
|
Runtime Error
|
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
//// < "d:\d_download\visual studio
///2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual
///studio 2015\projects\programing_contest_c++\debug\b.txt"
int main() {
int N;
cin >> N;
set<string> dangers;
for (int i = 0; i < N; ++i) {
string st;
cin >> st;
for (int asize = 1; asize <= 4; ++asize) {
for (int l = 0; l <= st.size() - asize; ++l) {
dangers.emplace(st.substr(l, asize));
}
}
}
int num = 1;
bool flag = false;
string ans = "dd";
for (int asize = 1; asize <= 4; ++asize) {
num *= 26;
for (int j = 0; j < num; ++j) {
string pass(asize, ' ');
int n(j);
for (int i = 0; i < asize; ++i) {
pass[asize - i - 1] = n % 26 + 'a';
n /= 26;
}
if (dangers.find(pass) == dangers.end()) {
ans = pass;
flag = true;
break;
}
}
if (flag)
break;
}
cout << ans << endl;
return 0;
}
|
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;
//// < "d:\d_download\visual studio
///2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual
///studio 2015\projects\programing_contest_c++\debug\b.txt"
int main() {
int N;
cin >> N;
set<string> dangers;
for (int i = 0; i < N; ++i) {
string st;
cin >> st;
for (int asize = 1; asize <= 4; ++asize) {
for (int l = 0; l <= int(st.size()) - asize; ++l) {
dangers.emplace(st.substr(l, asize));
}
}
}
int num = 1;
bool flag = false;
string ans = "dd";
for (int asize = 1; asize <= 4; ++asize) {
num *= 26;
for (int j = 0; j < num; ++j) {
string pass(asize, ' ');
int n(j);
for (int i = 0; i < asize; ++i) {
pass[asize - i - 1] = n % 26 + 'a';
n /= 26;
}
if (dangers.find(pass) == dangers.end()) {
ans = pass;
flag = true;
break;
}
}
if (flag)
break;
}
cout << ans << endl;
return 0;
}
|
replace
| 20 | 21 | 20 | 21 |
0
| |
p01908
|
C++
|
Memory Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, x, y) for (int i = (x); i < (y); ++i)
#define debug(x) #x << "=" << (x)
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
const int inf = 1e9;
const int64_t inf64 = 1e18;
const double eps = 1e-9;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (const auto &v : vec) {
os << v << ",";
}
os << "]";
return os;
}
using i64 = int64_t;
class trie {
public:
trie *next[26];
trie() { fill(next, next + 26, (trie *)0); }
void insert(const string &str) { insert(str, 0); }
bool find(const string &str) { return find(str, 0); }
void insert(const string &str, const int idx) {
if (idx == str.size())
return;
if (this->next[str[idx] - 'a'] == NULL)
this->next[str[idx] - 'a'] = new trie();
this->next[str[idx] - 'a']->insert(str, idx + 1);
}
bool find(const string &str, const int idx) {
if (idx == str.size())
return true;
if (this->next[str[idx] - 'a'] == NULL)
return false;
return this->next[str[idx] - 'a']->find(str, idx + 1);
}
};
void solve() {
int n;
cin >> n;
set<string> st;
rep(i, 0, n) {
string s;
cin >> s;
rep(j, 0, s.size()) {
rep(k, 1, 5) {
if (j + k > s.size())
break;
st.insert(s.substr(j, k));
}
}
}
queue<string> que;
rep(i, 0, 26) que.push(string(1, 'a' + i));
while (true) {
auto s = que.front();
que.pop();
if (st.find(s) == st.end()) {
cout << s << endl;
return;
}
rep(i, 0, 26) {
s.push_back('a' + i);
que.push(s);
s.pop_back();
}
}
}
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(10);
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, x, y) for (int i = (x); i < (y); ++i)
#define debug(x) #x << "=" << (x)
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
const int inf = 1e9;
const int64_t inf64 = 1e18;
const double eps = 1e-9;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (const auto &v : vec) {
os << v << ",";
}
os << "]";
return os;
}
using i64 = int64_t;
class trie {
public:
trie *next[26];
trie() { fill(next, next + 26, (trie *)0); }
void insert(const string &str) { insert(str, 0); }
bool find(const string &str) { return find(str, 0); }
void insert(const string &str, const int idx) {
if (idx == str.size())
return;
if (this->next[str[idx] - 'a'] == NULL)
this->next[str[idx] - 'a'] = new trie();
this->next[str[idx] - 'a']->insert(str, idx + 1);
}
bool find(const string &str, const int idx) {
if (idx == str.size())
return true;
if (this->next[str[idx] - 'a'] == NULL)
return false;
return this->next[str[idx] - 'a']->find(str, idx + 1);
}
};
void solve() {
int n;
cin >> n;
set<string> st;
rep(i, 0, n) {
string s;
cin >> s;
rep(j, 0, s.size()) {
rep(k, 1, 5) {
if (j + k > s.size())
break;
st.insert(s.substr(j, k));
}
}
}
queue<string> que;
rep(i, 0, 26) que.push(string(1, 'a' + i));
while (true) {
auto s = que.front();
que.pop();
if (st.find(s) == st.end()) {
cout << s << endl;
return;
}
if (s.size() == 4)
continue;
rep(i, 0, 26) {
s.push_back('a' + i);
que.push(s);
s.pop_back();
}
}
}
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(10);
solve();
return 0;
}
|
insert
| 75 | 75 | 75 | 77 |
MLE
| |
p01908
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const int MAX = 1000000;
bool a[MAX];
int main() {
int n;
cin >> n;
vector<string> s(n);
REP(i, n) cin >> s[i];
FOR(l, 1, 5) {
REP(i, n) {
REP(j, s[i].length() - l + 1) {
ll p = 0;
REP(k, l) { p = 27 * p + s[i][j + k] - 'a' + 1; }
if (p >= MAX)
break;
a[p] = true;
}
}
}
FOR(i, 1, MAX - 1) {
if (a[i])
continue;
int x = i;
string ans;
bool f = true;
while (x) {
if (x % 27 == 0)
f = false;
char c = (x % 27) - 1 + 'a';
ans = c + ans;
x /= 27;
}
if (f) {
cout << ans << endl;
return 0;
}
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const int MAX = 1000000;
bool a[MAX];
int main() {
int n;
cin >> n;
vector<string> s(n);
REP(i, n) cin >> s[i];
FOR(l, 1, 5) {
REP(i, n) {
if (s[i].length() < l)
continue;
REP(j, s[i].length() - l + 1) {
ll p = 0;
REP(k, l) { p = 27 * p + s[i][j + k] - 'a' + 1; }
if (p >= MAX)
break;
a[p] = true;
}
}
}
FOR(i, 1, MAX - 1) {
if (a[i])
continue;
int x = i;
string ans;
bool f = true;
while (x) {
if (x % 27 == 0)
f = false;
char c = (x % 27) - 1 + 'a';
ans = c + ans;
x /= 27;
}
if (f) {
cout << ans << endl;
return 0;
}
}
return 0;
}
|
insert
| 37 | 37 | 37 | 39 |
0
| |
p01908
|
C++
|
Runtime Error
|
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
using namespace std;
typedef pair<long long int, long long int> P;
long long int INF = 1e18;
long long int MOD = 1e9 + 7;
unordered_map<string, bool> m;
string str = "";
bool func(int pos, int num) {
if (pos == num) {
if (m.find(str) == m.end()) {
cout << str << endl;
return true;
}
return false;
}
for (int i = 0; i < 26; i++) {
str[pos] = 'a' + i;
if (func(pos + 1, num)) {
return true;
}
}
return false;
}
int main() {
int N;
cin >> N;
for (int i = 0; i < N; i++) {
string S;
cin >> S;
for (int i = 1; i <= 4; i++) {
for (int j = 0; j < S.size() - i + 1; j++) {
m[S.substr(j, i)] = true;
}
}
}
for (int i = 1; i <= 4; i++) {
str += " ";
if (func(0, i)) {
return 0;
}
}
return 0;
}
|
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
using namespace std;
typedef pair<long long int, long long int> P;
long long int INF = 1e18;
long long int MOD = 1e9 + 7;
unordered_map<string, bool> m;
string str = "";
bool func(int pos, int num) {
if (pos == num) {
if (m.find(str) == m.end()) {
cout << str << endl;
return true;
}
return false;
}
for (int i = 0; i < 26; i++) {
str[pos] = 'a' + i;
if (func(pos + 1, num)) {
return true;
}
}
return false;
}
int main() {
int N;
cin >> N;
for (int i = 0; i < N; i++) {
string S;
cin >> S;
for (int i = 1; i <= 4; i++) {
for (int j = 0; j < (int)S.size() - i + 1; j++) {
m[S.substr(j, i)] = true;
}
}
}
for (int i = 1; i <= 4; i++) {
str += " ";
if (func(0, i)) {
return 0;
}
}
return 0;
}
|
replace
| 47 | 48 | 47 | 48 |
0
| |
p01908
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
#define MAX_L 8
#define MAX_N 100005
typedef long long ll;
ll mod = 1e9 + 7;
ll B = 5575777;
int N;
string S[MAX_N];
set<ll> t[MAX_L + 1];
char tmp[MAX_L + 5];
bool dfs(ll hash, int depth, int anslen) {
if (depth == anslen) {
if (t[anslen].count(hash) == 1)
return false;
for (int i = 0; i < depth; i++)
cout << tmp[i];
cout << endl;
return true;
}
for (char ch = 'a'; ch <= 'z'; ch++) {
tmp[depth] = ch;
ll nhash = (hash * B + ch) % mod;
if (dfs(nhash, depth + 1, anslen))
return true;
}
return false;
}
void solve() {
for (int i = 0; i < N; i++) {
int size = S[i].size();
for (int j = 1; j <= MAX_L; j++) {
ll key = 0, nb = 1;
for (int k = 0; k < size; k++) {
key = (key * B + S[i][k]) % mod;
if (k - j >= 0) {
key += (mod - (S[i][k - j] * nb) % mod);
key %= mod;
} else
nb = (nb * B) % mod;
if (k + 1 >= j)
t[j].insert(key);
}
}
}
ll cnt = 1;
int anslen = 1;
for (int i = 1; i <= MAX_L; i++) {
cnt *= 26;
if ((ll)t[i].size() < cnt) {
anslen = i;
break;
}
}
dfs(0, 0, anslen);
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
cin >> N;
for (int i = 0; i < N; i++)
cin >> S[i];
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define MAX_L 8
#define MAX_N 100005
typedef long long ll;
ll mod = 1e9 + 7;
ll B = 5575777;
int N;
string S[MAX_N];
unordered_set<ll> t[MAX_L + 1];
char tmp[MAX_L + 5];
bool dfs(ll hash, int depth, int anslen) {
if (depth == anslen) {
if (t[anslen].count(hash) == 1)
return false;
for (int i = 0; i < depth; i++)
cout << tmp[i];
cout << endl;
return true;
}
for (char ch = 'a'; ch <= 'z'; ch++) {
tmp[depth] = ch;
ll nhash = (hash * B + ch) % mod;
if (dfs(nhash, depth + 1, anslen))
return true;
}
return false;
}
void solve() {
for (int i = 0; i < N; i++) {
int size = S[i].size();
for (int j = 1; j <= MAX_L; j++) {
ll key = 0, nb = 1;
for (int k = 0; k < size; k++) {
key = (key * B + S[i][k]) % mod;
if (k - j >= 0) {
key += (mod - (S[i][k - j] * nb) % mod);
key %= mod;
} else
nb = (nb * B) % mod;
if (k + 1 >= j)
t[j].insert(key);
}
}
}
ll cnt = 1;
int anslen = 1;
for (int i = 1; i <= MAX_L; i++) {
cnt *= 26;
if ((ll)t[i].size() < cnt) {
anslen = i;
break;
}
}
dfs(0, 0, anslen);
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
cin >> N;
for (int i = 0; i < N; i++)
cin >> S[i];
solve();
return 0;
}
|
replace
| 10 | 11 | 10 | 11 |
TLE
| |
p01908
|
C++
|
Memory Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<string> S;
for (int i = 0; i < N; i++) {
string s;
cin >> s;
S.push_back(s);
}
set<string> st;
for (int i = 0; i < N; i++) {
string s = S[i];
for (int j = 1; j <= s.size(); j++) {
for (int k = 0; k + j <= s.size(); k++) {
st.insert(s.substr(k, j));
}
}
}
vector<int> vec(5, -1);
while (1) {
bool carry = true;
for (int i = 0; carry; i++) {
carry = false;
vec[i]++;
if (vec[i] >= 26) {
vec[i] = 0;
carry = true;
}
}
if (~vec[4])
break;
string ans = "";
for (int i = 0; vec[i] != -1; i++)
ans += 'a' + vec[i];
reverse(ans.begin(), ans.end());
if (st.count(ans))
continue;
else {
cout << ans << endl;
return 0;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<string> S;
for (int i = 0; i < N; i++) {
string s;
cin >> s;
S.push_back(s);
}
set<string> st;
for (int i = 0; i < N; i++) {
string s = S[i];
for (int j = 1; j <= 4; j++) {
for (int k = 0; k + j <= s.size(); k++) {
st.insert(s.substr(k, j));
}
}
}
vector<int> vec(5, -1);
while (1) {
bool carry = true;
for (int i = 0; carry; i++) {
carry = false;
vec[i]++;
if (vec[i] >= 26) {
vec[i] = 0;
carry = true;
}
}
if (~vec[4])
break;
string ans = "";
for (int i = 0; vec[i] != -1; i++)
ans += 'a' + vec[i];
reverse(ans.begin(), ans.end());
if (st.count(ans))
continue;
else {
cout << ans << endl;
return 0;
}
}
return 0;
}
|
replace
| 15 | 16 | 15 | 16 |
MLE
| |
p01908
|
C++
|
Memory Limit Exceeded
|
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
const int width = 20;
bool dfs(const int len, unordered_set<string> &S, string pas) {
if ((int)pas.size() >= len) {
if (S.count(pas) == 0) {
cout << pas << endl;
return true;
}
return false;
}
rep(i, 26) {
string npas = pas + string(1, (char)('a' + i));
if (dfs(len, S, npas))
return true;
}
return false;
}
int main() {
int n;
cin >> n;
unordered_set<string> S;
rep(i, n) {
string s;
cin >> s;
rep(j, (int)s.size()) {
rep(k, width) {
if (j + k >= (int)s.size())
break;
S.insert(s.substr(j, k + 1));
}
}
}
REP(len, 1, width) if (dfs(len, S, "")) break;
return 0;
}
|
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
const int width = 7;
bool dfs(const int len, unordered_set<string> &S, string pas) {
if ((int)pas.size() >= len) {
if (S.count(pas) == 0) {
cout << pas << endl;
return true;
}
return false;
}
rep(i, 26) {
string npas = pas + string(1, (char)('a' + i));
if (dfs(len, S, npas))
return true;
}
return false;
}
int main() {
int n;
cin >> n;
unordered_set<string> S;
rep(i, n) {
string s;
cin >> s;
rep(j, (int)s.size()) {
rep(k, width) {
if (j + k >= (int)s.size())
break;
S.insert(s.substr(j, k + 1));
}
}
}
REP(len, 1, width) if (dfs(len, S, "")) break;
return 0;
}
|
replace
| 7 | 8 | 7 | 8 |
MLE
| |
p01908
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i++)
string _s;
int _n;
int sa_k;
vector<int> Rank, tmp, sa, lcp;
bool cmp_sa(int i, int j) {
if (Rank[i] != Rank[j])
return Rank[i] < Rank[j];
return (i + sa_k <= _n ? Rank[i + sa_k] : -1) <
(j + sa_k <= _n ? Rank[j + sa_k] : -1);
}
void construct_sa() {
for (int i = 0; i <= _n; i++) {
sa[i] = i;
Rank[i] = i < _n ? _s[i] : -1;
}
for (sa_k = 1; sa_k <= _n; sa_k *= 2) {
sort(sa.begin(), sa.end(), cmp_sa);
tmp[sa[0]] = 0;
for (int i = 1; i <= _n; i++)
tmp[sa[i]] = tmp[sa[i - 1]] + (cmp_sa(sa[i - 1], sa[i]) ? 1 : 0);
for (int i = 0; i <= _n; i++)
Rank[i] = tmp[i];
}
}
void construct_lcp() {
for (int i = 0; i <= _n; i++)
Rank[sa[i]] = i;
int h = 0;
lcp[0] = 0;
for (int i = 0; i < _n; i++) {
int j = sa[Rank[i] - 1];
if (h > 0)
h--;
for (; j + h < _n && i + h < _n; h++)
if (_s[j + h] != _s[i + h])
break;
lcp[Rank[i] - 1] = h;
}
}
void init(string s) {
_s = s;
_n = s.length();
Rank = vector<int>(_n + 1);
tmp = vector<int>(_n + 1);
sa = vector<int>(_n + 1);
lcp = vector<int>(_n + 1);
construct_sa();
construct_lcp();
}
bool chk(string s) {
int lo = 0, hi = _n + 1;
while (lo + 1 != hi) {
int md = (lo + hi) / 2;
if (s <= _s.substr(sa[md]))
hi = md;
else
lo = md;
}
string t = _s.substr(sa[hi], s.length());
return s == t;
}
//-----------------------------------------------------------------------------------
int N;
string S[101010];
//-----------------------------------------------------------------------------------
#define rrep(i, a, b) for (int i = a; i >= b; i--)
string nxt(string x) {
int carry = 1;
rrep(i, x.length() - 1, 0) {
int n = x[i] - 'a' + carry;
carry = 0;
if (26 <= n) {
n %= 26;
carry = 1;
}
x[i] = 'a' + n;
}
if (carry)
x = "a" + x;
return x;
}
//-----------------------------------------------------------------------------------
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N;
rep(i, 0, N) cin >> S[i];
string SS = "";
rep(i, 0, N) SS += "#" + S[i];
init(SS);
string ans = "a";
while (chk(ans))
ans = nxt(ans);
cout << ans << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i++)
string _s;
int _n;
int sa_k;
vector<int> Rank, tmp, sa, lcp;
bool cmp_sa(int i, int j) {
if (Rank[i] != Rank[j])
return Rank[i] < Rank[j];
return (i + sa_k <= _n ? Rank[i + sa_k] : -1) <
(j + sa_k <= _n ? Rank[j + sa_k] : -1);
}
void construct_sa() {
for (int i = 0; i <= _n; i++) {
sa[i] = i;
Rank[i] = i < _n ? _s[i] : -1;
}
for (sa_k = 1; sa_k <= _n; sa_k *= 2) {
sort(sa.begin(), sa.end(), cmp_sa);
tmp[sa[0]] = 0;
for (int i = 1; i <= _n; i++)
tmp[sa[i]] = tmp[sa[i - 1]] + (cmp_sa(sa[i - 1], sa[i]) ? 1 : 0);
for (int i = 0; i <= _n; i++)
Rank[i] = tmp[i];
}
}
void construct_lcp() {
for (int i = 0; i <= _n; i++)
Rank[sa[i]] = i;
int h = 0;
lcp[0] = 0;
for (int i = 0; i < _n; i++) {
int j = sa[Rank[i] - 1];
if (h > 0)
h--;
for (; j + h < _n && i + h < _n; h++)
if (_s[j + h] != _s[i + h])
break;
lcp[Rank[i] - 1] = h;
}
}
void init(string s) {
_s = s;
_n = s.length();
Rank = vector<int>(_n + 1);
tmp = vector<int>(_n + 1);
sa = vector<int>(_n + 1);
lcp = vector<int>(_n + 1);
construct_sa();
construct_lcp();
}
bool chk(string s) {
int lo = 0, hi = _n + 1;
while (lo + 1 != hi) {
int md = (lo + hi) / 2;
if (s <= _s.substr(sa[md], s.length()))
hi = md;
else
lo = md;
}
string t = _s.substr(sa[hi], s.length());
return s == t;
}
//-----------------------------------------------------------------------------------
int N;
string S[101010];
//-----------------------------------------------------------------------------------
#define rrep(i, a, b) for (int i = a; i >= b; i--)
string nxt(string x) {
int carry = 1;
rrep(i, x.length() - 1, 0) {
int n = x[i] - 'a' + carry;
carry = 0;
if (26 <= n) {
n %= 26;
carry = 1;
}
x[i] = 'a' + n;
}
if (carry)
x = "a" + x;
return x;
}
//-----------------------------------------------------------------------------------
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N;
rep(i, 0, N) cin >> S[i];
string SS = "";
rep(i, 0, N) SS += "#" + S[i];
init(SS);
string ans = "a";
while (chk(ans))
ans = nxt(ans);
cout << ans << endl;
}
|
replace
| 57 | 58 | 57 | 58 |
TLE
| |
p01909
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define mp(a, b) make_pair((a), (b))
#define pb(a) push_back((a))
#define all(x) (x).begin(), (x).end()
#define uniq(x) sort(all(x)), (x).erase(unique(all(x)), end(x))
#define fi first
#define se second
#define dbg(x) cout << #x " = " << ((x)) << endl
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &p) {
o << "(" << p.fi << "," << p.se << ")";
return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
o << "[";
for (T t : v) {
o << t << ",";
}
o << "]";
return o;
}
#define INF 147483600
int k;
void solve(vector<char> &s, vector<int> &ans, string str) {
int n = s.size();
for (auto c : str) {
vector<vector<int>> dp(n, vector<int>(k + 1, -INF));
dp[0][0] = (s[0] == c);
dp[0][1] = (s[0] != c);
repl(i, 1, n) {
dp[i][0] = dp[i - 1][0] + (s[i] == c);
repl(j, 1, k + 1) {
if (j % 2 == 0)
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - 1]) + (s[i] == c);
else
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - 1]) + (s[i] != c);
}
}
rep(i, k + 1) ans[i] = max(ans[i], 2 * dp[n - 1][i] - n);
}
}
int main() {
string s;
cin >> s >> k;
vector<char> x, y;
for (auto c : s) {
if (c == 'R' || c == 'L')
x.pb(c);
else
y.pb(c);
}
vector<int> xx(k + 1, 0), yy(k + 1, 0);
solve(x, xx, "RL");
solve(y, yy, "UD");
int ans = 0;
rep(i, k + 1) rep(j, k + 1) if (i + j <= k) ans = max(ans, xx[i] + yy[j]);
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define mp(a, b) make_pair((a), (b))
#define pb(a) push_back((a))
#define all(x) (x).begin(), (x).end()
#define uniq(x) sort(all(x)), (x).erase(unique(all(x)), end(x))
#define fi first
#define se second
#define dbg(x) cout << #x " = " << ((x)) << endl
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &p) {
o << "(" << p.fi << "," << p.se << ")";
return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
o << "[";
for (T t : v) {
o << t << ",";
}
o << "]";
return o;
}
#define INF 147483600
int k;
void solve(vector<char> &s, vector<int> &ans, string str) {
int n = s.size();
if (n == 0)
return;
for (auto c : str) {
vector<vector<int>> dp(n, vector<int>(k + 1, -INF));
dp[0][0] = (s[0] == c);
dp[0][1] = (s[0] != c);
repl(i, 1, n) {
dp[i][0] = dp[i - 1][0] + (s[i] == c);
repl(j, 1, k + 1) {
if (j % 2 == 0)
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - 1]) + (s[i] == c);
else
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - 1]) + (s[i] != c);
}
}
rep(i, k + 1) ans[i] = max(ans[i], 2 * dp[n - 1][i] - n);
}
}
int main() {
string s;
cin >> s >> k;
vector<char> x, y;
for (auto c : s) {
if (c == 'R' || c == 'L')
x.pb(c);
else
y.pb(c);
}
vector<int> xx(k + 1, 0), yy(k + 1, 0);
solve(x, xx, "RL");
solve(y, yy, "UD");
int ans = 0;
rep(i, k + 1) rep(j, k + 1) if (i + j <= k) ans = max(ans, xx[i] + yy[j]);
cout << ans << endl;
return 0;
}
|
insert
| 31 | 31 | 31 | 33 |
0
| |
p01910
|
C++
|
Runtime Error
|
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int, int> pii;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb emplace_back
#define INF (1LL << 60)
// verified AOJ GRL_1
#define MAX_V 100020
template <typename T> struct edge {
int to;
T cost;
};
template <typename T>
void dijkstra(int s, vector<T> &d, vector<edge<T>> G[MAX_V]) {
priority_queue<pii, vector<pii>, greater<pii>> que;
rep(i, d.size()) d[i] = INF;
d[s] = 0;
que.push(pii(0, s));
while (que.size()) {
pii p = que.top();
que.pop();
int v = p.second;
if (d[v] < p.first)
continue;
rep(i, G[v].size()) {
edge<T> e = G[v][i];
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
que.push(pii(d[e.to], e.to));
}
}
}
}
signed main() {
int n, m, r, q;
cin >> n >> m >> r >> q;
vector<edge<int>> G[MAX_V];
rep(i, m) {
int s, t, c;
cin >> s >> t >> c;
G[t].pb(edge<int>{s, c});
}
for (int i = 1; i <= n; i++) {
G[n + 1 + i % r].pb(edge<int>{i, 0});
}
static vector<vector<int>> d(r, vector<int>(n + r));
for (int i = 0; i < r; i++) {
dijkstra<int>(n + i + 1, d[i], G);
}
int ans = 0;
rep(i, q) {
int x, y, z;
cin >> x >> y >> z;
int mini = INF;
rep(j, r) { mini = min(mini, d[j][x] + d[j][y]); }
if (z - mini > 0)
ans += z - mini;
}
cout << ans << endl;
}
|
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int, int> pii;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb emplace_back
#define INF (1LL << 60)
// verified AOJ GRL_1
#define MAX_V 100020
template <typename T> struct edge {
int to;
T cost;
};
template <typename T>
void dijkstra(int s, vector<T> &d, vector<edge<T>> G[MAX_V]) {
priority_queue<pii, vector<pii>, greater<pii>> que;
rep(i, d.size()) d[i] = INF;
d[s] = 0;
que.push(pii(0, s));
while (que.size()) {
pii p = que.top();
que.pop();
int v = p.second;
if (d[v] < p.first)
continue;
rep(i, G[v].size()) {
edge<T> e = G[v][i];
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
que.push(pii(d[e.to], e.to));
}
}
}
}
signed main() {
int n, m, r, q;
cin >> n >> m >> r >> q;
vector<edge<int>> G[MAX_V];
rep(i, m) {
int s, t, c;
cin >> s >> t >> c;
G[t].pb(edge<int>{s, c});
}
for (int i = 1; i <= n; i++) {
G[n + 1 + i % r].pb(edge<int>{i, 0});
}
static vector<vector<int>> d(r, vector<int>(n + r + 1));
for (int i = 0; i < r; i++) {
dijkstra<int>(n + i + 1, d[i], G);
}
int ans = 0;
rep(i, q) {
int x, y, z;
cin >> x >> y >> z;
int mini = INF;
rep(j, r) { mini = min(mini, d[j][x] + d[j][y]); }
if (z - mini > 0)
ans += z - mini;
}
cout << ans << endl;
}
|
replace
| 56 | 57 | 56 | 57 |
0
| |
p01911
|
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 each(itr, c) \
for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second
typedef pair<int, int> pi;
const int V = 100000;
const int N = 202020;
const int INF = 123456789;
set<int> TIMESET[V];
map<pi, int> v_to_id;
struct edge {
int to, cost;
};
vector<edge> G[N];
int dist[N];
int main() {
int n, m, s, g;
scanf(" %d %d %d %d", &n, &m, &s, &g);
--s;
--g;
TIMESET[s].insert(0);
v_to_id[pi(s, 0)] = 0;
int idx = 1;
rep(i, m) {
int u, v, t, c;
scanf(" %d %d %d %d", &u, &v, &t, &c);
--u;
--v;
TIMESET[u].insert(t);
TIMESET[v].insert(t + c);
if (v_to_id.find(pi(u, t)) == v_to_id.end())
v_to_id[pi(u, t)] = idx++;
if (v_to_id.find(pi(v, t + c)) == v_to_id.end())
v_to_id[pi(v, t + c)] = idx++;
int S = v_to_id[pi(u, t)], T = v_to_id[pi(v, t + c)];
G[S].pb(edge{T, 0});
}
rep(i, n) {
int SZ = TIMESET[i].size();
auto itr = TIMESET[i].begin();
rep(j, SZ - 1) {
auto nx = itr;
++nx;
int d = *nx - *itr;
int S = v_to_id[pi(i, *itr)], T = v_to_id[pi(i, *nx)];
G[S].pb(edge{T, d});
++itr;
}
}
priority_queue<pi, vector<pi>, greater<pi>> pq;
pq.push(pi(0, 0));
fill(dist, dist + N, INF);
dist[0] = 0;
while (!pq.empty()) {
pi p = pq.top();
pq.pop();
int v = p.se;
if (dist[v] < p.fi)
continue;
for (edge &e : G[v]) {
if (dist[e.to] > dist[v] + e.cost) {
dist[e.to] = dist[v] + e.cost;
pq.push(pi(dist[e.to], e.to));
}
}
}
int ans = INF;
for (const auto &x : TIMESET[g]) {
int S = v_to_id[pi(g, x)];
ans = min(ans, dist[S]);
}
printf("%d\n", ans);
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 each(itr, c) \
for (__typeof(c.begin()) itr = c.begin(); itr != c.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second
typedef pair<int, int> pi;
const int V = 100000;
const int N = 404040;
const int INF = 123456789;
set<int> TIMESET[V];
map<pi, int> v_to_id;
struct edge {
int to, cost;
};
vector<edge> G[N];
int dist[N];
int main() {
int n, m, s, g;
scanf(" %d %d %d %d", &n, &m, &s, &g);
--s;
--g;
TIMESET[s].insert(0);
v_to_id[pi(s, 0)] = 0;
int idx = 1;
rep(i, m) {
int u, v, t, c;
scanf(" %d %d %d %d", &u, &v, &t, &c);
--u;
--v;
TIMESET[u].insert(t);
TIMESET[v].insert(t + c);
if (v_to_id.find(pi(u, t)) == v_to_id.end())
v_to_id[pi(u, t)] = idx++;
if (v_to_id.find(pi(v, t + c)) == v_to_id.end())
v_to_id[pi(v, t + c)] = idx++;
int S = v_to_id[pi(u, t)], T = v_to_id[pi(v, t + c)];
G[S].pb(edge{T, 0});
}
rep(i, n) {
int SZ = TIMESET[i].size();
auto itr = TIMESET[i].begin();
rep(j, SZ - 1) {
auto nx = itr;
++nx;
int d = *nx - *itr;
int S = v_to_id[pi(i, *itr)], T = v_to_id[pi(i, *nx)];
G[S].pb(edge{T, d});
++itr;
}
}
priority_queue<pi, vector<pi>, greater<pi>> pq;
pq.push(pi(0, 0));
fill(dist, dist + N, INF);
dist[0] = 0;
while (!pq.empty()) {
pi p = pq.top();
pq.pop();
int v = p.se;
if (dist[v] < p.fi)
continue;
for (edge &e : G[v]) {
if (dist[e.to] > dist[v] + e.cost) {
dist[e.to] = dist[v] + e.cost;
pq.push(pi(dist[e.to], e.to));
}
}
}
int ans = INF;
for (const auto &x : TIMESET[g]) {
int S = v_to_id[pi(g, x)];
ans = min(ans, dist[S]);
}
printf("%d\n", ans);
return 0;
}
|
replace
| 15 | 16 | 15 | 16 |
0
| |
p01911
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define CIN_ONLY if (1)
struct cww {
cww() {
CIN_ONLY {
ios::sync_with_stdio(false);
cin.tie(0);
}
}
} star;
#define fin "\n"
#define FOR(i, bg, ed) for (int i = (bg); i < (ed); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if (0)
#define REC(ret, ...) std::function<ret(__VA_ARGS__)>
template <typename T> inline void chmin(T &l, T r) { l = min(l, r); }
template <typename T> inline void chmax(T &l, T r) { l = max(l, r); }
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &it : v)
is >> it;
return is;
}
typedef tuple<int, int, int, LL> T;
const LL INF = 1e15;
LL a[112345];
LL b[112345];
LL c[112345];
LL t[112345];
int main() {
int N, M, S, G;
cin >> N >> M >> S >> G;
priority_queue<T> sc;
vector<LL> ame(N + 1, INF);
REP(i, M) {
cin >> a[i] >> b[i] >> t[i] >> c[i];
sc.push(T(-t[i], 0, i, 0));
}
ame[S] = 0;
LL res = INF;
while (sc.size()) {
int tt, type, e;
LL cww;
tie(tt, type, e, cww) = sc.top();
sc.pop();
LL bg = t[e];
LL ed = t[e] + c[e];
if (type == 0) {
LL cost = ame[a[e]] + t[e];
sc.push(T(-ed, 1, e, cost));
} else {
if (b[e] == G)
chmin(res, cww);
chmin(ame[b[e]], cww - t[e] - c[e]);
}
}
cout << res << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define CIN_ONLY if (1)
struct cww {
cww() {
CIN_ONLY {
ios::sync_with_stdio(false);
cin.tie(0);
}
}
} star;
#define fin "\n"
#define FOR(i, bg, ed) for (int i = (bg); i < (ed); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if (0)
#define REC(ret, ...) std::function<ret(__VA_ARGS__)>
template <typename T> inline void chmin(T &l, T r) { l = min(l, r); }
template <typename T> inline void chmax(T &l, T r) { l = max(l, r); }
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (auto &it : v)
is >> it;
return is;
}
typedef tuple<int, int, int, LL> T;
const LL INF = 1e15;
LL a[212345];
LL b[212345];
LL c[212345];
LL t[212345];
int main() {
int N, M, S, G;
cin >> N >> M >> S >> G;
priority_queue<T> sc;
vector<LL> ame(N + 1, INF);
REP(i, M) {
cin >> a[i] >> b[i] >> t[i] >> c[i];
sc.push(T(-t[i], 0, i, 0));
}
ame[S] = 0;
LL res = INF;
while (sc.size()) {
int tt, type, e;
LL cww;
tie(tt, type, e, cww) = sc.top();
sc.pop();
LL bg = t[e];
LL ed = t[e] + c[e];
if (type == 0) {
LL cost = ame[a[e]] + t[e];
sc.push(T(-ed, 1, e, cost));
} else {
if (b[e] == G)
chmin(res, cww);
chmin(ame[b[e]], cww - t[e] - c[e]);
}
}
cout << res << endl;
return 0;
}
|
replace
| 31 | 35 | 31 | 35 |
0
| |
p01912
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define mp(a, b) make_pair((a), (b))
#define pb(a) push_back((a))
#define all(x) (x).begin(), (x).end()
#define uniq(x) sort(all(x)), (x).erase(unique(all(x)), end(x))
#define fi first
#define se second
#define dbg(x) cout << #x " = " << ((x)) << endl
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &p) {
o << "(" << p.fi << "," << p.se << ")";
return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
o << "[";
for (T t : v) {
o << t << ",";
}
o << "]";
return o;
}
#define INF 2147483600
int main() {
int h, w, n;
cin >> h >> w >> n;
vector<int> vec(h * w);
rep(i, h) rep(j, w) {
int a, b;
scanf("%d %d", &a, &b);
vec[i * w + j] = a * h + b;
}
vector<int> p(n);
rep(i, n) {
int a, b;
scanf("%d %d", &a, &b);
p[i] = a * w + b;
}
vector<vector<int>> mat(20, vector<int>(h * w));
rep(i, h * w) mat[0][i] = vec[i];
repl(i, 1, 20) rep(j, h * w) { mat[i][j] = mat[i - 1][mat[i - 1][j]]; }
int l = 0, r = 2 * h * w;
while (r - l > 1) {
int m = (l + r) / 2;
auto exe = [&](int x) {
vector<bool> vis(h * w, false);
vector<int> v(p);
int q = 0;
while (x > 0) {
if (x % 2) {
rep(i, n) v[i] = mat[q][v[i]];
}
x /= 2;
q++;
}
rep(i, n) {
if (vis[v[i]])
return true;
vis[v[i]] = true;
}
return false;
};
if (exe(m))
r = m;
else
l = m;
}
if (r == 2 * h * w)
r = -1;
cout << r << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define mp(a, b) make_pair((a), (b))
#define pb(a) push_back((a))
#define all(x) (x).begin(), (x).end()
#define uniq(x) sort(all(x)), (x).erase(unique(all(x)), end(x))
#define fi first
#define se second
#define dbg(x) cout << #x " = " << ((x)) << endl
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U> &p) {
o << "(" << p.fi << "," << p.se << ")";
return o;
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
o << "[";
for (T t : v) {
o << t << ",";
}
o << "]";
return o;
}
#define INF 2147483600
int main() {
int h, w, n;
cin >> h >> w >> n;
vector<int> vec(h * w);
rep(i, h) rep(j, w) {
int a, b;
scanf("%d %d", &a, &b);
vec[i * w + j] = a * w + b;
}
vector<int> p(n);
rep(i, n) {
int a, b;
scanf("%d %d", &a, &b);
p[i] = a * w + b;
}
vector<vector<int>> mat(20, vector<int>(h * w));
rep(i, h * w) mat[0][i] = vec[i];
repl(i, 1, 20) rep(j, h * w) { mat[i][j] = mat[i - 1][mat[i - 1][j]]; }
int l = 0, r = 2 * h * w;
while (r - l > 1) {
int m = (l + r) / 2;
auto exe = [&](int x) {
vector<bool> vis(h * w, false);
vector<int> v(p);
int q = 0;
while (x > 0) {
if (x % 2) {
rep(i, n) v[i] = mat[q][v[i]];
}
x /= 2;
q++;
}
rep(i, n) {
if (vis[v[i]])
return true;
vis[v[i]] = true;
}
return false;
};
if (exe(m))
r = m;
else
l = m;
}
if (r == 2 * h * w)
r = -1;
cout << r << endl;
return 0;
}
|
replace
| 34 | 35 | 34 | 35 |
0
| |
p01912
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int h, w, n;
int G[25001][22];
bool used[22][25001];
bool C(int v) {
for (int i = 0; i < 20; i++) {
memset(used[i + 1], false, sizeof(used[i + 1]));
if ((v >> i) & 1) {
for (int j = 0; j < w * h; j++) {
if (used[i][j]) {
if (used[i + 1][G[j][i]])
return true;
used[i + 1][G[j][i]] = true;
}
}
} else {
for (int j = 0; j < w * h; j++) {
used[i + 1][j] = used[i][j];
}
}
}
return false;
}
int main(void) {
scanf("%d%d%d", &h, &w, &n);
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
int r, c;
scanf("%d%d", &r, &c);
G[i * w + j][0] = r * w + c;
}
}
for (int i = 0; i < n; i++) {
int r, c;
scanf("%d%d", &r, &c);
used[0][r * w + c] = true;
}
for (int i = 1; i < 20; i++) {
for (int j = 0; j < h * w; j++) {
G[j][i] = G[G[j][i - 1]][i - 1];
}
}
int l = 0, r = h * w + 1;
while (r - l > 1) {
int mid = (l + r) / 2;
if (C(mid))
r = mid;
else
l = mid;
}
printf("%d\n", r == h * w + 1 ? -1 : r);
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int h, w, n;
int G[250001][22];
bool used[22][250001];
bool C(int v) {
for (int i = 0; i < 20; i++) {
memset(used[i + 1], false, sizeof(used[i + 1]));
if ((v >> i) & 1) {
for (int j = 0; j < w * h; j++) {
if (used[i][j]) {
if (used[i + 1][G[j][i]])
return true;
used[i + 1][G[j][i]] = true;
}
}
} else {
for (int j = 0; j < w * h; j++) {
used[i + 1][j] = used[i][j];
}
}
}
return false;
}
int main(void) {
scanf("%d%d%d", &h, &w, &n);
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
int r, c;
scanf("%d%d", &r, &c);
G[i * w + j][0] = r * w + c;
}
}
for (int i = 0; i < n; i++) {
int r, c;
scanf("%d%d", &r, &c);
used[0][r * w + c] = true;
}
for (int i = 1; i < 20; i++) {
for (int j = 0; j < h * w; j++) {
G[j][i] = G[G[j][i - 1]][i - 1];
}
}
int l = 0, r = h * w + 1;
while (r - l > 1) {
int mid = (l + r) / 2;
if (C(mid))
r = mid;
else
l = mid;
}
printf("%d\n", r == h * w + 1 ? -1 : r);
return 0;
}
|
replace
| 16 | 18 | 16 | 18 |
0
| |
p01913
|
C++
|
Memory Limit Exceeded
|
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
int rand_int(int a, int b) {
static random_device rd;
static mt19937 gen(rd());
return uniform_int_distribution<int>(a, b)(gen);
}
struct UnionFind {
V<int> id;
V<int> data;
VV<int> groups;
UnionFind(int n) {
id = V<int>(n);
data = V<int>(n);
groups = VV<int>(n);
for (int i = 0; i < n; i++) {
id[i] = i;
groups[i].push_back(i);
}
}
void setd(int a, int x) {
data[id[a]] = x;
return;
}
int getd(int a) { return data[id[a]]; }
bool same(int a, int b) { return id[a] == id[b]; }
void merge(int a, int b) {
if (same(a, b))
return;
int x = id[a], y = id[b];
if (groups[x].size() > groups[y].size())
swap(x, y);
for (int d : groups[y]) {
id[d] = x;
groups[x].push_back(d);
}
groups[y].clear();
}
};
using P = pair<int, int>;
const int MN = 300300;
V<P> ed[MN];
int n;
P vs[MN]; // start, size
V<int> g[MN];
ll pnt[MN];
void dfs(int p, int nw, ll sm) {
// cout << p << endl;
sm += ll(vs[p].first - nw) * vs[p].second;
if (p < n) {
// cout << "last " << p << " " << sm << endl;
pnt[p] = sm;
return;
}
for (int d : g[p]) {
dfs(d, vs[p].first, sm);
}
}
V<P> gg[MN]; // to, time
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(20);
int m, t;
cin >> n >> m >> t;
for (int i = 0; i < m; i++) {
int a, b, t;
cin >> a >> b >> t;
a--;
b--;
t--;
ed[t].push_back(P(a, b));
gg[a].push_back(P(b, t));
gg[b].push_back(P(a, t));
}
UnionFind uf(n);
for (int i = 0; i < n; i++) {
vs[i] = P(t, 1);
uf.setd(i, i);
}
int vc = n;
for (int i = t - 1; i >= 0; i--) {
for (auto p : ed[i]) {
int a, b;
tie(a, b) = p;
if (uf.same(a, b))
continue;
int ad = uf.getd(a);
int bd = uf.getd(b);
uf.merge(a, b);
int vid = vc;
vc++;
vs[vid] = P(i + 1, vs[ad].second + vs[bd].second);
g[vid].push_back(ad);
g[vid].push_back(bd);
uf.setd(a, vid);
}
}
dfs(vc - 1, 0, 0);
ll ans = 0;
queue<P> que;
V<bool> used(n);
que.push(P(0, 0));
while (!que.empty()) {
P p = que.front();
que.pop();
int a, tm;
tie(a, tm) = p;
if (used[a])
continue;
used[a] = true;
ans = max(ans, pnt[a]);
for (auto ed : gg[a]) {
if (ed.second < tm)
continue;
que.push(P(ed.first, tm + 1));
}
}
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
int rand_int(int a, int b) {
static random_device rd;
static mt19937 gen(rd());
return uniform_int_distribution<int>(a, b)(gen);
}
struct UnionFind {
V<int> id;
V<int> data;
VV<int> groups;
UnionFind(int n) {
id = V<int>(n);
data = V<int>(n);
groups = VV<int>(n);
for (int i = 0; i < n; i++) {
id[i] = i;
groups[i].push_back(i);
}
}
void setd(int a, int x) {
data[id[a]] = x;
return;
}
int getd(int a) { return data[id[a]]; }
bool same(int a, int b) { return id[a] == id[b]; }
void merge(int a, int b) {
if (same(a, b))
return;
int x = id[a], y = id[b];
if (groups[x].size() < groups[y].size())
swap(x, y);
for (int d : groups[y]) {
id[d] = x;
groups[x].push_back(d);
}
groups[y].clear();
}
};
using P = pair<int, int>;
const int MN = 300300;
V<P> ed[MN];
int n;
P vs[MN]; // start, size
V<int> g[MN];
ll pnt[MN];
void dfs(int p, int nw, ll sm) {
// cout << p << endl;
sm += ll(vs[p].first - nw) * vs[p].second;
if (p < n) {
// cout << "last " << p << " " << sm << endl;
pnt[p] = sm;
return;
}
for (int d : g[p]) {
dfs(d, vs[p].first, sm);
}
}
V<P> gg[MN]; // to, time
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(20);
int m, t;
cin >> n >> m >> t;
for (int i = 0; i < m; i++) {
int a, b, t;
cin >> a >> b >> t;
a--;
b--;
t--;
ed[t].push_back(P(a, b));
gg[a].push_back(P(b, t));
gg[b].push_back(P(a, t));
}
UnionFind uf(n);
for (int i = 0; i < n; i++) {
vs[i] = P(t, 1);
uf.setd(i, i);
}
int vc = n;
for (int i = t - 1; i >= 0; i--) {
for (auto p : ed[i]) {
int a, b;
tie(a, b) = p;
if (uf.same(a, b))
continue;
int ad = uf.getd(a);
int bd = uf.getd(b);
uf.merge(a, b);
int vid = vc;
vc++;
vs[vid] = P(i + 1, vs[ad].second + vs[bd].second);
g[vid].push_back(ad);
g[vid].push_back(bd);
uf.setd(a, vid);
}
}
dfs(vc - 1, 0, 0);
ll ans = 0;
queue<P> que;
V<bool> used(n);
que.push(P(0, 0));
while (!que.empty()) {
P p = que.front();
que.pop();
int a, tm;
tie(a, tm) = p;
if (used[a])
continue;
used[a] = true;
ans = max(ans, pnt[a]);
for (auto ed : gg[a]) {
if (ed.second < tm)
continue;
que.push(P(ed.first, tm + 1));
}
}
cout << ans << endl;
return 0;
}
|
replace
| 56 | 57 | 56 | 57 |
MLE
| |
p01914
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
template <class S, class T>
ostream &operator<<(ostream &o, const pair<S, T> &p) {
return o << "(" << p.fs << "," << p.sc << ")";
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &vc) {
o << "sz = " << vc.size() << endl << "[";
for (const T &v : vc)
o << v << ",";
o << "]";
return o;
}
int inf = 1e9;
struct segtree {
static const int N = 1 << 18;
int seg[N * 2];
segtree() { rep(i, N * 2) seg[i] = 0; }
segtree(vector<int> &vi) {
rep(i, N * 2) seg[i] = 0;
rep(i, vi.size()) seg[N + i] = vi[i];
for (int i = N - 1; i > 0; i--)
seg[i] = max(seg[i * 2], seg[i * 2 + 1]);
}
void update(int x, int v) {
x += N;
chmax(seg[x], v);
x /= 2;
while (x) {
seg[x] = max(seg[x * 2], seg[x * 2 + 1]);
x /= 2;
}
}
int getmax(int a, int b, int l = 0, int r = N, int k = 1) {
if (b <= l || r <= a)
return 0;
if (a <= l && r <= b)
return seg[k];
return max(getmax(a, b, l, (l + r) / 2, k * 2),
getmax(a, b, (l + r) / 2, r, k * 2 + 1));
}
} seg[2];
vector<int> xs;
const int MN = 100000;
typedef pair<int, int> P;
typedef pair<P, int> PP;
int a[MN], b[MN], c[MN];
int main() {
int N;
cin >> N;
vector<PP> vp;
rep(i, N) cin >> a[i] >> b[i];
rep(i, N) xs.pb(a[i]), xs.pb(b[i]);
sort(all(xs));
xs.erase(unique(xs.begin(), xs.end()), xs.end());
rep(i, N) a[i] = lower_bound(all(xs), a[i]) - xs.begin(),
b[i] = lower_bound(all(xs), b[i]) - xs.begin();
rep(i, N) {
vp.pb(PP(P(a[i], -b[i]), 0));
vp.pb(PP(P(b[i], -a[i]), 1));
}
sort(all(vp));
int K = xs.size();
int ans = 0;
vector<P> upd[2];
rep(i, N * 2) {
PP pp = vp[i];
int x = pp.fs.fs, y = -pp.fs.sc, c = pp.sc;
int mx = seg[c].getmax(0, y) + 1;
chmax(ans, mx);
// seg[1-c].update(y,mx);
upd[1 - c].pb(P(y, mx));
if (i == N * 2 - 1 || x != vp[i + 1].fs.fs) {
rep(t, 2) {
for (P p : upd[t])
seg[t].update(p.fs, p.sc);
}
}
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
template <class S, class T>
ostream &operator<<(ostream &o, const pair<S, T> &p) {
return o << "(" << p.fs << "," << p.sc << ")";
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &vc) {
o << "sz = " << vc.size() << endl << "[";
for (const T &v : vc)
o << v << ",";
o << "]";
return o;
}
int inf = 1e9;
struct segtree {
static const int N = 1 << 18;
int seg[N * 2];
segtree() { rep(i, N * 2) seg[i] = 0; }
segtree(vector<int> &vi) {
rep(i, N * 2) seg[i] = 0;
rep(i, vi.size()) seg[N + i] = vi[i];
for (int i = N - 1; i > 0; i--)
seg[i] = max(seg[i * 2], seg[i * 2 + 1]);
}
void update(int x, int v) {
x += N;
chmax(seg[x], v);
x /= 2;
while (x) {
seg[x] = max(seg[x * 2], seg[x * 2 + 1]);
x /= 2;
}
}
int getmax(int a, int b, int l = 0, int r = N, int k = 1) {
if (b <= l || r <= a)
return 0;
if (a <= l && r <= b)
return seg[k];
return max(getmax(a, b, l, (l + r) / 2, k * 2),
getmax(a, b, (l + r) / 2, r, k * 2 + 1));
}
} seg[2];
vector<int> xs;
const int MN = 100000;
typedef pair<int, int> P;
typedef pair<P, int> PP;
int a[MN], b[MN], c[MN];
int main() {
int N;
cin >> N;
vector<PP> vp;
rep(i, N) cin >> a[i] >> b[i];
rep(i, N) xs.pb(a[i]), xs.pb(b[i]);
sort(all(xs));
xs.erase(unique(xs.begin(), xs.end()), xs.end());
rep(i, N) a[i] = lower_bound(all(xs), a[i]) - xs.begin(),
b[i] = lower_bound(all(xs), b[i]) - xs.begin();
rep(i, N) {
vp.pb(PP(P(a[i], -b[i]), 0));
vp.pb(PP(P(b[i], -a[i]), 1));
}
sort(all(vp));
int K = xs.size();
int ans = 0;
vector<P> upd[2];
rep(i, N * 2) {
PP pp = vp[i];
int x = pp.fs.fs, y = -pp.fs.sc, c = pp.sc;
int mx = seg[c].getmax(0, y) + 1;
chmax(ans, mx);
// seg[1-c].update(y,mx);
upd[1 - c].pb(P(y, mx));
if (i == N * 2 - 1 || x != vp[i + 1].fs.fs) {
rep(t, 2) {
for (P p : upd[t])
seg[t].update(p.fs, p.sc);
upd[t].clear();
}
}
}
cout << ans << endl;
}
|
insert
| 90 | 90 | 90 | 91 |
TLE
| |
p01915
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
struct Primal_Dual {
typedef pair<int, int> Pi;
struct edge {
int to, cap, cost, rev;
};
vector<vector<edge>> graph;
vector<int> potential, min_cost, prevv, preve;
Primal_Dual(int V) : graph(V) {}
void add_edge(int from, int to, int cap, int cost) {
graph[from].push_back((edge){to, cap, cost, (int)graph[to].size()});
graph[to].push_back((edge){from, 0, -cost, (int)graph[from].size() - 1});
}
int min_cost_flow(int s, int t, int f) {
int V = graph.size(), ret = 0;
priority_queue<Pi, vector<Pi>, greater<Pi>> que;
potential.assign(V, 0);
preve.assign(V, -1);
prevv.assign(V, -1);
while (f > 0) {
min_cost.assign(V, INF);
que.push(Pi(0, s));
min_cost[s] = 0;
while (!que.empty()) {
Pi p = que.top();
que.pop();
if (min_cost[p.second] < p.first)
continue;
for (int i = 0; i < graph[p.second].size(); i++) {
edge &e = graph[p.second][i];
int nextCost = min_cost[p.second] + e.cost + potential[p.second] -
potential[e.to];
if (e.cap > 0 && min_cost[e.to] > nextCost) {
min_cost[e.to] = nextCost;
prevv[e.to] = p.second, preve[e.to] = i;
que.push(Pi(min_cost[e.to], e.to));
}
}
}
if (min_cost[t] == INF)
return -1;
for (int v = 0; v < V; v++)
potential[v] += min_cost[v];
int addflow = f;
for (int v = t; v != s; v = prevv[v]) {
addflow = min(addflow, graph[prevv[v]][preve[v]].cap);
}
f -= addflow;
ret += addflow * potential[t];
for (int v = t; v != s; v = prevv[v]) {
edge &e = graph[prevv[v]][preve[v]];
e.cap -= addflow;
graph[v][e.rev].cap += addflow;
}
}
return ret;
}
};
int main() {
int N, M, K;
int A[100], B[100][100], T[100];
cin >> N >> M >> K;
++M;
for (int i = 0; i < M; i++) {
for (int j = 0; j < N; j++)
cin >> B[i][j];
}
for (int i = 0; i < M - 1; i++) {
cin >> T[i];
}
Primal_Dual flow(N + M + 3);
int s = N + M, t = N + M + 1, add = N + M + 2;
for (int i = 0; i < N; i++)
flow.add_edge(s, i, 1, 0);
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
flow.add_edge(i, j + N, 1, 100 - B[j][i]);
}
for (int j = 1; j < M; j++)
flow.add_edge(j + N, add, T[j - 1], 0);
flow.add_edge(N, t, INF, 0);
flow.add_edge(add, t, N - K, 0);
cout << 100 * N - flow.min_cost_flow(s, t, N) << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
struct Primal_Dual {
typedef pair<int, int> Pi;
struct edge {
int to, cap, cost, rev;
};
vector<vector<edge>> graph;
vector<int> potential, min_cost, prevv, preve;
Primal_Dual(int V) : graph(V) {}
void add_edge(int from, int to, int cap, int cost) {
graph[from].push_back((edge){to, cap, cost, (int)graph[to].size()});
graph[to].push_back((edge){from, 0, -cost, (int)graph[from].size() - 1});
}
int min_cost_flow(int s, int t, int f) {
int V = graph.size(), ret = 0;
priority_queue<Pi, vector<Pi>, greater<Pi>> que;
potential.assign(V, 0);
preve.assign(V, -1);
prevv.assign(V, -1);
while (f > 0) {
min_cost.assign(V, INF);
que.push(Pi(0, s));
min_cost[s] = 0;
while (!que.empty()) {
Pi p = que.top();
que.pop();
if (min_cost[p.second] < p.first)
continue;
for (int i = 0; i < graph[p.second].size(); i++) {
edge &e = graph[p.second][i];
int nextCost = min_cost[p.second] + e.cost + potential[p.second] -
potential[e.to];
if (e.cap > 0 && min_cost[e.to] > nextCost) {
min_cost[e.to] = nextCost;
prevv[e.to] = p.second, preve[e.to] = i;
que.push(Pi(min_cost[e.to], e.to));
}
}
}
if (min_cost[t] == INF)
return -1;
for (int v = 0; v < V; v++)
potential[v] += min_cost[v];
int addflow = f;
for (int v = t; v != s; v = prevv[v]) {
addflow = min(addflow, graph[prevv[v]][preve[v]].cap);
}
f -= addflow;
ret += addflow * potential[t];
for (int v = t; v != s; v = prevv[v]) {
edge &e = graph[prevv[v]][preve[v]];
e.cap -= addflow;
graph[v][e.rev].cap += addflow;
}
}
return ret;
}
};
int main() {
int N, M, K, B[101][100], T[100];
cin >> N >> M >> K;
++M;
for (int i = 0; i < M; i++) {
for (int j = 0; j < N; j++)
cin >> B[i][j];
}
for (int i = 0; i < M - 1; i++) {
cin >> T[i];
}
Primal_Dual flow(N + M + 3);
int s = N + M, t = N + M + 1, add = N + M + 2;
for (int i = 0; i < N; i++)
flow.add_edge(s, i, 1, 0);
for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++)
flow.add_edge(i, j + N, 1, 100 - B[j][i]);
}
for (int j = 1; j < M; j++)
flow.add_edge(j + N, add, T[j - 1], 0);
flow.add_edge(N, t, INF, 0);
flow.add_edge(add, t, N - K, 0);
cout << 100 * N - flow.min_cost_flow(s, t, N) << endl;
}
|
replace
| 71 | 73 | 71 | 72 |
0
| |
p01917
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;
int n, score[101], a[101][3];
bool ch() {
int t[10] = {}, x[10];
r(i, 3) {
int cnt = 0, pre, c2 = 0;
memset(x, 0, sizeof(x));
vector<P> v;
r(j, n) v.push_back(P(a[j][i], j));
sort(v.begin(), v.end(), greater<P>());
r(k, n) {
if (!k) {
t[v[k].se] += score[cnt];
pre = v[k].fi;
} else {
if (pre == v[k].fi) {
c2++;
t[v[k].se] += score[cnt];
} else {
pre = v[k].fi;
cnt += c2 + 1;
c2 = 0;
t[v[k].se] += score[cnt];
}
}
}
}
vector<P> v;
r(j, n) v.push_back(P(t[j], j));
sort(v.begin(), v.end(), greater<P>());
int cnt = 0, c2 = 0, pre;
r(i, n) {
if (!i) {
if (!v[i].se && cnt <= 7)
return 1;
pre = v[i].fi;
} else {
if (pre == v[i].fi) {
if (!v[i].se && cnt <= 7)
return 1;
pre = v[i].fi;
c2++;
} else {
cnt += c2 + 1;
c2 = 0;
if (!v[i].se && cnt <= 7)
return 1;
pre = v[i].fi;
}
}
}
return 0;
}
int main() {
cin >> n;
r(i, n) cin >> score[i];
r(i, n) r(j, 3) cin >> a[i][j];
r(i, 1000) r(j, 3) {
a[0][j] += i;
if (ch()) {
cout << i << endl;
return 0;
}
a[0][j] -= i;
}
cout << "Saiko" << endl;
}
|
#include <bits/stdc++.h>
#define r(i, n) for (int i = 0; i < n; i++)
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;
int n, score[101], a[101][3];
bool ch() {
int t[101] = {}, x[101];
r(i, 3) {
int cnt = 0, pre, c2 = 0;
memset(x, 0, sizeof(x));
vector<P> v;
r(j, n) v.push_back(P(a[j][i], j));
sort(v.begin(), v.end(), greater<P>());
r(k, n) {
if (!k) {
t[v[k].se] += score[cnt];
pre = v[k].fi;
} else {
if (pre == v[k].fi) {
c2++;
t[v[k].se] += score[cnt];
} else {
pre = v[k].fi;
cnt += c2 + 1;
c2 = 0;
t[v[k].se] += score[cnt];
}
}
}
}
vector<P> v;
r(j, n) v.push_back(P(t[j], j));
sort(v.begin(), v.end(), greater<P>());
int cnt = 0, c2 = 0, pre;
r(i, n) {
if (!i) {
if (!v[i].se && cnt <= 7)
return 1;
pre = v[i].fi;
} else {
if (pre == v[i].fi) {
if (!v[i].se && cnt <= 7)
return 1;
pre = v[i].fi;
c2++;
} else {
cnt += c2 + 1;
c2 = 0;
if (!v[i].se && cnt <= 7)
return 1;
pre = v[i].fi;
}
}
}
return 0;
}
int main() {
cin >> n;
r(i, n) cin >> score[i];
r(i, n) r(j, 3) cin >> a[i][j];
r(i, 1000) r(j, 3) {
a[0][j] += i;
if (ch()) {
cout << i << endl;
return 0;
}
a[0][j] -= i;
}
cout << "Saiko" << endl;
}
|
replace
| 10 | 11 | 10 | 11 |
0
| |
p01919
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
template <typename T> inline size_t hashCombine(size_t seed, const T &v) {
return seed ^ (hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2));
}
namespace std {
template <typename T, typename S> class hash<pair<T, S>> {
public:
size_t operator()(const pair<T, S> &p) const {
size_t seed = 0;
seed = hashCombine(seed, p.first);
seed = hashCombine(seed, p.second);
return seed;
}
};
template <typename... Ts> class hash<tuple<Ts...>> {
public:
size_t operator()(const tuple<Ts...> &t) const { return impl<0>(t); }
private:
template <size_t Index>
typename enable_if<Index == tuple_size<tuple<Ts...>>::value, size_t>::type
impl(const tuple<Ts...> &) const {
return 0;
}
template <size_t Index>
typename enable_if<Index != tuple_size<tuple<Ts...>>::value, size_t>::type
impl(const tuple<Ts...> &t) const {
return hashCombine(impl<Index + 1>(t), get<Index>(t));
}
};
} // namespace std
int n, m;
int a, b, c;
int v0;
struct Edge {
int to, t;
Edge(int to = 0, int t = 0) : to(to), t(t) {}
};
int update(int v) { return (a * v + b) % c; }
vector<Edge> G[502];
using State = tuple<int, int, int>;
unordered_map<State, ll> dp;
priority_queue<pair<ll, State>> que;
int main() {
cin >> n >> m;
rep(i, m) {
int x, y, t;
cin >> x >> y >> t;
G[x].push_back(Edge(y, t));
G[y].push_back(Edge(x, t));
}
cin >> v0;
cin >> a >> b >> c;
auto initState = State(1, v0, 0);
dp[initState] = 0;
que.push(make_pair(0, initState));
while (que.size()) {
auto p = que.top();
que.pop();
auto nowCost = p.first;
auto nowState = p.second;
auto v = get<0>(nowState);
auto v1 = get<1>(nowState);
auto s = get<2>(nowState);
auto v2 = update(v1);
// printf("%d %d %d %d\n", v, v1, s, dp[nowState]);
if (s == 0 && v == n)
s = 1;
rep(i, G[v].size()) {
auto e = G[v][i];
ll cost = 1LL * e.t * v1;
auto nextState = State(e.to, v2, s);
if (dp.count(nextState) == 0 || dp[nowState] + cost < dp[nextState]) {
dp[nextState] = dp[nowState] + cost;
que.push(make_pair(-dp[nextState], nextState));
}
}
}
ll ans = INF;
rep(i, 50) {
auto s = State(1, i, 1);
if (dp.count(s))
ans = min(ans, dp[s]);
}
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
template <typename T> inline size_t hashCombine(size_t seed, const T &v) {
return seed ^ (hash<T>()(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2));
}
namespace std {
template <typename T, typename S> class hash<pair<T, S>> {
public:
size_t operator()(const pair<T, S> &p) const {
size_t seed = 0;
seed = hashCombine(seed, p.first);
seed = hashCombine(seed, p.second);
return seed;
}
};
template <typename... Ts> class hash<tuple<Ts...>> {
public:
size_t operator()(const tuple<Ts...> &t) const { return impl<0>(t); }
private:
template <size_t Index>
typename enable_if<Index == tuple_size<tuple<Ts...>>::value, size_t>::type
impl(const tuple<Ts...> &) const {
return 0;
}
template <size_t Index>
typename enable_if<Index != tuple_size<tuple<Ts...>>::value, size_t>::type
impl(const tuple<Ts...> &t) const {
return hashCombine(impl<Index + 1>(t), get<Index>(t));
}
};
} // namespace std
int n, m;
int a, b, c;
int v0;
struct Edge {
int to, t;
Edge(int to = 0, int t = 0) : to(to), t(t) {}
};
int update(int v) { return (a * v + b) % c; }
vector<Edge> G[502];
using State = tuple<int, int, int>;
unordered_map<State, ll> dp;
priority_queue<pair<ll, State>> que;
int main() {
cin >> n >> m;
rep(i, m) {
int x, y, t;
cin >> x >> y >> t;
G[x].push_back(Edge(y, t));
G[y].push_back(Edge(x, t));
}
cin >> v0;
cin >> a >> b >> c;
auto initState = State(1, v0, 0);
dp[initState] = 0;
que.push(make_pair(0, initState));
while (que.size()) {
auto p = que.top();
que.pop();
auto nowCost = p.first;
auto nowState = p.second;
auto v = get<0>(nowState);
auto v1 = get<1>(nowState);
auto s = get<2>(nowState);
auto v2 = update(v1);
if (dp[nowState] < -nowCost)
continue;
// printf("%d %d %d %d\n", v, v1, s, dp[nowState]);
if (s == 0 && v == n)
s = 1;
rep(i, G[v].size()) {
auto e = G[v][i];
ll cost = 1LL * e.t * v1;
auto nextState = State(e.to, v2, s);
if (dp.count(nextState) == 0 || dp[nowState] + cost < dp[nextState]) {
dp[nextState] = dp[nowState] + cost;
que.push(make_pair(-dp[nextState], nextState));
}
}
}
ll ans = INF;
rep(i, 50) {
auto s = State(1, i, 1);
if (dp.count(s))
ans = min(ans, dp[s]);
}
cout << ans << endl;
return 0;
}
|
insert
| 97 | 97 | 97 | 99 |
TLE
| |
p01919
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FF first
#define SS second
template <class S, class T> istream &operator>>(istream &is, pair<S, T> &p) {
return is >> p.FF >> p.SS;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &p) {
return os << p.FF << " " << p.SS;
}
template <class T> void maxi(T &x, T y) {
if (x < y)
x = y;
}
template <class T> void mini(T &x, T y) {
if (x > y)
x = y;
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
const LL INF = 1e15;
struct Edge {
LL to, cost;
Edge(LL t, LL c) : to(t), cost(c) {}
bool operator>(const Edge &rhs) const { return cost > rhs.cost; }
bool operator<(const Edge &rhs) const { return cost < rhs.cost; }
};
typedef vector<vector<Edge>> Graph;
void Dijkstra(const Graph &edges, vector<LL> &d, int s) {
using Type = PLL;
priority_queue<Type, vector<Type>, greater<Type>> pq;
fill(d.begin(), d.end(), INF);
d[s] = 0;
pq.push(MP(0, s));
while (!pq.empty()) {
Type pii = pq.top();
pq.pop();
int v = pii.second;
if (d[v] < pii.first)
continue;
for (unsigned int i = 0; i < edges[v].size(); ++i) {
const Edge &e = edges[v][i];
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
pq.push(MP(d[e.to], e.to));
}
}
}
}
int idx(int u, int v, int flag) { return (u * 500 + v) * 2 + flag; }
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int N, M;
cin >> N >> M;
VL xs(M), ys(M), ts(M);
REP(i, M) {
cin >> xs[i] >> ys[i] >> ts[i];
--xs[i];
--ys[i];
}
LL V, A, B, C;
cin >> V >> A >> B >> C;
Graph G(500 * 50 * 2);
REP(i, M) {
REP(k, C) {
G[idx(xs[i], k, 0)].EB(idx(ys[i], (A * k + B) % C, 0), k * ts[i]);
G[idx(ys[i], k, 0)].EB(idx(xs[i], (A * k + B) % C, 0), k * ts[i]);
G[idx(xs[i], k, 1)].EB(idx(ys[i], (A * k + B) % C, 1), k * ts[i]);
G[idx(ys[i], k, 1)].EB(idx(xs[i], (A * k + B) % C, 1), k * ts[i]);
}
}
REP(k, C)
G[idx(N - 1, k, 0)].EB(idx(N - 1, k, 1), 0);
VL d(500 * 50 * 2);
Dijkstra(G, d, idx(0, V, 0));
LL ans = INF;
REP(k, C)
mini(ans, d[idx(0, k, 1)]);
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define FF first
#define SS second
template <class S, class T> istream &operator>>(istream &is, pair<S, T> &p) {
return is >> p.FF >> p.SS;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &p) {
return os << p.FF << " " << p.SS;
}
template <class T> void maxi(T &x, T y) {
if (x < y)
x = y;
}
template <class T> void mini(T &x, T y) {
if (x > y)
x = y;
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
const LL INF = 1e15;
struct Edge {
LL to, cost;
Edge(LL t, LL c) : to(t), cost(c) {}
bool operator>(const Edge &rhs) const { return cost > rhs.cost; }
bool operator<(const Edge &rhs) const { return cost < rhs.cost; }
};
typedef vector<vector<Edge>> Graph;
void Dijkstra(const Graph &edges, vector<LL> &d, int s) {
using Type = PLL;
priority_queue<Type, vector<Type>, greater<Type>> pq;
fill(d.begin(), d.end(), INF);
d[s] = 0;
pq.push(MP(0, s));
while (!pq.empty()) {
Type pii = pq.top();
pq.pop();
int v = pii.second;
if (d[v] < pii.first)
continue;
for (unsigned int i = 0; i < edges[v].size(); ++i) {
const Edge &e = edges[v][i];
if (d[e.to] > d[v] + e.cost) {
d[e.to] = d[v] + e.cost;
pq.push(MP(d[e.to], e.to));
}
}
}
}
int idx(int u, int v, int flag) { return (u * 50 + v) * 2 + flag; }
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int N, M;
cin >> N >> M;
VL xs(M), ys(M), ts(M);
REP(i, M) {
cin >> xs[i] >> ys[i] >> ts[i];
--xs[i];
--ys[i];
}
LL V, A, B, C;
cin >> V >> A >> B >> C;
Graph G(500 * 50 * 2);
REP(i, M) {
REP(k, C) {
G[idx(xs[i], k, 0)].EB(idx(ys[i], (A * k + B) % C, 0), k * ts[i]);
G[idx(ys[i], k, 0)].EB(idx(xs[i], (A * k + B) % C, 0), k * ts[i]);
G[idx(xs[i], k, 1)].EB(idx(ys[i], (A * k + B) % C, 1), k * ts[i]);
G[idx(ys[i], k, 1)].EB(idx(xs[i], (A * k + B) % C, 1), k * ts[i]);
}
}
REP(k, C)
G[idx(N - 1, k, 0)].EB(idx(N - 1, k, 1), 0);
VL d(500 * 50 * 2);
Dijkstra(G, d, idx(0, V, 0));
LL ans = INF;
REP(k, C)
mini(ans, d[idx(0, k, 1)]);
cout << ans << endl;
return 0;
}
|
replace
| 79 | 80 | 79 | 80 |
0
| |
p01919
|
C++
|
Runtime Error
|
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
#define MAX 1e9
int INF = MAX * MAX;
typedef pair<int, int> pii;
typedef pair<pii, pii> piii;
// vector<vector<long long> >d(501,vector<long long>(51,INF));
int d[501][2][51];
signed main() {
rep(i, 501) rep(j, 2) rep(k, 51) d[i][j][k] = INF;
int n, m;
cin >> n >> m;
vector<vector<pii>> edge(n, vector<pii>());
rep(i, m) {
int a, b, c;
cin >> a >> b >> c;
--a, --b;
edge[a].push_back(pii(b, c));
edge[b].push_back(pii(a, c));
}
int v0, a, b, c;
cin >> v0 >> a >> b >> c;
priority_queue<piii> que;
d[0][0][v0] = 0;
que.push(piii(pii(0, 0), {0, v0}));
while (!que.empty()) {
piii now = que.top();
que.pop();
now.first.first *= -1;
int v = now.second.second;
int t = now.second.first;
int _v = (v * a + b) % c;
if (d[now.first.second][t][v] < now.first.first)
continue;
for (int i = 0; i < edge[now.first.second].size(); i++) {
int nt = t | edge[now.first.second][i].first == n - 1;
pii next = edge[now.first.second][i];
if (d[next.first][nt][_v] < now.first.first + next.second * v)
continue;
d[next.first][nt][_v] = now.first.first + next.second * v;
que.push(piii(pii(-d[next.first][nt][_v], next.first), {nt, _v}));
}
}
int ans = INF;
rep(i, 51) ans = min(ans, d[0][1][i]);
/* rep(i,51)if(d[n-1][i]!=INF){
vector<vector<long long> >_d(501,vector<long long>(51,INF));
_d[n-1][i]=d[n-1][i];
que.push(piii(pii(d[n-1][i],n-1),i));
while(!que.empty()){
piii now=que.top(); que.pop();
int v=now.second;
int _v=(v*a+b)%c;
if(_d[now.first.second][v]<now.first.first)continue;
for(int i=0; i<edge[now.first.second].size();i++){
pii next=edge[now.first.second][i];
if(_d[next.first][_v]<now.first.first+next.second*v)continue;
_d[next.first][_v]=now.first.first+next.second*v;
que.push(piii(pii(_d[next.first][_v],next.first),_v));
}
}
rep(i,51)ans=min(ans,_d[0][i]);
} */
cout << ans << endl;
}
|
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
#define MAX 1e9
int INF = MAX * MAX;
typedef pair<int, int> pii;
typedef pair<pii, pii> piii;
// vector<vector<long long> >d(501,vector<long long>(51,INF));
int d[501][2][51];
signed main() {
rep(i, 501) rep(j, 2) rep(k, 51) d[i][j][k] = INF;
int n, m;
cin >> n >> m;
vector<vector<pii>> edge(n, vector<pii>());
rep(i, m) {
int a, b, c;
cin >> a >> b >> c;
--a, --b;
edge[a].push_back(pii(b, c));
edge[b].push_back(pii(a, c));
}
int v0, a, b, c;
cin >> v0 >> a >> b >> c;
priority_queue<piii> que;
d[0][0][v0] = 0;
que.push(piii(pii(0, 0), {0, v0}));
while (!que.empty()) {
piii now = que.top();
que.pop();
now.first.first *= -1;
int v = now.second.second;
int t = now.second.first;
int _v = (v * a + b) % c;
if (d[now.first.second][t][v] < now.first.first)
continue;
for (int i = 0; i < edge[now.first.second].size(); i++) {
int nt = t | edge[now.first.second][i].first == n - 1;
pii next = edge[now.first.second][i];
if (d[next.first][nt][_v] <= now.first.first + next.second * v)
continue;
d[next.first][nt][_v] = now.first.first + next.second * v;
que.push(piii(pii(-d[next.first][nt][_v], next.first), {nt, _v}));
}
}
int ans = INF;
rep(i, 51) ans = min(ans, d[0][1][i]);
/* rep(i,51)if(d[n-1][i]!=INF){
vector<vector<long long> >_d(501,vector<long long>(51,INF));
_d[n-1][i]=d[n-1][i];
que.push(piii(pii(d[n-1][i],n-1),i));
while(!que.empty()){
piii now=que.top(); que.pop();
int v=now.second;
int _v=(v*a+b)%c;
if(_d[now.first.second][v]<now.first.first)continue;
for(int i=0; i<edge[now.first.second].size();i++){
pii next=edge[now.first.second][i];
if(_d[next.first][_v]<now.first.first+next.second*v)continue;
_d[next.first][_v]=now.first.first+next.second*v;
que.push(piii(pii(_d[next.first][_v],next.first),_v));
}
}
rep(i,51)ans=min(ans,_d[0][i]);
} */
cout << ans << endl;
}
|
replace
| 43 | 44 | 43 | 44 |
0
| |
p01919
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
#define MAX 1e9
int INF = MAX * MAX;
typedef pair<int, int> pii;
typedef pair<pii, long long> piii;
vector<vector<long long>> d(501, vector<long long>(51, INF));
signed main() {
int n, m;
cin >> n >> m;
vector<vector<pii>> edge(500, vector<pii>());
rep(i, m) {
int a, b, c;
cin >> a >> b >> c;
--a, --b;
edge[a].push_back(pii(b, c));
edge[b].push_back(pii(a, c));
}
int v0, a, b, c;
cin >> v0 >> a >> b >> c;
priority_queue<piii, vector<piii>, greater<piii>> que;
d[0][v0] = 0;
que.push(piii(pii(0, 0), v0));
while (!que.empty()) {
piii now = que.top();
que.pop();
int v = now.second;
int _v = (v * a + b) % c;
if (d[now.first.second][v] < now.first.first)
continue;
for (int i = 0; i < edge[now.first.second].size(); i++) {
pii next = edge[now.first.second][i];
if (d[next.first][_v] <= now.first.first + next.second * v)
continue;
d[next.first][_v] = now.first.first + next.second * v;
que.push(piii(pii(d[next.first][_v], next.first), _v));
}
}
int ans = INF;
rep(i, 51) if (d[n - 1][i] != INF) {
vector<vector<long long>> _d(501, vector<long long>(51, INF));
_d[n - 1][i] = d[n - 1][i];
que.push(piii(pii(d[n - 1][i], n - 1), i));
while (!que.empty()) {
piii now = que.top();
que.pop();
int v = now.second;
int _v = (v * a + b) % c;
if (_d[now.first.second][v] < now.first.first)
continue;
for (int i = 0; i < edge[now.first.second].size(); i++) {
pii next = edge[now.first.second][i];
if (_d[next.first][_v] < now.first.first + next.second * v)
continue;
_d[next.first][_v] = now.first.first + next.second * v;
que.push(piii(pii(_d[next.first][_v], next.first), _v));
}
}
rep(i, 51) ans = min(ans, _d[0][i]);
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
#define MAX 1e9
int INF = MAX * MAX;
typedef pair<int, int> pii;
typedef pair<pii, long long> piii;
vector<vector<long long>> d(501, vector<long long>(51, INF));
signed main() {
int n, m;
cin >> n >> m;
vector<vector<pii>> edge(500, vector<pii>());
rep(i, m) {
int a, b, c;
cin >> a >> b >> c;
--a, --b;
edge[a].push_back(pii(b, c));
edge[b].push_back(pii(a, c));
}
int v0, a, b, c;
cin >> v0 >> a >> b >> c;
priority_queue<piii, vector<piii>, greater<piii>> que;
d[0][v0] = 0;
que.push(piii(pii(0, 0), v0));
while (!que.empty()) {
piii now = que.top();
que.pop();
int v = now.second;
int _v = (v * a + b) % c;
if (d[now.first.second][v] < now.first.first)
continue;
for (int i = 0; i < edge[now.first.second].size(); i++) {
pii next = edge[now.first.second][i];
if (d[next.first][_v] <= now.first.first + next.second * v)
continue;
d[next.first][_v] = now.first.first + next.second * v;
que.push(piii(pii(d[next.first][_v], next.first), _v));
}
}
int ans = INF;
rep(i, 51) if (d[n - 1][i] != INF) {
vector<vector<long long>> _d(501, vector<long long>(51, INF));
_d[n - 1][i] = d[n - 1][i];
que.push(piii(pii(d[n - 1][i], n - 1), i));
while (!que.empty()) {
piii now = que.top();
que.pop();
int v = now.second;
int _v = (v * a + b) % c;
if (_d[now.first.second][v] < now.first.first)
continue;
for (int i = 0; i < edge[now.first.second].size(); i++) {
pii next = edge[now.first.second][i];
if (_d[next.first][_v] <= now.first.first + next.second * v)
continue;
_d[next.first][_v] = now.first.first + next.second * v;
que.push(piii(pii(_d[next.first][_v], next.first), _v));
}
}
rep(i, 51) ans = min(ans, _d[0][i]);
}
cout << ans << endl;
}
|
replace
| 55 | 56 | 55 | 56 |
0
| |
p01920
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, buckets, y) for (int i = (buckets); i < (y); ++i)
#define debug(buckets) #buckets << "=" << (buckets)
#ifdef DEBUG
#define _GLIBCbucketsbuckets_DEBUG
#define print(buckets) \
std::cerr << debug(buckets) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(buckets)
#endif
const int inf = 1e9;
const int64_t inf64 = 1e18;
const double eps = 1e-9;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (const auto &v : vec) {
os << v << ",";
}
os << "]";
return os;
}
using i64 = int64_t;
struct sqrt_decomp {
const int bucket_size = 1024;
int length, bucket_num;
vector<vector<int>> buckets;
vector<int> update, bucket_sum;
sqrt_decomp(const vector<int> &x)
: length(x.size()),
bucket_num((x.size() + bucket_size - 1) / bucket_size) {
buckets.resize(bucket_num);
update.resize(bucket_num);
bucket_sum.resize(bucket_num);
for (int i = 0; i < x.size(); ++i) {
buckets[i / bucket_size].push_back(x[i]);
bucket_sum[i / bucket_size] += x[i];
update[i / bucket_size] = 2;
}
}
int sum() {
int res = 0;
for (int i = 0; i < bucket_num; ++i) {
if (update[i] == 2)
res += bucket_sum[i];
else
res += update[i] * buckets[i].size();
}
return res;
}
void query(int l, int r, int b) { //[l,r]
l = max(0, l);
r = min(length - 1, r);
while (l % bucket_size != 0 && l <= r) {
int bucket_index = l / bucket_size;
if (update[bucket_index] < 2) {
for (auto &a : buckets[bucket_index])
a = update[bucket_index];
bucket_sum[bucket_index] =
update[bucket_index] * buckets[bucket_index].size();
update[bucket_index] = 2;
}
bucket_sum[bucket_index] -= buckets[bucket_index][l % bucket_size];
buckets[bucket_index][l % bucket_size] = b;
bucket_sum[bucket_index] += b;
++l;
}
while ((r + 1) % bucket_size != 0 and l <= r) {
int bucket_index = r / bucket_size;
if (update[bucket_index] < 2) {
for (auto &a : buckets[bucket_index])
a = update[bucket_index];
bucket_sum[bucket_index] =
update[bucket_index] * buckets[bucket_index].size();
update[bucket_index] = 2;
}
bucket_sum[bucket_index] -= buckets[bucket_index][r % bucket_size];
buckets[bucket_index][r % bucket_size] = b;
bucket_sum[bucket_index] += b;
--r;
}
if (l > r)
return;
rep(i, l / bucket_size, r / bucket_size + 1) update[i] = b;
}
int at(int i) {
int bucket_index = i / bucket_size;
if (update[bucket_index] < 2)
return update[bucket_index];
else
return buckets[bucket_index][i % bucket_size];
}
};
void solve() {
int n, q;
string s;
cin >> n >> s >> q;
vector<int> x1, x2;
rep(i, 0, n) {
x1.push_back(s[i] - '0');
if (i + 1 < n)
x2.push_back((s[i] - '0') * (s[i + 1] - '0'));
}
sqrt_decomp f(x1), g(x2);
for (int i = 0; i < q; i++) {
int l, r, b;
cin >> l >> r >> b;
l--;
r--;
f.query(l, r, b);
if (b == 0)
g.query(l - 1, r, 0);
else {
int l_ = l, r_ = r - 1;
if (0 <= l - 1 and f.at(l - 1))
--l_;
if (r + 1 < n and f.at(r + 1))
++r_;
g.query(l_, r_, 1);
}
cout << f.sum() - g.sum() << endl;
}
}
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(10);
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, buckets, y) for (int i = (buckets); i < (y); ++i)
#define debug(buckets) #buckets << "=" << (buckets)
#ifdef DEBUG
#define _GLIBCbucketsbuckets_DEBUG
#define print(buckets) \
std::cerr << debug(buckets) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(buckets)
#endif
const int inf = 1e9;
const int64_t inf64 = 1e18;
const double eps = 1e-9;
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (const auto &v : vec) {
os << v << ",";
}
os << "]";
return os;
}
using i64 = int64_t;
struct sqrt_decomp {
const int bucket_size = 256;
int length, bucket_num;
vector<vector<int>> buckets;
vector<int> update, bucket_sum;
sqrt_decomp(const vector<int> &x)
: length(x.size()),
bucket_num((x.size() + bucket_size - 1) / bucket_size) {
buckets.resize(bucket_num);
update.resize(bucket_num);
bucket_sum.resize(bucket_num);
for (int i = 0; i < x.size(); ++i) {
buckets[i / bucket_size].push_back(x[i]);
bucket_sum[i / bucket_size] += x[i];
update[i / bucket_size] = 2;
}
}
int sum() {
int res = 0;
for (int i = 0; i < bucket_num; ++i) {
if (update[i] == 2)
res += bucket_sum[i];
else
res += update[i] * buckets[i].size();
}
return res;
}
void query(int l, int r, int b) { //[l,r]
l = max(0, l);
r = min(length - 1, r);
while (l % bucket_size != 0 && l <= r) {
int bucket_index = l / bucket_size;
if (update[bucket_index] < 2) {
for (auto &a : buckets[bucket_index])
a = update[bucket_index];
bucket_sum[bucket_index] =
update[bucket_index] * buckets[bucket_index].size();
update[bucket_index] = 2;
}
bucket_sum[bucket_index] -= buckets[bucket_index][l % bucket_size];
buckets[bucket_index][l % bucket_size] = b;
bucket_sum[bucket_index] += b;
++l;
}
while ((r + 1) % bucket_size != 0 and l <= r) {
int bucket_index = r / bucket_size;
if (update[bucket_index] < 2) {
for (auto &a : buckets[bucket_index])
a = update[bucket_index];
bucket_sum[bucket_index] =
update[bucket_index] * buckets[bucket_index].size();
update[bucket_index] = 2;
}
bucket_sum[bucket_index] -= buckets[bucket_index][r % bucket_size];
buckets[bucket_index][r % bucket_size] = b;
bucket_sum[bucket_index] += b;
--r;
}
if (l > r)
return;
rep(i, l / bucket_size, r / bucket_size + 1) update[i] = b;
}
int at(int i) {
int bucket_index = i / bucket_size;
if (update[bucket_index] < 2)
return update[bucket_index];
else
return buckets[bucket_index][i % bucket_size];
}
};
void solve() {
int n, q;
string s;
cin >> n >> s >> q;
vector<int> x1, x2;
rep(i, 0, n) {
x1.push_back(s[i] - '0');
if (i + 1 < n)
x2.push_back((s[i] - '0') * (s[i + 1] - '0'));
}
sqrt_decomp f(x1), g(x2);
for (int i = 0; i < q; i++) {
int l, r, b;
cin >> l >> r >> b;
l--;
r--;
f.query(l, r, b);
if (b == 0)
g.query(l - 1, r, 0);
else {
int l_ = l, r_ = r - 1;
if (0 <= l - 1 and f.at(l - 1))
--l_;
if (r + 1 < n and f.at(r + 1))
++r_;
g.query(l_, r_, 1);
}
cout << f.sum() - g.sum() << endl;
}
}
int main() {
std::cin.tie(0);
std::ios::sync_with_stdio(false);
cout.setf(ios::fixed);
cout.precision(10);
solve();
return 0;
}
|
replace
| 30 | 31 | 30 | 31 |
TLE
| |
p01925
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cstdio>
#include <vector>
int testcase_ends() {
size_t N, M;
scanf("%zu %zu", &N, &M);
if (N == 0 && M == 0)
return 1;
std::vector<int> min(N), max(N);
for (size_t i = 0; i < M; ++i) {
int S;
size_t k;
scanf("%d %zu", &S, &k);
std::vector<size_t> c(k);
for (size_t j = 0; j < k; ++j) {
scanf("%zu", &c[j]);
--c[j];
}
if (k == 1) {
min[c[0]] += S;
max[c[0]] += S;
continue;
}
for (size_t j = 0; j < k; ++j) {
max[c[j]] += S;
}
}
std::vector<int> max_left(N), max_right(N + 1);
for (size_t i = 0; i < N; ++i) {
max_left[i + 1] = std::max(max_left[i], max[i]);
}
for (size_t i = N; i--;) {
max_right[i] = std::max(max_right[i + 1], max[i]);
}
int res = 0;
for (size_t i = 0; i < N; ++i) {
int max0 = std::max(max_left[i], max_right[i + 1]);
res = std::max(res, max0 - min[i] + 1);
}
printf("%d\n", res);
return 0;
}
int main() {
while (!testcase_ends()) {
}
}
|
#include <algorithm>
#include <cstdio>
#include <vector>
int testcase_ends() {
size_t N, M;
scanf("%zu %zu", &N, &M);
if (N == 0 && M == 0)
return 1;
std::vector<int> min(N), max(N);
for (size_t i = 0; i < M; ++i) {
int S;
size_t k;
scanf("%d %zu", &S, &k);
std::vector<size_t> c(k);
for (size_t j = 0; j < k; ++j) {
scanf("%zu", &c[j]);
--c[j];
}
if (k == 1) {
min[c[0]] += S;
max[c[0]] += S;
continue;
}
for (size_t j = 0; j < k; ++j) {
max[c[j]] += S;
}
}
std::vector<int> max_left(N + 1), max_right(N + 1);
for (size_t i = 0; i < N; ++i) {
max_left[i + 1] = std::max(max_left[i], max[i]);
}
for (size_t i = N; i--;) {
max_right[i] = std::max(max_right[i + 1], max[i]);
}
int res = 0;
for (size_t i = 0; i < N; ++i) {
int max0 = std::max(max_left[i], max_right[i + 1]);
res = std::max(res, max0 - min[i] + 1);
}
printf("%d\n", res);
return 0;
}
int main() {
while (!testcase_ends()) {
}
}
|
replace
| 31 | 32 | 31 | 32 |
0
| |
p01927
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <bitset>
#include <ciso646>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod;
typedef pair<int, int> P;
#define stop \
char nyaa; \
cin >> nyaa;
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define per1(i, n) for (int i = n; i >= 1; i--)
#define Rep1(i, sta, n) for (int i = sta; i <= n; i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
struct Line {
public:
Point a, b;
};
ld dot(Point a, Point b) { return real(conj(a) * b); }
ld cross(Point a, Point b) { return imag(conj(a) * b); }
bool isis_sp(Line s, Point p) {
return (abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps);
}
bool isis_ss(Line s, Line t) {
if (isis_sp(s, t.a) || isis_sp(s, t.b) || isis_sp(t, s.a) || isis_sp(t, s.b))
return true;
return (cross(s.b - s.a, t.a - s.a) * cross(s.b - s.a, t.b - s.a) < -eps &&
cross(t.b - t.a, s.a - t.a) * cross(t.b - t.a, s.b - t.a) < -eps);
}
Point proj(Line l, Point p) {
ld t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
return l.a + t * (l.a - l.b);
}
ld dist_sp(Line s, Point p) {
Point r = proj(s, p);
return isis_sp(s, r) ? abs(p - r) : min(abs(p - s.a), abs(p - s.b));
}
ld dist_ss(Line s, Line t) {
if (isis_ss(s, t))
return 0;
return min(
{dist_sp(s, t.a), dist_sp(s, t.b), dist_sp(t, s.a), dist_sp(t, s.b)});
}
int n;
ld h[100];
vector<Point> vp[100];
vector<Point> rvp[100];
vector<Line> vl[100];
struct edge {
int to;
ld cost;
};
vector<edge> G[102];
ld dist[102];
typedef pair<ld, int> speP;
priority_queue<speP, vector<speP>, greater<speP>> q;
void solve() {
cout << fixed << setprecision(5);
while (cin >> n, n) {
rep(i, n + 2) G[i].clear();
rep(i, n) {
vl[i].clear();
vp[i].clear();
rvp[i].clear();
int l;
cin >> l >> h[i];
vp[i].resize(l);
rep(j, l) {
ld x, y;
cin >> x >> y;
vp[i][j] = {x, y};
}
}
ld theta, phi;
cin >> theta >> phi;
theta = theta * pi / 180.0;
phi = phi * pi / 180.0;
theta += pi;
rep(i, n) {
rvp[i].resize(vp[i].size());
ld rh = h[i] / tan(phi);
rep(j, vp[i].size()) {
ld dx = cos(theta) * rh, dy = sin(theta) * rh;
rvp[i][j] = {dx + real(vp[i][j]), dy + imag(vp[i][j])};
vl[i].push_back({vp[i][j], rvp[i][j]});
}
rep(j, vp[i].size() - 1) { vl[i].push_back({vp[i][j], vp[i][j + 1]}); }
vl[i].push_back({vp[i][0], vp[i][vp[i].size() - 1]});
rep(j, vp[i].size() - 1) { vl[i].push_back({rvp[i][j], rvp[i][j + 1]}); }
vl[i].push_back({rvp[i][0], rvp[i][rvp[i].size() - 1]});
}
rep(i, n) {
Rep(j, i + 1, n) {
ld d = INF;
rep(k, vp[i].size()) {
Rep(l, vp[j].size(), vl[j].size()) {
if (isis_ss(vl[i][k], vl[j][l])) {
d = 0;
break;
}
}
if (d == 0)
break;
rep(l, vp[j].size()) {
d = min(d, dist_sp(vl[i][k], vp[j][l]));
d = min(d, dist_sp(vl[i][k], rvp[j][l]));
}
}
if (d > 0) {
rep(l, vp[j].size()) {
Rep(k, vp[i].size(), vl[i].size()) {
if (isis_ss(vl[i][k], vl[j][l])) {
d = 0;
break;
}
}
if (d == 0)
break;
rep(k, vp[i].size()) {
d = min(d, dist_sp(vl[j][l], vp[i][k]));
d = min(d, dist_sp(vl[j][l], rvp[i][k]));
}
}
}
if (d > 0) {
Rep(k, vp[i].size(), vl[i].size()) {
Rep(l, vp[j].size(), vl[j].size()) {
if (k >= 2 * vp[i].size() && l >= 2 * vp[j].size())
continue;
d = min(d, dist_ss(vl[i][k], vl[j][l]));
}
}
}
/*rep(k, vl[i].size()) {
rep(l, vl[j].size()) {
if (k < vp[i].size() && l < vp[j].size())continue;
if (k >= 2 * vp[i].size() && l >= 2 *
vp[j].size())continue; d = min(d, dist_ss(vl[i][k], vl[j][l]));
}
}*/
G[i].push_back({j, d});
G[j].push_back({i, d});
}
}
Point s, g;
ld x, y;
cin >> x >> y;
s = {x, y};
cin >> x >> y;
g = {x, y};
theta -= pi;
Point ps, pg;
rep(i, n) {
ld rh = h[i] / tan(phi);
ps = {real(s) + rh * cos(theta), imag(s) + rh * sin(theta)};
pg = {real(g) + rh * cos(theta), imag(g) + rh * sin(theta)};
Line ls = {s, ps};
Line lg = {g, pg};
bool fs = false, fg = false;
rep(j, vp[i].size()) {
Line vpl = {vp[i][j], vp[i][(j + 1) % vp[i].size()]};
if (isis_ss(ls, vpl)) {
fs = true;
}
if (isis_ss(lg, vpl)) {
fg = true;
}
}
if (fs) {
G[n].push_back({i, 0});
G[i].push_back({n, 0});
} else {
ld d = INF;
rep(j, vl[i].size()) { d = min(d, dist_sp(vl[i][j], s)); }
G[n].push_back({i, d});
G[i].push_back({n, d});
}
if (fg) {
G[n + 1].push_back({i, 0});
G[i].push_back({n + 1, 0});
} else {
ld d = INF;
rep(j, vl[i].size()) { d = min(d, dist_sp(vl[i][j], g)); }
G[n + 1].push_back({i, d});
G[i].push_back({n + 1, d});
}
}
G[n].push_back({n + 1, abs(g - s)});
G[n + 1].push_back({n, abs(g - s)});
fill(dist, dist + n + 2, INF);
dist[n] = 0;
q.push({0, n});
while (!q.empty()) {
speP p = q.top();
q.pop();
int id = p.second;
if (p.first > dist[id])
continue;
rep(j, G[id].size()) {
int to = G[id][j].to;
ld nd = G[id][j].cost + p.first;
if (nd < dist[to]) {
dist[to] = nd;
q.push({nd, to});
}
}
}
cout << dist[n + 1] << endl;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
solve();
// stop
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <ciso646>
#include <cmath>
#include <complex>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod;
typedef pair<int, int> P;
#define stop \
char nyaa; \
cin >> nyaa;
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i >= 0; i--)
#define Rep(i, sta, n) for (int i = sta; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define per1(i, n) for (int i = n; i >= 1; i--)
#define Rep1(i, sta, n) for (int i = sta; i <= n; i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
struct Line {
public:
Point a, b;
};
ld dot(Point a, Point b) { return real(conj(a) * b); }
ld cross(Point a, Point b) { return imag(conj(a) * b); }
bool isis_sp(Line s, Point p) {
return (abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps);
}
bool isis_ss(Line s, Line t) {
// if (isis_sp(s, t.a) || isis_sp(s, t.b) || isis_sp(t, s.a) || isis_sp(t,
// s.b))return true;
return (cross(s.b - s.a, t.a - s.a) * cross(s.b - s.a, t.b - s.a) < -eps &&
cross(t.b - t.a, s.a - t.a) * cross(t.b - t.a, s.b - t.a) < -eps);
}
Point proj(Line l, Point p) {
ld t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
return l.a + t * (l.a - l.b);
}
ld dist_sp(Line s, Point p) {
Point r = proj(s, p);
return isis_sp(s, r) ? abs(p - r) : min(abs(p - s.a), abs(p - s.b));
}
ld dist_ss(Line s, Line t) {
if (isis_ss(s, t))
return 0;
return min(
{dist_sp(s, t.a), dist_sp(s, t.b), dist_sp(t, s.a), dist_sp(t, s.b)});
}
int n;
ld h[100];
vector<Point> vp[100];
vector<Point> rvp[100];
vector<Line> vl[100];
struct edge {
int to;
ld cost;
};
vector<edge> G[102];
ld dist[102];
typedef pair<ld, int> speP;
priority_queue<speP, vector<speP>, greater<speP>> q;
void solve() {
cout << fixed << setprecision(5);
while (cin >> n, n) {
rep(i, n + 2) G[i].clear();
rep(i, n) {
vl[i].clear();
vp[i].clear();
rvp[i].clear();
int l;
cin >> l >> h[i];
vp[i].resize(l);
rep(j, l) {
ld x, y;
cin >> x >> y;
vp[i][j] = {x, y};
}
}
ld theta, phi;
cin >> theta >> phi;
theta = theta * pi / 180.0;
phi = phi * pi / 180.0;
theta += pi;
rep(i, n) {
rvp[i].resize(vp[i].size());
ld rh = h[i] / tan(phi);
rep(j, vp[i].size()) {
ld dx = cos(theta) * rh, dy = sin(theta) * rh;
rvp[i][j] = {dx + real(vp[i][j]), dy + imag(vp[i][j])};
vl[i].push_back({vp[i][j], rvp[i][j]});
}
rep(j, vp[i].size() - 1) { vl[i].push_back({vp[i][j], vp[i][j + 1]}); }
vl[i].push_back({vp[i][0], vp[i][vp[i].size() - 1]});
rep(j, vp[i].size() - 1) { vl[i].push_back({rvp[i][j], rvp[i][j + 1]}); }
vl[i].push_back({rvp[i][0], rvp[i][rvp[i].size() - 1]});
}
rep(i, n) {
Rep(j, i + 1, n) {
ld d = INF;
rep(k, vp[i].size()) {
Rep(l, vp[j].size(), vl[j].size()) {
if (isis_ss(vl[i][k], vl[j][l])) {
d = 0;
break;
}
}
if (d == 0)
break;
rep(l, vp[j].size()) {
d = min(d, dist_sp(vl[i][k], vp[j][l]));
d = min(d, dist_sp(vl[i][k], rvp[j][l]));
}
}
if (d > 0) {
rep(l, vp[j].size()) {
Rep(k, vp[i].size(), vl[i].size()) {
if (isis_ss(vl[i][k], vl[j][l])) {
d = 0;
break;
}
}
if (d == 0)
break;
rep(k, vp[i].size()) {
d = min(d, dist_sp(vl[j][l], vp[i][k]));
d = min(d, dist_sp(vl[j][l], rvp[i][k]));
}
}
}
if (d > 0) {
Rep(k, vp[i].size(), vl[i].size()) {
Rep(l, vp[j].size(), vl[j].size()) {
if (k >= 2 * vp[i].size() && l >= 2 * vp[j].size())
continue;
d = min(d, dist_ss(vl[i][k], vl[j][l]));
}
}
}
/*rep(k, vl[i].size()) {
rep(l, vl[j].size()) {
if (k < vp[i].size() && l < vp[j].size())continue;
if (k >= 2 * vp[i].size() && l >= 2 *
vp[j].size())continue; d = min(d, dist_ss(vl[i][k], vl[j][l]));
}
}*/
G[i].push_back({j, d});
G[j].push_back({i, d});
}
}
Point s, g;
ld x, y;
cin >> x >> y;
s = {x, y};
cin >> x >> y;
g = {x, y};
theta -= pi;
Point ps, pg;
rep(i, n) {
ld rh = h[i] / tan(phi);
ps = {real(s) + rh * cos(theta), imag(s) + rh * sin(theta)};
pg = {real(g) + rh * cos(theta), imag(g) + rh * sin(theta)};
Line ls = {s, ps};
Line lg = {g, pg};
bool fs = false, fg = false;
rep(j, vp[i].size()) {
Line vpl = {vp[i][j], vp[i][(j + 1) % vp[i].size()]};
if (isis_ss(ls, vpl)) {
fs = true;
}
if (isis_ss(lg, vpl)) {
fg = true;
}
}
if (fs) {
G[n].push_back({i, 0});
G[i].push_back({n, 0});
} else {
ld d = INF;
rep(j, vl[i].size()) { d = min(d, dist_sp(vl[i][j], s)); }
G[n].push_back({i, d});
G[i].push_back({n, d});
}
if (fg) {
G[n + 1].push_back({i, 0});
G[i].push_back({n + 1, 0});
} else {
ld d = INF;
rep(j, vl[i].size()) { d = min(d, dist_sp(vl[i][j], g)); }
G[n + 1].push_back({i, d});
G[i].push_back({n + 1, d});
}
}
G[n].push_back({n + 1, abs(g - s)});
G[n + 1].push_back({n, abs(g - s)});
fill(dist, dist + n + 2, INF);
dist[n] = 0;
q.push({0, n});
while (!q.empty()) {
speP p = q.top();
q.pop();
int id = p.second;
if (p.first > dist[id])
continue;
rep(j, G[id].size()) {
int to = G[id][j].to;
ld nd = G[id][j].cost + p.first;
if (nd < dist[to]) {
dist[to] = nd;
q.push({nd, to});
}
}
}
cout << dist[n + 1] << endl;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
solve();
// stop
return 0;
}
|
replace
| 54 | 56 | 54 | 57 |
TLE
| |
p01928
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <vector>
#define llint long long
#define inf 1e18
using namespace std;
struct Edge {
llint to, cost;
Edge() {}
Edge(llint a, llint b) { to = a, cost = b; }
};
llint N;
llint L[105][3];
vector<Edge> g[105];
llint volume(llint x) {
llint ret = 1;
for (llint i = 0; i < 3; i++)
ret *= L[x][i];
return ret;
}
bool compare(llint x, llint y) {
for (llint i = 0; i < 3; i++) {
if (L[x][i] <= L[y][i])
return false;
}
return true;
}
struct edge {
llint to, cap, cost, rev;
edge() {}
edge(llint a, llint b, llint c, llint d) {
to = a, cap = b, cost = c, rev = d;
}
};
llint S, T;
vector<edge> G[205];
llint dist[205];
llint prevv[205], preve[205];
void BellmanFord() {
for (llint i = 0; i <= T; i++)
dist[i] = inf;
dist[S] = 0, prevv[S] = -1;
bool update = true;
while (update) {
update = false;
for (llint i = 0; i <= T; i++) {
for (llint j = 0; j < G[i].size(); j++) {
if (G[i][j].cap == 0)
continue;
if (dist[G[i][j].to] > dist[i] + G[i][j].cost) {
dist[G[i][j].to] = dist[i] + G[i][j].cost;
prevv[G[i][j].to] = i;
preve[G[i][j].to] = j;
update = true;
}
}
}
}
}
void add_edge(llint from, llint to, llint cap, llint cost) {
G[from].push_back(edge(to, cap, cost, G[to].size()));
G[to].push_back(edge(from, 0, -cost, G[from].size() - 1));
}
int main(void) {
while (1) {
cin >> N;
if (N == 0)
break;
for (llint i = 0; i < N; i++) {
for (llint j = 0; j < 3; j++) {
cin >> L[i][j];
}
sort(L[i], L[i] + 3);
}
for (llint i = 0; i < N; i++)
g[i].clear();
for (llint i = 0; i < N; i++) {
for (llint j = 0; j < N; j++) {
if (compare(i, j)) {
g[i].push_back(Edge(j, volume(j)));
}
}
}
S = 2 * N + 1, T = 2 * N + 2;
for (llint i = 0; i <= T; i++)
G[i].clear();
for (llint i = 0; i < N; i++) {
for (llint j = 0; j < g[i].size(); j++) {
add_edge(i, N + g[j][j].to, inf, -g[i][j].cost);
}
}
for (llint i = 0; i < N; i++) {
add_edge(S, i, 1, 0);
add_edge(i + N, T, 1, 0);
}
llint ans = 0;
while (1) {
BellmanFord();
if (dist[T] >= inf / 2)
break;
llint p = T, flow = N;
while (prevv[p] != -1) {
flow = min(flow, G[prevv[p]][preve[p]].cap);
p = prevv[p];
}
p = T;
while (prevv[p] != -1) {
G[prevv[p]][preve[p]].cap -= flow;
G[p][G[prevv[p]][preve[p]].rev].cap += flow;
p = prevv[p];
}
ans += dist[T] * flow;
}
llint sum = 0;
for (llint i = 0; i < N; i++)
sum += volume(i);
ans = sum + ans;
cout << ans << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
#define llint long long
#define inf 1e18
using namespace std;
struct Edge {
llint to, cost;
Edge() {}
Edge(llint a, llint b) { to = a, cost = b; }
};
llint N;
llint L[105][3];
vector<Edge> g[105];
llint volume(llint x) {
llint ret = 1;
for (llint i = 0; i < 3; i++)
ret *= L[x][i];
return ret;
}
bool compare(llint x, llint y) {
for (llint i = 0; i < 3; i++) {
if (L[x][i] <= L[y][i])
return false;
}
return true;
}
struct edge {
llint to, cap, cost, rev;
edge() {}
edge(llint a, llint b, llint c, llint d) {
to = a, cap = b, cost = c, rev = d;
}
};
llint S, T;
vector<edge> G[205];
llint dist[205];
llint prevv[205], preve[205];
void BellmanFord() {
for (llint i = 0; i <= T; i++)
dist[i] = inf;
dist[S] = 0, prevv[S] = -1;
bool update = true;
while (update) {
update = false;
for (llint i = 0; i <= T; i++) {
for (llint j = 0; j < G[i].size(); j++) {
if (G[i][j].cap == 0)
continue;
if (dist[G[i][j].to] > dist[i] + G[i][j].cost) {
dist[G[i][j].to] = dist[i] + G[i][j].cost;
prevv[G[i][j].to] = i;
preve[G[i][j].to] = j;
update = true;
}
}
}
}
}
void add_edge(llint from, llint to, llint cap, llint cost) {
G[from].push_back(edge(to, cap, cost, G[to].size()));
G[to].push_back(edge(from, 0, -cost, G[from].size() - 1));
}
int main(void) {
while (1) {
cin >> N;
if (N == 0)
break;
for (llint i = 0; i < N; i++) {
for (llint j = 0; j < 3; j++) {
cin >> L[i][j];
}
sort(L[i], L[i] + 3);
}
for (llint i = 0; i < N; i++)
g[i].clear();
for (llint i = 0; i < N; i++) {
for (llint j = 0; j < N; j++) {
if (compare(i, j)) {
g[i].push_back(Edge(j, volume(j)));
}
}
}
S = 2 * N + 1, T = 2 * N + 2;
for (llint i = 0; i <= T; i++)
G[i].clear();
for (llint i = 0; i < N; i++) {
for (llint j = 0; j < g[i].size(); j++) {
add_edge(i, N + g[i][j].to, inf, -g[i][j].cost);
}
}
for (llint i = 0; i < N; i++) {
add_edge(S, i, 1, 0);
add_edge(i + N, T, 1, 0);
}
llint ans = 0;
while (1) {
BellmanFord();
if (dist[T] >= inf / 2)
break;
llint p = T, flow = N;
while (prevv[p] != -1) {
flow = min(flow, G[prevv[p]][preve[p]].cap);
p = prevv[p];
}
p = T;
while (prevv[p] != -1) {
G[prevv[p]][preve[p]].cap -= flow;
G[p][G[prevv[p]][preve[p]].rev].cap += flow;
p = prevv[p];
}
ans += dist[T] * flow;
}
llint sum = 0;
for (llint i = 0; i < N; i++)
sum += volume(i);
ans = sum + ans;
cout << ans << endl;
}
return 0;
}
|
replace
| 101 | 102 | 101 | 102 |
-11
| |
p01933
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = ((int)a); i < ((int)n); i++)
#define INF (1 << 30)
using namespace std;
int N, K, A;
vector<int> R, E[100000];
bool ans[100000];
int dfs(int v) {
int depth = INF;
for (int u : E[v])
depth = min(depth, dfs(u));
if (depth == INF)
depth = 0;
if (depth < K)
ans[v] = true;
return depth + 1;
}
int main(void) {
cin >> N >> K;
REP(i, 0, N) {
cin >> A;
if (A >= 1)
E[A - 1].push_back(i);
else
R.push_back(i);
}
REP(i, 0, N) ans[i] = false;
REP(i, 0, R.size()) ans[R[i]] = true, dfs(R[i]);
int cnt = 0;
REP(i, 0, N) if (ans[i]) cnt++;
cout << cnt << endl;
}
|
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = ((int)a); i < ((int)n); i++)
#define INF (1 << 30)
using namespace std;
int N, K, A;
vector<int> R, E[100000];
bool ans[100000];
int dfs(int v) {
int depth = INF;
REP(i, 0, E[v].size()) depth = min(depth, dfs(E[v][i]));
if (depth == INF)
depth = 0;
if (depth < K)
ans[v] = true;
return depth + 1;
}
int main(void) {
cin >> N >> K;
REP(i, 0, N) {
cin >> A;
if (A >= 1)
E[A - 1].push_back(i);
else
R.push_back(i);
}
REP(i, 0, N) ans[i] = false;
REP(i, 0, R.size()) ans[R[i]] = true, dfs(R[i]);
int cnt = 0;
REP(i, 0, N) if (ans[i]) cnt++;
cout << cnt << endl;
}
|
replace
| 11 | 13 | 11 | 12 |
0
| |
p01933
|
C++
|
Time Limit Exceeded
|
#include <iostream>
#include <vector>
using namespace std;
#define repeat(i, n) for (int i = 0; i < (n); i++)
vector<int> g[100005]; // 0-indexed
int root[100005];
const int inf = 1e8;
vector<int> d(100005, inf);
int N, K;
void f(int i, int p = -1) {
int ret = inf;
for (int j : g[i])
if (j != p) {
f(j, i);
ret = min(ret, d[j]);
}
if (ret == inf)
d[i] = 0;
else
d[i] = ret + 1;
}
int main() {
cin >> N >> K;
repeat(i, N) {
int x;
cin >> x;
if (x == 0) {
root[i] = 1;
} else {
g[x - 1].push_back(i);
g[i].push_back(x - 1);
}
}
repeat(i, N) if (root[i]) { f(i); }
int c = 0;
repeat(i, N) {
if (root[i])
c++;
else
c += (d[i] < K);
}
cout << c << endl;
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
#define repeat(i, n) for (int i = 0; i < (n); i++)
vector<int> g[100005]; // 0-indexed
int root[100005];
const int inf = 1e8;
vector<int> d(100005, inf);
int N, K;
void f(int i, int p = -1) {
int ret = inf;
for (int j : g[i])
if (j != p) {
f(j, i);
ret = min(ret, d[j]);
}
if (ret == inf)
d[i] = 0;
else
d[i] = ret + 1;
}
int main() {
cin >> N >> K;
repeat(i, N) {
int x;
cin >> x;
if (x == 0) {
root[i] = 1;
} else {
g[x - 1].push_back(i);
// g[i].push_back(x-1);
}
}
repeat(i, N) if (root[i]) { f(i); }
int c = 0;
repeat(i, N) {
if (root[i])
c++;
else
c += (d[i] < K);
}
cout << c << endl;
return 0;
}
|
replace
| 35 | 36 | 35 | 36 |
TLE
| |
p01934
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
struct cww {
cww() {
ios::sync_with_stdio(false);
cin.tie(0);
}
} star;
#define FOR(i, bg, ed) for (int i = (bg); i < (ed); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret(__VA_ARGS__)>
template <typename T> inline bool chmin(T &l, T r) {
bool a = l > r;
if (a)
l = r;
return a;
}
template <typename T> inline bool chmax(T &l, T r) {
bool a = l < r;
if (a)
l = r;
return a;
}
typedef vector<LL> V;
typedef vector<V> VV;
const LL INF = 1e15;
int a[112345];
int b[112345];
LL c[112345];
LL d[112345];
int main() {
int N, M, s, t;
cin >> N >> M >> s >> t;
s--;
t--;
V dist(N, INF);
VV g(N);
REP(i, N) cin >> d[i];
REP(i, M) {
cin >> a[i] >> b[i];
a[i]--;
b[i]--;
c[i] = d[b[i]];
g[a[i]].pb(i);
}
REP(i, N - 1) {
a[i + M] = i + 1;
b[i + M] = i;
c[i + M] = 0;
g[a[i + M]].pb(i + M);
}
dist[s] = 0;
priority_queue<pair<LL, int>> Q;
Q.push({0ll, s});
while (Q.size()) {
auto q = Q.top();
Q.pop();
LL cost = -q.fi;
int v = q.se;
if (cost > dist[v])
continue;
for (auto &e : g[v]) {
int u = b[e];
LL nxtcost = c[e] + cost;
if (chmin(dist[u], nxtcost)) {
Q.push({-nxtcost, u});
}
}
}
cout << dist[t] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
struct cww {
cww() {
ios::sync_with_stdio(false);
cin.tie(0);
}
} star;
#define FOR(i, bg, ed) for (int i = (bg); i < (ed); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define fi first
#define se second
#define pb push_back
#define REC(ret, ...) std::function<ret(__VA_ARGS__)>
template <typename T> inline bool chmin(T &l, T r) {
bool a = l > r;
if (a)
l = r;
return a;
}
template <typename T> inline bool chmax(T &l, T r) {
bool a = l < r;
if (a)
l = r;
return a;
}
typedef vector<LL> V;
typedef vector<V> VV;
const LL INF = 1e15;
int a[212345];
int b[212345];
LL c[212345];
LL d[212345];
int main() {
int N, M, s, t;
cin >> N >> M >> s >> t;
s--;
t--;
V dist(N, INF);
VV g(N);
REP(i, N) cin >> d[i];
REP(i, M) {
cin >> a[i] >> b[i];
a[i]--;
b[i]--;
c[i] = d[b[i]];
g[a[i]].pb(i);
}
REP(i, N - 1) {
a[i + M] = i + 1;
b[i + M] = i;
c[i + M] = 0;
g[a[i + M]].pb(i + M);
}
dist[s] = 0;
priority_queue<pair<LL, int>> Q;
Q.push({0ll, s});
while (Q.size()) {
auto q = Q.top();
Q.pop();
LL cost = -q.fi;
int v = q.se;
if (cost > dist[v])
continue;
for (auto &e : g[v]) {
int u = b[e];
LL nxtcost = c[e] + cost;
if (chmin(dist[u], nxtcost)) {
Q.push({-nxtcost, u});
}
}
}
cout << dist[t] << endl;
return 0;
}
|
replace
| 34 | 38 | 34 | 38 |
0
| |
p01935
|
C++
|
Time Limit Exceeded
|
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = double;
const ld eps = 1e-9;
//
// using Graph = vector<vector<int>>;
//
// int dfs(const Graph&g, const int now, vector<int>&ch_cnts) {
// ch_cnts[now]++;
// for (auto&& e : g[now]) {
// ch_cnts[now] += dfs(g, e, ch_cnts);
// }
// return ch_cnts[now];
//}
//
// struct HL_Edge {
// int from;
// int to;
// bool heavy;
//};
//
// void dfs2(const Graph&g, vector<vector<HL_Edge>>&hl_tree, const int now,
// const vector<int>&ch_cnts) {
//
// int max_ch_id = 1;
// {
// int max_ch_num = -1;
// for (auto&&e : g[now]) {
// if (max_ch_num < ch_cnts[e]) {
// max_ch_num = ch_cnts[e];
// max_ch_id = e;
// }
// }
// }
// for (auto e : g[now]) {
// bool heavy = (e == max_ch_id);
//
// hl_tree[now].push_back(HL_Edge{ now,e,heavy });
// }
// return;
//}
//
// void HL(const vector<vector<int>>&ro_tree) {
// vector<int>ch_cnts(ro_tree.size());
//
// dfs(ro_tree, 0, ch_cnts);
//
// vector<vector<HL_Edge>>hl_tree(ro_tree.size());
//
// dfs2(ro_tree, hl_tree, 0, ch_cnts);
//}
//
// namespace FastFourierTransform
//{
// using C = complex< double >;
//
// void DiscreteFourierTransform(vector< C > &F, bool rev)
// {
// const int N = (int)F.size();
// const double PI = (rev ? -1 : 1) * acos(-1);
// for (int i = 0, j = 1; j + 1 < N; j++) {
// for (int k = N >> 1; k > (i ^= k); k >>= 1);
// if (i > j) swap(F[i], F[j]);
// }
// C w, s, t;
// for (int i = 1; i < N; i <<= 1) {
// for (int k = 0; k < i; k++) {
// w = polar(1.0, PI / i * k);
// for (int j = 0; j < N; j += i * 2) {
// s = F[j + k];
// t = C(F[j + k + i].real() * w.real() - F[j + k + i].imag() *
// w.imag(),
// F[j + k + i].real() * w.imag() + F[j + k + i].imag() *
// w.real());
// F[j + k] = s + t, F[j + k + i] = s - t;
// }
// }
// }
// if (rev) for (int i = 0; i < N; i++) F[i] /= N;
// }
//
// vector< int> Multiply(const vector<int > &A, const vector<int > &B)
// {
// int sz = 1;
// while (sz <= A.size() + B.size()) sz <<= 1;
// vector< C > F(sz), G(sz);
// for (int i = 0; i < A.size(); i++) F[i] = A[i];
// for (int i = 0; i < B.size(); i++) G[i] = B[i];
// DiscreteFourierTransform(F, false);
// DiscreteFourierTransform(G, false);
// for (int i = 0; i < sz; i++) F[i] *= G[i];
// DiscreteFourierTransform(F, true);
// vector< int > X(A.size() + B.size() - 1);
// for (int i = 0; i < A.size() + B.size() - 1; i++) X[i] = F[i].real() +
// 0.5; return (X);
// }
//};
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
// const int INF = 2147483647;
// const long long int L_INF = 9223372036854775807;
typedef long long int Weight;
const Weight INF = 1e18;
const Weight ZERO = 0;
struct Edge {
int src, dst;
Weight weight;
Edge(int src, int dst, Weight weight) : src(src), dst(dst), weight(weight) {}
Edge() : src(0), dst(0), weight(0) {}
};
bool operator<(const Edge &e, const Edge &f) {
return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
e.src != f.src ? e.src < f.src
: e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
#define RESIDUE(s, t) (capacity[s * 1e4 + t] - flow[s * 1e4 + t])
// 流量0の逆辺も張らないと正しく求まらないので注意
Weight maximumFlow(const Graph &ag, int s, int t) {
Graph g(ag);
for (int i = 0; i < ag.size(); ++i) {
for (int j = 0; j < ag[i].size(); ++j) {
int d = ag[i][j].dst;
int s = ag[i][j].src;
bool ok = false;
for (int k = 0; k < ag[d].size(); ++k) {
if (ag[d][k].src == s) {
ok = true;
break;
}
}
if (!ok) {
g[d].push_back(Edge(d, s, ZERO));
}
}
}
int n = g.size();
// Matrix flow(n, Array(n,ZERO)), capacity(n, Array(n,ZERO));
map<int, Weight> flow, capacity;
REP(u, n)
FOR(e, g[u]) capacity[e->src * 1e4 + e->dst] =
capacity[1e4 * e->src + e->dst] + e->weight;
Weight total = ZERO;
while (1) {
queue<int> Q;
Q.push(s);
vector<int> prev(n, -1);
prev[s] = s;
while (!Q.empty() && prev[t] < 0) {
int u = Q.front();
Q.pop();
FOR(e, g[u]) if (prev[e->dst] < 0 && RESIDUE(u, e->dst) > ZERO) {
prev[e->dst] = u;
Q.push(e->dst);
}
}
if (prev[t] < 0)
break; // prev[x] == -1 <=> t-side
Weight inc = INF;
for (int j = t; prev[j] != j; j = prev[j]) {
auto v(RESIDUE(prev[j], j));
if (inc > v) {
inc = v;
}
}
for (int j = t; prev[j] != j; j = prev[j])
flow[prev[j] * 1e4 + j] = flow[j + 1e4 * prev[j]] + inc,
flow[j * 1e4 + prev[j]] =
flow[j * 1e4 + prev[j]] - inc;
;
total += inc;
}
return total;
}
int main() {
int V, E;
cin >> V >> E;
Graph g(V);
for (int i = 0; i < E; ++i) {
int f, t, c;
cin >> f >> t >> c;
long long int num = c * static_cast<long long int>(1e9);
if (num == 1e9)
num--;
g[f].push_back(Edge(f, t, num));
g[t].push_back(Edge(t, f, num));
}
auto ans = maximumFlow(g, 0, V - 1);
long long int nn = ans / (1e9);
if (nn > 1e4)
nn = -1;
cout << nn << endl;
return 0;
}
|
#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = double;
const ld eps = 1e-9;
//
// using Graph = vector<vector<int>>;
//
// int dfs(const Graph&g, const int now, vector<int>&ch_cnts) {
// ch_cnts[now]++;
// for (auto&& e : g[now]) {
// ch_cnts[now] += dfs(g, e, ch_cnts);
// }
// return ch_cnts[now];
//}
//
// struct HL_Edge {
// int from;
// int to;
// bool heavy;
//};
//
// void dfs2(const Graph&g, vector<vector<HL_Edge>>&hl_tree, const int now,
// const vector<int>&ch_cnts) {
//
// int max_ch_id = 1;
// {
// int max_ch_num = -1;
// for (auto&&e : g[now]) {
// if (max_ch_num < ch_cnts[e]) {
// max_ch_num = ch_cnts[e];
// max_ch_id = e;
// }
// }
// }
// for (auto e : g[now]) {
// bool heavy = (e == max_ch_id);
//
// hl_tree[now].push_back(HL_Edge{ now,e,heavy });
// }
// return;
//}
//
// void HL(const vector<vector<int>>&ro_tree) {
// vector<int>ch_cnts(ro_tree.size());
//
// dfs(ro_tree, 0, ch_cnts);
//
// vector<vector<HL_Edge>>hl_tree(ro_tree.size());
//
// dfs2(ro_tree, hl_tree, 0, ch_cnts);
//}
//
// namespace FastFourierTransform
//{
// using C = complex< double >;
//
// void DiscreteFourierTransform(vector< C > &F, bool rev)
// {
// const int N = (int)F.size();
// const double PI = (rev ? -1 : 1) * acos(-1);
// for (int i = 0, j = 1; j + 1 < N; j++) {
// for (int k = N >> 1; k > (i ^= k); k >>= 1);
// if (i > j) swap(F[i], F[j]);
// }
// C w, s, t;
// for (int i = 1; i < N; i <<= 1) {
// for (int k = 0; k < i; k++) {
// w = polar(1.0, PI / i * k);
// for (int j = 0; j < N; j += i * 2) {
// s = F[j + k];
// t = C(F[j + k + i].real() * w.real() - F[j + k + i].imag() *
// w.imag(),
// F[j + k + i].real() * w.imag() + F[j + k + i].imag() *
// w.real());
// F[j + k] = s + t, F[j + k + i] = s - t;
// }
// }
// }
// if (rev) for (int i = 0; i < N; i++) F[i] /= N;
// }
//
// vector< int> Multiply(const vector<int > &A, const vector<int > &B)
// {
// int sz = 1;
// while (sz <= A.size() + B.size()) sz <<= 1;
// vector< C > F(sz), G(sz);
// for (int i = 0; i < A.size(); i++) F[i] = A[i];
// for (int i = 0; i < B.size(); i++) G[i] = B[i];
// DiscreteFourierTransform(F, false);
// DiscreteFourierTransform(G, false);
// for (int i = 0; i < sz; i++) F[i] *= G[i];
// DiscreteFourierTransform(F, true);
// vector< int > X(A.size() + B.size() - 1);
// for (int i = 0; i < A.size() + B.size() - 1; i++) X[i] = F[i].real() +
// 0.5; return (X);
// }
//};
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define FOR(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
// const int INF = 2147483647;
// const long long int L_INF = 9223372036854775807;
typedef long long int Weight;
const Weight INF = 1e18;
const Weight ZERO = 0;
struct Edge {
int src, dst;
Weight weight;
Edge(int src, int dst, Weight weight) : src(src), dst(dst), weight(weight) {}
Edge() : src(0), dst(0), weight(0) {}
};
bool operator<(const Edge &e, const Edge &f) {
return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
e.src != f.src ? e.src < f.src
: e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
#define RESIDUE(s, t) (capacity[s * 1e4 + t] - flow[s * 1e4 + t])
// 流量0の逆辺も張らないと正しく求まらないので注意
Weight maximumFlow(const Graph &ag, int s, int t) {
Graph g(ag);
int n = g.size();
// Matrix flow(n, Array(n,ZERO)), capacity(n, Array(n,ZERO));
map<int, Weight> flow, capacity;
REP(u, n)
FOR(e, g[u]) capacity[e->src * 1e4 + e->dst] =
capacity[1e4 * e->src + e->dst] + e->weight;
Weight total = ZERO;
while (1) {
queue<int> Q;
Q.push(s);
vector<int> prev(n, -1);
prev[s] = s;
while (!Q.empty() && prev[t] < 0) {
int u = Q.front();
Q.pop();
FOR(e, g[u]) if (prev[e->dst] < 0 && RESIDUE(u, e->dst) > ZERO) {
prev[e->dst] = u;
Q.push(e->dst);
}
}
if (prev[t] < 0)
break; // prev[x] == -1 <=> t-side
Weight inc = INF;
for (int j = t; prev[j] != j; j = prev[j]) {
auto v(RESIDUE(prev[j], j));
if (inc > v) {
inc = v;
}
}
for (int j = t; prev[j] != j; j = prev[j])
flow[prev[j] * 1e4 + j] = flow[j + 1e4 * prev[j]] + inc,
flow[j * 1e4 + prev[j]] =
flow[j * 1e4 + prev[j]] - inc;
;
total += inc;
}
return total;
}
int main() {
int V, E;
cin >> V >> E;
Graph g(V);
for (int i = 0; i < E; ++i) {
int f, t, c;
cin >> f >> t >> c;
long long int num = c * static_cast<long long int>(1e9);
if (num == 1e9)
num--;
g[f].push_back(Edge(f, t, num));
g[t].push_back(Edge(t, f, num));
}
auto ans = maximumFlow(g, 0, V - 1);
long long int nn = ans / (1e9);
if (nn > 1e4)
nn = -1;
cout << nn << endl;
return 0;
}
|
replace
| 138 | 155 | 138 | 139 |
TLE
| |
p01935
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;
template <typename A, typename B> inline void chmin(A &a, B b) {
if (a > b)
a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
if (a < b)
a = b;
}
const int INF = 1001001001;
struct edge {
int to, cap, rev;
edge(int a, int b, int c) : to(a), cap(b), rev(c) {}
};
int N, E, Q;
const int MAX_V = 3333;
vector<edge> G[MAX_V];
bool used[MAX_V];
void add_edge(int from, int to, int cap) {
G[from].pb(edge(to, cap, G[to].size()));
G[to].pb(edge(from, cap, G[from].size() - 1));
}
int dfs(int v, int t, int f) {
if (v == t)
return f;
used[v] = true;
for (int i = 0; i < G[v].size(); i++) {
edge &e = G[v][i];
if (used[e.to] || e.cap == 0)
continue;
int d = dfs(e.to, t, min(f, e.cap));
if (d == 0)
continue;
e.cap -= d;
G[e.to][e.rev].cap += d;
return d;
}
return 0;
}
int max_flow(int s, int t, int lim) {
int f = 0;
while (lim) {
memset(used, 0, sizeof(used));
int ff = dfs(s, t, lim);
if (ff == 0)
return f;
f += ff;
lim -= ff;
}
return f;
}
int f;
void q1(int a, int b) {
add_edge(a, b, 1);
f += max_flow(0, N - 1, INF);
}
void q2(int a, int b) {
bool f1 = false, f2 = false;
for (auto &e : G[a]) {
if (e.to != b || e.cap == 0)
continue;
if (e.cap == 2)
f2 = true, e.cap = 0;
}
for (auto &e : G[b]) {
if (e.to != a || e.cap == 0)
continue;
if (e.cap == 2)
f1 = true, e.cap = 0;
}
if (!f1 && !f2)
return;
if (f2)
swap(a, b);
int tmp = max_flow(a, b, 1);
if (tmp)
return;
add_edge(0, N - 1, 1);
tmp = max_flow(a, b, 1);
assert(tmp);
G[0].pop_back();
G[N - 1].pop_back();
f--;
}
signed main() {
cin >> N >> E;
vpint lis;
rep(i, E) {
int a, b, c;
cin >> a >> b >> c;
if (c == 1)
lis.pb({a, b});
add_edge(a, b, c);
}
f = max_flow(0, N - 1, INF);
int ans = f;
rep(i, lis.size()) {
int a = lis[i].fi, b = lis[i].se;
q2(a, b);
chmin(ans, f);
q1(a, b);
}
if (ans > 10000)
cout << -1 << endl;
else
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;
template <typename A, typename B> inline void chmin(A &a, B b) {
if (a > b)
a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
if (a < b)
a = b;
}
const int INF = 1001001001;
struct edge {
int to, cap, rev;
edge(int a, int b, int c) : to(a), cap(b), rev(c) {}
};
int N, E, Q;
const int MAX_V = 5555;
vector<edge> G[MAX_V];
bool used[MAX_V];
void add_edge(int from, int to, int cap) {
G[from].pb(edge(to, cap, G[to].size()));
G[to].pb(edge(from, cap, G[from].size() - 1));
}
int dfs(int v, int t, int f) {
if (v == t)
return f;
used[v] = true;
for (int i = 0; i < G[v].size(); i++) {
edge &e = G[v][i];
if (used[e.to] || e.cap == 0)
continue;
int d = dfs(e.to, t, min(f, e.cap));
if (d == 0)
continue;
e.cap -= d;
G[e.to][e.rev].cap += d;
return d;
}
return 0;
}
int max_flow(int s, int t, int lim) {
int f = 0;
while (lim) {
memset(used, 0, sizeof(used));
int ff = dfs(s, t, lim);
if (ff == 0)
return f;
f += ff;
lim -= ff;
}
return f;
}
int f;
void q1(int a, int b) {
add_edge(a, b, 1);
f += max_flow(0, N - 1, INF);
}
void q2(int a, int b) {
bool f1 = false, f2 = false;
for (auto &e : G[a]) {
if (e.to != b || e.cap == 0)
continue;
if (e.cap == 2)
f2 = true, e.cap = 0;
}
for (auto &e : G[b]) {
if (e.to != a || e.cap == 0)
continue;
if (e.cap == 2)
f1 = true, e.cap = 0;
}
if (!f1 && !f2)
return;
if (f2)
swap(a, b);
int tmp = max_flow(a, b, 1);
if (tmp)
return;
add_edge(0, N - 1, 1);
tmp = max_flow(a, b, 1);
assert(tmp);
G[0].pop_back();
G[N - 1].pop_back();
f--;
}
signed main() {
cin >> N >> E;
vpint lis;
rep(i, E) {
int a, b, c;
cin >> a >> b >> c;
if (c == 1)
lis.pb({a, b});
add_edge(a, b, c);
}
f = max_flow(0, N - 1, INF);
int ans = f;
rep(i, lis.size()) {
int a = lis[i].fi, b = lis[i].se;
q2(a, b);
chmin(ans, f);
q1(a, b);
}
if (ans > 10000)
cout << -1 << endl;
else
cout << ans << endl;
return 0;
}
|
replace
| 32 | 33 | 32 | 33 |
0
| |
p01939
|
C++
|
Runtime Error
|
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; (i) < (n); (i)++)
#define ll long long
static const int MOD = 1000000007;
int n, m;
int ns, f, d;
int ans;
signed main() {
cin >> n >> m;
ns = ((m + 1) / (n - 1)) % MOD;
f = (m + 1 - (n - 1)) % MOD;
d = -(n - 1) % MOD;
ans = (ns * ((2 * f + ((ns - 1) * d) % MOD) % MOD) % MOD + m + 1) % MOD;
cout << ans << endl;
return 0;
}
|
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; (i) < (n); (i)++)
#define ll long long
static const int MOD = 1000000007;
int n, m;
int ns, f, d;
int ans;
signed main() {
cin >> n >> m;
if (n == 1) {
ns = 0;
} else
ns = ((m + 1) / (n - 1)) % MOD;
f = (m + 1 - (n - 1)) % MOD;
d = -(n - 1) % MOD;
ans = (ns * ((2 * f + ((ns - 1) * d) % MOD) % MOD) % MOD + m + 1) % MOD;
cout << ans << endl;
return 0;
}
|
replace
| 26 | 27 | 26 | 30 |
0
| |
p01939
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll mod = 1000000007;
ll n;
ll m;
cin >> n >> m;
// ll ks=m/(n-1)
if (n == 1) {
assert(0);
cout << m + 1 << endl;
return 0;
}
ll sy = m + 1;
ll ma = sy % (n - 1);
ll ks = sy / (n - 1);
// if(ma)ks++;
ks++;
cout << ((((sy + ma) % mod) * (ks % mod)) % mod - sy % mod + mod) % mod
<< endl;
// cout << (m+1)%mod*((m+1)/(n-1))%mod<< endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ll mod = 1000000007;
ll n;
ll m;
cin >> n >> m;
// ll ks=m/(n-1)
if (n == 1) {
cout << (m + 1) % mod << endl;
return 0;
}
ll sy = m + 1;
ll ma = sy % (n - 1);
ll ks = sy / (n - 1);
// if(ma)ks++;
ks++;
cout << ((((sy + ma) % mod) * (ks % mod)) % mod - sy % mod + mod) % mod
<< endl;
// cout << (m+1)%mod*((m+1)/(n-1))%mod<< endl;
return 0;
}
|
replace
| 10 | 12 | 10 | 11 |
0
| |
p01940
|
C++
|
Time Limit Exceeded
|
#include <iostream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
int main(void) {
string S;
string P;
cin >> S;
cin >> P;
int search = 0;
int count = 0;
bool finish = false;
int preserch = 0;
bool many_same_char = false;
vector<tuple<int, int>> st;
for (int ptr = 0; !finish; ptr++) {
if (S[ptr] == P[search]) {
preserch = search;
if (search >= P.length() - 1) {
int oldcount = count;
for (int subptr = ptr; subptr < S.length(); subptr++) {
if (S[subptr] == P[search]) {
count++;
}
}
if (count - oldcount == 1) {
if (many_same_char) {
count = 2000;
} else {
count = 1;
}
finish = true;
}
if (!st.empty()) {
tuple<int, int> t = st.back();
st.pop_back();
ptr = get<0>(t);
search = get<1>(t);
} else {
finish = true;
}
if (count >= 2) {
finish = true;
}
} else {
st.push_back(make_tuple(ptr, search));
search++;
}
} else if (ptr >= S.length() - 1) {
if (!st.empty()) {
tuple<int, int> t = st.back();
st.pop_back();
ptr = get<0>(t);
search = get<1>(t);
} else {
finish = true;
}
} else if (S[ptr] == P[preserch]) {
many_same_char = true;
}
}
if (count == 1) {
cout << "yes" << endl;
} else {
cout << "no" << endl;
}
return 0;
}
|
#include <iostream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
int main(void) {
string S;
string P;
cin >> S;
cin >> P;
int search = 0;
int count = 0;
bool finish = false;
int preserch = 0;
bool many_same_char = false;
vector<tuple<int, int>> st;
for (int ptr = 0; !finish; ptr++) {
if (S[ptr] == P[search]) {
preserch = search;
if (search >= P.length() - 1) {
int oldcount = count;
for (int subptr = ptr; subptr < S.length(); subptr++) {
if (S[subptr] == P[search]) {
count++;
}
}
if (count - oldcount == 1) {
if (many_same_char) {
count = 2000;
} else {
count = 1;
}
finish = true;
}
if (!st.empty()) {
tuple<int, int> t = st.back();
st.pop_back();
ptr = get<0>(t);
search = get<1>(t);
} else {
finish = true;
}
if (count >= 2) {
finish = true;
}
} else {
st.push_back(make_tuple(ptr, search));
search++;
}
} else if (ptr >= S.length() - 1) {
finish = true;
} else if (S[ptr] == P[preserch]) {
many_same_char = true;
}
}
if (count == 1) {
cout << "yes" << endl;
} else {
cout << "no" << endl;
}
return 0;
}
|
replace
| 56 | 64 | 56 | 57 |
TLE
| |
p01942
|
C++
|
Runtime Error
|
#include "bits/stdc++.h"
using namespace std;
using VS = vector<string>;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
using VL = vector<LL>;
using VVL = vector<VL>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;
const LL LINF = 1e16;
const LL MOD = 1000000007;
const double PI = acos(-1.0);
int DX[8] = {0, 0, 1, -1, 1, 1, -1, -1};
int DY[8] = {1, -1, 0, 0, 1, -1, 1, -1};
using P = pair<int, PII>;
/* ----- 2017/09/20 Problem: ACPC2017_day3_e / Link: ----- */
/* ------??????------
-----?????????????????§----- */
/* -----?§£??¬???-----
----?§£??¬???????????§---- */
LL N;
struct BIT2D {
int _H, _W;
VVI data;
BIT2D(int h, int w) {
_H = h;
_W = w;
data = VVI(_H + 1, VI(_W + 1, 0));
}
void add(int a, int b, int val) {
for (int x = a; x <= _W; x += x & -x) {
for (int y = b; y <= _H; y += y & -y) {
data[x][y] += val;
}
}
}
int _sum(int a, int b) {
int ret = 0;
for (int x = a; x > 0; x -= x & -x) {
for (int y = b; y > 0; y -= y & -y) {
ret += data[x][y];
}
}
return ret;
}
int sum(int lx, int ly, int rx, int ry) {
return _sum(rx, ry) - _sum(lx - 1, ry) - _sum(rx, ly - 1) +
_sum(lx - 1, ly - 1);
}
};
LL ans = 0LL;
int H, W, T, Q;
int main() {
scanf("%d%d%d%d", &H, &W, &T, &Q);
BIT2D yet(W, H); // 1index
BIT2D done(W, H); // 1index
// bit.add(1, 1, 1); bit.add(2, 2, 2);
// cout << bit.sum(2, 2) << endl; (2,2)??????
queue<P> que;
FOR(i, 0, Q) {
int t, c, h1, w1, h2, w2;
scanf("%d%d%d%d", &t, &c, &h1, &w1);
while (!que.empty()) {
P p = que.front();
if (p.first + T <= t) {
que.pop();
int Y = p.second.first, X = p.second.second;
yet.add(Y, X, -1);
done.add(Y, X, 1);
} else
break;
}
if (c != 2) {
if (c == 0) {
if (yet.sum(h1, w1, h1, w1) == 0 && done.sum(h1, w1, h1, w1) == 0) {
yet.add(h1, w1, 1);
que.push({t, PII(h1, w1)});
}
} else { // c ==1
if (done.sum(h1, w1, h1, w1) == 1) {
done.add(h1, w1, -1);
}
}
} else {
scanf("%d%d", &h2, &w2);
printf("%d %d\n", done.sum(h1, w1, h2, w2), yet.sum(h1, w1, h2, w2));
}
}
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
using VS = vector<string>;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
using VL = vector<LL>;
using VVL = vector<VL>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;
const LL LINF = 1e16;
const LL MOD = 1000000007;
const double PI = acos(-1.0);
int DX[8] = {0, 0, 1, -1, 1, 1, -1, -1};
int DY[8] = {1, -1, 0, 0, 1, -1, 1, -1};
using P = pair<int, PII>;
/* ----- 2017/09/20 Problem: ACPC2017_day3_e / Link: ----- */
/* ------??????------
-----?????????????????§----- */
/* -----?§£??¬???-----
----?§£??¬???????????§---- */
LL N;
struct BIT2D {
int _H, _W;
VVI data;
BIT2D(int h, int w) {
_H = h;
_W = w;
data = VVI(_H + 1, VI(_W + 1, 0));
}
void add(int a, int b, int val) {
for (int x = a; x <= _W; x += x & -x) {
for (int y = b; y <= _H; y += y & -y) {
data[x][y] += val;
}
}
}
int _sum(int a, int b) {
int ret = 0;
for (int x = a; x > 0; x -= x & -x) {
for (int y = b; y > 0; y -= y & -y) {
ret += data[x][y];
}
}
return ret;
}
int sum(int lx, int ly, int rx, int ry) {
return _sum(rx, ry) - _sum(lx - 1, ry) - _sum(rx, ly - 1) +
_sum(lx - 1, ly - 1);
}
};
LL ans = 0LL;
int H, W, T, Q;
int main() {
scanf("%d%d%d%d", &H, &W, &T, &Q);
BIT2D yet(max(W, H) + 1, max(W, H) + 1); // 1index
BIT2D done(max(W, H) + 1, max(W, H) + 1); // 1index
// bit.add(1, 1, 1); bit.add(2, 2, 2);
// cout << bit.sum(2, 2) << endl; (2,2)??????
queue<P> que;
FOR(i, 0, Q) {
int t, c, h1, w1, h2, w2;
scanf("%d%d%d%d", &t, &c, &h1, &w1);
while (!que.empty()) {
P p = que.front();
if (p.first + T <= t) {
que.pop();
int Y = p.second.first, X = p.second.second;
yet.add(Y, X, -1);
done.add(Y, X, 1);
} else
break;
}
if (c != 2) {
if (c == 0) {
if (yet.sum(h1, w1, h1, w1) == 0 && done.sum(h1, w1, h1, w1) == 0) {
yet.add(h1, w1, 1);
que.push({t, PII(h1, w1)});
}
} else { // c ==1
if (done.sum(h1, w1, h1, w1) == 1) {
done.add(h1, w1, -1);
}
}
} else {
scanf("%d%d", &h2, &w2);
printf("%d %d\n", done.sum(h1, w1, h2, w2), yet.sum(h1, w1, h2, w2));
}
}
return 0;
}
|
replace
| 82 | 84 | 82 | 84 |
0
| |
p01942
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll)a); i < ((ll)n); i++)
using namespace std;
typedef long long ll;
template <typename T> class BinaryIndexedTree2D {
vector<vector<ll>> vec;
const ll m, n;
public:
BinaryIndexedTree2D(ll _m, ll _n)
: vec(_m + 1, vector<T>(_n + 1)), m(_m), n(_n) {}
T query(ll y, ll x) { /* query for [(1, 1), (y, x)] */
T ret = 0;
for (ll i = y; i > 0; i -= i & (-i))
for (ll j = x; j > 0; j -= j & (-j))
ret += vec[i][j];
return ret;
}
void update(ll y, ll x, T k) { /* update for [(1, 1,), (y, x)] */
for (ll i = y; i <= n; i += i & (-i))
for (ll j = x; j <= m; j += j & (-j))
vec[i][j] += k;
}
};
struct event {
ll t, c, h1, w1, h2, w2;
public:
bool operator<(const event &e) const { return t > e.t; }
};
ll H, W, T, Q;
int main(void) {
priority_queue<event> q;
cin >> H >> W >> T >> Q;
REP(i, 0, Q) {
ll t, c, h1, w1, h2, w2;
cin >> t >> c >> h1 >> w1;
if (c == 2)
cin >> h2 >> w2;
else
h2 = 0, w2 = 0;
q.push((event){t * 2, c, h1, w1, h2, w2});
}
BinaryIndexedTree2D<ll> bit1(H, W);
BinaryIndexedTree2D<ll> bit2(H, W);
ll f[H + 1][W + 1];
REP(i, 1, H + 1) REP(j, 1, W + 1) f[i][j] = 0;
while (!q.empty()) {
event e = q.top();
q.pop();
// cout << e.t << " " << e.c << " " << e.h1 << " " << e.w1 << " " << e.h2 <<
// " " << e.w2 << endl;
if (e.c == 0) { // set
bit1.update(e.h1, e.w1, 1);
q.push((event){e.t + T * 2 - 1, 3, e.h1, e.w1, 0, 0});
f[e.h1][e.w1] = 1;
}
if (e.c == 1) { // remove
if (f[e.h1][e.w1] == 2) {
bit2.update(e.h1, e.w1, -1);
f[e.h1][e.w1] = 0;
}
}
if (e.c == 2) { // query
ll ans1 = bit1.query(e.h2, e.w2) - bit1.query(e.h1 - 1, e.w2) -
bit1.query(e.h2, e.w1 - 1) + bit1.query(e.h1 - 1, e.w1 - 1);
ll ans2 = bit2.query(e.h2, e.w2) - bit2.query(e.h1 - 1, e.w2) -
bit2.query(e.h2, e.w1 - 1) + bit2.query(e.h1 - 1, e.w1 - 1);
cout << ans2 << " " << ans1 << endl;
}
if (e.c == 3) { // complete
if (f[e.h1][e.w1] == 1) {
bit1.update(e.h1, e.w1, -1);
bit2.update(e.h1, e.w1, 1);
f[e.h1][e.w1] = 2;
}
}
}
}
|
#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll)a); i < ((ll)n); i++)
using namespace std;
typedef long long ll;
template <typename T> class BinaryIndexedTree2D {
vector<vector<ll>> vec;
const ll m, n;
public:
BinaryIndexedTree2D(ll _m, ll _n)
: vec(_m + 1, vector<T>(_n + 1)), m(_m), n(_n) {}
T query(ll y, ll x) { /* query for [(1, 1), (y, x)] */
T ret = 0;
for (ll i = y; i > 0; i -= i & (-i))
for (ll j = x; j > 0; j -= j & (-j))
ret += vec[i][j];
return ret;
}
void update(ll y, ll x, T k) { /* update for [(1, 1,), (y, x)] */
for (ll i = y; i <= m; i += i & (-i))
for (ll j = x; j <= n; j += j & (-j))
vec[i][j] += k;
}
};
struct event {
ll t, c, h1, w1, h2, w2;
public:
bool operator<(const event &e) const { return t > e.t; }
};
ll H, W, T, Q;
int main(void) {
priority_queue<event> q;
cin >> H >> W >> T >> Q;
REP(i, 0, Q) {
ll t, c, h1, w1, h2, w2;
cin >> t >> c >> h1 >> w1;
if (c == 2)
cin >> h2 >> w2;
else
h2 = 0, w2 = 0;
q.push((event){t * 2, c, h1, w1, h2, w2});
}
BinaryIndexedTree2D<ll> bit1(H, W);
BinaryIndexedTree2D<ll> bit2(H, W);
ll f[H + 1][W + 1];
REP(i, 1, H + 1) REP(j, 1, W + 1) f[i][j] = 0;
while (!q.empty()) {
event e = q.top();
q.pop();
// cout << e.t << " " << e.c << " " << e.h1 << " " << e.w1 << " " << e.h2 <<
// " " << e.w2 << endl;
if (e.c == 0) { // set
bit1.update(e.h1, e.w1, 1);
q.push((event){e.t + T * 2 - 1, 3, e.h1, e.w1, 0, 0});
f[e.h1][e.w1] = 1;
}
if (e.c == 1) { // remove
if (f[e.h1][e.w1] == 2) {
bit2.update(e.h1, e.w1, -1);
f[e.h1][e.w1] = 0;
}
}
if (e.c == 2) { // query
ll ans1 = bit1.query(e.h2, e.w2) - bit1.query(e.h1 - 1, e.w2) -
bit1.query(e.h2, e.w1 - 1) + bit1.query(e.h1 - 1, e.w1 - 1);
ll ans2 = bit2.query(e.h2, e.w2) - bit2.query(e.h1 - 1, e.w2) -
bit2.query(e.h2, e.w1 - 1) + bit2.query(e.h1 - 1, e.w1 - 1);
cout << ans2 << " " << ans1 << endl;
}
if (e.c == 3) { // complete
if (f[e.h1][e.w1] == 1) {
bit1.update(e.h1, e.w1, -1);
bit2.update(e.h1, e.w1, 1);
f[e.h1][e.w1] = 2;
}
}
}
}
|
replace
| 22 | 24 | 22 | 24 |
0
| |
p01944
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
typedef vector<ll> V;
typedef vector<V> MATRIX;
int N, M;
ll table[10000];
MATRIX calc_ans(MATRIX left, MATRIX right) {
MATRIX RET(1, V(N));
for (int col = 0; col < N; col++) {
RET[0][col] = 0;
for (int row = 0; row < N; row++) {
RET[0][col] += left[0][row] * right[row][col];
RET[0][col] %= MOD;
}
}
return RET;
}
MATRIX calc(MATRIX left, MATRIX right) {
MATRIX ret(N, V(N));
for (int i = 0; i < N; i++) {
for (int k = 0; k < N; k++)
ret[i][k] = 0;
}
for (int row = 0; row < N; row++) {
for (int col = 0; col < N; col++) {
for (int a = 0; a < N; a++) {
ret[row][col] += left[row][a] * right[a][col];
ret[row][col] %= MOD;
}
}
}
return ret;
}
MATRIX pow(MATRIX MULT, int count) {
MATRIX ret(N, V(N));
for (int row = 0; row < N; row++) {
for (int col = 0; col < N; col++) {
if (row == col)
ret[row][col] = 1;
else {
ret[row][col] = 0;
}
}
}
while (count > 0) {
if (count % 2 == 1)
ret = calc(ret, MULT);
MULT = calc(MULT, MULT);
count /= 2;
}
return ret;
}
int main() {
int K;
scanf("%d %d %d", &N, &M, &K);
for (int i = 0; i < M; i++) {
scanf("%lld", &table[i]);
table[i] %= N;
}
ll work[N];
work[0] = 1;
for (int i = 1; i <= N - 1; i++)
work[i] = 0;
for (int i = 0; i < M; i++) {
work[table[i]]++;
}
MATRIX first_state(1, V(N));
first_state[0][0] = 1;
for (int i = 1; i <= N - 1; i++)
first_state[0][i] = 0;
MATRIX transition(N, V(N));
for (int i = 0; i <= N - 1; i++)
transition[0][i] = work[i];
for (int row = 0; row <= N - 2; row++) {
for (int col = 0; col <= N - 1; col++) {
transition[row + 1][(col + 1) % N] = transition[row][col];
}
}
if (K > 1) {
transition = pow(transition, K);
}
MATRIX ans = calc_ans(first_state, transition);
for (int i = 0; i < N; i++) {
printf("%lld\n", ans[0][i] % MOD);
}
return 0;
}
|
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
typedef vector<ll> V;
typedef vector<V> MATRIX;
int N, M;
ll table[10000];
MATRIX calc_ans(MATRIX left, MATRIX right) {
MATRIX RET(1, V(N));
for (int col = 0; col < N; col++) {
RET[0][col] = 0;
for (int row = 0; row < N; row++) {
RET[0][col] += left[0][row] * right[row][col];
RET[0][col] %= MOD;
}
}
return RET;
}
MATRIX calc(MATRIX left, MATRIX right) {
MATRIX ret(N, V(N));
for (int i = 0; i < N; i++) {
for (int k = 0; k < N; k++)
ret[i][k] = 0;
}
for (int col = 0; col < N; col++) {
ret[0][col] = 0;
for (int row = 0; row < N; row++) {
ret[0][col] += left[0][row] * right[row][col];
ret[0][col] %= MOD;
}
}
for (int row = 0; row <= N - 2; row++) {
for (int col = 0; col <= N - 1; col++) {
ret[row + 1][(col + 1) % N] = ret[row][col];
}
}
return ret;
}
MATRIX pow(MATRIX MULT, int count) {
MATRIX ret(N, V(N));
for (int row = 0; row < N; row++) {
for (int col = 0; col < N; col++) {
if (row == col)
ret[row][col] = 1;
else {
ret[row][col] = 0;
}
}
}
while (count > 0) {
if (count % 2 == 1)
ret = calc(ret, MULT);
MULT = calc(MULT, MULT);
count /= 2;
}
return ret;
}
int main() {
int K;
scanf("%d %d %d", &N, &M, &K);
for (int i = 0; i < M; i++) {
scanf("%lld", &table[i]);
table[i] %= N;
}
ll work[N];
work[0] = 1;
for (int i = 1; i <= N - 1; i++)
work[i] = 0;
for (int i = 0; i < M; i++) {
work[table[i]]++;
}
MATRIX first_state(1, V(N));
first_state[0][0] = 1;
for (int i = 1; i <= N - 1; i++)
first_state[0][i] = 0;
MATRIX transition(N, V(N));
for (int i = 0; i <= N - 1; i++)
transition[0][i] = work[i];
for (int row = 0; row <= N - 2; row++) {
for (int col = 0; col <= N - 1; col++) {
transition[row + 1][(col + 1) % N] = transition[row][col];
}
}
if (K > 1) {
transition = pow(transition, K);
}
MATRIX ans = calc_ans(first_state, transition);
for (int i = 0; i < N; i++) {
printf("%lld\n", ans[0][i] % MOD);
}
return 0;
}
|
replace
| 47 | 53 | 47 | 58 |
TLE
| |
p01956
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for (int64 i = 0; i < (n); i++)
#define FOR(i, a, b) for (int64 i = (a); i < (b); i++)
#define all(x) x.begin(), x.end()
#define fs first
#define sc second
using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;
const double eps = 1e-10;
template <typename A, typename B> inline void chmin(A &a, B b) {
if (a > b)
a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
if (a < b)
a = b;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type fill_v(U &u, const V... v) {
u = U(v...);
}
template <typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type fill_v(U &u, const V... v) {
for (auto &e : u)
fill_v<T>(e, v...);
}
int main(void) {
int64 N, H, W;
cin >> N >> H >> W;
vector<int64> x(N);
REP(i, N) cin >> x[i];
vector<int64> sum(N * W + 1, 0);
REP(i, N) {
if (i % 2 == 0) {
sum[W * i + x[i]] += 1;
sum[W * i + x[i] + W] += -1;
} else {
sum[W * i - x[i]] += -1;
sum[W * i - x[i] - W] += 1;
}
}
int64 res = 0;
REP(i, N * W) sum[i + 1] += sum[i];
REP(i, N * W) {
if (sum[i] == 0)
res += H;
}
cout << res << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for (int64 i = 0; i < (n); i++)
#define FOR(i, a, b) for (int64 i = (a); i < (b); i++)
#define all(x) x.begin(), x.end()
#define fs first
#define sc second
using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;
const double eps = 1e-10;
template <typename A, typename B> inline void chmin(A &a, B b) {
if (a > b)
a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
if (a < b)
a = b;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type fill_v(U &u, const V... v) {
u = U(v...);
}
template <typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type fill_v(U &u, const V... v) {
for (auto &e : u)
fill_v<T>(e, v...);
}
int main(void) {
int64 N, H, W;
cin >> N >> H >> W;
vector<int64> x(N);
REP(i, N) cin >> x[i];
vector<int64> sum(N * W + 1, 0);
REP(i, N) {
if (i % 2 == 0) {
sum[W * i + x[i]] += 1;
sum[W * i + x[i] + W] += -1;
} else {
sum[W * i - x[i]] += 1;
sum[W * i - x[i] + W] += -1;
}
}
int64 res = 0;
REP(i, N * W) sum[i + 1] += sum[i];
REP(i, N * W) {
if (sum[i] == 0)
res += H;
}
cout << res << endl;
}
|
replace
| 57 | 59 | 57 | 59 |
-6
|
munmap_chunk(): invalid pointer
|
p01961
|
C++
|
Runtime Error
|
#include "bits/stdc++.h"
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
vector<int> solve(int H, int W, int y, int x) {
vector<int> anss;
bool h_swap = false;
bool hw_swap = false;
bool w_swap = false;
bool rot = false;
if (y % 2 == 0) {
y = H - 1 - y;
h_swap = true;
} else {
h_swap = false;
}
if (x % 2 == 0) {
x = W - x - 1;
w_swap = true;
} else {
w_swap = false;
}
if (x == H - 1 && y == W - 1) {
for (int k = 0; k < (H + 1) / 2; ++k) {
if (k) {
anss.push_back(3);
}
for (int n = 0; n < W - 1; ++n) {
anss.push_back(0);
}
anss.push_back(3);
for (int n = 0; n < W - 1; ++n) {
anss.push_back(2);
}
}
} else {
if (x == W - 1) {
hw_swap = true;
swap(x, y);
swap(H, W);
} else {
hw_swap = false;
}
int l = x;
int r = W - 1 - x;
int u = y;
int d = H - 1 - y;
for (int k = 0; k < (u + 1) / 2; ++k) {
if (k) {
anss.push_back(3);
}
for (int n = 0; n < l; ++n) {
anss.push_back(0);
}
anss.push_back(3);
for (int n = 0; n < l; ++n) {
anss.push_back(2);
}
}
anss.push_back(2);
for (int k = 0; k < H / 2; ++k) {
if (k)
anss.push_back(1);
for (int n = 0; n < r - 1; ++n) {
anss.push_back(2);
}
anss.push_back(1);
for (int n = 0; n < r - 1; ++n) {
anss.push_back(0);
}
}
if (d) {
anss.push_back(0);
for (int k = 0; k < (d + 1) / 2; ++k) {
if (k) {
anss.push_back(3);
}
for (int n = 0; n < l; ++n) {
anss.push_back(0);
}
anss.push_back(3);
for (int n = 0; n < l; ++n) {
anss.push_back(2);
}
}
}
}
for (auto &ans : anss) {
if (hw_swap) {
ans = 3 - ans;
}
if (h_swap && ans % 2 == 1) {
ans = 4 - ans;
}
if (w_swap && ans % 2 == 0) {
ans = 2 - ans;
}
}
assert(anss.size() == H * W - 1);
return anss;
}
int main() {
int H, W;
cin >> H >> W;
vector<string> field(H);
int sx, sy;
int num = 0;
for (int i = 0; i < H; ++i) {
cin >> field[i];
for (int j = 0; j < W; ++j) {
if (field[i][j] == '@') {
sx = j;
sy = i;
} else if (field[i][j] == '*') {
num++;
}
}
}
vector<int> move_ways =
solve((H + 1) / 2, (W + 1) / 2, (sy + 1) / 2, (sx + 1) / 2);
int nx = sx;
int ny = sy;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
for (auto m_way : move_ways) {
for (int ti = 0; ti < 2; ++ti) {
nx += dx[m_way];
ny += dy[m_way];
if (field[ny][nx] == '.') {
field[ny][nx] = '#';
} else {
num--;
if (num == 0)
break;
}
}
if (num == 0)
break;
}
for (int i = 0; i < H; ++i) {
cout << field[i] << endl;
}
return 0;
}
|
#include "bits/stdc++.h"
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
vector<int> solve(int H, int W, int y, int x) {
vector<int> anss;
bool h_swap = false;
bool hw_swap = false;
bool w_swap = false;
bool rot = false;
if (y % 2 == 0) {
y = H - 1 - y;
h_swap = true;
} else {
h_swap = false;
}
if (x % 2 == 0) {
x = W - x - 1;
w_swap = true;
} else {
w_swap = false;
}
if (y == H - 1 && x == W - 1) {
for (int k = 0; k < (H + 1) / 2; ++k) {
if (k) {
anss.push_back(3);
}
for (int n = 0; n < W - 1; ++n) {
anss.push_back(0);
}
anss.push_back(3);
for (int n = 0; n < W - 1; ++n) {
anss.push_back(2);
}
}
} else {
if (x == W - 1) {
hw_swap = true;
swap(x, y);
swap(H, W);
} else {
hw_swap = false;
}
int l = x;
int r = W - 1 - x;
int u = y;
int d = H - 1 - y;
for (int k = 0; k < (u + 1) / 2; ++k) {
if (k) {
anss.push_back(3);
}
for (int n = 0; n < l; ++n) {
anss.push_back(0);
}
anss.push_back(3);
for (int n = 0; n < l; ++n) {
anss.push_back(2);
}
}
anss.push_back(2);
for (int k = 0; k < H / 2; ++k) {
if (k)
anss.push_back(1);
for (int n = 0; n < r - 1; ++n) {
anss.push_back(2);
}
anss.push_back(1);
for (int n = 0; n < r - 1; ++n) {
anss.push_back(0);
}
}
if (d) {
anss.push_back(0);
for (int k = 0; k < (d + 1) / 2; ++k) {
if (k) {
anss.push_back(3);
}
for (int n = 0; n < l; ++n) {
anss.push_back(0);
}
anss.push_back(3);
for (int n = 0; n < l; ++n) {
anss.push_back(2);
}
}
}
}
for (auto &ans : anss) {
if (hw_swap) {
ans = 3 - ans;
}
if (h_swap && ans % 2 == 1) {
ans = 4 - ans;
}
if (w_swap && ans % 2 == 0) {
ans = 2 - ans;
}
}
assert(anss.size() == H * W - 1);
return anss;
}
int main() {
int H, W;
cin >> H >> W;
vector<string> field(H);
int sx, sy;
int num = 0;
for (int i = 0; i < H; ++i) {
cin >> field[i];
for (int j = 0; j < W; ++j) {
if (field[i][j] == '@') {
sx = j;
sy = i;
} else if (field[i][j] == '*') {
num++;
}
}
}
vector<int> move_ways =
solve((H + 1) / 2, (W + 1) / 2, (sy + 1) / 2, (sx + 1) / 2);
int nx = sx;
int ny = sy;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
for (auto m_way : move_ways) {
for (int ti = 0; ti < 2; ++ti) {
nx += dx[m_way];
ny += dy[m_way];
if (field[ny][nx] == '.') {
field[ny][nx] = '#';
} else {
num--;
if (num == 0)
break;
}
}
if (num == 0)
break;
}
for (int i = 0; i < H; ++i) {
cout << field[i] << endl;
}
return 0;
}
|
replace
| 25 | 26 | 25 | 26 |
0
| |
p01967
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
#define NUM 101
int capacity[NUM], table[NUM];
int main() {
int N;
scanf("%d", &N);
for (int i = 1; i <= N; i++) {
scanf("%d", &capacity[i]);
table[i] = 0;
}
int Q;
scanf("%d", &Q);
int command, apple_id, num;
for (int loop = 0; loop < Q; loop++) {
scanf("%d %d %d", &command, &apple_id, &num);
if (command == 1) {
table[apple_id] += num;
if (table[apple_id] > capacity[apple_id]) {
printf("%d\n", apple_id);
return 0;
}
} else {
table[apple_id] -= num;
if (table[apple_id] < 0) {
printf("%d\n", apple_id);
return 0;
}
}
}
printf("0\n");
return 0;
}
|
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <time.h>
#include <vector>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
#define NUM 1001
int capacity[NUM], table[NUM];
int main() {
int N;
scanf("%d", &N);
for (int i = 1; i <= N; i++) {
scanf("%d", &capacity[i]);
table[i] = 0;
}
int Q;
scanf("%d", &Q);
int command, apple_id, num;
for (int loop = 0; loop < Q; loop++) {
scanf("%d %d %d", &command, &apple_id, &num);
if (command == 1) {
table[apple_id] += num;
if (table[apple_id] > capacity[apple_id]) {
printf("%d\n", apple_id);
return 0;
}
} else {
table[apple_id] -= num;
if (table[apple_id] < 0) {
printf("%d\n", apple_id);
return 0;
}
}
}
printf("0\n");
return 0;
}
|
replace
| 19 | 20 | 19 | 20 |
0
| |
p01970
|
C++
|
Runtime Error
|
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}
using ll = long long;
const ll MOD = 1000000007;
char prime[1000005];
void init_prime() {
fill(prime, prime + 1000005, 1);
prime[0] = prime[1] = 0;
for (int x = 2; x <= 1000000; ++x) {
if (prime[x]) {
for (int y = x * x; y <= 1000000; y += x)
prime[y] = 0;
}
}
}
ll N, Q[101010];
ll memo[101010];
int main() {
init_prime();
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N;
for (int j = 1; j <= N; ++j)
cin >> Q[j];
reverse(Q + 1, Q + N + 1);
fill(memo, memo + N + 1, 0);
memo[0] = 1;
memo[1] = prime[Q[1]] ? 1 : 0;
for (int j = 2; j <= N; ++j) {
if (prime[Q[j]]) {
if (Q[j - 1] > Q[j]) {
memo[j] = (memo[j] + memo[j - 1]) % MOD;
}
if (Q[j - 1] > 1 && (j < 3 || (prime[Q[j - 2]] && Q[j - 2] > Q[j]))) {
memo[j] = (memo[j] + memo[j - 2]) % MOD;
}
}
}
cout << memo[N] << endl;
return 0;
}
|
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}
using ll = long long;
const ll MOD = 1000000007;
char prime[1000005];
void init_prime() {
fill(prime, prime + 1000005, 1);
prime[0] = prime[1] = 0;
for (int x = 2; x <= 1000000; ++x) {
if (prime[x] && x <= 1000) {
for (int y = x * x; y <= 1000000; y += x)
prime[y] = 0;
}
}
}
ll N, Q[101010];
ll memo[101010];
int main() {
init_prime();
cin.tie(0);
ios::sync_with_stdio(false);
cin >> N;
for (int j = 1; j <= N; ++j)
cin >> Q[j];
reverse(Q + 1, Q + N + 1);
fill(memo, memo + N + 1, 0);
memo[0] = 1;
memo[1] = prime[Q[1]] ? 1 : 0;
for (int j = 2; j <= N; ++j) {
if (prime[Q[j]]) {
if (Q[j - 1] > Q[j]) {
memo[j] = (memo[j] + memo[j - 1]) % MOD;
}
if (Q[j - 1] > 1 && (j < 3 || (prime[Q[j - 2]] && Q[j - 2] > Q[j]))) {
memo[j] = (memo[j] + memo[j - 2]) % MOD;
}
}
}
cout << memo[N] << endl;
return 0;
}
|
replace
| 34 | 35 | 34 | 35 |
-11
| |
p01970
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define int long long
using namespace std;
bool prime[1000009];
void era() {
prime[0] = 1;
prime[1] = 1;
for (int i = 2; i < 1000009; i++) {
if (!prime[i]) {
for (int j = i + i; j < 1000009; j += i)
prime[j] = 1;
}
}
}
int dp[100009][2];
signed main() {
era();
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
if (!prime[a[0]]) {
dp[0][0] = 1;
dp[0][1] = 1;
}
for (int i = 0; i < n; i++) {
// 1
if (i + 1 < n && a[i] < a[i + 1] && !prime[a[i + 1]])
dp[i + 1][0] += dp[i][0];
if (i + 2 < n && a[i] < a[i + 1] && !prime[a[i + 1]])
dp[i + 1][1] += dp[i][0];
// 2
if (i + 2 < n && a[i] < a[i + 2] && !prime[a[i + 2]])
dp[i + 2][0] += dp[i][1];
if (i + 3 < n && a[i] < a[i + 2] && !prime[a[i + 2]])
dp[i + 2][1] += dp[i][1];
dp[i + 1][0] %= 1000000007;
dp[i + 1][1] %= 1000000007;
dp[i + 2][0] %= 1000000007;
dp[i + 2][1] %= 1000000007;
}
cout << (dp[n - 1][0] + dp[n - 2][1]) % 1000000007 << endl;
}
|
#include <bits/stdc++.h>
#define int long long
using namespace std;
bool prime[1000009];
void era() {
prime[0] = 1;
prime[1] = 1;
for (int i = 2; i < 1000009; i++) {
if (!prime[i]) {
for (int j = i + i; j < 1000009; j += i)
prime[j] = 1;
}
}
}
int dp[100009][2];
signed main() {
era();
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
scanf("%ld", &a[i]);
if (!prime[a[0]]) {
dp[0][0] = 1;
dp[0][1] = 1;
}
for (int i = 0; i < n; i++) {
// 1
if (i + 1 < n && a[i] < a[i + 1] && !prime[a[i + 1]])
dp[i + 1][0] += dp[i][0];
if (i + 2 < n && a[i] < a[i + 1] && !prime[a[i + 1]])
dp[i + 1][1] += dp[i][0];
// 2
if (i + 2 < n && a[i] < a[i + 2] && !prime[a[i + 2]])
dp[i + 2][0] += dp[i][1];
if (i + 3 < n && a[i] < a[i + 2] && !prime[a[i + 2]])
dp[i + 2][1] += dp[i][1];
dp[i + 1][0] %= 1000000007;
dp[i + 1][1] %= 1000000007;
dp[i + 2][0] %= 1000000007;
dp[i + 2][1] %= 1000000007;
}
cout << (dp[n - 1][0] + dp[n - 2][1]) % 1000000007 << endl;
}
|
replace
| 25 | 26 | 25 | 26 |
-11
| |
p01973
|
C++
|
Runtime Error
|
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
// #include <boost/multiprecision/cpp_int.hpp>
#include <functional>
// #define int long long
#define inf 1000000007
#define pa pair<int, int>
#define ll long long
#define pal pair<double, double>
#define ppap pair<pa, int>
#define ssa pair<string, int>
#define mp make_pair
#define pb push_back
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};
using namespace std;
class pa3 {
public:
int x, y, z;
pa3(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {}
bool operator<(const pa3 &p) const {
if (x != p.x)
return x < p.x;
if (y != p.y)
return y < p.y;
return z < p.z;
// return x != p.x ? x<p.x: y<p.y;
}
bool operator>(const pa3 &p) const {
if (x != p.x)
return x > p.x;
if (y != p.y)
return y > p.y;
return z > p.z;
// return x != p.x ? x<p.x: y<p.y;
}
bool operator==(const pa3 &p) const {
return x == p.x && y == p.y && z == p.z;
}
bool operator!=(const pa3 &p) const {
return !(x == p.x && y == p.y && z == p.z);
}
};
class pa4 {
public:
double x;
int y, z, w;
pa4(double x = 0, int y = 0, int z = 0, int w = 0) : x(x), y(y), z(z), w(w) {}
bool operator<(const pa4 &p) const {
if (x != p.x)
return x < p.x;
if (y != p.y)
return y < p.y;
if (z != p.z)
return z < p.z;
return w < p.w;
// return x != p.x ? x<p.x: y<p.y;
}
bool operator>(const pa4 &p) const {
if (x != p.x)
return x > p.x;
if (y != p.y)
return y > p.y;
if (z != p.z)
return z > p.z;
return w > p.w;
// return x != p.x ? x<p.x: y<p.y;
}
bool operator==(const pa4 &p) const {
return x == p.x && y == p.y && z == p.z && w == p.w;
}
};
class pa2 {
public:
int x, y;
pa2(int x = 0, int y = 0) : x(x), y(y) {}
pa2 operator+(pa2 p) { return pa2(x + p.x, y + p.y); }
pa2 operator-(pa2 p) { return pa2(x - p.x, y - p.y); }
bool operator<(const pa2 &p) const { return y != p.y ? y < p.y : x < p.x; }
bool operator>(const pa2 &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const pa2 &p) const {
return abs(x - p.x) == 0 && abs(y - p.y) == 0;
}
bool operator!=(const pa2 &p) const {
return !(abs(x - p.x) == 0 && abs(y - p.y) == 0);
}
};
#define ppa pair<int, pas>
class Point {
public:
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
Point operator+(Point p) { return Point(x + p.x, y + p.y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
Point operator*(double a) { return Point(x * a, y * a); }
Point operator/(double a) { return Point(x / a, y / a); }
double absv() { return sqrt(norm()); }
double norm() { return x * x + y * y; }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
}
};
typedef Point Vector;
#define pl pair<int, pas>
struct Segment {
Point p1, p2;
};
double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
bool parareru(Point a, Point b, Point c, Point d) {
// if(abs(cross(a-b,d-c))<EPS)cout<<"dd "<<cross(a-b,d-c)<<endl;
return abs(cross(a - b, d - c)) < EPS;
}
double distance_ls_p(Point a, Point b, Point c) {
if (dot(b - a, c - a) < EPS)
return (c - a).absv();
if (dot(a - b, c - b) < EPS)
return (c - b).absv();
return abs(cross(b - a, c - a)) / (b - a).absv();
}
bool is_intersected_ls(Segment a, Segment b) {
if (a.p1 == b.p1 || a.p2 == b.p1 || a.p1 == b.p2 || a.p2 == b.p2)
return false;
if (parareru((a.p2), (a.p1), (a.p1), (b.p2)) &&
parareru((a.p2), (a.p1), (a.p1), (b.p1))) {
// cout<<"sss"<<endl;
if (dot(a.p1 - b.p1, a.p1 - b.p2) < EPS)
return true;
if (dot(a.p2 - b.p1, a.p2 - b.p2) < EPS)
return true;
if (dot(a.p1 - b.p1, a.p2 - b.p1) < EPS)
return true;
if (dot(a.p1 - b.p2, a.p2 - b.p2) < EPS)
return true;
return false;
} else
return (cross(a.p2 - a.p1, b.p1 - a.p1) * cross(a.p2 - a.p1, b.p2 - a.p1) <
EPS) &&
(cross(b.p2 - b.p1, a.p1 - b.p1) * cross(b.p2 - b.p1, a.p2 - b.p1) <
EPS);
}
double segment_dis(Segment a, Segment b) {
if (is_intersected_ls(a, b))
return 0;
double r = distance_ls_p(a.p1, a.p2, b.p1);
r = min(r, distance_ls_p(a.p1, a.p2, b.p2));
r = min(r, distance_ls_p(b.p1, b.p2, a.p2));
r = min(r, distance_ls_p(b.p1, b.p2, a.p1));
return r;
}
Point intersection_ls(Segment a, Segment b) {
Point ba = b.p2 - b.p1;
double d1 = abs(cross(ba, a.p1 - b.p1));
double d2 = abs(cross(ba, a.p2 - b.p1));
double t = d1 / (d1 + d2);
return a.p1 + (a.p2 - a.p1) * t;
}
string itos(int i) {
ostringstream s;
s << i;
return s.str();
}
int gcd(int v, int b) {
if (v > b)
return gcd(b, v);
if (v == b)
return b;
if (b % v == 0)
return v;
return gcd(v, b % v);
}
double distans(double x1, double y1, double x2, double y2) {
double rr = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
return sqrt(rr);
}
// int pr[2000010];
// int inv[2000010];
int beki(int wa, int rr, int warukazu) {
if (rr == 0)
return 1 % warukazu;
if (rr == 1)
return wa % warukazu;
if (rr % 2 == 1)
return (beki(wa, rr - 1, warukazu) * wa) % warukazu;
int zx = beki(wa, rr / 2, warukazu);
return (zx * zx) % warukazu;
}
double bekid(double w, int r) {
if (r == 0)
return 1.0;
if (r == 1)
return w;
if (r % 2)
return bekid(w, r - 1) * w;
double f = bekid(w, r / 2);
return f * f;
}
/*
int comb(int nn,int rr){
int r=pr[nn]*inv[rr];
r%=inf;
r*=inv[nn-rr];
r%=inf;
return r;
}
void gya(int ert){
pr[0]=1;
for(int i=1;i<ert;i++){
pr[i]=(pr[i-1]*i)%inf;
}
for(int i=0;i<ert;i++) inv[i]=beki(pr[i],inf-2,inf);
}
*/
// priority_queue<pa3,vector<pa3>,greater<pa3>> pq;
// sort(ve.begin(),ve.end(),greater<int>());
//----------------kokomade tenpure------------
// vector<double> ans(100000000),ans2(100000000)
const int MAXN = 100020;
namespace SA {
int rank[MAXN], tmp[MAXN];
int n, k;
bool compare_sa(int i, int j) {
if (rank[i] != rank[j])
return rank[i] < rank[j];
int ri = (i + k <= n) ? rank[i + k] : -1;
int rj = (j + k <= n) ? rank[j + k] : -1;
return ri < rj;
}
void createSA(const string &s, int *sa) {
n = s.size();
for (int i = 0; i <= n; i++) {
sa[i] = i;
rank[i] = i < n ? s[i] : -1;
}
for (k = 1; k <= n; k *= 2) {
sort(sa, sa + n + 1, compare_sa);
tmp[sa[0]] = 0;
for (int i = 1; i <= n; i++) {
tmp[sa[i]] = tmp[sa[i - 1]] + (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
}
for (int i = 0; i <= n; i++)
rank[i] = tmp[i];
}
}
} // namespace SA
struct segsum {
// 1
// 2 3
// 4 5 6 7
private:
public:
// (1<<15)=32768
// 1<<16 = 65536
// 1<<17 = 131072
// 1<<18 = 262144
int cor = (1 << 17);
vector<int> vec;
vector<int> lazy;
void shoki1() { vec.resize(2 * cor + 3, 0); }
void shoki2() {
for (int i = cor - 1; i > 0; i--)
vec[i] = vec[2 * i] + vec[2 * i + 1];
}
void updadd(int x, int w) {
// x ���ڂ� w���Z
x += cor;
vec[x] += w;
while (1) {
x /= 2;
if (x == 0)
break;
vec[x] = vec[2 * x] + vec[2 * x + 1];
}
}
void updchan(int x, int w) {
// x���ڂ�w�ɕύX
x += cor;
vec[x] = w;
while (1) {
x /= 2;
if (x == 0)
break;
vec[x] = vec[2 * x] + vec[2 * x + 1];
}
}
// [a,b)
// k-th node
// k no kukanha [l,r)
int sum(int a, int b, int k = 1, int l = 0, int r = -10) {
if (r < 0)
r = cor;
// cout<<a<<" "<<b<<" "<<k<<" "<<l<<" "<<r<<endl;
if (a <= l && r <= b) {
return vec[k];
}
if (r <= a || b <= l) {
return 0;
}
int v1 = sum(a, b, k * 2, l, (l + r) / 2),
v2 = sum(a, b, k * 2 + 1, (l + r) / 2, r);
return v1 + v2;
}
};
segsum SE;
int sa[100020];
vector<pa2> ve;
signed main() {
string s;
cin >> s;
SA::createSA(s, sa);
int l = s.length();
// for(int i=0;i<=l;i++)cout<<sa[i]<<" "<<s.substr(sa[i])<<endl;;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string t;
cin >> t;
int tl = t.length();
sa[l + 1] = 100001;
int si = 0, ue = l + 1, me;
while (ue - si > 1) {
me = (ue + si) / 2;
if (s.substr(sa[me]) < t)
si = me;
else
ue = me;
}
char c = 'z' + 1;
while (s.length() <= 100000)
s += 'A';
while (s.length() < 100030)
s += c;
int kagen = ue;
// cout<<kagen<<endl;
si = 0, ue = l + 1;
t.back()++;
while (ue - si > 1) {
me = (ue + si) / 2;
if (s.substr(sa[me], tl) < t)
si = me;
else
ue = me;
}
int jougen = ue;
// cout<<jougen<<endl;
for (int i = kagen; i < jougen; i++) {
// cout<<sa[i]<<" "<<s.substr(sa[i])<<endl;
ve.pb((pa2){sa[i], sa[i] + tl});
if (ve.size() > 10000000)
exit(1);
}
// cout<<endl;
}
sort(ve.begin(), ve.end());
SE.shoki1();
SE.shoki2();
int ans = 0;
for (int i = 0; i < ve.size(); i++) {
// cout<<ve[i].x<<" "<<ve[i].y<<endl;
if (SE.sum(ve[i].x, ve[i].y) > 0)
continue;
ans++;
SE.updadd(ve[i].y - 1, 1);
}
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <string>
#include <vector>
// #include <boost/multiprecision/cpp_int.hpp>
#include <functional>
// #define int long long
#define inf 1000000007
#define pa pair<int, int>
#define ll long long
#define pal pair<double, double>
#define ppap pair<pa, int>
#define ssa pair<string, int>
#define mp make_pair
#define pb push_back
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};
using namespace std;
class pa3 {
public:
int x, y, z;
pa3(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {}
bool operator<(const pa3 &p) const {
if (x != p.x)
return x < p.x;
if (y != p.y)
return y < p.y;
return z < p.z;
// return x != p.x ? x<p.x: y<p.y;
}
bool operator>(const pa3 &p) const {
if (x != p.x)
return x > p.x;
if (y != p.y)
return y > p.y;
return z > p.z;
// return x != p.x ? x<p.x: y<p.y;
}
bool operator==(const pa3 &p) const {
return x == p.x && y == p.y && z == p.z;
}
bool operator!=(const pa3 &p) const {
return !(x == p.x && y == p.y && z == p.z);
}
};
class pa4 {
public:
double x;
int y, z, w;
pa4(double x = 0, int y = 0, int z = 0, int w = 0) : x(x), y(y), z(z), w(w) {}
bool operator<(const pa4 &p) const {
if (x != p.x)
return x < p.x;
if (y != p.y)
return y < p.y;
if (z != p.z)
return z < p.z;
return w < p.w;
// return x != p.x ? x<p.x: y<p.y;
}
bool operator>(const pa4 &p) const {
if (x != p.x)
return x > p.x;
if (y != p.y)
return y > p.y;
if (z != p.z)
return z > p.z;
return w > p.w;
// return x != p.x ? x<p.x: y<p.y;
}
bool operator==(const pa4 &p) const {
return x == p.x && y == p.y && z == p.z && w == p.w;
}
};
class pa2 {
public:
int x, y;
pa2(int x = 0, int y = 0) : x(x), y(y) {}
pa2 operator+(pa2 p) { return pa2(x + p.x, y + p.y); }
pa2 operator-(pa2 p) { return pa2(x - p.x, y - p.y); }
bool operator<(const pa2 &p) const { return y != p.y ? y < p.y : x < p.x; }
bool operator>(const pa2 &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const pa2 &p) const {
return abs(x - p.x) == 0 && abs(y - p.y) == 0;
}
bool operator!=(const pa2 &p) const {
return !(abs(x - p.x) == 0 && abs(y - p.y) == 0);
}
};
#define ppa pair<int, pas>
class Point {
public:
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
Point operator+(Point p) { return Point(x + p.x, y + p.y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
Point operator*(double a) { return Point(x * a, y * a); }
Point operator/(double a) { return Point(x / a, y / a); }
double absv() { return sqrt(norm()); }
double norm() { return x * x + y * y; }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
}
};
typedef Point Vector;
#define pl pair<int, pas>
struct Segment {
Point p1, p2;
};
double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
bool parareru(Point a, Point b, Point c, Point d) {
// if(abs(cross(a-b,d-c))<EPS)cout<<"dd "<<cross(a-b,d-c)<<endl;
return abs(cross(a - b, d - c)) < EPS;
}
double distance_ls_p(Point a, Point b, Point c) {
if (dot(b - a, c - a) < EPS)
return (c - a).absv();
if (dot(a - b, c - b) < EPS)
return (c - b).absv();
return abs(cross(b - a, c - a)) / (b - a).absv();
}
bool is_intersected_ls(Segment a, Segment b) {
if (a.p1 == b.p1 || a.p2 == b.p1 || a.p1 == b.p2 || a.p2 == b.p2)
return false;
if (parareru((a.p2), (a.p1), (a.p1), (b.p2)) &&
parareru((a.p2), (a.p1), (a.p1), (b.p1))) {
// cout<<"sss"<<endl;
if (dot(a.p1 - b.p1, a.p1 - b.p2) < EPS)
return true;
if (dot(a.p2 - b.p1, a.p2 - b.p2) < EPS)
return true;
if (dot(a.p1 - b.p1, a.p2 - b.p1) < EPS)
return true;
if (dot(a.p1 - b.p2, a.p2 - b.p2) < EPS)
return true;
return false;
} else
return (cross(a.p2 - a.p1, b.p1 - a.p1) * cross(a.p2 - a.p1, b.p2 - a.p1) <
EPS) &&
(cross(b.p2 - b.p1, a.p1 - b.p1) * cross(b.p2 - b.p1, a.p2 - b.p1) <
EPS);
}
double segment_dis(Segment a, Segment b) {
if (is_intersected_ls(a, b))
return 0;
double r = distance_ls_p(a.p1, a.p2, b.p1);
r = min(r, distance_ls_p(a.p1, a.p2, b.p2));
r = min(r, distance_ls_p(b.p1, b.p2, a.p2));
r = min(r, distance_ls_p(b.p1, b.p2, a.p1));
return r;
}
Point intersection_ls(Segment a, Segment b) {
Point ba = b.p2 - b.p1;
double d1 = abs(cross(ba, a.p1 - b.p1));
double d2 = abs(cross(ba, a.p2 - b.p1));
double t = d1 / (d1 + d2);
return a.p1 + (a.p2 - a.p1) * t;
}
string itos(int i) {
ostringstream s;
s << i;
return s.str();
}
int gcd(int v, int b) {
if (v > b)
return gcd(b, v);
if (v == b)
return b;
if (b % v == 0)
return v;
return gcd(v, b % v);
}
double distans(double x1, double y1, double x2, double y2) {
double rr = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
return sqrt(rr);
}
// int pr[2000010];
// int inv[2000010];
int beki(int wa, int rr, int warukazu) {
if (rr == 0)
return 1 % warukazu;
if (rr == 1)
return wa % warukazu;
if (rr % 2 == 1)
return (beki(wa, rr - 1, warukazu) * wa) % warukazu;
int zx = beki(wa, rr / 2, warukazu);
return (zx * zx) % warukazu;
}
double bekid(double w, int r) {
if (r == 0)
return 1.0;
if (r == 1)
return w;
if (r % 2)
return bekid(w, r - 1) * w;
double f = bekid(w, r / 2);
return f * f;
}
/*
int comb(int nn,int rr){
int r=pr[nn]*inv[rr];
r%=inf;
r*=inv[nn-rr];
r%=inf;
return r;
}
void gya(int ert){
pr[0]=1;
for(int i=1;i<ert;i++){
pr[i]=(pr[i-1]*i)%inf;
}
for(int i=0;i<ert;i++) inv[i]=beki(pr[i],inf-2,inf);
}
*/
// priority_queue<pa3,vector<pa3>,greater<pa3>> pq;
// sort(ve.begin(),ve.end(),greater<int>());
//----------------kokomade tenpure------------
// vector<double> ans(100000000),ans2(100000000)
const int MAXN = 100020;
namespace SA {
int rank[MAXN], tmp[MAXN];
int n, k;
bool compare_sa(int i, int j) {
if (rank[i] != rank[j])
return rank[i] < rank[j];
int ri = (i + k <= n) ? rank[i + k] : -1;
int rj = (j + k <= n) ? rank[j + k] : -1;
return ri < rj;
}
void createSA(const string &s, int *sa) {
n = s.size();
for (int i = 0; i <= n; i++) {
sa[i] = i;
rank[i] = i < n ? s[i] : -1;
}
for (k = 1; k <= n; k *= 2) {
sort(sa, sa + n + 1, compare_sa);
tmp[sa[0]] = 0;
for (int i = 1; i <= n; i++) {
tmp[sa[i]] = tmp[sa[i - 1]] + (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
}
for (int i = 0; i <= n; i++)
rank[i] = tmp[i];
}
}
} // namespace SA
struct segsum {
// 1
// 2 3
// 4 5 6 7
private:
public:
// (1<<15)=32768
// 1<<16 = 65536
// 1<<17 = 131072
// 1<<18 = 262144
int cor = (1 << 17);
vector<int> vec;
vector<int> lazy;
void shoki1() { vec.resize(2 * cor + 3, 0); }
void shoki2() {
for (int i = cor - 1; i > 0; i--)
vec[i] = vec[2 * i] + vec[2 * i + 1];
}
void updadd(int x, int w) {
// x ���ڂ� w���Z
x += cor;
vec[x] += w;
while (1) {
x /= 2;
if (x == 0)
break;
vec[x] = vec[2 * x] + vec[2 * x + 1];
}
}
void updchan(int x, int w) {
// x���ڂ�w�ɕύX
x += cor;
vec[x] = w;
while (1) {
x /= 2;
if (x == 0)
break;
vec[x] = vec[2 * x] + vec[2 * x + 1];
}
}
// [a,b)
// k-th node
// k no kukanha [l,r)
int sum(int a, int b, int k = 1, int l = 0, int r = -10) {
if (r < 0)
r = cor;
// cout<<a<<" "<<b<<" "<<k<<" "<<l<<" "<<r<<endl;
if (a <= l && r <= b) {
return vec[k];
}
if (r <= a || b <= l) {
return 0;
}
int v1 = sum(a, b, k * 2, l, (l + r) / 2),
v2 = sum(a, b, k * 2 + 1, (l + r) / 2, r);
return v1 + v2;
}
};
segsum SE;
int sa[100020];
vector<pa2> ve;
signed main() {
string s;
cin >> s;
SA::createSA(s, sa);
int l = s.length();
// for(int i=0;i<=l;i++)cout<<sa[i]<<" "<<s.substr(sa[i])<<endl;;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string t;
cin >> t;
int tl = t.length();
sa[l + 1] = 100001;
int si = 0, ue = l + 1, me;
while (ue - si > 1) {
me = (ue + si) / 2;
if (s.substr(sa[me]) < t)
si = me;
else
ue = me;
}
char c = 'z' + 1;
while (s.length() <= 100000)
s += 'A';
while (s.length() < 100030)
s += c;
int kagen = ue;
// cout<<kagen<<endl;
si = 0, ue = l + 1;
t.back()++;
while (ue - si > 1) {
me = (ue + si) / 2;
if (s.substr(sa[me], tl) < t)
si = me;
else
ue = me;
}
int jougen = ue;
// cout<<jougen<<endl;
for (int i = kagen; i < jougen; i++) {
// cout<<sa[i]<<" "<<s.substr(sa[i])<<endl;
ve.pb((pa2){sa[i], sa[i] + tl});
if (ve.size() > 10000000) {
cout << l << endl;
return 0;
}
}
// cout<<endl;
}
sort(ve.begin(), ve.end());
SE.shoki1();
SE.shoki2();
int ans = 0;
for (int i = 0; i < ve.size(); i++) {
// cout<<ve[i].x<<" "<<ve[i].y<<endl;
if (SE.sum(ve[i].x, ve[i].y) > 0)
continue;
ans++;
SE.updadd(ve[i].y - 1, 1);
}
cout << ans << endl;
return 0;
}
|
replace
| 386 | 388 | 386 | 390 |
0
| |
p01973
|
C++
|
Time Limit Exceeded
|
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
using ull = unsigned long long;
const ull b = 1000000007;
ull f(string s) {
ull h = 0;
rep(i, s.size()) h = b * h + s[i];
return h;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
string s;
cin >> s;
int n = s.size();
int q;
cin >> q;
vector<unordered_set<ull>> hashs(n + 1);
rep(i, q) {
string t;
cin >> t;
int m = t.size();
if (m > n)
continue;
hashs[m].insert(f(t));
}
vector<int> l(n, -1);
ull bb = 1;
for (int len = 1; len <= n; len++) {
bb *= b;
ull h = f(s.substr(0, len));
int r = len - 1;
while (true) {
if (hashs[len].count(h) && l[r] == -1) {
l[r] = r - len + 1;
}
r++;
if (r >= n)
break;
h = b * h - bb * s[r - len] + s[r];
}
}
int cnt = 0;
int r = -1;
rep(i, n) {
if (r < l[i]) {
cnt++;
r = i;
}
}
cout << cnt << endl;
}
|
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
using ull = unsigned long long;
const ull b = 1000000007;
ull f(string s) {
ull h = 0;
rep(i, s.size()) h = b * h + s[i];
return h;
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
string s;
cin >> s;
int n = s.size();
int q;
cin >> q;
vector<unordered_set<ull>> hashs(n + 1);
rep(i, q) {
string t;
cin >> t;
int m = t.size();
if (m > n)
continue;
hashs[m].insert(f(t));
}
vector<int> l(n, -1);
ull bb = 1;
for (int len = 1; len <= n; len++) {
bb *= b;
if (hashs[len].empty())
continue;
ull h = f(s.substr(0, len));
int r = len - 1;
while (true) {
if (hashs[len].count(h) && l[r] == -1) {
l[r] = r - len + 1;
}
r++;
if (r >= n)
break;
h = b * h - bb * s[r - len] + s[r];
}
}
int cnt = 0;
int r = -1;
rep(i, n) {
if (r < l[i]) {
cnt++;
r = i;
}
}
cout << cnt << endl;
}
|
insert
| 37 | 37 | 37 | 39 |
TLE
| |
p01973
|
C++
|
Time Limit Exceeded
|
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>
#include <functional>
typedef long long ll;
using namespace std;
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#define mod 1000000007 // 1e9+7(prime number)
#define INF 1000000000 // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 100010
/* Trie */
struct ACNode {
int val;
ACNode *next[26], *failure;
ACNode() : val(0) { memset(next, 0, sizeof(next)); }
void insert(char *s) {
if (!*s) {
val++;
return;
}
int al = *s - 'a';
if (next[al] == NULL)
next[al] = new ACNode;
next[al]->insert(s + 1);
}
ACNode *nextNode(char c) {
int al = c - 'a';
return next[al] ? next[al] : failure->nextNode(c);
}
};
struct AhoCorasick {
ACNode *node;
AhoCorasick() { node = new ACNode; }
void insert(char *s) { node->insert(s); }
void build() {
queue<ACNode *> que;
node->failure = node;
que.push(node);
while (que.size()) {
ACNode *p = que.front();
que.pop();
for (int i = 0; i < 26; i++) {
if (p->next[i]) {
ACNode *failure = p->failure;
while (!failure->next[i] && failure != node) {
failure = failure->failure;
}
if (failure->next[i] && !(failure == p && p == node)) {
p->next[i]->failure = failure->next[i];
p->next[i]->val += failure->next[i]->val;
} else {
p->next[i]->failure = node;
}
que.push(p->next[i]);
}
}
}
}
};
int main() {
char s[SIZE], p[SIZE];
int n;
AhoCorasick ac;
scanf("%s%d", s, &n);
for (int i = 0; i < n; i++) {
scanf("%s", p);
ac.insert(p);
}
ac.build();
ACNode *now = ac.node;
int ans = 0;
for (int i = 0; s[i] != '\0'; i++) {
now = now->nextNode(s[i]);
if (now->val) {
ans++;
now = ac.node;
}
}
printf("%d\n", ans);
return 0;
}
|
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>
#include <functional>
typedef long long ll;
using namespace std;
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
#define mod 1000000007 // 1e9+7(prime number)
#define INF 1000000000 // 1e9
#define LLINF 2000000000000000000LL // 2e18
#define SIZE 100010
/* Trie */
struct ACNode {
int val;
ACNode *next[26], *failure;
ACNode() : val(0) { memset(next, 0, sizeof(next)); }
void insert(char *s) {
if (!*s) {
val++;
return;
}
int al = *s - 'a';
if (next[al] == NULL)
next[al] = new ACNode;
next[al]->insert(s + 1);
}
ACNode *nextNode(char c) {
int al = c - 'a';
if (next[al])
return next[al];
return failure == this ? this : failure->nextNode(c);
}
};
struct AhoCorasick {
ACNode *node;
AhoCorasick() { node = new ACNode; }
void insert(char *s) { node->insert(s); }
void build() {
queue<ACNode *> que;
node->failure = node;
que.push(node);
while (que.size()) {
ACNode *p = que.front();
que.pop();
for (int i = 0; i < 26; i++) {
if (p->next[i]) {
ACNode *failure = p->failure;
while (!failure->next[i] && failure != node) {
failure = failure->failure;
}
if (failure->next[i] && !(failure == p && p == node)) {
p->next[i]->failure = failure->next[i];
p->next[i]->val += failure->next[i]->val;
} else {
p->next[i]->failure = node;
}
que.push(p->next[i]);
}
}
}
}
};
int main() {
char s[SIZE], p[SIZE];
int n;
AhoCorasick ac;
scanf("%s%d", s, &n);
for (int i = 0; i < n; i++) {
scanf("%s", p);
ac.insert(p);
}
ac.build();
ACNode *now = ac.node;
int ans = 0;
for (int i = 0; s[i] != '\0'; i++) {
now = now->nextNode(s[i]);
if (now->val) {
ans++;
now = ac.node;
}
}
printf("%d\n", ans);
return 0;
}
|
replace
| 51 | 52 | 51 | 54 |
TLE
| |
p01975
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld = long double;
#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
template <class T, class S> void cmin(T &a, const S &b) {
if (a > b)
a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
if (a < b)
a = b;
}
#define MAX 9999999
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int W, H;
bool inrange(int x, int y) { return (0 <= x && x < W) && (0 <= y && y < H); }
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
#define MP make_pair
signed main() {
int n;
cin >> n;
vector<int> vvataarne(n);
rep(i, n) cin >> vvataarne[i];
vector<int> kitikuyarou(n);
rep(i, n) cin >> kitikuyarou[i];
set<int> vvhaAORIkaiwanotourist;
rep(i, n) vvhaAORIkaiwanotourist.insert(kitikuyarou[i]);
if (vvhaAORIkaiwanotourist.size() == n)
return puts("Yes") * 0;
map<int, int> vvhasinntyokukaiwainotourist;
rep(i, n) vvhasinntyokukaiwainotourist[kitikuyarou[i]]++;
int safe = INF;
puts("No");
rep(i, n) {
if (i)
cout << " ";
cout << kitikuyarou[i];
}
cout << endl;
assert(safe != INF);
rep(i, n) {
if (i)
cout << " ";
if (vvhasinntyokukaiwainotourist[vvataarne[i]])
cout << kitikuyarou[i];
else
cout << vvataarne[i];
}
cout << endl;
}
|
#include <bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld = long double;
#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i, n) for (int i = 0; i < n; i++)
#define loop(i, s, n) for (int i = s; i < n; i++)
#define all(in) in.begin(), in.end()
template <class T, class S> void cmin(T &a, const S &b) {
if (a > b)
a = b;
}
template <class T, class S> void cmax(T &a, const S &b) {
if (a < b)
a = b;
}
#define MAX 9999999
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int W, H;
bool inrange(int x, int y) { return (0 <= x && x < W) && (0 <= y && y < H); }
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
#define MP make_pair
signed main() {
int n;
cin >> n;
vector<int> vvataarne(n);
rep(i, n) cin >> vvataarne[i];
vector<int> kitikuyarou(n);
rep(i, n) cin >> kitikuyarou[i];
set<int> vvhaAORIkaiwanotourist;
rep(i, n) vvhaAORIkaiwanotourist.insert(kitikuyarou[i]);
if (vvhaAORIkaiwanotourist.size() == n)
return puts("Yes") * 0;
map<int, int> vvhasinntyokukaiwainotourist;
rep(i, n) vvhasinntyokukaiwainotourist[kitikuyarou[i]]++;
int safe = INF;
puts("No");
rep(i, n) {
if (i)
cout << " ";
cout << kitikuyarou[i];
}
cout << endl;
rep(i, n) {
if (i)
cout << " ";
if (vvhasinntyokukaiwainotourist[vvataarne[i]])
cout << kitikuyarou[i];
else
cout << vvataarne[i];
}
cout << endl;
}
|
delete
| 54 | 55 | 54 | 54 |
0
| |
p01978
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T> constexpr T inf;
template <> constexpr int inf<int> = 1e9;
template <> constexpr ll inf<ll> = 1e18;
template <> constexpr double inf<double> = 1e18;
template <typename T> std::vector<T> table(int n, T v) {
return std::vector<T>(n, v);
}
template <class... Args> auto table(int n, Args... args) {
auto val = table(args...);
return std::vector<decltype(val)>(n, std::move(val));
}
struct edge {
int to;
ll cost;
int id;
};
using edges = vector<edge>;
using graph = vector<edges>;
void add_edge(graph &g, int u, int v, ll cost, int id) {
g[u].push_back(edge{v, cost, id});
g[v].push_back(edge{u, cost, id});
}
struct node {
int v, pre;
ll dist;
node(int v, ll dist, int prev) : v(v), pre(prev), dist(dist) {}
bool operator<(const node &other) const { return dist > other.dist; }
};
int main() {
int N, M, s, t;
scanf("%d %d %d %d", &N, &M, &s, &t);
s--, t--;
graph g(N);
for (int i = 0; i < M; ++i) {
int a, b, c, d;
scanf("%d %d %d %d", &a, &b, &c, &d);
a--;
b--;
c--;
add_edge(g, a, b, d, i);
add_edge(g, b, c, d, i);
add_edge(g, c, a, d, i);
}
priority_queue<node> que;
vector<unordered_map<int, ll>> d(N);
vector<ll> min_d(N, 1e18);
que.emplace(s, 0, -1);
d[s][-1] = 0;
min_d[s] = 0;
ll ans = 0;
while (!que.empty()) {
auto now = que.top();
que.pop();
if (min_d[now.v] < now.dist)
continue;
if (now.v == t) {
ans = now.dist;
break;
}
for (const auto &e : g[now.v]) {
if (min_d[e.to] > now.dist + e.cost &&
(d[e.to].count(e.id) == 0 ||
(d[e.to].count(e.id) == 1 && d[e.to][e.id] > now.dist + e.cost))) {
d[e.to][e.id] = now.dist + e.cost;
que.emplace(e.to, d[e.to][e.id], e.id);
}
}
}
cout << ans << endl;
}
// ll solve(ll n) {
// const auto s = to_string(n);
// const int m = s.size();
// // [pos][i - 3][i - 2][i - 1][already ok][strictly less]
// auto dp = table<ll>(m + 1, 10, 10, 10, 2, 2, 0);
// dp[0][0][0][0][0][0] = 1;
// for(int i = 0; i < m; ++i) {
// for(int i3 = 0; i3 <= 9; ++i3) for(int i2 = 0; i2 <= 9; ++i2) for(int
// i1 = 0; i1 <= 9; ++i1) {
// for(int aok = 0; aok <= 1; ++aok) {
// for(int le = 0; le <= 1; ++le) {
// const int lim = le ? 9 : s[i] - '0';
// for(int add = 0; add <= lim; ++add) {
// int nok = aok || (i3 == 5 && i2 == 1 && add == 3);
// int nle = le || s[i] - '0' > add;
// dp[i + 1][i2][i1][add][nok][nle] +=
// dp[i][i3][i2][i1][aok][le];
// }
// }
// }
// }
// }
//
// ll ans = 0;
// for(int i = 0; i <= 9; ++i) {
// for(int j = 0; j <= 9; ++j) {
// for(int k = 0; k <= 9; ++k) {
// ans += dp[m][i][j][k][1][0] + dp[m][i][j][k][1][1];
// }
// }
// }
// return ans;
// }
// int main() {
// ll N;
// cin >> N;
// cout << solve(N) << endl;
// }
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T> constexpr T inf;
template <> constexpr int inf<int> = 1e9;
template <> constexpr ll inf<ll> = 1e18;
template <> constexpr double inf<double> = 1e18;
template <typename T> std::vector<T> table(int n, T v) {
return std::vector<T>(n, v);
}
template <class... Args> auto table(int n, Args... args) {
auto val = table(args...);
return std::vector<decltype(val)>(n, std::move(val));
}
struct edge {
int to;
ll cost;
int id;
};
using edges = vector<edge>;
using graph = vector<edges>;
void add_edge(graph &g, int u, int v, ll cost, int id) {
g[u].push_back(edge{v, cost, id});
g[v].push_back(edge{u, cost, id});
}
struct node {
int v, pre;
ll dist;
node(int v, ll dist, int prev) : v(v), pre(prev), dist(dist) {}
bool operator<(const node &other) const { return dist > other.dist; }
};
int main() {
int N, M, s, t;
scanf("%d %d %d %d", &N, &M, &s, &t);
s--, t--;
graph g(N);
for (int i = 0; i < M; ++i) {
int a, b, c, d;
scanf("%d %d %d %d", &a, &b, &c, &d);
a--;
b--;
c--;
add_edge(g, a, b, d, i);
add_edge(g, b, c, d, i);
add_edge(g, c, a, d, i);
}
priority_queue<node> que;
vector<unordered_map<int, ll>> d(N);
vector<ll> min_d(N, 1e18);
que.emplace(s, 0, -1);
d[s][-1] = 0;
min_d[s] = 0;
ll ans = 0;
while (!que.empty()) {
auto now = que.top();
que.pop();
if (min_d[now.v] < now.dist)
continue;
if (now.v == t) {
ans = now.dist;
break;
}
for (const auto &e : g[now.v]) {
if (min_d[e.to] > now.dist + e.cost &&
(d[e.to].count(e.id) == 0 ||
(d[e.to].count(e.id) == 1 && d[e.to][e.id] > now.dist + e.cost))) {
d[e.to][e.id] = now.dist + e.cost;
que.emplace(e.to, d[e.to][e.id], e.id);
min_d[e.to] = now.dist + e.cost;
}
}
}
cout << ans << endl;
}
// ll solve(ll n) {
// const auto s = to_string(n);
// const int m = s.size();
// // [pos][i - 3][i - 2][i - 1][already ok][strictly less]
// auto dp = table<ll>(m + 1, 10, 10, 10, 2, 2, 0);
// dp[0][0][0][0][0][0] = 1;
// for(int i = 0; i < m; ++i) {
// for(int i3 = 0; i3 <= 9; ++i3) for(int i2 = 0; i2 <= 9; ++i2) for(int
// i1 = 0; i1 <= 9; ++i1) {
// for(int aok = 0; aok <= 1; ++aok) {
// for(int le = 0; le <= 1; ++le) {
// const int lim = le ? 9 : s[i] - '0';
// for(int add = 0; add <= lim; ++add) {
// int nok = aok || (i3 == 5 && i2 == 1 && add == 3);
// int nle = le || s[i] - '0' > add;
// dp[i + 1][i2][i1][add][nok][nle] +=
// dp[i][i3][i2][i1][aok][le];
// }
// }
// }
// }
// }
//
// ll ans = 0;
// for(int i = 0; i <= 9; ++i) {
// for(int j = 0; j <= 9; ++j) {
// for(int k = 0; k <= 9; ++k) {
// ans += dp[m][i][j][k][1][0] + dp[m][i][j][k][1][1];
// }
// }
// }
// return ans;
// }
// int main() {
// ll N;
// cin >> N;
// cout << solve(N) << endl;
// }
|
insert
| 84 | 84 | 84 | 85 |
TLE
| |
p01980
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64, i64> P;
#define rep(i, s, e) for (int i = (s); i <= (e); i++)
/* include file*/
#include <functional>
#include <vector>
using namespace std;
template <class Monoid> struct Segment {
using Func = function<Monoid(Monoid, Monoid)>;
vector<Monoid> node;
Monoid ide;
int n = 1;
Func bin_f;
Func update_f;
Segment(const vector<Monoid> &init, Monoid ide_, Func f_, Func u_f)
: bin_f(f_), ide(ide_), update_f(u_f) {
int sz = init.size();
while (n < sz)
n *= 2;
node.assign(n * 2 - 1, ide);
for (int i = 0; i < sz; i++)
node[i + n - 1] = init[i];
for (int i = n - 2; i >= 0; i--)
node[i] = bin_f(node[i * 2 + 1], node[i * 2 + 2]);
}
void update(int i, Monoid x) {
i += n - 1;
node[i] = update_f(node[i], x);
while (i) {
i = (i - 1) / 2;
node[i] = bin_f(node[i * 2 + 1], node[i * 2 + 2]);
}
}
Monoid get_inter(int a, int b, int k = 0, int l = 0, int r = -1) {
if (r < 0)
r = n;
if (a <= l && r <= b)
return node[k];
if (r <= a || b <= l)
return ide;
Monoid lm = get_inter(a, b, k * 2 + 1, l, (l + r) / 2);
Monoid rm = get_inter(a, b, k * 2 + 2, (l + r) / 2, r);
return bin_f(lm, rm);
}
};
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2730414#1
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2730425#1
typedef long long ll;
struct LazySegment {
vector<ll> node;
vector<ll> lazy;
vector<bool> lazyFlag;
ll n;
ll init = 0;
LazySegment(const vector<ll> &vec) {
int sz = vec.size();
n = 1;
while (n < sz)
n <<= 1;
node.resize(2 * n - 1);
lazy.resize(2 * n - 1, init);
lazyFlag.resize(2 * n - 1, false);
for (int i = 0; i < sz; i++) {
node[n - 1 + i] = vec[i];
}
for (int i = n - 2; i >= 0; i--) {
node[i] = max(node[2 * i + 1], node[2 * i + 2]);
}
}
void eval(int k, int l, int r) {
if (lazyFlag[k]) {
node[k] = max(node[k], lazy[k]);
if (r - l > 1) {
lazy[2 * k + 1] = max(lazy[2 * k + 1], lazy[k]);
lazy[2 * k + 2] = max(lazy[2 * k + 2], lazy[k]);
lazyFlag[2 * k + 1] = true;
lazyFlag[2 * k + 2] = true;
}
lazy[k] = 0;
lazyFlag[k] = false;
}
}
void add_inter(int a, int b, ll x, int k = 0, int l = 0, int r = -1) {
if (r < 0)
r = n;
eval(k, l, r);
if (b <= l || r <= a)
return;
if (a <= l && r <= b) {
lazy[k] = max(lazy[k], x);
lazyFlag[k] = true;
eval(k, l, r);
}
else {
add_inter(a, b, x, 2 * k + 1, l, (l + r) / 2);
add_inter(a, b, x, 2 * k + 2, (l + r) / 2, r);
node[k] = max(node[2 * k + 1], node[2 * k + 2]);
}
}
ll get_inter(int a, int b, int k = 0, int l = 0, int r = -1) {
if (r < 0)
r = n;
eval(k, l, r);
if (b <= l || r <= a)
return init;
if (a <= l && r <= b)
return node[k];
ll lv = get_inter(a, b, k * 2 + 1, l, (l + r) / 2);
ll rv = get_inter(a, b, k * 2 + 2, (l + r) / 2, r);
return max(lv, rv);
}
};
int n;
int m;
int q;
vector<int> days;
vector<int> d(101010);
vector<int> a(101010);
vector<int> b(101010);
vector<P> D[101010];
vector<int> e(101010);
vector<int> s(101010);
vector<int> t(101010);
int now = 0;
using query = pair<P, P>;
vector<query> Query;
int main() {
cin >> n >> m >> q;
rep(i, 0, m - 1) {
cin >> d[i] >> a[i] >> b[i];
a[i]--;
b[i]--;
}
rep(i, 0, m - 1) days.push_back(d[i]);
rep(i, 0, q - 1) {
cin >> e[i] >> s[i] >> t[i];
days.push_back(e[i]);
s[i]--;
t[i]--;
}
sort(days.begin(), days.end());
days.erase(unique(days.begin(), days.end()), days.end());
rep(i, 0, m - 1) {
int ite = lower_bound(days.begin(), days.end(), d[i]) - days.begin();
D[ite].push_back({a[i], b[i]});
}
rep(i, 0, q - 1) {
int ite = lower_bound(days.begin(), days.end(), e[i]) - days.begin();
Query.push_back({{ite, s[i]}, {t[i], i}});
}
vector<int> vec;
for (int i = 0; i < n; i++) {
vec.push_back(i);
}
Segment<int> seg(
vec, 0, [](int a, int b) { return max(a, b); },
[](int node, int x) { return max(node, x); });
vector<string> ans(q);
sort(Query.begin(), Query.end());
int now = 0;
for (int i = 0; i < q; i++) {
int Q = Query[i].first.first;
for (; now < Q; now++) {
for (auto &v : D[now]) {
seg.update(v.first, v.second);
}
}
int temp;
int point = Query[i].first.second;
while ((temp = seg.get_inter(0, point + 1)) > point) {
point = temp;
}
if (point >= Query[i].second.first) {
ans[Query[i].second.second] = "Yes";
} else {
ans[Query[i].second.second] = "No";
}
}
for (string an : ans) {
cout << an << endl;
}
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64, i64> P;
#define rep(i, s, e) for (int i = (s); i <= (e); i++)
/* include file*/
#include <functional>
#include <vector>
using namespace std;
template <class Monoid> struct Segment {
using Func = function<Monoid(Monoid, Monoid)>;
vector<Monoid> node;
Monoid ide;
int n = 1;
Func bin_f;
Func update_f;
Segment(const vector<Monoid> &init, Monoid ide_, Func f_, Func u_f)
: bin_f(f_), ide(ide_), update_f(u_f) {
int sz = init.size();
while (n < sz)
n *= 2;
node.assign(n * 2 - 1, ide);
for (int i = 0; i < sz; i++)
node[i + n - 1] = init[i];
for (int i = n - 2; i >= 0; i--)
node[i] = bin_f(node[i * 2 + 1], node[i * 2 + 2]);
}
void update(int i, Monoid x) {
i += n - 1;
node[i] = update_f(node[i], x);
while (i) {
i = (i - 1) / 2;
node[i] = bin_f(node[i * 2 + 1], node[i * 2 + 2]);
}
}
Monoid get_inter(int a, int b, int k = 0, int l = 0, int r = -1) {
if (r < 0)
r = n;
if (a <= l && r <= b)
return node[k];
if (r <= a || b <= l)
return ide;
Monoid lm = get_inter(a, b, k * 2 + 1, l, (l + r) / 2);
Monoid rm = get_inter(a, b, k * 2 + 2, (l + r) / 2, r);
return bin_f(lm, rm);
}
};
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2730414#1
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2730425#1
typedef long long ll;
struct LazySegment {
vector<ll> node;
vector<ll> lazy;
vector<bool> lazyFlag;
ll n;
ll init = 0;
LazySegment(const vector<ll> &vec) {
int sz = vec.size();
n = 1;
while (n < sz)
n <<= 1;
node.resize(2 * n - 1);
lazy.resize(2 * n - 1, init);
lazyFlag.resize(2 * n - 1, false);
for (int i = 0; i < sz; i++) {
node[n - 1 + i] = vec[i];
}
for (int i = n - 2; i >= 0; i--) {
node[i] = max(node[2 * i + 1], node[2 * i + 2]);
}
}
void eval(int k, int l, int r) {
if (lazyFlag[k]) {
node[k] = max(node[k], lazy[k]);
if (r - l > 1) {
lazy[2 * k + 1] = max(lazy[2 * k + 1], lazy[k]);
lazy[2 * k + 2] = max(lazy[2 * k + 2], lazy[k]);
lazyFlag[2 * k + 1] = true;
lazyFlag[2 * k + 2] = true;
}
lazy[k] = 0;
lazyFlag[k] = false;
}
}
void add_inter(int a, int b, ll x, int k = 0, int l = 0, int r = -1) {
if (r < 0)
r = n;
eval(k, l, r);
if (b <= l || r <= a)
return;
if (a <= l && r <= b) {
lazy[k] = max(lazy[k], x);
lazyFlag[k] = true;
eval(k, l, r);
}
else {
add_inter(a, b, x, 2 * k + 1, l, (l + r) / 2);
add_inter(a, b, x, 2 * k + 2, (l + r) / 2, r);
node[k] = max(node[2 * k + 1], node[2 * k + 2]);
}
}
ll get_inter(int a, int b, int k = 0, int l = 0, int r = -1) {
if (r < 0)
r = n;
eval(k, l, r);
if (b <= l || r <= a)
return init;
if (a <= l && r <= b)
return node[k];
ll lv = get_inter(a, b, k * 2 + 1, l, (l + r) / 2);
ll rv = get_inter(a, b, k * 2 + 2, (l + r) / 2, r);
return max(lv, rv);
}
};
int n;
int m;
int q;
vector<int> days;
vector<int> d(101010);
vector<int> a(101010);
vector<int> b(101010);
vector<P> D[202020];
vector<int> e(101010);
vector<int> s(101010);
vector<int> t(101010);
int now = 0;
using query = pair<P, P>;
vector<query> Query;
int main() {
cin >> n >> m >> q;
rep(i, 0, m - 1) {
cin >> d[i] >> a[i] >> b[i];
a[i]--;
b[i]--;
}
rep(i, 0, m - 1) days.push_back(d[i]);
rep(i, 0, q - 1) {
cin >> e[i] >> s[i] >> t[i];
days.push_back(e[i]);
s[i]--;
t[i]--;
}
sort(days.begin(), days.end());
days.erase(unique(days.begin(), days.end()), days.end());
rep(i, 0, m - 1) {
int ite = lower_bound(days.begin(), days.end(), d[i]) - days.begin();
D[ite].push_back({a[i], b[i]});
}
rep(i, 0, q - 1) {
int ite = lower_bound(days.begin(), days.end(), e[i]) - days.begin();
Query.push_back({{ite, s[i]}, {t[i], i}});
}
vector<int> vec;
for (int i = 0; i < n; i++) {
vec.push_back(i);
}
Segment<int> seg(
vec, 0, [](int a, int b) { return max(a, b); },
[](int node, int x) { return max(node, x); });
vector<string> ans(q);
sort(Query.begin(), Query.end());
int now = 0;
for (int i = 0; i < q; i++) {
int Q = Query[i].first.first;
for (; now < Q; now++) {
for (auto &v : D[now]) {
seg.update(v.first, v.second);
}
}
int temp;
int point = Query[i].first.second;
while ((temp = seg.get_inter(0, point + 1)) > point) {
point = temp;
}
if (point >= Query[i].second.first) {
ans[Query[i].second.second] = "Yes";
} else {
ans[Query[i].second.second] = "No";
}
}
for (string an : ans) {
cout << an << endl;
}
}
|
replace
| 161 | 162 | 161 | 162 |
0
| |
p01980
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using LL = long long;
int N, M, Q;
struct query {
int T;
int make; // 0:ques 1:make
int A, B;
int id;
};
vector<int> par;
int getPar(int x) {
if (x == par[x])
return x;
return par[x] = getPar(par[x]);
}
void unite(int a, int b) {
a = getPar(a);
b = getPar(b);
if (a == b) {
return;
}
if (a > b) {
par[b] = a;
} else {
par[a] = b;
}
}
int main(void) {
cin >> N >> M >> Q;
vector<query> que;
for (int i = 0; i < N; ++i) {
par.push_back(i);
}
for (int i = 0; i < M; ++i) {
int d, a, b;
cin >> d >> a >> b;
--a;
--b;
que.push_back({d, 1, a, b});
}
set<int> suk;
for (int i = 0; i < N - 1; ++i) {
suk.insert(i);
}
for (int i = 0; i < Q; ++i) {
int e, s, t;
cin >> e >> s >> t;
--s;
--t;
que.push_back({e, 0, s, t, i});
}
sort(que.begin(), que.end(), [](const query &q1, const query &q2) {
return make_pair(q1.T, q1.make) < make_pair(q2.T, q2.make);
});
vector<pair<int, bool>> ans;
for (auto &q : que) {
int T = q.T;
int make = q.make;
if (make == 1) {
int A = q.A;
int B = q.B;
auto itr = suk.lower_bound(A);
auto ptr = suk.lower_bound(B);
while (itr != ptr) {
int x = *itr;
unite(x, x + 1);
++itr;
}
} else {
int S = q.A;
int T = q.B;
int id = q.id;
if (S >= T) {
// cout << "Yes" << endl;
ans.push_back({id, true});
} else {
int SS = getPar(S);
if (SS >= T) {
// cout << "Yes" << endl;
ans.push_back({id, true});
} else {
// cout << "No" << endl;
ans.push_back({id, false});
}
}
}
}
sort(ans.begin(), ans.end());
for (auto x : ans) {
cout << (x.second ? "Yes" : "No") << endl;
}
return 0;
}
|
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using LL = long long;
int N, M, Q;
struct query {
int T;
int make; // 0:ques 1:make
int A, B;
int id;
};
vector<int> par;
int getPar(int x) {
if (x == par[x])
return x;
return par[x] = getPar(par[x]);
}
void unite(int a, int b) {
a = getPar(a);
b = getPar(b);
if (a == b) {
return;
}
if (a > b) {
par[b] = a;
} else {
par[a] = b;
}
}
int main(void) {
cin >> N >> M >> Q;
vector<query> que;
for (int i = 0; i < N; ++i) {
par.push_back(i);
}
for (int i = 0; i < M; ++i) {
int d, a, b;
cin >> d >> a >> b;
--a;
--b;
que.push_back({d, 1, a, b});
}
set<int> suk;
for (int i = 0; i < N - 1; ++i) {
suk.insert(i);
}
for (int i = 0; i < Q; ++i) {
int e, s, t;
cin >> e >> s >> t;
--s;
--t;
que.push_back({e, 0, s, t, i});
}
sort(que.begin(), que.end(), [](const query &q1, const query &q2) {
return make_pair(q1.T, q1.make) < make_pair(q2.T, q2.make);
});
vector<pair<int, bool>> ans;
for (auto &q : que) {
int T = q.T;
int make = q.make;
if (make == 1) {
int A = q.A;
int B = q.B;
auto itr = suk.lower_bound(A);
auto ptr = suk.lower_bound(B);
while (itr != ptr) {
int x = *itr;
unite(x, x + 1);
//++itr;
itr = suk.erase(itr);
}
} else {
int S = q.A;
int T = q.B;
int id = q.id;
if (S >= T) {
// cout << "Yes" << endl;
ans.push_back({id, true});
} else {
int SS = getPar(S);
if (SS >= T) {
// cout << "Yes" << endl;
ans.push_back({id, true});
} else {
// cout << "No" << endl;
ans.push_back({id, false});
}
}
}
}
sort(ans.begin(), ans.end());
for (auto x : ans) {
cout << (x.second ? "Yes" : "No") << endl;
}
return 0;
}
|
replace
| 96 | 97 | 96 | 98 |
TLE
| |
p01980
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) _range(i, 0, n)
#define _range(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _overload(__VA_ARGS__, _range, _rep, )(__VA_ARGS__)
#define _rrep(i, n) _rrange(i, n, 0)
#define _rrange(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)
#define rrep(...) _overload(__VA_ARGS__, _rrange, _rrep, )(__VA_ARGS__)
#define _all(arg) begin(arg), end(arg)
#define uniq(arg) sort(_all(arg)), (arg).erase(unique(_all(arg)), end(arg))
#define getidx(ary, key) lower_bound(_all(ary), key) - begin(ary)
#define clr(a, b) memset((a), (b), sizeof(a))
#define bit(n) (1LL << (n))
#define popcount(n) (__builtin_popcountll(n))
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
return (a < b) ? (a = b, 1) : 0;
}
template <class T> bool chmin(T &a, const T &b) {
return (b < a) ? (a = b, 1) : 0;
}
using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R &r) { return (r > EPS) - (r < -EPS); }
inline R sq(R x) { return sqrt(max(x, 0.0L)); }
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// Problem Specific Parameter:
// Description: セグメント木 点更新 区間クエリ
// TimeComplexity: 初期化$\mathcal{O}(n \log n)$ 更新とクエリ$\mathcal{O}(\log
// n)$ Verifyed: AOJ DSL_2_A
template <int depth> struct Segment_tree {
const static int h = depth;
const static int n = 1 << h;
using T = long long;
T data[2 * n];
const T out = 0LL;
inline T vmerge(T l, T r) { return max(l, r); }
void init() { fill_n(data, 2 * n, out); }
void update(int p, T x) { // set value at position p
for (data[p += n] = x; p > 1; p >>= 1) {
data[p >> 1] = vmerge(data[p], data[p ^ 1]);
}
}
T query(int l, int r) { // sum on interval [l, r)
T resl = out, resr = out;
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1)
resl = vmerge(data[l++], resl);
if (r & 1)
resr = vmerge(resr, data[--r]);
}
return vmerge(resl, resr);
}
};
const int limit = 100010;
const int inf = 1 << 30;
int ary[limit];
multiset<int> st;
vector<int> s[limit], t[limit];
Segment_tree<17> seg;
int main(void) {
int n, m, q;
cin >> n >> m >> q;
st.insert(inf);
rep(i, m) {
int d, a, b;
cin >> d >> a >> b;
a--, b--;
s[a].push_back(d);
t[b].push_back(d);
}
rep(i, n - 1) {
for (auto &elem : t[i]) {
auto it = st.find(elem);
st.erase(it);
}
for (auto &elem : s[i]) {
st.insert(elem);
}
ary[i] = *begin(st);
cerr << i << " " << ary[i] << endl;
}
seg.init();
rep(i, n - 1) seg.update(i, ary[i]);
rep(loop, q) {
int e, a, b;
cin >> e >> a >> b;
a--, b--;
// cerr << seg.query(a, b) << endl;
if (a >= b or seg.query(a, b) < e) {
puts("Yes");
} else {
puts("No");
}
}
return 0;
}
// 1 2 3
|
#include <bits/stdc++.h>
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) _range(i, 0, n)
#define _range(i, a, b) for (int i = int(a); i < int(b); ++i)
#define rep(...) _overload(__VA_ARGS__, _range, _rep, )(__VA_ARGS__)
#define _rrep(i, n) _rrange(i, n, 0)
#define _rrange(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)
#define rrep(...) _overload(__VA_ARGS__, _rrange, _rrep, )(__VA_ARGS__)
#define _all(arg) begin(arg), end(arg)
#define uniq(arg) sort(_all(arg)), (arg).erase(unique(_all(arg)), end(arg))
#define getidx(ary, key) lower_bound(_all(ary), key) - begin(ary)
#define clr(a, b) memset((a), (b), sizeof(a))
#define bit(n) (1LL << (n))
#define popcount(n) (__builtin_popcountll(n))
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
return (a < b) ? (a = b, 1) : 0;
}
template <class T> bool chmin(T &a, const T &b) {
return (b < a) ? (a = b, 1) : 0;
}
using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R &r) { return (r > EPS) - (r < -EPS); }
inline R sq(R x) { return sqrt(max(x, 0.0L)); }
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// Problem Specific Parameter:
// Description: セグメント木 点更新 区間クエリ
// TimeComplexity: 初期化$\mathcal{O}(n \log n)$ 更新とクエリ$\mathcal{O}(\log
// n)$ Verifyed: AOJ DSL_2_A
template <int depth> struct Segment_tree {
const static int h = depth;
const static int n = 1 << h;
using T = long long;
T data[2 * n];
const T out = 0LL;
inline T vmerge(T l, T r) { return max(l, r); }
void init() { fill_n(data, 2 * n, out); }
void update(int p, T x) { // set value at position p
for (data[p += n] = x; p > 1; p >>= 1) {
data[p >> 1] = vmerge(data[p], data[p ^ 1]);
}
}
T query(int l, int r) { // sum on interval [l, r)
T resl = out, resr = out;
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1)
resl = vmerge(data[l++], resl);
if (r & 1)
resr = vmerge(resr, data[--r]);
}
return vmerge(resl, resr);
}
};
const int limit = 100010;
const int inf = 1 << 30;
int ary[limit];
multiset<int> st;
vector<int> s[limit], t[limit];
Segment_tree<17> seg;
int main(void) {
int n, m, q;
cin >> n >> m >> q;
st.insert(inf);
rep(i, m) {
int d, a, b;
cin >> d >> a >> b;
a--, b--;
s[a].push_back(d);
t[b].push_back(d);
}
rep(i, n - 1) {
for (auto &elem : t[i]) {
auto it = st.find(elem);
st.erase(it);
}
for (auto &elem : s[i]) {
st.insert(elem);
}
ary[i] = *begin(st);
// cerr << i << " " << ary[i] << endl;
}
seg.init();
rep(i, n - 1) seg.update(i, ary[i]);
rep(loop, q) {
int e, a, b;
cin >> e >> a >> b;
a--, b--;
// cerr << seg.query(a, b) << endl;
if (a >= b or seg.query(a, b) < e) {
puts("Yes");
} else {
puts("No");
}
}
return 0;
}
// 1 2 3
|
replace
| 106 | 107 | 106 | 107 |
0
|
0 3
1 3
2 3
3 3
|
p01981
|
Python
|
Runtime Error
|
while True:
a = list(map(str, input().split()))
if a[0] == "0":
break
elif int(a[1]) <= 30:
print(" ".join(a))
elif int(a[1]) == 31 and int(a[2]) <= 4:
print(" ".join(a))
else:
a[0] = "?"
s = int(a[1])
s -= 30
a[1] = str(s)
print(" ".join(a))
|
while True:
a = list(map(str, input().split()))
if a[0] == "#":
break
elif int(a[1]) <= 30:
print(" ".join(a))
elif int(a[1]) == 31 and int(a[2]) <= 4:
print(" ".join(a))
else:
a[0] = "?"
s = int(a[1])
s -= 30
a[1] = str(s)
print(" ".join(a))
|
replace
| 2 | 3 | 2 | 3 |
IndexError: list index out of range
|
Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p01981/Python/s158524109.py", line 5, in <module>
elif int(a[1]) <= 30:
IndexError: list index out of range
|
p01984
|
C++
|
Time Limit Exceeded
|
// 数学をしたほうが実装は楽だと思うけど、さきほどやってみたらバグ死したので、桁DP
// + 2分探索します。
#include <algorithm>
#include <iostream>
#include <vector>
#define int long long
using namespace std;
// a[i] … 10進数における下位i(>=0)桁目.
vector<int> add(vector<int> a, vector<int> b, int n) {
for (int i = 0; i < n; i++) {
a[i] += b[i];
if (i + 1 < n) {
a[i + 1] += a[i] / 10;
a[i] %= 10;
}
}
return a;
}
vector<int> sub(vector<int> a, vector<int> b, int n) {
for (int i = 0; i < n; i++) {
a[i] -= b[i];
if (i + 1 < n && a[i] < 0) {
int kariru = ((-a[i]) + 9) / 10;
a[i] += 10 * kariru;
a[i + 1] -= kariru;
}
}
return a;
}
// 2で割る
vector<int> half(vector<int> a, int n) {
vector<int> ret(n, 0);
int val = 0;
for (int i = n - 1; i >= 0; i--) {
val *= 10;
val += a[i];
ret[i] = val / 2;
val -= ret[i] * 2;
}
return ret;
}
int bitCnt[1024];
void initBitCnt() {
for (int i = 0; i < 1024; i++) {
bitCnt[i] = 0;
for (int j = 0; j < 10; j++) {
if ((i >> j) & 1)
bitCnt[i]++;
}
}
}
// 桁DPで, a以下の短歌数を数える.
int INF = 1e+18;
int dp[101][1024][2]; // dp[残り桁数][今までに使った数の集合(leading
// 0はカウントしない)][aと一致しているか]
int dfs(int ketasu, int used, bool flag, vector<int> &a) {
if (ketasu == 0)
return (bitCnt[used] == 2);
if (dp[ketasu][used][flag] != -1)
return dp[ketasu][used][flag];
int ret = 0;
for (int i = 0; i < 10; i++) { // 次の桁をiにする
if (flag && a[ketasu - 1] < i)
break;
int nUsed;
if (used == 0 && i == 0)
nUsed = 0;
else
nUsed = (used | (1 << i));
ret += dfs(ketasu - 1, nUsed, flag && a[ketasu - 1] == i, a);
}
return dp[ketasu][used][flag] = ret;
}
// メモの初期化
void initDp() {
for (int i = 0; i < 101; i++)
for (int j = 0; j < 1024; j++)
for (int k = 0; k < 2; k++)
dp[i][j][k] = -1;
}
// 2分探索の終了条件
bool isContinue(vector<int> st, vector<int> ed, int n) {
vector<int> res = sub(ed, st, n);
if (res[0] >= 2)
return true;
for (int i = 1; i < n; i++) {
if (res[i] != 0)
return true;
}
return false;
}
int n;
void solve() {
initBitCnt();
int i, cnt = 0;
for (i = 1;; i++) {
cnt += 81 * ((1LL << (i - 1)) - 1);
if (cnt >= n)
break;
}
int ketasu = i;
vector<int> st(ketasu), ed(ketasu), mid(ketasu);
for (i = 0; i < ketasu; i++)
st[i] = 0;
for (i = 0; i < ketasu; i++)
ed[i] = 9;
// 2分探索. xxxooo, (st, ed]
while (isContinue(st, ed, ketasu)) {
mid = add(st, ed, ketasu);
mid = half(mid, ketasu);
initDp();
int res = dfs(ketasu, 0, true, mid);
if (res >= n)
ed = mid;
else
st = mid;
}
for (i = ketasu - 1; i >= 0; i--) {
if (ed[i] != 0)
break;
}
for (; i >= 0; i--) {
cout << ed[i];
}
cout << endl;
}
signed main() {
while (cin >> n) {
if (!n)
break;
solve();
}
return 0;
}
|
// 数学をしたほうが実装は楽だと思うけど、さきほどやってみたらバグ死したので、桁DP
// + 2分探索します。
#include <algorithm>
#include <iostream>
#include <vector>
#define int long long
using namespace std;
// a[i] … 10進数における下位i(>=0)桁目.
vector<int> add(vector<int> a, vector<int> b, int n) {
for (int i = 0; i < n; i++) {
a[i] += b[i];
if (i + 1 < n) {
a[i + 1] += a[i] / 10;
a[i] %= 10;
}
}
return a;
}
vector<int> sub(vector<int> a, vector<int> b, int n) {
for (int i = 0; i < n; i++) {
a[i] -= b[i];
if (i + 1 < n && a[i] < 0) {
int kariru = ((-a[i]) + 9) / 10;
a[i] += 10 * kariru;
a[i + 1] -= kariru;
}
}
return a;
}
// 2で割る
vector<int> half(vector<int> a, int n) {
vector<int> ret(n, 0);
int val = 0;
for (int i = n - 1; i >= 0; i--) {
val *= 10;
val += a[i];
ret[i] = val / 2;
val -= ret[i] * 2;
}
return ret;
}
int bitCnt[1024];
void initBitCnt() {
for (int i = 0; i < 1024; i++) {
bitCnt[i] = 0;
for (int j = 0; j < 10; j++) {
if ((i >> j) & 1)
bitCnt[i]++;
}
}
}
// 桁DPで, a以下の短歌数を数える.
int INF = 1e+18;
int dp[101][1024][2]; // dp[残り桁数][今までに使った数の集合(leading
// 0はカウントしない)][aと一致しているか]
int dfs(int ketasu, int used, bool flag, vector<int> &a) {
if (bitCnt[used] > 2)
return 0;
if (ketasu == 0)
return (bitCnt[used] == 2);
if (dp[ketasu][used][flag] != -1)
return dp[ketasu][used][flag];
int ret = 0;
for (int i = 0; i < 10; i++) { // 次の桁をiにする
if (flag && a[ketasu - 1] < i)
break;
int nUsed;
if (used == 0 && i == 0)
nUsed = 0;
else
nUsed = (used | (1 << i));
ret += dfs(ketasu - 1, nUsed, flag && a[ketasu - 1] == i, a);
}
return dp[ketasu][used][flag] = ret;
}
// メモの初期化
void initDp() {
for (int i = 0; i < 101; i++)
for (int j = 0; j < 1024; j++)
for (int k = 0; k < 2; k++)
dp[i][j][k] = -1;
}
// 2分探索の終了条件
bool isContinue(vector<int> st, vector<int> ed, int n) {
vector<int> res = sub(ed, st, n);
if (res[0] >= 2)
return true;
for (int i = 1; i < n; i++) {
if (res[i] != 0)
return true;
}
return false;
}
int n;
void solve() {
initBitCnt();
int i, cnt = 0;
for (i = 1;; i++) {
cnt += 81 * ((1LL << (i - 1)) - 1);
if (cnt >= n)
break;
}
int ketasu = i;
vector<int> st(ketasu), ed(ketasu), mid(ketasu);
for (i = 0; i < ketasu; i++)
st[i] = 0;
for (i = 0; i < ketasu; i++)
ed[i] = 9;
// 2分探索. xxxooo, (st, ed]
while (isContinue(st, ed, ketasu)) {
mid = add(st, ed, ketasu);
mid = half(mid, ketasu);
initDp();
int res = dfs(ketasu, 0, true, mid);
if (res >= n)
ed = mid;
else
st = mid;
}
for (i = ketasu - 1; i >= 0; i--) {
if (ed[i] != 0)
break;
}
for (; i >= 0; i--) {
cout << ed[i];
}
cout << endl;
}
signed main() {
while (cin >> n) {
if (!n)
break;
solve();
}
return 0;
}
|
insert
| 62 | 62 | 62 | 64 |
TLE
| |
p01985
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
const int SIZE = 100010;
vector<int> way[SIZE];
bool visited[SIZE];
int id[SIZE];
int counter[2];
bool dfs(int now, int f) {
if (visited[now]) {
return id[now] == f;
}
visited[now] = true;
id[now] = f;
counter[f]++;
for (int i = 0; i < (int)way[now].size(); i++)
if (dfs(way[now][i], !f) == false)
return false;
return true;
}
bool solve() {
int n, m;
int a, b;
scanf("%d%d", &n, &m);
if (n == 0)
return false;
for (int i = 0; i < n; i++)
way[i] = vector<int>();
memset(visited, 0, sizeof(visited));
counter[0] = counter[1] = 0;
for (int i = 0; i < m; i++) {
scanf("%d%d", &a, &b);
a--;
b--;
way[a].push_back(b);
way[b].push_back(a);
}
if (!dfs(0, 0)) {
puts("0");
} else {
cerr << counter[0] << " " << counter[1] << endl;
if (counter[0] > counter[1])
swap(counter[0], counter[1]);
vector<int> vec;
if (counter[0] % 2 == 0) {
vec.push_back(counter[0] / 2);
}
if (counter[0] != counter[1] && counter[1] % 2 == 0) {
vec.push_back(counter[1] / 2);
}
printf("%d\n", (int)vec.size());
for (int i = 0; i < vec.size(); i++) {
printf("%d\n", vec[i]);
}
}
return true;
}
int main() {
while (solve())
;
}
|
#include <bits/stdc++.h>
using namespace std;
const int SIZE = 100010;
vector<int> way[SIZE];
bool visited[SIZE];
int id[SIZE];
int counter[2];
bool dfs(int now, int f) {
if (visited[now]) {
return id[now] == f;
}
visited[now] = true;
id[now] = f;
counter[f]++;
for (int i = 0; i < (int)way[now].size(); i++)
if (dfs(way[now][i], !f) == false)
return false;
return true;
}
bool solve() {
int n, m;
int a, b;
scanf("%d%d", &n, &m);
if (n == 0)
return false;
for (int i = 0; i < n; i++)
way[i] = vector<int>();
memset(visited, 0, sizeof(visited));
counter[0] = counter[1] = 0;
for (int i = 0; i < m; i++) {
scanf("%d%d", &a, &b);
a--;
b--;
way[a].push_back(b);
way[b].push_back(a);
}
if (!dfs(0, 0)) {
puts("0");
} else {
// cerr << counter[0] << " " << counter[1] << endl;
if (counter[0] > counter[1])
swap(counter[0], counter[1]);
vector<int> vec;
if (counter[0] % 2 == 0) {
vec.push_back(counter[0] / 2);
}
if (counter[0] != counter[1] && counter[1] % 2 == 0) {
vec.push_back(counter[1] / 2);
}
printf("%d\n", (int)vec.size());
for (int i = 0; i < vec.size(); i++) {
printf("%d\n", vec[i]);
}
}
return true;
}
int main() {
while (solve())
;
}
|
replace
| 53 | 54 | 53 | 54 |
0
|
4 2
1 1
2 2
3 2
|
p01985
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for (int i = 0; i < n; i++)
int main() {
while (1) {
int n, m;
cin >> n >> m;
if (n == 0 && m == 0)
break;
vector<int> road[1000];
lp(i, n) { road[i].clear(); }
lp(i, m) {
int a, b;
cin >> a >> b;
a--;
b--;
road[a].push_back(b);
road[b].push_back(a);
}
int ans[1000], anscount = 0;
lp(i, 1000) { ans[i] = 0; }
lp(i, n) {
int a[1000];
lp(j, n) { a[j] = 0; }
int result = 0, act;
int hoge;
lp(i, n) { cout << a[i]; }
cin >> hoge;
a[i] = 1;
while (1) {
act = 0;
for (int j = 0; j < n; j++) {
if (a[j] == 1) {
for (int k = 0; k < road[j].size(); k++) {
if (a[road[j][k]] == 0) {
a[road[j][k]] = 2;
act = 1;
}
}
}
if (a[j] == 2) {
for (int k = 0; k < road[j].size(); k++) {
if (a[road[j][k]] == 0) {
a[road[j][k]] = 1;
act = 1;
}
}
}
}
if (act == 0)
break;
}
lp(i, n) {
for (int j = 0; j < road[i].size(); j++) {
if (a[i] == a[road[i][j]]) {
result = -1;
break;
}
}
if (result == -1)
break;
}
if (result == 0) {
int count = 0;
lp(i, n) {
if (a[i] == 1)
count++;
}
if (count % 2 == 0) {
if (ans[count / 2] == 0) {
ans[count / 2] = 1;
anscount++;
}
}
}
}
cout << anscount << endl;
lp(i, 500) {
if (ans[i] == 1)
cout << i << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define lp(i, n) for (int i = 0; i < n; i++)
int main() {
while (1) {
int n, m;
cin >> n >> m;
if (n == 0 && m == 0)
break;
vector<int> road[1000];
lp(i, n) { road[i].clear(); }
lp(i, m) {
int a, b;
cin >> a >> b;
a--;
b--;
road[a].push_back(b);
road[b].push_back(a);
}
int ans[1000], anscount = 0;
lp(i, 1000) { ans[i] = 0; }
lp(i, n) {
int a[1000];
lp(j, n) { a[j] = 0; }
int result = 0, act;
a[i] = 1;
while (1) {
act = 0;
for (int j = 0; j < n; j++) {
if (a[j] == 1) {
for (int k = 0; k < road[j].size(); k++) {
if (a[road[j][k]] == 0) {
a[road[j][k]] = 2;
act = 1;
}
}
}
if (a[j] == 2) {
for (int k = 0; k < road[j].size(); k++) {
if (a[road[j][k]] == 0) {
a[road[j][k]] = 1;
act = 1;
}
}
}
}
if (act == 0)
break;
}
lp(i, n) {
for (int j = 0; j < road[i].size(); j++) {
if (a[i] == a[road[i][j]]) {
result = -1;
break;
}
}
if (result == -1)
break;
}
if (result == 0) {
int count = 0;
lp(i, n) {
if (a[i] == 1)
count++;
}
if (count % 2 == 0) {
if (ans[count / 2] == 0) {
ans[count / 2] = 1;
anscount++;
}
}
}
}
cout << anscount << endl;
lp(i, 500) {
if (ans[i] == 1)
cout << i << endl;
}
}
return 0;
}
|
delete
| 26 | 29 | 26 | 26 |
-6
|
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p02022
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6;
const ll LINF = 1e18;
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (int i = (a); i < (b); i++)
#define rrrep(i, a, b) for (int i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
ll n, cnt, ans, a[ohara], b[ohara], c, d, tmp, tmpp, m, h, w, x, y, sum, pos, k;
ld doua;
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;
bool fl;
struct edge {
int to, cost;
};
//-------------------------↓↓↓↓↓↓------------------------
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> m;
rep(i, n) cin >> a[i];
rep(i, m) cin >> b[i];
rep(i, n) {
rep(j, m) { ans += a[i] * b[j]; }
}
Cout(ans);
return 0;
}
|
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6;
const ll LINF = 1e18;
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (int i = (a); i < (b); i++)
#define rrrep(i, a, b) for (int i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
ll n, cnt, ans, a[ohara], b[ohara], c, d, tmp, tmpp, m, h, w, x, y, sum, pos, k;
ld doua;
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;
bool fl;
struct edge {
int to, cost;
};
//-------------------------↓↓↓↓↓↓------------------------
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n >> m;
rep(i, n) cin >> a[i];
rep(i, m) cin >> b[i], sum += b[i];
rep(i, n) { ans += a[i] * sum; }
Cout(ans);
return 0;
}
|
replace
| 34 | 38 | 34 | 36 |
TLE
| |
p02022
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define int long long
using namespace std;
int a[1919], b[1919];
signed main() {
int n, m, cnt = 0, cnta = 0;
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int j = 0; j < m; j++)
cin >> b[j];
for (int i = 0; i < n; i++) {
cnt += a[i];
}
for (int j = 0; j < m; j++) {
cnta += b[j];
}
cout << cnt * cnta << endl;
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define int long long
using namespace std;
int a[191919], b[191919];
signed main() {
int n, m, cnt = 0, cnta = 0;
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> a[i];
for (int j = 0; j < m; j++)
cin >> b[j];
for (int i = 0; i < n; i++) {
cnt += a[i];
}
for (int j = 0; j < m; j++) {
cnta += b[j];
}
cout << cnt * cnta << endl;
}
|
replace
| 8 | 9 | 8 | 9 |
0
| |
p02022
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
long long a[1010];
long long ans = 0;
long long tmp = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
long long b;
for (int i = 0; i < m; i++) {
cin >> b;
tmp += b;
}
for (int i = 0; i < n; i++) {
ans += a[i] * tmp;
}
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
long long a[100010];
long long ans = 0;
long long tmp = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
long long b;
for (int i = 0; i < m; i++) {
cin >> b;
tmp += b;
}
for (int i = 0; i < n; i++) {
ans += a[i] * tmp;
}
cout << ans << endl;
return 0;
}
|
replace
| 7 | 8 | 7 | 8 |
0
| |
p02026
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
int a[200000], b[200000];
ll d[200000];
vector<P> E[200000];
int main() {
int n;
cin >> n;
vector<P> A, B;
rep(i, n) scanf("%d", &a[i]), A.push_back(P(a[i], i));
rep(i, n) scanf("%d", &b[i]), B.push_back(P(b[i], i));
sort(A.begin(), A.end());
sort(B.begin(), B.end());
rep(i, n - 1) {
E[A[i + 1].second].push_back(P(A[i + 1].first - A[i].first, A[i].second));
E[A[i].second].push_back(P(A[i + 1].first - A[i].first, A[i + 1].second));
E[B[i + 1].second].push_back(P(B[i + 1].first - B[i].first, B[i].second));
E[B[i].second].push_back(P(B[i + 1].first - B[i].first, B[i + 1].second));
}
memset(d, 0x3f, sizeof(d));
priority_queue<P> que;
d[0] = 0;
que.push(P(0, 0));
while (!que.empty()) {
P p = que.top();
que.pop();
if (d[p.second] != p.first)
continue;
for (auto u : E[p.second]) {
if (p.first + u.first < d[u.second]) {
d[u.second] = p.first + u.first;
que.push(P(d[u.second], u.second));
}
}
}
rep(i, n) { printf("%lld\n", d[i]); }
}
|
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<ll, int> P;
int a[200000], b[200000];
ll d[200000];
vector<P> E[200000];
int main() {
int n;
cin >> n;
vector<P> A, B;
rep(i, n) scanf("%d", &a[i]), A.push_back(P(a[i], i));
rep(i, n) scanf("%d", &b[i]), B.push_back(P(b[i], i));
sort(A.begin(), A.end());
sort(B.begin(), B.end());
rep(i, n - 1) {
E[A[i + 1].second].push_back(P(A[i + 1].first - A[i].first, A[i].second));
E[A[i].second].push_back(P(A[i + 1].first - A[i].first, A[i + 1].second));
E[B[i + 1].second].push_back(P(B[i + 1].first - B[i].first, B[i].second));
E[B[i].second].push_back(P(B[i + 1].first - B[i].first, B[i + 1].second));
}
memset(d, 0x3f, sizeof(d));
priority_queue<P, vector<P>, greater<P>> que;
d[0] = 0;
que.push(P(0, 0));
while (!que.empty()) {
P p = que.top();
que.pop();
if (d[p.second] != p.first)
continue;
for (auto u : E[p.second]) {
if (p.first + u.first < d[u.second]) {
d[u.second] = p.first + u.first;
que.push(P(d[u.second], u.second));
}
}
}
rep(i, n) { printf("%lld\n", d[i]); }
}
|
replace
| 29 | 30 | 29 | 30 |
TLE
| |
p02026
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll, ll>
#define iP pair<int, int>
typedef long long ll;
using namespace std;
const int mod = 1e9 + 7;
ll N, A[100000], B[100000], MIN[100000], aa[100000], bb[100000];
lP a[100000], b[100000];
priority_queue<lP, vector<lP>, greater<lP>> q;
int main() {
cin >> N;
for (int i = 0; i != N; ++i) {
cin >> A[i];
a[i] = mkp(A[i], i);
MIN[i] = llmax;
}
for (int i = 0; i != N; ++i) {
cin >> B[i];
b[i] = mkp(B[i], i);
}
sort(a, a + N);
sort(b, b + N);
for (int i = 0; i != N; ++i) {
aa[a[i].second] = i;
bb[b[i].second] = i;
}
MIN[0] = 0;
q.push(mkp(0, 0));
while (!q.empty()) {
int qf = q.top().first, qs = q.top().second;
q.pop();
if (qf == MIN[qs]) {
for (int i = aa[qs] - 1; i != -1; --i) {
if (qf + a[aa[qs]].first - a[i].first < MIN[a[i].second]) {
MIN[a[i].second] = qf + a[aa[qs]].first - a[i].first;
q.push(mkp(qf + a[aa[qs]].first - a[i].first, a[i].second));
} else
break;
}
for (int i = aa[qs] + 1; i != N; ++i) {
if (qf + a[i].first - a[aa[qs]].first < MIN[a[i].second]) {
MIN[a[i].second] = qf + a[i].first - a[aa[qs]].first;
q.push(mkp(qf + a[i].first - a[aa[qs]].first, a[i].second));
} else
break;
}
for (int i = bb[qs] - 1; i != -1; --i) {
if (qf + b[bb[qs]].first - b[i].first < MIN[b[i].second]) {
MIN[b[i].second] = qf + b[bb[qs]].first - b[i].first;
q.push(mkp(qf + b[bb[qs]].first - b[i].first, b[i].second));
} else
break;
}
for (int i = bb[qs] + 1; i != N; ++i) {
if (qf + b[i].first - b[bb[qs]].first < MIN[b[i].second]) {
MIN[b[i].second] = qf + b[i].first - b[bb[qs]].first;
q.push(mkp(qf + b[i].first - b[bb[qs]].first, b[i].second));
}
}
}
}
for (int i = 0; i != N; ++i) {
cout << MIN[i] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll, ll>
#define iP pair<int, int>
typedef long long ll;
using namespace std;
const int mod = 1e9 + 7;
ll N, A[100000], B[100000], MIN[100000], aa[100000], bb[100000];
lP a[100000], b[100000];
priority_queue<lP, vector<lP>, greater<lP>> q;
int main() {
cin >> N;
for (int i = 0; i != N; ++i) {
cin >> A[i];
a[i] = mkp(A[i], i);
MIN[i] = llmax;
}
for (int i = 0; i != N; ++i) {
cin >> B[i];
b[i] = mkp(B[i], i);
}
sort(a, a + N);
sort(b, b + N);
for (int i = 0; i != N; ++i) {
aa[a[i].second] = i;
bb[b[i].second] = i;
}
MIN[0] = 0;
q.push(mkp(0, 0));
while (!q.empty()) {
int qf = q.top().first, qs = q.top().second;
q.pop();
if (qf == MIN[qs]) {
for (int i = aa[qs] - 1; i != -1; --i) {
if (qf + a[aa[qs]].first - a[i].first < MIN[a[i].second]) {
MIN[a[i].second] = qf + a[aa[qs]].first - a[i].first;
q.push(mkp(qf + a[aa[qs]].first - a[i].first, a[i].second));
} else
break;
}
for (int i = aa[qs] + 1; i != N; ++i) {
if (qf + a[i].first - a[aa[qs]].first < MIN[a[i].second]) {
MIN[a[i].second] = qf + a[i].first - a[aa[qs]].first;
q.push(mkp(qf + a[i].first - a[aa[qs]].first, a[i].second));
} else
break;
}
for (int i = bb[qs] - 1; i != -1; --i) {
if (qf + b[bb[qs]].first - b[i].first < MIN[b[i].second]) {
MIN[b[i].second] = qf + b[bb[qs]].first - b[i].first;
q.push(mkp(qf + b[bb[qs]].first - b[i].first, b[i].second));
} else
break;
}
for (int i = bb[qs] + 1; i != N; ++i) {
if (qf + b[i].first - b[bb[qs]].first < MIN[b[i].second]) {
MIN[b[i].second] = qf + b[i].first - b[bb[qs]].first;
q.push(mkp(qf + b[i].first - b[bb[qs]].first, b[i].second));
} else
break;
}
}
}
for (int i = 0; i != N; ++i) {
cout << MIN[i] << endl;
}
return 0;
}
|
replace
| 64 | 65 | 64 | 66 |
TLE
| |
p02028
|
C++
|
Runtime Error
|
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfenv>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
// #include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7; // 924844033 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr << #x << ": " << x << '\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll {
LL first, second, third;
};
struct Fll {
LL first, second, third, fourth;
};
typedef pair<LL, Tll> Ptll;
#define rep(i, rept) for (LL i = 0; i < rept; i++)
#define Rrep(i, mf) for (LL i = mf - 1; i >= 0; i--)
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum[2][300000], ans,
dp[30][200000], a[200000], b[200000];
string str, ss;
bool f;
char c;
int di[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
struct Edge {
LL to, cost;
};
struct edge {
LL from, to, cost;
};
vector<vector<Edge>> vec;
vector<edge> ed;
vector<LL> v;
map<LL, LL> ma;
set<LL> st;
void YN(bool f) {
if (f)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
void yn(bool f) {
if (f)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
map<LL, LL> zip;
int unzip[20000];
int compress(vector<LL> &x) {
sort(x.begin(), x.end());
x.erase(unique(x.begin(), x.end()), x.end());
for (int i = 0; i < x.size(); i++) {
zip[x[i]] = i;
unzip[i] = x[i];
}
return x.size();
}
int main() {
cin >> n >> m;
rep(i, n) {
cin >> a[i];
v.push_back(a[i]);
k += a[i];
}
rep(i, m) {
cin >> b[i];
v.push_back(b[i]);
}
v.push_back(0);
compress(v);
rep(i, n) a[i] = zip[a[i]], sum[0][a[i]]++, sum[1][a[i]] += unzip[a[i]];
rep(i, m) b[i] = zip[b[i]];
rep(i, 210000) sum[0][i + 1] += sum[0][i], sum[1][i + 1] += sum[1][i];
rep(i, m) { ans += (n - sum[0][b[i]]) * unzip[b[i]] + sum[1][b[i]]; }
cout << ans << endl;
return 0;
}
/*
245
3
1
5
*/
|
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfenv>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
// #include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7; // 924844033 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr << #x << ": " << x << '\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll {
LL first, second, third;
};
struct Fll {
LL first, second, third, fourth;
};
typedef pair<LL, Tll> Ptll;
#define rep(i, rept) for (LL i = 0; i < rept; i++)
#define Rrep(i, mf) for (LL i = mf - 1; i >= 0; i--)
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum[2][300000], ans,
dp[30][200000], a[200000], b[200000];
string str, ss;
bool f;
char c;
int di[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
struct Edge {
LL to, cost;
};
struct edge {
LL from, to, cost;
};
vector<vector<Edge>> vec;
vector<edge> ed;
vector<LL> v;
map<LL, LL> ma;
set<LL> st;
void YN(bool f) {
if (f)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
void yn(bool f) {
if (f)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
map<LL, LL> zip;
LL unzip[300000];
int compress(vector<LL> &x) {
sort(x.begin(), x.end());
x.erase(unique(x.begin(), x.end()), x.end());
for (int i = 0; i < x.size(); i++) {
zip[x[i]] = i;
unzip[i] = x[i];
}
return x.size();
}
int main() {
cin >> n >> m;
rep(i, n) {
cin >> a[i];
v.push_back(a[i]);
k += a[i];
}
rep(i, m) {
cin >> b[i];
v.push_back(b[i]);
}
v.push_back(0);
compress(v);
rep(i, n) a[i] = zip[a[i]], sum[0][a[i]]++, sum[1][a[i]] += unzip[a[i]];
rep(i, m) b[i] = zip[b[i]];
rep(i, 210000) sum[0][i + 1] += sum[0][i], sum[1][i + 1] += sum[1][i];
rep(i, m) { ans += (n - sum[0][b[i]]) * unzip[b[i]] + sum[1][b[i]]; }
cout << ans << endl;
return 0;
}
/*
245
3
1
5
*/
|
replace
| 91 | 92 | 91 | 92 |
0
| |
p02030
|
C++
|
Memory Limit Exceeded
|
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;
int main(void) {
int n, m;
scanf("%d %d", &n, &m);
int a[n];
int b[m];
vector<int> dup, all;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (int j = 0; j < m; j++) {
scanf("%d", &b[j]);
}
int ap = 0;
int bp = 0;
int i = 1;
while (ap != n or bp != m) {
if (a[ap] == i and b[bp] == i)
dup.push_back(i);
if (a[ap] == i or b[bp] == i)
all.push_back(i);
while (a[ap] <= i and ap != n)
ap++;
while (b[bp] <= i and bp != m)
bp++;
if (ap != n and a[ap] < b[bp]) {
i = a[ap];
} else if (bp != n and a[ap] >= b[bp]) {
i = b[bp];
} else if (ap == n) {
i = b[bp];
} else {
i = a[ap];
}
}
printf("%d %d\n", dup.size(), all.size());
for (auto itr = dup.begin(); itr != dup.end(); ++itr) {
printf("%d\n", *itr);
}
for (auto itr = all.begin(); itr != all.end(); ++itr) {
printf("%d\n", *itr);
}
return 0;
}
|
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;
int main(void) {
int n, m;
scanf("%d %d", &n, &m);
int a[n];
int b[m];
vector<int> dup, all;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (int j = 0; j < m; j++) {
scanf("%d", &b[j]);
}
int ap = 0;
int bp = 0;
int i = 1;
while (ap != n or bp != m) {
if (a[ap] == i and b[bp] == i)
dup.push_back(i);
if (a[ap] == i or b[bp] == i)
all.push_back(i);
while (a[ap] <= i and ap != n)
ap++;
while (b[bp] <= i and bp != m)
bp++;
if (ap != n and a[ap] < b[bp]) {
i = a[ap];
} else if (bp != m and a[ap] >= b[bp]) {
i = b[bp];
} else if (ap == n) {
i = b[bp];
} else {
i = a[ap];
}
}
printf("%d %d\n", dup.size(), all.size());
for (auto itr = dup.begin(); itr != dup.end(); ++itr) {
printf("%d\n", *itr);
}
for (auto itr = all.begin(); itr != all.end(); ++itr) {
printf("%d\n", *itr);
}
return 0;
}
|
replace
| 36 | 37 | 36 | 37 |
MLE
| |
p02100
|
C++
|
Runtime Error
|
// need
#include <algorithm>
#include <iostream>
// data structure
#include <bitset>
// #include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
// #include <array>
// #include <tuple>
#include <complex>
#include <unordered_map>
#include <unordered_set>
// #include <deque>
#include <valarray>
// stream
// #include <istream>
// #include <sstream>
// #include <ostream>
// etc
#include <cassert>
#include <functional>
#include <iomanip>
// #include <typeinfo>
#include <chrono>
#include <numeric>
#include <random>
#define INIT \
std::ios::sync_with_stdio(false); \
std::cin.tie(0);
#define VAR(type, ...) \
type __VA_ARGS__; \
MACRO_VAR_Scan(__VA_ARGS__);
template <typename T> void MACRO_VAR_Scan(T &t) { std::cin >> t; }
template <typename First, typename... Rest>
void MACRO_VAR_Scan(First &first, Rest &...rest) {
std::cin >> first;
MACRO_VAR_Scan(rest...);
}
#define VEC_ROW(type, n, ...) \
std::vector<type> __VA_ARGS__; \
MACRO_VEC_ROW_Init(n, __VA_ARGS__); \
for (int i = 0; i < n; ++i) { \
MACRO_VEC_ROW_Scan(i, __VA_ARGS__); \
}
template <typename T> void MACRO_VEC_ROW_Init(int n, T &t) { t.resize(n); }
template <typename First, typename... Rest>
void MACRO_VEC_ROW_Init(int n, First &first, Rest &...rest) {
first.resize(n);
MACRO_VEC_ROW_Init(n, rest...);
}
template <typename T> void MACRO_VEC_ROW_Scan(int p, T &t) { std::cin >> t[p]; }
template <typename First, typename... Rest>
void MACRO_VEC_ROW_Scan(int p, First &first, Rest &...rest) {
std::cin >> first[p];
MACRO_VEC_ROW_Scan(p, rest...);
}
#define OUT(d) std::cout << d;
#define FOUT(n, d) std::cout << std::fixed << std::setprecision(n) << d;
#define SOUT(n, c, d) std::cout << std::setw(n) << std::setfill(c) << d;
#define SP std::cout << " ";
#define TAB std::cout << "\t";
#define BR std::cout << "\n";
#define ENDL std::cout << std::endl;
#define FLUSH std::cout << std::flush;
#define VEC(type, c, n) \
std::vector<type> c(n); \
for (auto &i : c) \
std::cin >> i;
#define MAT(type, c, m, n) \
std::vector<std::vector<type>> c(m, std::vector<type>(n)); \
for (auto &r : c) \
for (auto &i : r) \
std::cin >> i;
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define FORLL(i, a, b) for (ll i = ll(a); i < ll(b); ++i)
#define RFORLL(i, a, b) for (ll i = ll(b) - 1; i >= ll(a); --i)
#define REPLL(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREPLL(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define PAIR std::pair<int, int>
#define PAIRLL std::pair<ll, ll>
#define IN(a, x, b) (a <= x && x < b)
#define SHOW(d) \
{ std::cerr << #d << "\t:" << d << "\n"; }
#define SHOWVECTOR(v) \
{ \
std::cerr << #v << "\t:"; \
for (const auto &xxx : v) { \
std::cerr << xxx << " "; \
} \
std::cerr << "\n"; \
}
#define SHOWVECTOR2(v) \
{ \
std::cerr << #v << "\t:\n"; \
for (const auto &xxx : v) { \
for (const auto &yyy : xxx) { \
std::cerr << yyy << " "; \
} \
std::cerr << "\n"; \
} \
}
#define SHOWPAIR(p) \
{ std::cerr << #p << "\t:(" << p.first << ",\t" << p.second << ")\n"; }
#define SHOWPAIRVECTOR2(v) \
{ \
std::cerr << #v << "\t:\n"; \
for (const auto &xxx : v) { \
for (const auto &yyy : xxx) { \
std::cerr << '(' << yyy.first << ", " << yyy.second << ") "; \
} \
std::cerr << "\n"; \
} \
}
#define SHOWPAIRVECTOR(v) \
{ \
for (const auto &xxx : v) { \
std::cerr << '(' << xxx.first << ", " << xxx.second << ") "; \
} \
std::cerr << "\n"; \
}
#define SHOWQUEUE(a) \
{ \
std::queue<decltype(a.front())> tmp(a); \
std::cerr << #a << "\t:"; \
for (int i = 0; i < static_cast<int>(a.size()); ++i) { \
std::cerr << tmp.front() << "\n"; \
tmp.pop(); \
} \
std::cerr << "\n"; \
}
template <typename T> inline T CHMAX(T &a, const T b) {
return a = (a < b) ? b : a;
}
template <typename T> inline T CHMIN(T &a, const T b) {
return a = (a > b) ? b : a;
}
#define EXCEPTION(msg) \
throw std::string("Exception : " msg " [ in ") + __func__ + " : " + \
std::to_string(__LINE__) + " lines ]"
#define TRY(cond, msg) \
try { \
if (cond) \
EXCEPTION(msg); \
} catch (std::string s) { \
std::cerr << s << std::endl; \
}
void CHECKTIME(std::function<void()> f) {
auto start = std::chrono::system_clock::now();
f();
auto end = std::chrono::system_clock::now();
auto res = std::chrono::duration_cast<std::chrono::nanoseconds>((end - start))
.count();
std::cerr << "[Time:" << res << "ns (" << res / (1.0e9) << "s)]\n";
}
#define int ll
using ll = long long;
using ull = unsigned long long;
constexpr int INFINT = 1 << 30; // 1.07x10^ 9
constexpr int INFINT_LIM = (1LL << 31) - 1; // 2.15x10^ 9
constexpr ll INFLL = 1LL << 60; // 1.15x10^18
constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62); // 9.22x10^18
constexpr double EPS = 1e-7;
constexpr int MOD = 1000000007;
constexpr double PI = 3.141592653589793238462643383279;
using State = std::string::const_iterator;
int number(State &it) {
int res = 0;
bool minus = false;
if (*it == '+') {
++it;
} else if (*it == '-') {
minus = true;
++it;
}
if (*it != 'x') {
while (isdigit(*it)) {
res *= 10;
res += *it - '0';
++it;
}
} else {
res = 1;
}
if (minus) {
res *= -1;
}
return res;
}
PAIR term(State &it) {
int t = number(it);
if (*it != 'x') {
return PAIR(0, t);
}
++it; // x
if (*it != '^') {
return PAIR(1, t);
}
++it; // ^
int p = number(it);
return PAIR(p, t);
}
std::vector<PAIR> expression(State &it) {
std::vector<PAIR> res;
do {
res.emplace_back(term(it));
} while (*it == '+' || *it == '-');
return res;
}
ll mypow(ll n, ll p) {
ll res = 1;
while (p) {
if (p & 1)
res *= n;
n *= n;
p >>= 1;
}
return res;
}
signed main() {
INIT;
VAR(std::string, s);
s = '+' + s + '$';
auto it = s.cbegin();
auto exp(expression(it));
SHOWPAIRVECTOR(exp);
std::string res;
RFOR(i, -2001, 2001) {
ll t = 0;
for (const auto &x : exp) {
t += x.second * mypow(i, x.first);
}
if (t == 0) {
res += "(x";
if (i < 0)
res += "+";
res += std::to_string(-i);
res += ")";
}
}
OUT(res) BR;
return 0;
}
|
// need
#include <algorithm>
#include <iostream>
// data structure
#include <bitset>
// #include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
// #include <array>
// #include <tuple>
#include <complex>
#include <unordered_map>
#include <unordered_set>
// #include <deque>
#include <valarray>
// stream
// #include <istream>
// #include <sstream>
// #include <ostream>
// etc
#include <cassert>
#include <functional>
#include <iomanip>
// #include <typeinfo>
#include <chrono>
#include <numeric>
#include <random>
#define INIT \
std::ios::sync_with_stdio(false); \
std::cin.tie(0);
#define VAR(type, ...) \
type __VA_ARGS__; \
MACRO_VAR_Scan(__VA_ARGS__);
template <typename T> void MACRO_VAR_Scan(T &t) { std::cin >> t; }
template <typename First, typename... Rest>
void MACRO_VAR_Scan(First &first, Rest &...rest) {
std::cin >> first;
MACRO_VAR_Scan(rest...);
}
#define VEC_ROW(type, n, ...) \
std::vector<type> __VA_ARGS__; \
MACRO_VEC_ROW_Init(n, __VA_ARGS__); \
for (int i = 0; i < n; ++i) { \
MACRO_VEC_ROW_Scan(i, __VA_ARGS__); \
}
template <typename T> void MACRO_VEC_ROW_Init(int n, T &t) { t.resize(n); }
template <typename First, typename... Rest>
void MACRO_VEC_ROW_Init(int n, First &first, Rest &...rest) {
first.resize(n);
MACRO_VEC_ROW_Init(n, rest...);
}
template <typename T> void MACRO_VEC_ROW_Scan(int p, T &t) { std::cin >> t[p]; }
template <typename First, typename... Rest>
void MACRO_VEC_ROW_Scan(int p, First &first, Rest &...rest) {
std::cin >> first[p];
MACRO_VEC_ROW_Scan(p, rest...);
}
#define OUT(d) std::cout << d;
#define FOUT(n, d) std::cout << std::fixed << std::setprecision(n) << d;
#define SOUT(n, c, d) std::cout << std::setw(n) << std::setfill(c) << d;
#define SP std::cout << " ";
#define TAB std::cout << "\t";
#define BR std::cout << "\n";
#define ENDL std::cout << std::endl;
#define FLUSH std::cout << std::flush;
#define VEC(type, c, n) \
std::vector<type> c(n); \
for (auto &i : c) \
std::cin >> i;
#define MAT(type, c, m, n) \
std::vector<std::vector<type>> c(m, std::vector<type>(n)); \
for (auto &r : c) \
for (auto &i : r) \
std::cin >> i;
#define ALL(a) (a).begin(), (a).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define REP(i, n) for (int i = 0; i < int(n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define FORLL(i, a, b) for (ll i = ll(a); i < ll(b); ++i)
#define RFORLL(i, a, b) for (ll i = ll(b) - 1; i >= ll(a); --i)
#define REPLL(i, n) for (ll i = 0; i < ll(n); ++i)
#define RREPLL(i, n) for (ll i = ll(n) - 1; i >= 0; --i)
#define PAIR std::pair<int, int>
#define PAIRLL std::pair<ll, ll>
#define IN(a, x, b) (a <= x && x < b)
#define SHOW(d) \
{ std::cerr << #d << "\t:" << d << "\n"; }
#define SHOWVECTOR(v) \
{ \
std::cerr << #v << "\t:"; \
for (const auto &xxx : v) { \
std::cerr << xxx << " "; \
} \
std::cerr << "\n"; \
}
#define SHOWVECTOR2(v) \
{ \
std::cerr << #v << "\t:\n"; \
for (const auto &xxx : v) { \
for (const auto &yyy : xxx) { \
std::cerr << yyy << " "; \
} \
std::cerr << "\n"; \
} \
}
#define SHOWPAIR(p) \
{ std::cerr << #p << "\t:(" << p.first << ",\t" << p.second << ")\n"; }
#define SHOWPAIRVECTOR2(v) \
{ \
std::cerr << #v << "\t:\n"; \
for (const auto &xxx : v) { \
for (const auto &yyy : xxx) { \
std::cerr << '(' << yyy.first << ", " << yyy.second << ") "; \
} \
std::cerr << "\n"; \
} \
}
#define SHOWPAIRVECTOR(v) \
{ \
for (const auto &xxx : v) { \
std::cerr << '(' << xxx.first << ", " << xxx.second << ") "; \
} \
std::cerr << "\n"; \
}
#define SHOWQUEUE(a) \
{ \
std::queue<decltype(a.front())> tmp(a); \
std::cerr << #a << "\t:"; \
for (int i = 0; i < static_cast<int>(a.size()); ++i) { \
std::cerr << tmp.front() << "\n"; \
tmp.pop(); \
} \
std::cerr << "\n"; \
}
template <typename T> inline T CHMAX(T &a, const T b) {
return a = (a < b) ? b : a;
}
template <typename T> inline T CHMIN(T &a, const T b) {
return a = (a > b) ? b : a;
}
#define EXCEPTION(msg) \
throw std::string("Exception : " msg " [ in ") + __func__ + " : " + \
std::to_string(__LINE__) + " lines ]"
#define TRY(cond, msg) \
try { \
if (cond) \
EXCEPTION(msg); \
} catch (std::string s) { \
std::cerr << s << std::endl; \
}
void CHECKTIME(std::function<void()> f) {
auto start = std::chrono::system_clock::now();
f();
auto end = std::chrono::system_clock::now();
auto res = std::chrono::duration_cast<std::chrono::nanoseconds>((end - start))
.count();
std::cerr << "[Time:" << res << "ns (" << res / (1.0e9) << "s)]\n";
}
#define int ll
using ll = long long;
using ull = unsigned long long;
constexpr int INFINT = 1 << 30; // 1.07x10^ 9
constexpr int INFINT_LIM = (1LL << 31) - 1; // 2.15x10^ 9
constexpr ll INFLL = 1LL << 60; // 1.15x10^18
constexpr ll INFLL_LIM = (1LL << 62) - 1 + (1LL << 62); // 9.22x10^18
constexpr double EPS = 1e-7;
constexpr int MOD = 1000000007;
constexpr double PI = 3.141592653589793238462643383279;
using State = std::string::const_iterator;
int number(State &it) {
int res = 0;
bool minus = false;
if (*it == '+') {
++it;
} else if (*it == '-') {
minus = true;
++it;
}
if (*it != 'x') {
while (isdigit(*it)) {
res *= 10;
res += *it - '0';
++it;
}
} else {
res = 1;
}
if (minus) {
res *= -1;
}
return res;
}
PAIR term(State &it) {
int t = number(it);
if (*it != 'x') {
return PAIR(0, t);
}
++it; // x
if (*it != '^') {
return PAIR(1, t);
}
++it; // ^
int p = number(it);
return PAIR(p, t);
}
std::vector<PAIR> expression(State &it) {
std::vector<PAIR> res;
do {
res.emplace_back(term(it));
} while (*it == '+' || *it == '-');
return res;
}
ll mypow(ll n, ll p) {
ll res = 1;
while (p) {
if (p & 1)
res *= n;
n *= n;
p >>= 1;
}
return res;
}
signed main() {
INIT;
VAR(std::string, s);
s = '+' + s + '$';
auto it = s.cbegin();
auto exp(expression(it));
std::string res;
RFOR(i, -2001, 2001) {
ll t = 0;
for (const auto &x : exp) {
t += x.second * mypow(i, x.first);
}
if (t == 0) {
res += "(x";
if (i < 0)
res += "+";
res += std::to_string(-i);
res += ")";
}
}
OUT(res) BR;
return 0;
}
|
delete
| 245 | 246 | 245 | 245 |
0
|
(2, 1) (1, 3) (0, 2)
|
p02100
|
C++
|
Runtime Error
|
#include "bits/stdc++.h"
using namespace std;
string st;
int a;
int getnum() {
int num = 0;
while (a != st.size() && isdigit(st[a])) {
num *= 10;
num += st[a] - '0';
a++;
}
return num;
}
vector<int> kou() {
vector<int> v(10);
if (st[a] == 'x') {
a++;
assert(st[a] == '^');
a++;
int n(getnum());
v[n] = 1;
} else {
int kei(getnum());
if (a == st.size() || st[a] == '+' || st[a] == '-') {
v[0] = kei;
} else {
assert(st[a] == 'x');
a++;
if (a == st.size() || st[a] == '+' || st[a] == '-') {
v[1] = kei;
} else {
assert(st[a] == '^');
a++;
int num(getnum());
v[num] = kei;
}
}
}
return v;
}
vector<int> takou() {
vector<int> v(kou());
while (a != st.size()) {
bool plus = true;
plus = st[a] == '+';
a++;
vector<int> w(kou());
if (plus) {
for (int i = 0; i < 10; ++i) {
v[i] += w[i];
}
} else {
for (int i = 0; i < 10; ++i) {
v[i] -= w[i];
}
}
}
return v;
}
long long int pow_int(long long int a, int b) {
if (b == 0)
return 1;
else {
return a * pow_int(a, b - 1);
}
}
int main() {
cin >> st;
a = 0;
auto v(takou());
vector<long long int> anss;
for (long long int i = -4000; i <= 4000; ++i) {
long long int sum = 0;
for (int j = 0; j <= 5; ++j) {
sum += pow_int(i, j) * v[j];
}
if (sum == 0) {
anss.push_back(i);
}
}
reverse(anss.begin(), anss.end());
for (auto ans : anss) {
cout << "(x";
if (ans > 0) {
cout << "-" << ans;
} else {
cout << "+" << -ans;
}
cout << ")";
}
cout << endl;
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
string st;
int a;
int getnum() {
int num = 0;
while (a != st.size() && isdigit(st[a])) {
num *= 10;
num += st[a] - '0';
a++;
}
return num;
}
vector<int> kou() {
vector<int> v(10);
if (st[a] == 'x') {
a++;
if (a == st.size() || st[a] != '^') {
v[1] = 1;
} else {
assert(st[a] == '^');
a++;
int n(getnum());
v[n] = 1;
}
} else {
int kei(getnum());
if (a == st.size() || st[a] == '+' || st[a] == '-') {
v[0] = kei;
} else {
assert(st[a] == 'x');
a++;
if (a == st.size() || st[a] == '+' || st[a] == '-') {
v[1] = kei;
} else {
assert(st[a] == '^');
a++;
int num(getnum());
v[num] = kei;
}
}
}
return v;
}
vector<int> takou() {
vector<int> v(kou());
while (a != st.size()) {
bool plus = true;
plus = st[a] == '+';
a++;
vector<int> w(kou());
if (plus) {
for (int i = 0; i < 10; ++i) {
v[i] += w[i];
}
} else {
for (int i = 0; i < 10; ++i) {
v[i] -= w[i];
}
}
}
return v;
}
long long int pow_int(long long int a, int b) {
if (b == 0)
return 1;
else {
return a * pow_int(a, b - 1);
}
}
int main() {
cin >> st;
a = 0;
auto v(takou());
vector<long long int> anss;
for (long long int i = -4000; i <= 4000; ++i) {
long long int sum = 0;
for (int j = 0; j <= 5; ++j) {
sum += pow_int(i, j) * v[j];
}
if (sum == 0) {
anss.push_back(i);
}
}
reverse(anss.begin(), anss.end());
for (auto ans : anss) {
cout << "(x";
if (ans > 0) {
cout << "-" << ans;
} else {
cout << "+" << -ans;
}
cout << ")";
}
cout << endl;
return 0;
}
|
replace
| 18 | 22 | 18 | 27 |
0
| |
p02100
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define ALL(x) (x).begin(), (x).end()
using namespace std;
ll f(vector<ll> &a, ll x) {
return a[0] + a[1] * x + a[2] * x * x + a[3] * x * x * x +
a[4] * x * x * x * x + a[5] * x * x * x * x * x;
}
signed main() {
string str;
cin >> str;
vector<ll> a(10, 0);
for (int i = 0; i < str.size(); i++) {
if (str[i] == '+' || str[i] == '-') {
int j = i;
while (str[j] != 'x' && j < str.size())
j++;
int s;
if (j < str.size()) {
if (j != str.size() && str[j + 1] == '^') {
s = str[j + 2] - '0';
} else {
s = 1;
}
} else {
s = 0;
}
string temp = str.substr(i + 1, j - i - 1);
bool flag = true;
for (auto t : temp) {
if (t < '0' || t > '9') {
flag = false;
break;
}
}
if (flag) {
a[s] = stoll(temp);
} else {
a[s] = 1;
}
if (str[i] == '-') {
a[s] *= -1;
}
}
}
if (str[0] == 'x') {
if (str[1] == '^') {
a[str[2] - '0'] = 1;
} else {
a[1] = 1;
}
}
vector<ll> b;
for (ll i = -2 * 1000; i <= 2 * 1000; i++) {
if (f(a, i) == 0LL) {
b.push_back(i);
}
}
sort(ALL(b));
for (int i = b.size() - 1; i >= 0; i--) {
cout << "(x";
if (b[i] > 0) {
cout << "-";
} else {
cout << "+";
}
cout << llabs(b[i]);
cout << ")";
}
cout << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define ALL(x) (x).begin(), (x).end()
using namespace std;
ll f(vector<ll> &a, ll x) {
return a[0] + a[1] * x + a[2] * x * x + a[3] * x * x * x +
a[4] * x * x * x * x + a[5] * x * x * x * x * x;
}
signed main() {
string str;
cin >> str;
vector<ll> a(10, 0);
for (int i = 0; i < str.size(); i++) {
if (str[i] == '+' || str[i] == '-') {
int j = i;
while (str[j] != 'x' && j < str.size())
j++;
int s;
if (j < str.size()) {
if (j != str.size() && str[j + 1] == '^') {
s = str[j + 2] - '0';
} else {
s = 1;
}
} else {
s = 0;
}
string temp = str.substr(i + 1, j - i - 1);
bool flag = true;
for (auto t : temp) {
if (t < '0' || t > '9') {
flag = false;
break;
}
}
if (flag && temp.size() > 0) {
try {
a[s] = stoll(temp);
} catch (const std::invalid_argument) {
continue;
}
} else {
a[s] = 1;
}
if (str[i] == '-') {
a[s] *= -1;
}
}
}
if (str[0] == 'x') {
if (str[1] == '^') {
a[str[2] - '0'] = 1;
} else {
a[1] = 1;
}
}
vector<ll> b;
for (ll i = -2 * 1000; i <= 2 * 1000; i++) {
if (f(a, i) == 0LL) {
b.push_back(i);
}
}
sort(ALL(b));
for (int i = b.size() - 1; i >= 0; i--) {
cout << "(x";
if (b[i] > 0) {
cout << "-";
} else {
cout << "+";
}
cout << llabs(b[i]);
cout << ")";
}
cout << endl;
return 0;
}
|
replace
| 40 | 42 | 40 | 46 |
0
| |
p02101
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, p;
cin >> n >> p;
vector<int> X(n);
vector<int> Y(n);
for (int i = 0; i < n; i++) {
cin >> X[i] >> Y[i];
}
// Need[i][j] := i日目から連続して励まされていて、j日目に必要な励まし力
vector<vector<int>> Need(n, vector<int>(n, -1));
for (int i = 0; i < n; i++) {
int t = 0;
for (int j = i; j < n; j++) {
int now_x = max(0, X[j] - t);
t = max(0, Y[j] - now_x);
Need[i][j] = t;
// cout << t << " ";
}
// cout << endl;
}
// dp[i][j][k] := いままでj日学校行くことができている,k日連続で励まされている
int dp[10][10][10];
// dp初期化
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
for (int k = 0; k <= n; k++) {
dp[i][j][k] = -1;
}
}
}
dp[0][0][0] = p;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k <= i; k++) {
// cout << i << " " << j << " " << k << " " << dp[2][0][0] << endl;
// 行かない
dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k]);
/*if(j==0 && k==0){
cout << i << " " << j << " " << k << " " << dp[i][j][k] << " " <<
dp[i + 1][j][k] << endl;
}*/
// 行く
int need = Need[i - k][i];
if (need == 0)
dp[i + 1][j + 1][0] = max(dp[i + 1][j + 1][0], dp[i][j][k]);
else
dp[i + 1][j + 1][k + 1] =
max(dp[i + 1][j + 1][k + 1], dp[i][j][k] - need);
}
}
}
int ans = 0;
for (int j = 0; j <= n; j++) {
for (int k = 0; k <= n; k++) {
if (dp[n][j][k] >= 0)
ans = max(ans, j);
}
}
/*for(int i = 0; i <= n; i++){
for(int j = 0; j <= n; j++){
for(int k = 0; k <= n; k++){
cout << dp[i][j][k] << " ";
}
cout << endl;
}
cout << endl;
}*/
cout << ans << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, p;
cin >> n >> p;
vector<int> X(n);
vector<int> Y(n);
for (int i = 0; i < n; i++) {
cin >> X[i] >> Y[i];
}
// Need[i][j] := i日目から連続して励まされていて、j日目に必要な励まし力
vector<vector<int>> Need(n, vector<int>(n, -1));
for (int i = 0; i < n; i++) {
int t = 0;
for (int j = i; j < n; j++) {
int now_x = max(0, X[j] - t);
t = max(0, Y[j] - now_x);
Need[i][j] = t;
// cout << t << " ";
}
// cout << endl;
}
// dp[i][j][k] := いままでj日学校行くことができている,k日連続で励まされている
int dp[110][110][110];
// dp初期化
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
for (int k = 0; k <= n; k++) {
dp[i][j][k] = -1;
}
}
}
dp[0][0][0] = p;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
for (int k = 0; k <= i; k++) {
// cout << i << " " << j << " " << k << " " << dp[2][0][0] << endl;
// 行かない
dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][k]);
/*if(j==0 && k==0){
cout << i << " " << j << " " << k << " " << dp[i][j][k] << " " <<
dp[i + 1][j][k] << endl;
}*/
// 行く
int need = Need[i - k][i];
if (need == 0)
dp[i + 1][j + 1][0] = max(dp[i + 1][j + 1][0], dp[i][j][k]);
else
dp[i + 1][j + 1][k + 1] =
max(dp[i + 1][j + 1][k + 1], dp[i][j][k] - need);
}
}
}
int ans = 0;
for (int j = 0; j <= n; j++) {
for (int k = 0; k <= n; k++) {
if (dp[n][j][k] >= 0)
ans = max(ans, j);
}
}
/*for(int i = 0; i <= n; i++){
for(int j = 0; j <= n; j++){
for(int k = 0; k <= n; k++){
cout << dp[i][j][k] << " ";
}
cout << endl;
}
cout << endl;
}*/
cout << ans << endl;
return 0;
}
|
replace
| 28 | 29 | 28 | 29 |
0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.