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
|
---|---|---|---|---|---|---|---|---|---|---|---|
p02104
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int n, p, ans[100005];
deque<int> q, q2[100005];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
scanf("%d", &p);
q2[p - 1].push_back(i + 1);
}
for (int i = 0; i < 2; i++) {
for (int j = 0; j < n; j++) {
while (!q2[j].empty()) {
q.push_front(q2[j].back());
q2[j].pop_back();
}
if (ans[j] == 0) {
ans[j] = q.front();
q.pop_front();
}
}
}
for (int i = 0; i < n; i++)
cout << ans[i] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, p, ans[100005];
deque<int> q, q2[100005];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
scanf("%d", &p);
q2[p - 1].push_back(i + 1);
}
for (int i = 0; i < 2; i++) {
for (int j = 0; j < n; j++) {
while (!q2[j].empty()) {
q.push_front(q2[j].back());
q2[j].pop_back();
}
if (ans[j] == 0 && !q.empty()) {
ans[j] = q.front();
q.pop_front();
}
}
}
for (int i = 0; i < n; i++)
cout << ans[i] << endl;
return 0;
}
|
replace
| 23 | 24 | 23 | 24 |
0
| |
p02109
|
C++
|
Memory 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;
#define NUM 22
int POW[NUM + 1], RANK[4194304], max_union[4194304], num[4194304];
vector<int> STATE[NUM + 1];
set<int> SET[4194304];
void calc() {
int count;
for (int state = 0; state < POW[NUM]; state++) {
count = 0;
for (int loop = 0; loop < NUM; loop++) {
if (state & (1 << loop)) {
count++;
}
}
RANK[state] = count;
STATE[count].push_back(state);
}
}
int main() {
for (int i = 0; i < NUM + 1; i++)
POW[i] = pow(2, i);
for (int i = 0; i < POW[NUM]; i++) {
num[i] = 0;
max_union[i] = i;
}
calc();
int N;
scanf("%d", &N);
int k, tmp, sum;
for (int loop = 0; loop < N; loop++) {
scanf("%d", &k);
sum = 0;
for (int i = 0; i < k; i++) {
scanf("%d", &tmp);
tmp--;
sum += POW[tmp];
}
num[sum]++;
SET[sum].insert(sum);
}
int current_state, plus_one_bit_state;
int ans = 0, copy_count;
for (int num_bit = NUM; num_bit >= 1; num_bit--) {
for (int k = 0; k < STATE[num_bit].size(); k++) {
current_state = STATE[num_bit][k];
for (int add_bit = 0; add_bit < NUM; add_bit++) {
if (current_state & (1 << add_bit))
continue;
plus_one_bit_state = current_state + POW[add_bit];
if (SET[plus_one_bit_state].size() > 0) {
set<int>::iterator it = SET[plus_one_bit_state].begin();
copy_count = 0;
while (copy_count < 3 && it != SET[plus_one_bit_state].end()) {
SET[current_state].insert(*it);
it++;
copy_count++;
}
max_union[current_state] |= max_union[plus_one_bit_state];
}
}
if ((SET[current_state].size() >= 3) ||
(num[current_state] > 0 &&
num[current_state] + SET[current_state].size() - 1 >= 3)) {
ans = max(ans, RANK[max_union[current_state]] * RANK[current_state]);
}
}
}
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;
#define NUM 22
int POW[NUM + 1], RANK[4194304], max_union[4194304], num[4194304];
vector<int> STATE[NUM + 1];
set<int> SET[4194304];
void calc() {
int count;
for (int state = 0; state < POW[NUM]; state++) {
count = 0;
for (int loop = 0; loop < NUM; loop++) {
if (state & (1 << loop)) {
count++;
}
}
RANK[state] = count;
STATE[count].push_back(state);
}
}
int main() {
for (int i = 0; i < NUM + 1; i++)
POW[i] = pow(2, i);
for (int i = 0; i < POW[NUM]; i++) {
num[i] = 0;
max_union[i] = i;
}
calc();
int N;
scanf("%d", &N);
int k, tmp, sum;
for (int loop = 0; loop < N; loop++) {
scanf("%d", &k);
sum = 0;
for (int i = 0; i < k; i++) {
scanf("%d", &tmp);
tmp--;
sum += POW[tmp];
}
num[sum]++;
SET[sum].insert(sum);
}
int current_state, plus_one_bit_state;
int ans = 0, copy_count;
for (int num_bit = NUM; num_bit >= 1; num_bit--) {
for (int k = 0; k < STATE[num_bit].size(); k++) {
current_state = STATE[num_bit][k];
for (int add_bit = 0; add_bit < NUM; add_bit++) {
if (current_state & (1 << add_bit))
continue;
plus_one_bit_state = current_state + POW[add_bit];
if (SET[plus_one_bit_state].size() > 0) {
set<int>::iterator it = SET[plus_one_bit_state].begin();
copy_count = 0;
while (SET[current_state].size() + copy_count < 3 &&
it != SET[plus_one_bit_state].end()) {
SET[current_state].insert(*it);
it++;
copy_count++;
}
max_union[current_state] |= max_union[plus_one_bit_state];
}
}
if ((SET[current_state].size() >= 3) ||
(num[current_state] > 0 &&
num[current_state] + SET[current_state].size() - 1 >= 3)) {
ans = max(ans, RANK[max_union[current_state]] * RANK[current_state]);
}
}
}
printf("%d\n", ans);
return 0;
}
|
replace
| 85 | 86 | 85 | 87 |
MLE
| |
p02115
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
long long N, a[1100], d = 0, ans1 = 0, ans2 = 0;
cin >> N;
for (int i = 1; i <= N; i++) {
cin >> a[i];
}
for (int i = 2; i <= N; i++) {
if (a[i] > a[i - 1]) {
d++;
if (d >= ans1) {
ans1 = d;
}
}
if (a[i] < a[i - 1]) {
d = 0;
}
}
d = 0;
for (int i = 2; i <= N; i++) {
if (a[i] < a[i - 1]) {
d++;
if (d >= ans2) {
ans2 = d;
}
}
if (a[i] > a[i - 1]) {
d = 0;
}
}
cout << max(ans1, ans2) + 1 << endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
long long N, a[1000000], d = 0, ans1 = 0, ans2 = 0;
cin >> N;
for (int i = 1; i <= N; i++) {
cin >> a[i];
}
for (int i = 2; i <= N; i++) {
if (a[i] > a[i - 1]) {
d++;
if (d >= ans1) {
ans1 = d;
}
}
if (a[i] < a[i - 1]) {
d = 0;
}
}
d = 0;
for (int i = 2; i <= N; i++) {
if (a[i] < a[i - 1]) {
d++;
if (d >= ans2) {
ans2 = d;
}
}
if (a[i] > a[i - 1]) {
d = 0;
}
}
cout << max(ans1, ans2) + 1 << endl;
return 0;
}
|
replace
| 9 | 10 | 9 | 10 |
0
| |
p02116
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#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;
ll calc(ll x, ll y) {
if (y == 0) {
return x;
} else {
return calc(y, x % y);
}
}
int main() {
ll N, POW[70];
POW[0] = 1;
POW[1] = 2;
for (int i = 2; i <= 69; i++) {
POW[i] = POW[i - 1] * 2;
}
scanf("%lld", &N);
for (int i = 0; i <= 69; i++) {
if (POW[i] - 1 == N) {
printf("%lld\n", N + 1);
return 0;
}
}
if (N % 2 == 0) {
printf("1\n");
return 0;
}
vector<ll> bunshi;
bunshi.push_back(N);
ll tmp, common;
for (ll m = 2;; m += 2) {
ll tmp = N - (m - 1);
if (tmp >= m) {
common = calc(tmp, m);
} else {
common = calc(m, tmp);
}
tmp /= common;
if (tmp % 2 == 0) {
printf("%lld\n", m);
return 0;
}
}
printf("%lld\n", N + 1);
return 0;
}
|
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string>
#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;
ll calc(ll x, ll y) {
if (y == 0) {
return x;
} else {
return calc(y, x % y);
}
}
int main() {
ll N, POW[70];
POW[0] = 1;
POW[1] = 2;
for (int i = 2; i <= 69; i++) {
POW[i] = POW[i - 1] * 2;
}
scanf("%lld", &N);
for (int i = 0; i <= 69; i++) {
if (POW[i] - 1 == N) {
printf("%lld\n", N + 1);
return 0;
}
}
if (N % 2 == 0) {
printf("1\n");
return 0;
}
vector<ll> bunshi;
bunshi.push_back(N);
ll tmp, common;
for (ll m = 2;; m *= 2) {
ll tmp = N - (m - 1);
if (tmp >= m) {
common = calc(tmp, m);
} else {
common = calc(m, tmp);
}
tmp /= common;
if (tmp % 2 == 0) {
printf("%lld\n", m);
return 0;
}
}
printf("%lld\n", N + 1);
return 0;
}
|
replace
| 54 | 55 | 54 | 55 |
TLE
| |
p02119
|
C++
|
Runtime Error
|
#include <algorithm>
#include <array>
#include <chrono>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
//<< setprecision(5)
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define dme \
cout << -1 << endl; \
return 0
const int mod = 1000000007;
const int big = 1e9;
const long double pai = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;
template <class T, class U> void mineq(T &a, U b) {
if (a > b) {
a = b;
}
}
template <class T, class U> void maxeq(T &a, U b) {
if (a < b) {
a = b;
}
}
llint gcd(llint a, llint b) {
if (a % b == 0) {
return b;
} else
return gcd(b, a % b);
}
llint lcm(llint a, llint b) { return a / gcd(a, b) * b; }
int main(void) {
int i, j, n;
cin >> n;
vector<int> p(n + 3);
vector<int> ans(n + 1);
vector<bool> ku(n + 1);
p[0] = n + 2;
for (i = 1; i <= n; i++) {
for (j = i; j >= 0; j--) {
ans[j] = 0;
ku[j] = 0;
}
cin >> p[i];
for (j = i; j >= 0; j--) {
if (ku[j]) {
ans[j]++;
} else {
ku[p[j]] = true;
}
ans[p[j]] += ans[j];
}
cout << ans[0] << endl;
}
return 0;
}
|
#include <algorithm>
#include <array>
#include <chrono>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
//<< setprecision(5)
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define dme \
cout << -1 << endl; \
return 0
const int mod = 1000000007;
const int big = 1e9;
const long double pai = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;
template <class T, class U> void mineq(T &a, U b) {
if (a > b) {
a = b;
}
}
template <class T, class U> void maxeq(T &a, U b) {
if (a < b) {
a = b;
}
}
llint gcd(llint a, llint b) {
if (a % b == 0) {
return b;
} else
return gcd(b, a % b);
}
llint lcm(llint a, llint b) { return a / gcd(a, b) * b; }
int main(void) {
int i, j, n;
cin >> n;
vector<int> p(n + 3);
vector<int> ans(n + 3);
vector<bool> ku(n + 3);
p[0] = n + 2;
for (i = 1; i <= n; i++) {
for (j = i; j >= 0; j--) {
ans[j] = 0;
ku[j] = 0;
}
cin >> p[i];
for (j = i; j >= 0; j--) {
if (ku[j]) {
ans[j]++;
} else {
ku[p[j]] = true;
}
ans[p[j]] += ans[j];
}
cout << ans[0] << endl;
}
return 0;
}
|
replace
| 61 | 63 | 61 | 63 |
0
| |
p02119
|
C++
|
Runtime Error
|
// ?????????????????????
#include <bits/stdc++.h>
using namespace std;
struct Bipartite_Matching {
vector<vector<int>> graph;
vector<int> match, alive, used;
int timestamp;
Bipartite_Matching(int n) {
timestamp = 0;
graph.resize(n);
alive.assign(n, 0);
used.assign(n, 0);
match.assign(n, -1);
}
void add_edge(int u, int v) {
graph[u].push_back(v);
graph[v].push_back(u);
}
bool dfs(int v) {
used[v] = timestamp;
for (int i = 0; i < graph[v].size(); i++) {
int u = graph[v][i], w = match[u];
if (alive[u] == 0)
continue;
if (w == -1 || (used[w] != timestamp && dfs(w))) {
match[v] = u;
match[u] = v;
return (true);
}
}
return (false);
}
int bipartite_matching() {
int ret = 0;
for (int i = 0; i < graph.size(); i++) {
if (alive[i] == 0)
continue;
if (match[i] == -1) {
++timestamp;
ret += dfs(i);
}
}
return (ret);
}
int add(int k) {
alive[k] = 1;
++timestamp;
return (dfs(k));
}
};
int main() {
int N, A[100000], idx[5000];
vector<int> g[5000];
bool dep[5000] = {};
cin >> N;
++N;
for (int i = 1; i < N; i++) {
cin >> idx[i];
g[idx[i]].push_back(i);
dep[i] = dep[idx[i]] ^ 1;
}
Bipartite_Matching flow(N);
vector<int> left, right;
for (int i = 0; i < N; i++) {
if (dep[i])
left.push_back(i);
else
right.push_back(i);
}
for (int i = 1; i < N; i++) {
int oi, beet;
if (dep[i])
oi = lower_bound(begin(left), end(left), i) - begin(left);
else
oi = (int)(lower_bound(begin(right), end(right), i) - begin(right)) +
left.size();
if (dep[idx[i]])
beet = lower_bound(begin(left), end(left), idx[i]) - begin(left);
else
beet =
(int)(lower_bound(begin(right), end(right), idx[i]) - begin(right)) +
left.size();
flow.add_edge(oi, beet);
}
flow.alive[(int)(lower_bound(begin(right), end(right), 0) - begin(right)) +
left.size()] = true;
flow.bipartite_matching();
int ret = 0;
for (int i = 1; i < N; i++) {
int oi;
if (dep[i])
oi = lower_bound(begin(left), end(left), i) - begin(left);
else
oi = (int)(lower_bound(begin(right), end(right), i) - begin(right)) +
left.size();
ret += flow.add(oi);
cout << ret << endl;
}
}
|
// ?????????????????????
#include <bits/stdc++.h>
using namespace std;
struct Bipartite_Matching {
vector<vector<int>> graph;
vector<int> match, alive, used;
int timestamp;
Bipartite_Matching(int n) {
timestamp = 0;
graph.resize(n);
alive.assign(n, 0);
used.assign(n, 0);
match.assign(n, -1);
}
void add_edge(int u, int v) {
graph[u].push_back(v);
graph[v].push_back(u);
}
bool dfs(int v) {
used[v] = timestamp;
for (int i = 0; i < graph[v].size(); i++) {
int u = graph[v][i], w = match[u];
if (alive[u] == 0)
continue;
if (w == -1 || (used[w] != timestamp && dfs(w))) {
match[v] = u;
match[u] = v;
return (true);
}
}
return (false);
}
int bipartite_matching() {
int ret = 0;
for (int i = 0; i < graph.size(); i++) {
if (alive[i] == 0)
continue;
if (match[i] == -1) {
++timestamp;
ret += dfs(i);
}
}
return (ret);
}
int add(int k) {
alive[k] = 1;
++timestamp;
return (dfs(k));
}
};
int main() {
int N, A[150000], idx[150000];
vector<int> g[150000];
bool dep[150000] = {};
cin >> N;
++N;
for (int i = 1; i < N; i++) {
cin >> idx[i];
g[idx[i]].push_back(i);
dep[i] = dep[idx[i]] ^ 1;
}
Bipartite_Matching flow(N);
vector<int> left, right;
for (int i = 0; i < N; i++) {
if (dep[i])
left.push_back(i);
else
right.push_back(i);
}
for (int i = 1; i < N; i++) {
int oi, beet;
if (dep[i])
oi = lower_bound(begin(left), end(left), i) - begin(left);
else
oi = (int)(lower_bound(begin(right), end(right), i) - begin(right)) +
left.size();
if (dep[idx[i]])
beet = lower_bound(begin(left), end(left), idx[i]) - begin(left);
else
beet =
(int)(lower_bound(begin(right), end(right), idx[i]) - begin(right)) +
left.size();
flow.add_edge(oi, beet);
}
flow.alive[(int)(lower_bound(begin(right), end(right), 0) - begin(right)) +
left.size()] = true;
flow.bipartite_matching();
int ret = 0;
for (int i = 1; i < N; i++) {
int oi;
if (dep[i])
oi = lower_bound(begin(left), end(left), i) - begin(left);
else
oi = (int)(lower_bound(begin(right), end(right), i) - begin(right)) +
left.size();
ret += flow.add(oi);
cout << ret << endl;
}
}
|
replace
| 60 | 63 | 60 | 63 |
0
| |
p02122
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
// const int B = 450;
const int B = 1;
const int MAX_S = (200000 / B) + 10;
int N, Q, S;
bool lazy[2][MAX_S];
int A[2][200000 + B];
int M[2][MAX_S];
void push(int k, int b) {
if (!lazy[k][b])
return;
rep(i, B) A[k][b * B + i] = A[k ^ 1][b * B + i];
lazy[k][b] = false;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N;
S = (N - 1) / B + 1;
rep(k, 2) {
rep(i, S) M[k][i] = INF;
rep(i, N + B) A[k][i] = INF;
rep(i, N) cin >> A[k][i], M[k][i / B] = min(M[k][i / B], A[k][i]);
}
cin >> Q;
rep(i, Q) {
int type, y, z;
cin >> type >> y >> z;
type--;
int k = type % 2;
if (type / 2 == 0) {
y--;
int b = y / B;
push(k, b);
push(k ^ 1, b);
A[k][y] = z;
M[k][b] = INF;
rep(i, B) M[k][b] = min(M[k][b], A[k][b * B + i]);
} else if (type / 2 == 1) {
y--, z--;
// min [y, z]
int lb = y / B, rb = z / B, m = INF;
push(k, lb);
push(k, rb);
if (lb == rb) {
for (int i = y; i <= z; i++)
m = min(m, A[k][i]);
} else {
for (int i = y; i < (lb + 1) * B; i++)
m = min(m, A[k][i]);
for (int i = rb * B; i <= z; i++)
m = min(m, A[k][i]);
for (int b = lb + 1; b <= rb - 1; b++)
m = min(m, M[k][b]);
}
cout << m << "\n";
} else {
rep(b, S) {
if (!lazy[k ^ 1][b]) {
lazy[k][b] = true;
M[k][b] = M[k ^ 1][b];
}
}
}
}
return 0;
}
|
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
const int B = 450;
const int MAX_S = (200000 / B) + 10;
int N, Q, S;
bool lazy[2][MAX_S];
int A[2][200000 + B];
int M[2][MAX_S];
void push(int k, int b) {
if (!lazy[k][b])
return;
rep(i, B) A[k][b * B + i] = A[k ^ 1][b * B + i];
lazy[k][b] = false;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N;
S = (N - 1) / B + 1;
rep(k, 2) {
rep(i, S) M[k][i] = INF;
rep(i, N + B) A[k][i] = INF;
rep(i, N) cin >> A[k][i], M[k][i / B] = min(M[k][i / B], A[k][i]);
}
cin >> Q;
rep(i, Q) {
int type, y, z;
cin >> type >> y >> z;
type--;
int k = type % 2;
if (type / 2 == 0) {
y--;
int b = y / B;
push(k, b);
push(k ^ 1, b);
A[k][y] = z;
M[k][b] = INF;
rep(i, B) M[k][b] = min(M[k][b], A[k][b * B + i]);
} else if (type / 2 == 1) {
y--, z--;
// min [y, z]
int lb = y / B, rb = z / B, m = INF;
push(k, lb);
push(k, rb);
if (lb == rb) {
for (int i = y; i <= z; i++)
m = min(m, A[k][i]);
} else {
for (int i = y; i < (lb + 1) * B; i++)
m = min(m, A[k][i]);
for (int i = rb * B; i <= z; i++)
m = min(m, A[k][i]);
for (int b = lb + 1; b <= rb - 1; b++)
m = min(m, M[k][b]);
}
cout << m << "\n";
} else {
rep(b, S) {
if (!lazy[k ^ 1][b]) {
lazy[k][b] = true;
M[k][b] = M[k ^ 1][b];
}
}
}
}
return 0;
}
|
replace
| 25 | 27 | 25 | 26 |
TLE
| |
p02126
|
C++
|
Runtime Error
|
#include "algorithm"
#include "bitset"
#include "climits"
#include "cmath"
#include "cstdio"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"
using namespace std;
const long long int MOD = 1000000007;
long long int N, M, K, H, W, L, R;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> M >> K;
vector<queue<int>> v(1001);
vector<int> num(N);
for (int i = 0; i < K; i++) {
cin >> num[i];
}
for (int i = 0; i < N; i++) {
cin >> L >> R;
L--;
v[R].push(L);
}
int ans = 0;
for (int i = 1000; i > 0; i--) {
while (!v[i].empty()) {
int box = v[i].front();
v[i].pop();
if (num[box]) {
num[box]--;
M--;
ans += i;
if (!M) {
cout << ans << endl;
return 0;
}
}
}
}
cout << ans << endl;
return 0;
}
|
#include "algorithm"
#include "bitset"
#include "climits"
#include "cmath"
#include "cstdio"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"
using namespace std;
const long long int MOD = 1000000007;
long long int N, M, K, H, W, L, R;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N >> M >> K;
vector<queue<int>> v(1001);
vector<int> num(K);
for (int i = 0; i < K; i++) {
cin >> num[i];
}
for (int i = 0; i < N; i++) {
cin >> L >> R;
L--;
v[R].push(L);
}
int ans = 0;
for (int i = 1000; i > 0; i--) {
while (!v[i].empty()) {
int box = v[i].front();
v[i].pop();
if (num[box]) {
num[box]--;
M--;
ans += i;
if (!M) {
cout << ans << endl;
return 0;
}
}
}
}
cout << ans << endl;
return 0;
}
|
replace
| 30 | 31 | 30 | 31 |
0
| |
p02127
|
C++
|
Memory Limit Exceeded
|
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define fore(i, a) for (auto &i : a)
#define all(x) (x).begin(), (x).end()
#pragma GCC optimize("-O3")
using namespace std;
void _main();
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
_main();
}
typedef long long ll;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
string S, T;
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> S >> T;
int ans = 0;
string s = "";
int i = 0;
while (s.length() <= S.length()) {
i++;
string ss = "";
fore(c, T) ss += s + c;
ss += s;
s = ss;
int j = 0;
fore(c, S) {
if (j < s.length()) {
if (c == s[j])
j++;
}
}
if (j == s.length())
ans = i;
}
cout << ans << endl;
}
|
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i >= b; i--)
#define fore(i, a) for (auto &i : a)
#define all(x) (x).begin(), (x).end()
#pragma GCC optimize("-O3")
using namespace std;
void _main();
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
_main();
}
typedef long long ll;
const int inf = INT_MAX / 2;
const ll infl = 1LL << 60;
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
∧_∧
∧_∧ (´<_` ) Welcome to My Coding Space!
( ´_ゝ`) / ⌒i
/ \ | |
/ / ̄ ̄ ̄ ̄/ |
__(__ニつ/ _/ .| .|____
\/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/
string S, T;
//---------------------------------------------------------------------------------------------------
void _main() {
cin >> S >> T;
int ans = 0;
string s = "";
int i = 0;
while (1) {
ll len = T.length() + 1LL * (T.length() + 1) * s.length();
if (S.length() < len)
break;
i++;
string ss = "";
fore(c, T) ss += s + c;
ss += s;
s = ss;
int j = 0;
fore(c, S) {
if (j < s.length()) {
if (c == s[j])
j++;
}
}
if (j == s.length())
ans = i;
}
cout << ans << endl;
}
|
replace
| 49 | 50 | 49 | 54 |
MLE
| |
p02127
|
C++
|
Memory Limit Exceeded
|
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back
const ll LLINF = (1LL << 60);
const int INF = (1LL << 30);
const int MOD = 1000000007;
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a <= x && x < b; }
template <typename T> T ceil(T a, T b) { return a / b + !!(a % b); }
template <class S, class T>
ostream &operator<<(ostream &out, const pair<S, T> &a) {
out << '(' << a.first << ',' << a.second << ')';
return out;
}
template <class T> ostream &operator<<(ostream &out, const vector<T> &a) {
out << '[';
REP(i, a.size()) {
out << a[i];
if (i != a.size() - 1)
out << ',';
}
out << ']';
return out;
}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
signed main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
string s, t;
cin >> s >> t;
string now = t;
REP(i, 30) {
// sの中にnowが含まれるか判定
int cnt = 0;
REP(j, s.size()) if (cnt < now.size() && s[j] == now[cnt]) cnt++;
if (cnt < now.size()) {
cout << i << endl;
return 0;
}
string n = now;
REP(j, t.size()) n += t[j] + now;
now = n;
}
return 0;
}
|
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back
const ll LLINF = (1LL << 60);
const int INF = (1LL << 30);
const int MOD = 1000000007;
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a <= x && x < b; }
template <typename T> T ceil(T a, T b) { return a / b + !!(a % b); }
template <class S, class T>
ostream &operator<<(ostream &out, const pair<S, T> &a) {
out << '(' << a.first << ',' << a.second << ')';
return out;
}
template <class T> ostream &operator<<(ostream &out, const vector<T> &a) {
out << '[';
REP(i, a.size()) {
out << a[i];
if (i != a.size() - 1)
out << ',';
}
out << ']';
return out;
}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
signed main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
string s, t;
cin >> s >> t;
string now = t;
REP(i, 30) {
// sの中にnowが含まれるか判定
int cnt = 0;
REP(j, s.size()) if (cnt < now.size() && s[j] == now[cnt]) cnt++;
if (cnt < now.size()) {
cout << i << endl;
return 0;
}
int n_sz = now.size() * t.size() + now.size() + t.size();
if (n_sz > s.size()) {
cout << i + 1 << endl;
return 0;
}
string n = now;
REP(j, t.size()) n += t[j] + now;
now = n;
}
return 0;
}
|
insert
| 57 | 57 | 57 | 62 |
MLE
| |
p02127
|
C++
|
Memory Limit Exceeded
|
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)
#define each(a, b) for (auto &(a) : (b))
#define all(v) (v).begin(), (v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)), v.erase(unique(all(v)), v.end())
#define cmx(x, y) x = max(x, y)
#define cmn(x, y) x = min(x, y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout << #x << " = " << (x) << endl
#define spair(p) cout << #p << ": " << p.fi << " " << p.se << endl
#define sar(a, n) \
cout << #a << ":"; \
rep(pachico, n) cout << " " << a[pachico]; \
cout << endl
#define svec(v) \
cout << #v << ":"; \
rep(pachico, v.size()) cout << " " << v[pachico]; \
cout << endl
#define svecp(v) \
cout << #v << ":"; \
each(pachico, v) cout << " {" << pachico.first << ":" << pachico.second \
<< "}"; \
cout << endl
#define sset(s) \
cout << #s << ":"; \
each(pachico, s) cout << " " << pachico; \
cout << endl
#define smap(m) \
cout << #m << ":"; \
each(pachico, m) cout << " {" << pachico.first << ":" << pachico.second \
<< "}"; \
cout << endl
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;
const int MAX_N = 100005;
int n;
bool ok(string &s, string &t) {
int pos = 0;
rep(i, len(s)) {
if (s[i] == t[pos]) {
pos++;
}
if (pos == len(t)) {
return true;
}
}
return false;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s, t;
cin >> s >> t;
string bf = t;
int moto = len(bf);
n = len(s);
int ans = 0;
while (1) {
if (ok(s, t)) {
ans++;
} else {
break;
}
int k = len(t);
if (n < k * (moto + 1) + moto) {
break;
}
string nw = t;
rep(i, moto) {
nw += bf[i];
nw += t;
}
swap(t, nw);
}
cout << ans << "\n";
return 0;
}
|
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)
#define each(a, b) for (auto &(a) : (b))
#define all(v) (v).begin(), (v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)), v.erase(unique(all(v)), v.end())
#define cmx(x, y) x = max(x, y)
#define cmn(x, y) x = min(x, y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout << #x << " = " << (x) << endl
#define spair(p) cout << #p << ": " << p.fi << " " << p.se << endl
#define sar(a, n) \
cout << #a << ":"; \
rep(pachico, n) cout << " " << a[pachico]; \
cout << endl
#define svec(v) \
cout << #v << ":"; \
rep(pachico, v.size()) cout << " " << v[pachico]; \
cout << endl
#define svecp(v) \
cout << #v << ":"; \
each(pachico, v) cout << " {" << pachico.first << ":" << pachico.second \
<< "}"; \
cout << endl
#define sset(s) \
cout << #s << ":"; \
each(pachico, s) cout << " " << pachico; \
cout << endl
#define smap(m) \
cout << #m << ":"; \
each(pachico, m) cout << " {" << pachico.first << ":" << pachico.second \
<< "}"; \
cout << endl
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;
const int MAX_N = 100005;
int n;
bool ok(string &s, string &t) {
int pos = 0;
rep(i, len(s)) {
if (s[i] == t[pos]) {
pos++;
}
if (pos == len(t)) {
return true;
}
}
return false;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
string s, t;
cin >> s >> t;
string bf = t;
int moto = len(bf);
n = len(s);
int ans = 0;
while (1) {
if (ok(s, t)) {
ans++;
} else {
break;
}
int k = len(t);
if (n < (ll)k * (moto + 1) + moto) {
break;
}
string nw = t;
rep(i, moto) {
nw += bf[i];
nw += t;
}
swap(t, nw);
}
cout << ans << "\n";
return 0;
}
|
replace
| 87 | 88 | 87 | 88 |
MLE
| |
p02127
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define _rep(i, n) _repl(i, 0, n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp make_pair
#define pb push_back
#define all(x) begin(x), end(x)
#define uniq(x) sort(all(x)), (x).erase(unique(all(x)), end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string) { cerr << endl; }
template <class H, class... T> void _dbg(string s, H h, T... t) {
int l = s.find(',');
cerr << s.substr(0, l) << " = " << h << ", ";
_dbg(s.substr(l + 1), t...);
}
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;
}
char tmp_str[2][100005];
int solve() {
string s, t;
cin >> s >> t;
if (s.size() == t.size()) {
if (s == t)
return 1;
else
return 0;
}
int r = 1;
int cur = t.size();
while (s.size() >= cur) {
cur += (cur + 1) * t.size();
r++;
}
auto f = [&](int x) {
if (x == 0)
return true;
auto s1 = tmp_str[0];
auto s2 = tmp_str[1];
int p_size = 0;
int q_size = 0;
rep(i, x) {
q_size = 0;
rep(j, p_size) s2[q_size++] = s1[j];
rep(j, t.size()) {
s2[q_size++] = t[j];
rep(k, p_size) s2[q_size++] = s1[k];
}
swap(s1, s2);
swap(p_size, q_size);
}
// dbg(x,string(s1, s1+p_size));
int is = 0, it = 0;
while (is < s.size() && it < p_size) {
if (s[is] == s1[it]) {
is++;
it++;
} else {
is++;
}
}
return it == p_size;
};
int l = 0;
r++;
while (r - l > 1) {
int mid = (l + r) / 2;
if (f(mid))
l = mid;
else
r = mid;
}
return l;
}
int main() {
cout << solve() << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define _rep(i, n) _repl(i, 0, n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp make_pair
#define pb push_back
#define all(x) begin(x), end(x)
#define uniq(x) sort(all(x)), (x).erase(unique(all(x)), end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string) { cerr << endl; }
template <class H, class... T> void _dbg(string s, H h, T... t) {
int l = s.find(',');
cerr << s.substr(0, l) << " = " << h << ", ";
_dbg(s.substr(l + 1), t...);
}
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;
}
char tmp_str[2][100005];
int solve() {
string s, t;
cin >> s >> t;
if (s.size() == t.size()) {
if (s == t)
return 1;
else
return 0;
}
int r = 1;
int cur = t.size();
while (s.size() >= cur) {
cur += (cur + 1) * t.size();
r++;
}
auto f = [&](int x) {
if (x == 0)
return true;
auto s1 = tmp_str[0];
auto s2 = tmp_str[1];
int p_size = 0;
int q_size = 0;
rep(i, x) {
q_size = 0;
rep(j, p_size) s2[q_size++] = s1[j];
rep(j, t.size()) {
s2[q_size++] = t[j];
rep(k, p_size) s2[q_size++] = s1[k];
}
swap(s1, s2);
swap(p_size, q_size);
}
// dbg(x,string(s1, s1+p_size));
int is = 0, it = 0;
while (is < s.size() && it < p_size) {
if (s[is] == s1[it]) {
is++;
it++;
} else {
is++;
}
}
return it == p_size;
};
int l = 0;
while (r - l > 1) {
int mid = (l + r) / 2;
if (f(mid))
l = mid;
else
r = mid;
}
return l;
}
int main() {
cout << solve() << endl;
return 0;
}
|
delete
| 84 | 85 | 84 | 84 |
0
| |
p02127
|
C++
|
Memory Limit Exceeded
|
#include <iostream>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
string x = t;
int ans = 0;
for (int i = 0; x.size() <= s.size(); i++) {
// check
// cerr << "x: " << x << endl;
int idx = 0;
for (char ch : s) {
if (idx < x.size() and ch == x[idx]) {
idx++;
}
}
if (idx != x.size())
break;
ans++;
string y = x;
for (char ch : t) {
y.push_back(ch);
y += x;
}
x = y;
}
cout << ans << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
string x = t;
int ans = 0;
for (int i = 0; x.size() <= s.size(); i++) {
// check
// cerr << "x: " << x << endl;
int idx = 0;
for (char ch : s) {
if (idx < x.size() and ch == x[idx]) {
idx++;
}
}
if (idx != x.size())
break;
ans++;
long long size = x.size() * (t.size() + 1) + t.size();
if (size > s.size())
break;
string y = x;
for (char ch : t) {
y.push_back(ch);
y += x;
}
x = y;
}
cout << ans << endl;
return 0;
}
|
insert
| 24 | 24 | 24 | 28 |
MLE
| |
p02127
|
C++
|
Memory Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) rep(i, (n) + 1)
#define per(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define pere(i, n) rep(i, (n) + 1)
#define all(x) (x).begin(), (x).end()
#define SP << " " <<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
typedef long long LL;
typedef long double LD;
bool ok(string &s, string &t) {
int now = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] == t[now]) {
now++;
if (now == t.length())
return true;
}
}
return false;
}
int main() {
string s, t;
cin >> s >> t;
vector<string> tt(100, "");
for (int i = 1; i < 100; i++) {
tt[i] = tt[i - 1];
for (int j = 0; j < t.length(); j++) {
tt[i] += string(1, t[j]);
tt[i] += tt[i - 1];
}
// cout << tt[i] << endl;
if (!ok(s, tt[i])) {
cout << i - 1 << endl;
return 0;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) rep(i, (n) + 1)
#define per(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define pere(i, n) rep(i, (n) + 1)
#define all(x) (x).begin(), (x).end()
#define SP << " " <<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
typedef long long LL;
typedef long double LD;
bool ok(string &s, string &t) {
int now = 0;
for (int i = 0; i < s.length(); i++) {
if (s[i] == t[now]) {
now++;
if (now == t.length())
return true;
}
}
return false;
}
int main() {
string s, t;
cin >> s >> t;
vector<string> tt(100, "");
for (int i = 1; i < 100; i++) {
tt[i] = tt[i - 1];
for (int j = 0; j < t.length(); j++) {
tt[i] += string(1, t[j]);
tt[i] += tt[i - 1];
if (tt[i].length() > s.length()) {
cout << i - 1 << endl;
return 0;
}
}
// cout << tt[i] << endl;
if (!ok(s, tt[i])) {
cout << i - 1 << endl;
return 0;
}
}
return 0;
}
|
insert
| 37 | 37 | 37 | 41 |
MLE
| |
p02127
|
C++
|
Memory 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;
bool check(string T, string P) {
if (P.length() > T.length())
return false;
int index = 0;
for (int i = 0; i < T.length(); i++) {
if (T[i] == P[index]) {
index++;
if (index == P.length())
return true;
}
}
return false;
}
int main() {
string T, base_P, work_P, next_P;
getline(cin, T);
getline(cin, base_P);
int ans = 0;
work_P = base_P;
while (check(T, work_P)) {
ans++;
next_P = base_P;
for (int i = 0; i < work_P.length(); i++) {
next_P += work_P[i] + base_P;
}
work_P = next_P;
}
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;
bool check(string T, string P) {
if (P.length() > T.length())
return false;
int index = 0;
for (int i = 0; i < T.length(); i++) {
if (T[i] == P[index]) {
index++;
if (index == P.length())
return true;
}
}
return false;
}
int main() {
string T, base_P, work_P, next_P;
getline(cin, T);
getline(cin, base_P);
int ans = 0;
work_P = base_P;
while (check(T, work_P)) {
ans++;
next_P = base_P;
if ((work_P.length() + 1) * (base_P.length()) + work_P.length() >
T.length())
break;
for (int i = 0; i < work_P.length(); i++) {
next_P += work_P[i] + base_P;
}
work_P = next_P;
}
printf("%d\n", ans);
return 0;
}
|
insert
| 48 | 48 | 48 | 52 |
MLE
| |
p02127
|
C++
|
Memory Limit Exceeded
|
#if 1
#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <cstdint>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
auto &in = std::cin;
auto &out = std::cout;
#define all(C) std::begin(C), std::end(C)
const double PI =
3.141592653589793238462643383279502884197169399375105820974944;
std::string s, t, tori;
int main() {
using std::endl;
in.sync_with_stdio(false);
out.sync_with_stdio(false);
in.tie(nullptr);
out.tie(nullptr);
in >> s >> t;
tori = t;
int32_t lev = 0;
auto s_iter = s.begin();
auto t_iter = t.begin();
while (s_iter != s.end()) {
if (*s_iter == *t_iter) {
++t_iter;
if (t_iter == t.end()) {
++lev;
std::string new_t = t;
for (auto &ss : tori) {
new_t.push_back(ss);
new_t += t;
}
auto oldt_size = t.size();
t = std::move(new_t);
t_iter = t.begin() + oldt_size;
}
}
++s_iter;
}
out << lev << endl;
return 0;
}
#endif
|
#if 1
#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <cstdint>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
auto &in = std::cin;
auto &out = std::cout;
#define all(C) std::begin(C), std::end(C)
const double PI =
3.141592653589793238462643383279502884197169399375105820974944;
std::string s, t, tori;
int main() {
using std::endl;
in.sync_with_stdio(false);
out.sync_with_stdio(false);
in.tie(nullptr);
out.tie(nullptr);
in >> s >> t;
tori = t;
int32_t lev = 0;
auto s_iter = s.begin();
auto t_iter = t.begin();
while (s_iter != s.end()) {
if (*s_iter == *t_iter) {
++t_iter;
if (t_iter == t.end()) {
++lev;
std::string new_t = t;
for (auto &ss : tori) {
new_t.push_back(ss);
new_t += t;
if (new_t.size() > s.size()) {
out << lev << endl;
return 0;
}
}
auto oldt_size = t.size();
t = std::move(new_t);
t_iter = t.begin() + oldt_size;
}
}
++s_iter;
}
out << lev << endl;
return 0;
}
#endif
|
insert
| 54 | 54 | 54 | 58 |
MLE
| |
p02127
|
C++
|
Memory Limit Exceeded
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
string s, t;
cin >> s >> t;
int dep = 1;
string targ = t;
while (1) {
int pos = 0;
rep(i, s.length()) {
if (pos >= (int)targ.length())
break;
if (s[i] == targ[pos]) {
pos++;
}
}
if (pos < (int)targ.length())
break;
dep++;
string nxt = targ;
rep(i, t.length()) nxt += t[i] + targ;
targ = nxt;
}
cout << dep - 1 << endl;
}
|
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
string s, t;
cin >> s >> t;
int dep = 1;
string targ = t;
while (1) {
int pos = 0;
rep(i, s.length()) {
if (pos >= (int)targ.length())
break;
if (s[i] == targ[pos]) {
pos++;
}
}
if (pos < (int)targ.length())
break;
dep++;
lint nxtlen = (t.length() + 1) * (lint)targ.size() + t.length();
if (s.length() < nxtlen)
break;
string nxt = targ;
rep(i, t.length()) nxt += t[i] + targ;
targ = nxt;
}
cout << dep - 1 << endl;
}
|
insert
| 26 | 26 | 26 | 29 |
MLE
| |
p02127
|
C++
|
Memory Limit Exceeded
|
#include "bits/stdc++.h"
using namespace std;
#define mod 1000000007
using ll = long long;
int dd[] = {0, 1, 0, -1, 0}; // →↓←↑
void solve() {
string S, T;
cin >> S >> T;
string B = T;
int cnt = 0;
while (true) {
// judge
int s = 0, b = 0;
while (b < B.size()) {
if (s == S.size()) {
cout << cnt << endl;
return;
}
if (S[s] == B[b]) {
b++;
}
s++;
}
cnt++;
// next
string tmp = B;
for (int i = 0; i < T.size(); i++) {
tmp += B[i] + B;
}
if (tmp.size() > S.size()) {
cout << cnt << endl;
return;
}
B = tmp;
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
solve();
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
#define mod 1000000007
using ll = long long;
int dd[] = {0, 1, 0, -1, 0}; // →↓←↑
void solve() {
string S, T;
cin >> S >> T;
string B = T;
int cnt = 0;
while (true) {
// judge
int s = 0, b = 0;
while (b < B.size()) {
if (s == S.size()) {
cout << cnt << endl;
return;
}
if (S[s] == B[b]) {
b++;
}
s++;
}
cnt++;
// next
string tmp = B;
for (int i = 0; i < T.size(); i++) {
tmp += B[i] + B;
if (tmp.size() > S.size()) {
cout << cnt << endl;
return;
}
}
B = tmp;
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
solve();
return 0;
}
|
replace
| 32 | 36 | 32 | 36 |
MLE
| |
p02128
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define maxch(x, y) x = mmax(x, y)
#define minch(x, y) x = mmin(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt __builtin_popcount
#define INF INT_MAX / 3
#define mod 1000000007
struct state {
int d;
P p;
};
bool operator<(const state &a, const state &b) { return a.d > b.d; }
int w, h, n;
int x[101], y[101];
int dist[105][1001];
int main() {
scanf("%d%d%d", &w, &h, &n);
rep(i, n) scanf("%d%d", x + i, y + i);
priority_queue<state> que;
rep(i, n + 1) rep(j, w + h + 1) dist[i][j] = INF;
que.push((state){0, P(n, 0)});
int res = INF;
while (que.size()) {
P p = que.top().p;
int d = que.top().d;
que.pop();
if (dist[p.fi][p.se] != INF)
continue;
dist[p.fi][p.se] = d;
if (p.fi == n) { // start
rep(i, n) {
int md = abs(x[i] - 1) + abs(y[i] - 1);
que.push((state){d + md, P(i, md)});
}
} else { // light
rep(i, n) {
int md = abs(x[i] - x[p.fi]) + abs(y[i] - y[p.fi]);
if (md <= p.se + 1) {
que.push((state){d, P(i, 0)});
} else {
md -= p.se + 1;
que.push((state){d + md, P(i, md)});
}
}
{ // -> end
int md = abs(x[p.fi] - w) + abs(y[p.fi] - h);
if (md <= p.se) {
minch(res, d);
} else {
md -= p.se;
minch(res, d + md);
}
}
}
}
cout << res << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
#define fi first
#define se second
#define repl(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define maxch(x, y) x = mmax(x, y)
#define minch(x, y) x = mmin(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt __builtin_popcount
#define INF INT_MAX / 3
#define mod 1000000007
struct state {
int d;
P p;
};
bool operator<(const state &a, const state &b) { return a.d > b.d; }
int w, h, n;
int x[101], y[101];
int dist[105][1001];
int main() {
scanf("%d%d%d", &w, &h, &n);
rep(i, n) scanf("%d%d", x + i, y + i);
priority_queue<state> que;
rep(i, n + 1) rep(j, w + h + 1) dist[i][j] = INF;
que.push((state){0, P(n, 0)});
int res = INF;
while (que.size()) {
P p = que.top().p;
int d = que.top().d;
que.pop();
if (dist[p.fi][p.se] != INF)
continue;
dist[p.fi][p.se] = d;
if (p.fi == n) { // start
rep(i, n) {
int md = abs(x[i] - 1) + abs(y[i] - 1);
que.push((state){d + md, P(i, md)});
}
} else { // light
rep(i, n) {
if (x[i] < x[p.fi] && y[i] < y[p.fi])
continue;
if (i == p.fi)
continue;
int md = abs(x[i] - x[p.fi]) + abs(y[i] - y[p.fi]);
if (md <= p.se + 1) {
que.push((state){d, P(i, 0)});
} else {
md -= p.se + 1;
que.push((state){d + md, P(i, md)});
}
}
{ // -> end
int md = abs(x[p.fi] - w) + abs(y[p.fi] - h);
if (md <= p.se) {
minch(res, d);
} else {
md -= p.se;
minch(res, d + md);
}
}
}
}
cout << res << endl;
return 0;
}
|
insert
| 53 | 53 | 53 | 57 |
TLE
| |
p02128
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<lint, pii> plpii;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
const int N = 1010;
const lint inf = 1e16;
int main() {
int w, h, n;
cin >> w >> h >> n;
int mi = 1e8;
vector<pii> pts(n + 2);
pts[0] = pii(1, 1);
pts[1] = pii(w, h);
rep(i, n) {
int x, y;
cin >> x >> y;
pts[i + 2] = pii(x, y);
}
priority_queue<plpii, vector<plpii>, greater<plpii>> que;
vector<vector<lint>> dis(n + 2, vector<lint>(N, inf));
rep(i, n) {
int d = abs(pts[i + 2].first - 1) + abs(pts[i + 2].second - 1);
que.push(plpii(d, pii(i + 2, d)));
}
while (!que.empty()) {
plpii top = que.top();
que.pop();
lint d = top.first;
pii xy = top.second;
int x = xy.first, y = xy.second;
if (dis[x][y] <= d)
continue;
dis[x][y] = d;
rep(i, n + 2) {
if (i == x || i == 0)
continue;
int c =
abs(pts[i].first - pts[x].first) + abs(pts[i].second - pts[x].second);
c = max(0, i == 1 ? c - y : (c - y - 1));
if (c >= N)
continue;
que.push(plpii(d + c, pii(i, i == 1 ? 0 : c)));
}
}
cout << dis[1][0] << endl;
}
|
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<lint, pii> plpii;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
const int N = 1010;
const lint inf = 1e16;
int main() {
int w, h, n;
cin >> w >> h >> n;
int mi = 1e8;
vector<pii> pts(n + 2);
pts[0] = pii(1, 1);
pts[1] = pii(w, h);
rep(i, n) {
int x, y;
cin >> x >> y;
pts[i + 2] = pii(x, y);
}
priority_queue<plpii, vector<plpii>, greater<plpii>> que;
vector<vector<lint>> dis(n + 2, vector<lint>(N, inf));
rep(i, n) {
int d = abs(pts[i + 2].first - 1) + abs(pts[i + 2].second - 1);
que.push(plpii(d, pii(i + 2, d)));
}
while (!que.empty()) {
plpii top = que.top();
que.pop();
lint d = top.first;
pii xy = top.second;
int x = xy.first, y = xy.second;
if (dis[x][y] <= d)
continue;
dis[x][y] = d;
rep(i, n + 2) {
if (i == x || i == 0)
continue;
int c =
abs(pts[i].first - pts[x].first) + abs(pts[i].second - pts[x].second);
c = max(0, i == 1 ? c - y : (c - y - 1));
if (c >= N)
continue;
int nx = i;
int ny = i == 1 ? 0 : c;
if (dis[nx][ny] <= d + c)
continue;
dis[nx][ny] = d + c + 1;
que.push(plpii(d + c, pii(nx, ny)));
}
}
cout << dis[1][0] << endl;
}
|
replace
| 49 | 50 | 49 | 55 |
TLE
| |
p02131
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
struct SuffixArray {
vector<int> SA;
string s;
void Build_SA(const string &str) {
s = str;
SA.resize(s.size());
iota(begin(SA), end(SA), 0);
sort(begin(SA), end(SA), [&](const int &a, const int &b) {
if (s[a] == s[b])
return (a > b);
return (s[a] < s[b]);
});
vector<int> classes(s.size()), c(s.size()), cnt(s.size());
for (int i = 0; i < s.size(); i++) {
c[i] = s[i];
}
for (int len = 1; len < s.size(); len <<= 1) {
for (int i = 0; i < s.size(); i++) {
if (i > 0 && c[SA[i - 1]] == c[SA[i]] && SA[i - 1] + len < s.size() &&
c[SA[i - 1] + len / 2] == c[SA[i] + len / 2]) {
classes[SA[i]] = classes[SA[i - 1]];
} else {
classes[SA[i]] = i;
}
}
iota(begin(cnt), end(cnt), 0);
copy(begin(SA), end(SA), begin(c));
for (int i = 0; i < s.size(); i++) {
int s1 = c[i] - len;
if (s1 >= 0)
SA[cnt[classes[s1]]++] = s1;
}
classes.swap(c);
}
}
int operator[](int k) const { return (SA[k]); }
int size() const { return (s.size()); }
bool lt_substr(string &t, int si = 0, int ti = 0) {
int sn = s.size(), tn = t.size();
while (si < sn && ti < tn) {
if (s[si] < t[ti])
return (true);
if (s[si] > t[ti])
return (false);
++si, ++ti;
}
return (si >= sn && ti < tn);
}
int lower_bound(string &t) {
int low = -1, high = SA.size();
while (high - low > 1) {
int mid = (low + high) >> 1;
if (lt_substr(t, SA[mid]))
low = mid;
else
high = mid;
}
return (high);
}
pair<int, int> lower_upper_bound(string &t) {
int idx = lower_bound(t);
int low = idx - 1, high = SA.size();
t.back()++;
while (high - low > 1) {
int mid = (low + high) >> 1;
if (lt_substr(t, SA[mid]))
low = mid;
else
high = mid;
}
t.back()--;
return (make_pair(idx, high));
}
void output() {
for (int i = 0; i < size(); i++) {
cout << i << ": " << s.substr(SA[i]) << endl;
}
}
};
using int64 = long long;
template <class T> struct BinaryIndexedTree {
vector<T> data;
BinaryIndexedTree(int sz) { data.assign(++sz, 0); }
T sum(int k) {
T ret = 0;
for (++k; k > 0; k -= k & -k)
ret += data[k];
return (ret);
}
void add(int k, T x) {
for (++k; k < data.size(); k += k & -k)
data[k] += x;
}
};
template <class T> struct AdditionalBIT : BinaryIndexedTree<T> {
int curr;
AdditionalBIT(int sz) : BinaryIndexedTree<T>(sz) {
curr = 1;
while (curr <= sz)
curr <<= 1;
}
int lower_bound(T w) {
if (w <= 0)
return (0);
int i = 0;
for (int k = curr; k > 0; k >>= 1) {
if (i + k < BinaryIndexedTree<T>::data.size() &&
BinaryIndexedTree<T>::data[i + k] < w) {
w -= BinaryIndexedTree<T>::data[i + k];
i += k;
}
}
return (i);
}
};
int main() {
int N, H;
string S;
cin >> N >> H;
cin >> S;
int wait = 0;
vector<int> weight(S.size());
for (int i = 0; i < S.size(); i++) {
if (S[i] == '0') {
++wait;
H -= wait;
} else {
weight[i] += wait + 1;
wait = 0;
}
}
SuffixArray sa;
sa.Build_SA(S);
if (H <= 0) {
cout << 0 << endl;
return (0);
}
vector<int> order;
for (int i = 0; i < S.size(); i++) {
if (S[sa[i]] == '0')
continue;
order.emplace_back(i);
}
AdditionalBIT<int64> bit(N);
vector<int> end[100001];
for (auto &v : order) {
bit.add(v, weight[sa[v]]);
end[N - sa[v]].emplace_back(v);
}
int keta = 1;
for (; H - bit.sum(N - 1) >= 1; ++keta) {
H -= bit.sum(N - 1);
for (auto &p : end[keta])
bit.add(p, -weight[sa[p]]);
}
cout << S.substr(sa[bit.lower_bound(H)], keta) << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
struct SuffixArray {
vector<int> SA;
string s;
void Build_SA(const string &str) {
s = str;
SA.resize(s.size());
iota(begin(SA), end(SA), 0);
sort(begin(SA), end(SA), [&](const int &a, const int &b) {
if (s[a] == s[b])
return (a > b);
return (s[a] < s[b]);
});
vector<int> classes(s.size()), c(s.size()), cnt(s.size());
for (int i = 0; i < s.size(); i++) {
c[i] = s[i];
}
for (int len = 1; len < s.size(); len <<= 1) {
for (int i = 0; i < s.size(); i++) {
if (i > 0 && c[SA[i - 1]] == c[SA[i]] && SA[i - 1] + len < s.size() &&
c[SA[i - 1] + len / 2] == c[SA[i] + len / 2]) {
classes[SA[i]] = classes[SA[i - 1]];
} else {
classes[SA[i]] = i;
}
}
iota(begin(cnt), end(cnt), 0);
copy(begin(SA), end(SA), begin(c));
for (int i = 0; i < s.size(); i++) {
int s1 = c[i] - len;
if (s1 >= 0)
SA[cnt[classes[s1]]++] = s1;
}
classes.swap(c);
}
}
int operator[](int k) const { return (SA[k]); }
int size() const { return (s.size()); }
bool lt_substr(string &t, int si = 0, int ti = 0) {
int sn = s.size(), tn = t.size();
while (si < sn && ti < tn) {
if (s[si] < t[ti])
return (true);
if (s[si] > t[ti])
return (false);
++si, ++ti;
}
return (si >= sn && ti < tn);
}
int lower_bound(string &t) {
int low = -1, high = SA.size();
while (high - low > 1) {
int mid = (low + high) >> 1;
if (lt_substr(t, SA[mid]))
low = mid;
else
high = mid;
}
return (high);
}
pair<int, int> lower_upper_bound(string &t) {
int idx = lower_bound(t);
int low = idx - 1, high = SA.size();
t.back()++;
while (high - low > 1) {
int mid = (low + high) >> 1;
if (lt_substr(t, SA[mid]))
low = mid;
else
high = mid;
}
t.back()--;
return (make_pair(idx, high));
}
void output() {
for (int i = 0; i < size(); i++) {
cout << i << ": " << s.substr(SA[i]) << endl;
}
}
};
using int64 = long long;
template <class T> struct BinaryIndexedTree {
vector<T> data;
BinaryIndexedTree(int sz) { data.assign(++sz, 0); }
T sum(int k) {
T ret = 0;
for (++k; k > 0; k -= k & -k)
ret += data[k];
return (ret);
}
void add(int k, T x) {
for (++k; k < data.size(); k += k & -k)
data[k] += x;
}
};
template <class T> struct AdditionalBIT : BinaryIndexedTree<T> {
int curr;
AdditionalBIT(int sz) : BinaryIndexedTree<T>(sz) {
curr = 1;
while (curr <= sz)
curr <<= 1;
}
int lower_bound(T w) {
if (w <= 0)
return (0);
int i = 0;
for (int k = curr; k > 0; k >>= 1) {
if (i + k < BinaryIndexedTree<T>::data.size() &&
BinaryIndexedTree<T>::data[i + k] < w) {
w -= BinaryIndexedTree<T>::data[i + k];
i += k;
}
}
return (i);
}
};
int main() {
int64 N, H;
string S;
cin >> N >> H;
cin >> S;
int wait = 0;
vector<int> weight(S.size());
for (int i = 0; i < S.size(); i++) {
if (S[i] == '0') {
++wait;
H -= wait;
} else {
weight[i] += wait + 1;
wait = 0;
}
}
SuffixArray sa;
sa.Build_SA(S);
if (H <= 0) {
cout << 0 << endl;
return (0);
}
vector<int> order;
for (int i = 0; i < S.size(); i++) {
if (S[sa[i]] == '0')
continue;
order.emplace_back(i);
}
AdditionalBIT<int64> bit(N);
vector<int> end[100001];
for (auto &v : order) {
bit.add(v, weight[sa[v]]);
end[N - sa[v]].emplace_back(v);
}
int keta = 1;
for (; H - bit.sum(N - 1) >= 1; ++keta) {
H -= bit.sum(N - 1);
for (auto &p : end[keta])
bit.add(p, -weight[sa[p]]);
}
cout << S.substr(sa[bit.lower_bound(H)], keta) << endl;
}
|
replace
| 136 | 137 | 136 | 137 |
0
| |
p02132
|
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();
}
}
};
// 円の定義
class Circle {
public:
Point p;
ld r;
Circle() : p(Point(0, 0)), r(0) {}
Circle(Point p, ld r) : p(p), r(r) {}
};
// ccw
// 1: a,b,cが反時計周りの順に並ぶ
//-1: a,b,cが時計周りの順に並ぶ
// 2: c,a,bの順に直線に並ぶ
//-2: a,b,cの順に直線に並ぶ
// 0: a,c,bの順に直線に並ぶ
int ccw(const Point &a, const Point &b, const Point &c) {
const Point nb(b - a);
const Point nc(c - a);
if (cross(nb, nc) > eps)
return 1; // a,b,cが反時計周りの順に並ぶ
if (cross(nb, nc) < -eps)
return -1; // a,b,cが時計周りの順に並ぶ
if (dot(nb, nc) < 0)
return 2; // c,a,bの順に直線に並ぶ
if (norm(nb) < norm(nc))
return -2; // a,b,cの順に直線に並ぶ
return 0; // a,c,bの順に直線に並ぶ
}
/* 交差判定 */
// 直線と直線の交差判定
bool isis_ll(const Line &l, const Line &m) {
return !eq(cross(l.b - l.a, m.b - m.a), 0);
}
// 直線と線分の交差判定
bool isis_ls(const Line &l, const Line &s) {
return isis_ll(l, s) &&
(cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < eps);
}
// 線分と線分の交差判定
bool isis_ss(const Line &s, const Line &t) {
return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 &&
ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0;
}
// 点の直線上判定
bool isis_lp(const Line &l, const Point &p) {
return (abs(cross(l.b - p, l.a - p)) < eps);
}
// 点の線分上判定
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);
}
// 線対象の位置にある点
Point reflect(const Line &l, const Point &p) {
Point pr = proj(l, p);
return pr * 2.l - p;
}
// 直線と直線の交点
Point is_ll(const Line &s, const Line &t) {
Point sv = s.b - s.a, tv = t.b - t.a;
assert(cross(sv, tv) != 0);
return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv);
}
// 直線と直線の交点
vector<Point> is_ll2(const Line &s, const Line &t) {
Point sv = s.b - s.a, tv = t.b - t.a;
if (cross(sv, tv) != 0)
return vector<Point>(1, is_ll(s, t));
else {
vector<Point> ans;
for (int k = 0; k < 2; ++k) {
if (isis_sp(s, t[k]) && find(ans.begin(), ans.end(), t[k]) == ans.end())
ans.push_back(t[k]);
if (isis_sp(t, s[k]) && find(ans.begin(), ans.end(), s[k]) == ans.end())
ans.push_back(s[k]);
}
return ans;
}
}
// 線分と線分の交点
// 重なってる部分あるとassert(false)
Point is_ss(const Line &s, const Line &t) {
if (isis_ss(s, t)) {
for (int k = 0; k < 2; ++k) {
for (int l = 0; l < 2; ++l) {
if (s[k] == t[l])
return s[k];
}
}
return is_ll(s, t);
} else {
// 先にisis_ssしてね
assert(false);
return Point(0, 0);
}
}
// 線分と線分の交点
vector<Point> is_ss2(const Line &s, const Line &t) {
vector<Point> kouho(is_ll2(s, t));
vector<Point> ans;
for (auto p : kouho) {
if (isis_sp(s, p) && isis_sp(t, p))
ans.emplace_back(p);
}
return ans;
}
// 直線と点の距離
ld dist_lp(const Line &l, const Point &p) { return abs(p - proj(l, p)); }
// 直線と直線の距離
ld dist_ll(const Line &l, const Line &m) {
return isis_ll(l, m) ? 0 : dist_lp(l, m.a);
}
// 直線と線分の距離
ld dist_ls(const Line &l, const Line &s) {
return isis_ls(l, s) ? 0 : min(dist_lp(l, s.a), dist_lp(l, s.b));
}
// 線分と点の距離
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));
}
// 線分と線分の距離
ld dist_ss(const Line &s, const 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)});
}
// 直線と直線の二等分線のベクトル
Line line_bisection(const Line &s, const Line &t) {
const Point laglanju(is_ll(s, t));
const Point avec =
!(abs(laglanju - s[0]) < eps) ? s[0] - laglanju : s[1] - laglanju;
const Point bvec =
!(abs(laglanju - t[0]) < eps) ? t[0] - laglanju : t[1] - laglanju;
return Line(laglanju, laglanju + (abs(bvec) * avec + abs(avec) * bvec) /
(abs(avec) + abs(bvec)));
}
// 点と点の垂直二等分線 aを左に見ながら
Line point_bisection(const Point &a, const Point &b) {
const Point cen((a + b) / 2.l);
const Point vec = (b - a) * Point(0, 1);
return Line(cen, cen + vec);
}
// 三つの点からなる外心
Point outer_center(const vector<Point> &ps) {
assert(ps.size() == 3);
Line l1 = point_bisection(ps[0], ps[1]);
Line l2 = point_bisection(ps[1], ps[2]);
return is_ll(l1, l2);
}
// 三つの直線からなる内心
// 三つの直線が並行でないことは確かめといてね
Point inner_center(const vector<Line> &ls) {
vector<Point> vertics;
for (int i = 0; i < static_cast<int>(ls.size()); ++i) {
vertics.push_back(is_ll(ls[i], ls[(i + 1) % 3]));
}
if (vertics[0] == vertics[1] || vertics[1] == vertics[2] ||
vertics[2] == vertics[0])
return vertics[0];
Line bi1(line_bisection(Line(vertics[0], vertics[1]),
Line(vertics[0], vertics[2])));
Line bi2(line_bisection(Line(vertics[1], vertics[2]),
Line(vertics[1], vertics[0])));
if (bi1[0] == bi2[0])
return bi1[0];
else {
return is_ll(bi1, bi2);
}
}
// 三つの直線からなる傍心
// 三つの直線が並行でないことは確かめといてね
vector<Point> ex_center(const vector<Line> &ls) {
vector<Point> vertics;
for (int i = 0; i < static_cast<int>(ls.size()); ++i) {
vertics.push_back(is_ll(ls[i], ls[(i + 1) % 3]));
}
if (abs(vertics[0] - vertics[1]) < eps ||
abs(vertics[1] - vertics[2]) < eps ||
(abs(vertics[2] - vertics[0]) < eps))
return vector<Point>();
vector<Point> ecs;
for (int i = 0; i < 3; ++i) {
Line bi1(line_bisection(
Line(vertics[i], vertics[i] * 2.0l - vertics[(i + 2) % 3]),
Line(vertics[i], vertics[(i + 1) % 3])));
Line bi2(
line_bisection(Line(vertics[(i + 1) % 3],
vertics[(i + 1) % 3] * 2.0l - vertics[(i + 2) % 3]),
Line(vertics[(i + 1) % 3], vertics[i])));
ecs.push_back(is_ll(bi1, bi2));
}
return ecs;
}
// a,b:並行
// c:並行でない
// 三つの直線から同距離の位置を求める。
vector<Point> same_dis(const vector<Line> &ls) {
vector<Point> vertics;
vertics.push_back(is_ll(ls[0], ls[2]));
vertics.push_back(is_ll(ls[1], ls[2]));
if (abs(vertics[0] - vertics[1]) < eps)
return vector<Point>{vertics[0]};
Line bis(line_bisection(ls[0], ls[1]));
vector<Point> ecs;
Line abi(line_bisection(Line(vertics[0], vertics[1]), ls[0]));
ecs.push_back(is_ll(bis, abi));
Line bbi(
line_bisection(Line(vertics[0], 2.l * vertics[0] - vertics[1]), ls[0]));
ecs.push_back(is_ll(bis, bbi));
return ecs;
}
/* 円 */
// 円と円の交点
vector<Point> is_cc(const Circle &c1, const Circle &c2) {
vector<Point> res;
ld d = abs(c1.p - c2.p);
ld rc = (d * d + c1.r * c1.r - c2.r * c2.r) / (2 * d);
ld dfr = c1.r * c1.r - rc * rc;
if (abs(dfr) < eps)
dfr = 0.0;
else if (dfr < 0.0)
return res; // no intersection
ld rs = sqrt(dfr);
Point diff = (c2.p - c1.p) / d;
res.push_back(c1.p + diff * Point(rc, rs));
if (dfr != 0.0)
res.push_back(c1.p + diff * Point(rc, -rs));
return res;
}
/*
点が円の中にいるか
0 => out
1 => on
2 => in*/
int is_in_Circle(const Point &p, const Circle &cir) {
ld dis = abs(cir.p - p);
if (dis > cir.r + eps)
return 0;
else if (dis < cir.r - eps)
return 2;
else
return 1;
}
int is_in_Circle(const Circle &cir, const Point &p) {
ld dis = abs(cir.p - p);
if (dis > cir.r + eps)
return 0;
else if (dis < cir.r - eps)
return 2;
else
return 1;
}
/*
円lcが円rcの中にいるか
0 => out
1 => on
2 => in*/
int Circle_in_Circle(const Circle &lc, const Circle &rc) {
ld dis = abs(lc.p - rc.p);
if (dis < rc.r - lc.r - eps)
return 2;
else if (dis > rc.r - lc.r + eps)
return 0;
else
return 1;
}
// 円と直線の交点
vector<Point> is_lc(const Circle &c, const Line &l) {
vector<Point> res;
ld d = dist_lp(l, c.p);
if (d < c.r + eps) {
ld len = (d > c.r) ? 0.0 : sqrt(c.r * c.r - d * d); // safety;
Point nor = (l.a - l.b) / abs(l.a - l.b);
res.push_back(proj(l, c.p) + len * nor);
res.push_back(proj(l, c.p) - len * nor);
}
return res;
}
// 円と線分の距離
vector<Point> is_sc(const Circle &c, const Line &l) {
vector<Point> v = is_lc(c, l), res;
for (Point p : v)
if (isis_sp(l, p))
res.push_back(p);
return res;
}
// 円と点の接線
vector<Line> tangent_cp(const Circle &c, const Point &p) {
vector<Line> ret;
Point v = c.p - p;
ld d = abs(v);
ld l = sqrt(norm(v) - c.r * c.r);
if (isnan(l)) {
return ret;
}
Point v1 = v * Point(l / d, c.r / d);
Point v2 = v * Point(l / d, -c.r / d);
ret.push_back(Line(p, p + v1));
if (l < eps)
return ret;
ret.push_back(Line(p, p + v2));
return ret;
}
// 円と円の接線
vector<Line> tangent_cc(const Circle &c1, const Circle &c2) {
vector<Line> ret;
if (abs(c1.p - c2.p) - (c1.r + c2.r) > -eps) {
Point center = (c1.p * c2.r + c2.p * c1.r) / (c1.r + c2.r);
ret = tangent_cp(c1, center);
}
if (abs(c1.r - c2.r) > eps) {
Point out = (-c1.p * c2.r + c2.p * c1.r) / (c1.r - c2.r);
vector<Line> nret = tangent_cp(c1, out);
ret.insert(ret.end(), nret.begin(), nret.end());
} else {
Point v = c2.p - c1.p;
v /= abs(v);
Point q1 = c1.p + v * Point(0, 1) * c1.r;
Point q2 = c1.p + v * Point(0, -1) * c1.r;
ret.push_back(Line(q1, q1 + v));
ret.push_back(Line(q2, q2 + v));
}
return ret;
}
// 二つの円の重なり面積
ld two_Circle_area(const Circle &l, const Circle &r) {
ld dis = abs(l.p - r.p);
if (dis > l.r + r.r)
return 0;
else if (dis + r.r < l.r) {
return r.r * r.r * pi;
} else if (dis + l.r < r.r) {
return l.r * l.r * pi;
} else {
ld ans = (l.r) * (l.r) *
acos((dis * dis + l.r * l.r - r.r * r.r) / (2 * dis * l.r)) +
(r.r) * (r.r) *
acos((dis * dis + r.r * r.r - l.r * l.r) / (2 * dis * r.r)) -
sqrt(4 * dis * dis * l.r * l.r -
(dis * dis + l.r * l.r - r.r * r.r) *
(dis * dis + l.r * l.r - r.r * r.r)) /
2;
return ans;
}
}
/* 多角形 */
typedef vector<Point> Polygon;
// 多角形(複数の点)の最小包含円をO(N=頂点数)で求めるアルゴリズム
// 同一直線上に三つの点がないこと
#include <random>
Circle welzl(vector<Point> ps) {
struct solver {
Circle solve(vector<Point> &ps, vector<Point> &rs) {
if (ps.empty() || rs.size() == 3) {
if (rs.size() == 1) {
return Circle(Point(rs[0]), 0);
} else if (rs.size() == 2) {
return Circle((rs[0] + rs[1]) / 2.0l, abs(rs[1] - rs[0]) / 2);
} else if (rs.size() == 3) {
vector<Line> ls(3);
for (int i = 0; i < 3; ++i) {
ls[i] = Line(rs[i], rs[(i + 1) % 3]);
}
Point center = outer_center(rs);
return Circle(center, abs(center - rs[0]));
} else {
return Circle(Point(), 0);
}
} else {
Point p_ba = ps.back();
ps.pop_back();
Circle d = solve(ps, rs);
ps.push_back(p_ba);
if (is_in_Circle(d, p_ba)) {
return d;
} else {
rs.push_back(p_ba);
ps.pop_back();
auto ans = solve(ps, rs);
ps.push_back(p_ba);
rs.pop_back();
return ans;
}
}
}
} so;
std::random_device rd;
std::mt19937 mt(rd());
shuffle(ps.begin(), ps.end(), mt);
vector<Point> rs;
Circle ans = so.solve(ps, rs);
return ans;
}
// 面積
ld get_area(const Polygon &p) {
ld res = 0;
int n = p.size();
for (int j = 0; j < n; ++j)
res += cross(p[j], p[(j + 1) % n]);
return res / 2;
}
// 多角形の回転方向
bool is_counter_clockwise(const Polygon &poly) {
ld angle = 0;
int n = poly.size();
for (int i = 0; i < n; ++i) {
Point a = poly[i], b = poly[(i + 1) % n], c = poly[(i + 2) % n];
angle += arg((c - b) / (b - a));
}
return angle > eps;
}
// 円の内外判定
/*0 => out
1 => on
2 => in*/
int is_in_Polygon(const Polygon &poly, const Point &p) {
ld angle = 0;
int n = poly.size();
for (int i = 0; i < n; ++i) {
Point a = poly[i], b = poly[(i + 1) % n];
if (isis_sp(Line(a, b), p))
return 1;
angle += arg((b - p) / (a - p));
}
return eq(angle, 0) ? 0 : 2;
}
// 円の内外判定2 高速
enum { out, on, in };
int convex_contains(const Polygon &P, const Point &p) {
const int n = P.size();
Point g = (P[0] + P[n / 3] + P[2 * n / 3]) / 3.0l; // inner-point
int a = 0, b = n;
while (a + 1 < b) { // invariant: c is in fan g-P[a]-P[b]
int c = (a + b) / 2;
if (cross(P[a] - g, P[c] - g) > 0) { // angle < 180 deg
if (cross(P[a] - g, p - g) > 0 && cross(P[c] - g, p - g) < 0)
b = c;
else
a = c;
} else {
if (cross(P[a] - g, p - g) < 0 && cross(P[c] - g, p - g) > 0)
a = c;
else
b = c;
}
}
b %= n;
if (cross(P[a] - p, P[b] - p) < 0)
return 0;
if (cross(P[a] - p, P[b] - p) > 0)
return 2;
return 1;
}
// 凸包
// 点や線を返すことも有り得るので注意
Polygon convex_hull(vector<Point> ps) {
int n = ps.size();
int k = 0;
sort(ps.begin(), ps.end());
Polygon ch(2 * n);
for (int i = 0; i < n; ch[k++] = ps[i++])
while (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0)
--k;
for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--])
while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0)
--k;
ch.resize(k - 1);
return ch;
}
// 凸カット
vector<Polygon> convex_cut(const Polygon &ps, const Line &l) {
int n = ps.size();
Polygon q;
Polygon r;
for (int i = 0; i < n; ++i) {
Point a = ps[i], b = ps[(i + 1) % n];
Line m = Line(a, b);
if (ccw(l.a, l.b, a) != -1)
q.push_back(a);
if (ccw(l.a, l.b, a) != 1)
r.push_back(a);
if (ccw(l.a, l.b, a) * ccw(l.a, l.b, b) < 0 && isis_ll(l, m)) {
q.push_back(is_ll(l, m));
r.push_back(is_ll(l, m));
}
}
const vector<Polygon> polys{q, r};
return polys;
}
/* アレンジメント */
void add_Point(vector<Point> &ps, const Point p) {
for (Point q : ps)
if (abs(q - p) < eps)
return;
ps.push_back(p);
}
bool solve(vector<pair<ld, vector<int>>> bombs, int N, int M, ld len) {
{
auto n_bombs(bombs);
n_bombs.clear();
for (int i = 0; i < bombs.size(); ++i) {
ld r = bombs[i].first;
if (r < len)
n_bombs.emplace_back(bombs[i]);
}
bombs = n_bombs;
}
vector<vector<int>> memo(M + 1, vector<int>(1 << N));
memo[0][0] = true;
for (int b_use = 0; b_use < M; ++b_use) {
for (int i = 0; i < (1 << N); ++i) {
if (!memo[b_use][i])
continue;
for (auto &&now_b : bombs) {
bitset<14> bs(i);
for (int j = 0; j < N; ++j) {
if (now_b.second[j])
bs[j] = true;
}
memo[b_use + 1][bs.to_ulong()] = true;
}
}
}
return memo[M][(1 << N) - 1];
}
int main() {
int N, M;
cin >> N >> M;
vector<Point> pos;
for (int i = 0; i < N; ++i) {
int x, y;
cin >> x >> y;
pos.push_back(Point(x, y));
}
vector<pair<ld, vector<int>>> bombs;
{
vector<int> v(3);
for (v[0] = 0; v[0] < N; ++v[0]) {
{
ld r = 1e-8;
Circle c(pos[v[0]], r);
vector<int> oks(N);
for (int i = 0; i < N; ++i) {
if (is_in_Circle(c, pos[i])) {
oks[i] = true;
}
}
bombs.push_back(make_pair(r, oks));
}
for (v[1] = v[0] + 1; v[1] < N; ++v[1]) {
{
Point p((pos[v[0]] + pos[v[1]]) / 2.0l);
const ld r = abs(p - pos[v[0]]);
Circle c(p, r);
vector<int> oks(N);
for (int i = 0; i < N; ++i) {
if (is_in_Circle(c, pos[i])) {
oks[i] = true;
}
}
bombs.push_back(make_pair(r, oks));
}
for (v[2] = v[1] + 1; v[2] < N; ++v[2]) {
vector<Point> ci_pos(3);
for (int i = 0; i < 3; ++i) {
ci_pos[i] = pos[v[i]];
}
Line l1 = point_bisection(ci_pos[0], ci_pos[1]);
Line l2 = point_bisection(ci_pos[1], ci_pos[2]);
Point sv = l1.b - l1.a, tv = l2.b - l2.a;
if (abs(cross(sv, tv)) < eps) {
continue;
}
Point p(outer_center(ci_pos));
const ld r = abs(p - ci_pos[0]);
Circle c(p, r);
vector<int> oks(N);
for (int i = 0; i < N; ++i) {
if (is_in_Circle(c, pos[i])) {
oks[i] = true;
}
}
bombs.push_back(make_pair(r, oks));
}
}
}
}
{
map<int, ld> mp;
for (auto &&bomb : bombs) {
bitset<14> bs;
for (int i = 0; i < bomb.second.size(); ++i) {
if (bomb.second[i])
bs[i] = true;
}
if (mp.find(bs.to_ulong()) == mp.end()) {
mp[bs.to_ulong()] = bomb.first;
} else {
mp[bs.to_ulong()] = min(bomb.first, mp[bs.to_ulong()]);
}
}
auto n_bombs(bombs);
n_bombs.clear();
for (auto m : mp) {
bitset<14> bs(m.first);
vector<int> v(N);
for (int i = 0; i < N; ++i) {
if (bs[i])
v[i] = true;
}
n_bombs.emplace_back(m.second, v);
}
bombs = n_bombs;
}
ld l = 0, r = 1e9;
int time = 50;
while (time--) {
ld m = (l + r) / 2;
if (solve(bombs, N, M, m)) {
r = m;
} else {
l = m;
}
}
cout << setprecision(10) << fixed;
cout << l << 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;
/* 幾何の基本 */
#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();
}
}
};
// 円の定義
class Circle {
public:
Point p;
ld r;
Circle() : p(Point(0, 0)), r(0) {}
Circle(Point p, ld r) : p(p), r(r) {}
};
// ccw
// 1: a,b,cが反時計周りの順に並ぶ
//-1: a,b,cが時計周りの順に並ぶ
// 2: c,a,bの順に直線に並ぶ
//-2: a,b,cの順に直線に並ぶ
// 0: a,c,bの順に直線に並ぶ
int ccw(const Point &a, const Point &b, const Point &c) {
const Point nb(b - a);
const Point nc(c - a);
if (cross(nb, nc) > eps)
return 1; // a,b,cが反時計周りの順に並ぶ
if (cross(nb, nc) < -eps)
return -1; // a,b,cが時計周りの順に並ぶ
if (dot(nb, nc) < 0)
return 2; // c,a,bの順に直線に並ぶ
if (norm(nb) < norm(nc))
return -2; // a,b,cの順に直線に並ぶ
return 0; // a,c,bの順に直線に並ぶ
}
/* 交差判定 */
// 直線と直線の交差判定
bool isis_ll(const Line &l, const Line &m) {
return !eq(cross(l.b - l.a, m.b - m.a), 0);
}
// 直線と線分の交差判定
bool isis_ls(const Line &l, const Line &s) {
return isis_ll(l, s) &&
(cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < eps);
}
// 線分と線分の交差判定
bool isis_ss(const Line &s, const Line &t) {
return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0 &&
ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0;
}
// 点の直線上判定
bool isis_lp(const Line &l, const Point &p) {
return (abs(cross(l.b - p, l.a - p)) < eps);
}
// 点の線分上判定
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);
}
// 線対象の位置にある点
Point reflect(const Line &l, const Point &p) {
Point pr = proj(l, p);
return pr * 2.l - p;
}
// 直線と直線の交点
Point is_ll(const Line &s, const Line &t) {
Point sv = s.b - s.a, tv = t.b - t.a;
assert(cross(sv, tv) != 0);
return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv);
}
// 直線と直線の交点
vector<Point> is_ll2(const Line &s, const Line &t) {
Point sv = s.b - s.a, tv = t.b - t.a;
if (cross(sv, tv) != 0)
return vector<Point>(1, is_ll(s, t));
else {
vector<Point> ans;
for (int k = 0; k < 2; ++k) {
if (isis_sp(s, t[k]) && find(ans.begin(), ans.end(), t[k]) == ans.end())
ans.push_back(t[k]);
if (isis_sp(t, s[k]) && find(ans.begin(), ans.end(), s[k]) == ans.end())
ans.push_back(s[k]);
}
return ans;
}
}
// 線分と線分の交点
// 重なってる部分あるとassert(false)
Point is_ss(const Line &s, const Line &t) {
if (isis_ss(s, t)) {
for (int k = 0; k < 2; ++k) {
for (int l = 0; l < 2; ++l) {
if (s[k] == t[l])
return s[k];
}
}
return is_ll(s, t);
} else {
// 先にisis_ssしてね
assert(false);
return Point(0, 0);
}
}
// 線分と線分の交点
vector<Point> is_ss2(const Line &s, const Line &t) {
vector<Point> kouho(is_ll2(s, t));
vector<Point> ans;
for (auto p : kouho) {
if (isis_sp(s, p) && isis_sp(t, p))
ans.emplace_back(p);
}
return ans;
}
// 直線と点の距離
ld dist_lp(const Line &l, const Point &p) { return abs(p - proj(l, p)); }
// 直線と直線の距離
ld dist_ll(const Line &l, const Line &m) {
return isis_ll(l, m) ? 0 : dist_lp(l, m.a);
}
// 直線と線分の距離
ld dist_ls(const Line &l, const Line &s) {
return isis_ls(l, s) ? 0 : min(dist_lp(l, s.a), dist_lp(l, s.b));
}
// 線分と点の距離
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));
}
// 線分と線分の距離
ld dist_ss(const Line &s, const 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)});
}
// 直線と直線の二等分線のベクトル
Line line_bisection(const Line &s, const Line &t) {
const Point laglanju(is_ll(s, t));
const Point avec =
!(abs(laglanju - s[0]) < eps) ? s[0] - laglanju : s[1] - laglanju;
const Point bvec =
!(abs(laglanju - t[0]) < eps) ? t[0] - laglanju : t[1] - laglanju;
return Line(laglanju, laglanju + (abs(bvec) * avec + abs(avec) * bvec) /
(abs(avec) + abs(bvec)));
}
// 点と点の垂直二等分線 aを左に見ながら
Line point_bisection(const Point &a, const Point &b) {
const Point cen((a + b) / 2.l);
const Point vec = (b - a) * Point(0, 1);
return Line(cen, cen + vec);
}
// 三つの点からなる外心
Point outer_center(const vector<Point> &ps) {
assert(ps.size() == 3);
Line l1 = point_bisection(ps[0], ps[1]);
Line l2 = point_bisection(ps[1], ps[2]);
return is_ll(l1, l2);
}
// 三つの直線からなる内心
// 三つの直線が並行でないことは確かめといてね
Point inner_center(const vector<Line> &ls) {
vector<Point> vertics;
for (int i = 0; i < static_cast<int>(ls.size()); ++i) {
vertics.push_back(is_ll(ls[i], ls[(i + 1) % 3]));
}
if (vertics[0] == vertics[1] || vertics[1] == vertics[2] ||
vertics[2] == vertics[0])
return vertics[0];
Line bi1(line_bisection(Line(vertics[0], vertics[1]),
Line(vertics[0], vertics[2])));
Line bi2(line_bisection(Line(vertics[1], vertics[2]),
Line(vertics[1], vertics[0])));
if (bi1[0] == bi2[0])
return bi1[0];
else {
return is_ll(bi1, bi2);
}
}
// 三つの直線からなる傍心
// 三つの直線が並行でないことは確かめといてね
vector<Point> ex_center(const vector<Line> &ls) {
vector<Point> vertics;
for (int i = 0; i < static_cast<int>(ls.size()); ++i) {
vertics.push_back(is_ll(ls[i], ls[(i + 1) % 3]));
}
if (abs(vertics[0] - vertics[1]) < eps ||
abs(vertics[1] - vertics[2]) < eps ||
(abs(vertics[2] - vertics[0]) < eps))
return vector<Point>();
vector<Point> ecs;
for (int i = 0; i < 3; ++i) {
Line bi1(line_bisection(
Line(vertics[i], vertics[i] * 2.0l - vertics[(i + 2) % 3]),
Line(vertics[i], vertics[(i + 1) % 3])));
Line bi2(
line_bisection(Line(vertics[(i + 1) % 3],
vertics[(i + 1) % 3] * 2.0l - vertics[(i + 2) % 3]),
Line(vertics[(i + 1) % 3], vertics[i])));
ecs.push_back(is_ll(bi1, bi2));
}
return ecs;
}
// a,b:並行
// c:並行でない
// 三つの直線から同距離の位置を求める。
vector<Point> same_dis(const vector<Line> &ls) {
vector<Point> vertics;
vertics.push_back(is_ll(ls[0], ls[2]));
vertics.push_back(is_ll(ls[1], ls[2]));
if (abs(vertics[0] - vertics[1]) < eps)
return vector<Point>{vertics[0]};
Line bis(line_bisection(ls[0], ls[1]));
vector<Point> ecs;
Line abi(line_bisection(Line(vertics[0], vertics[1]), ls[0]));
ecs.push_back(is_ll(bis, abi));
Line bbi(
line_bisection(Line(vertics[0], 2.l * vertics[0] - vertics[1]), ls[0]));
ecs.push_back(is_ll(bis, bbi));
return ecs;
}
/* 円 */
// 円と円の交点
vector<Point> is_cc(const Circle &c1, const Circle &c2) {
vector<Point> res;
ld d = abs(c1.p - c2.p);
ld rc = (d * d + c1.r * c1.r - c2.r * c2.r) / (2 * d);
ld dfr = c1.r * c1.r - rc * rc;
if (abs(dfr) < eps)
dfr = 0.0;
else if (dfr < 0.0)
return res; // no intersection
ld rs = sqrt(dfr);
Point diff = (c2.p - c1.p) / d;
res.push_back(c1.p + diff * Point(rc, rs));
if (dfr != 0.0)
res.push_back(c1.p + diff * Point(rc, -rs));
return res;
}
/*
点が円の中にいるか
0 => out
1 => on
2 => in*/
int is_in_Circle(const Point &p, const Circle &cir) {
ld dis = abs(cir.p - p);
if (dis > cir.r + eps)
return 0;
else if (dis < cir.r - eps)
return 2;
else
return 1;
}
int is_in_Circle(const Circle &cir, const Point &p) {
ld dis = abs(cir.p - p);
if (dis > cir.r + eps)
return 0;
else if (dis < cir.r - eps)
return 2;
else
return 1;
}
/*
円lcが円rcの中にいるか
0 => out
1 => on
2 => in*/
int Circle_in_Circle(const Circle &lc, const Circle &rc) {
ld dis = abs(lc.p - rc.p);
if (dis < rc.r - lc.r - eps)
return 2;
else if (dis > rc.r - lc.r + eps)
return 0;
else
return 1;
}
// 円と直線の交点
vector<Point> is_lc(const Circle &c, const Line &l) {
vector<Point> res;
ld d = dist_lp(l, c.p);
if (d < c.r + eps) {
ld len = (d > c.r) ? 0.0 : sqrt(c.r * c.r - d * d); // safety;
Point nor = (l.a - l.b) / abs(l.a - l.b);
res.push_back(proj(l, c.p) + len * nor);
res.push_back(proj(l, c.p) - len * nor);
}
return res;
}
// 円と線分の距離
vector<Point> is_sc(const Circle &c, const Line &l) {
vector<Point> v = is_lc(c, l), res;
for (Point p : v)
if (isis_sp(l, p))
res.push_back(p);
return res;
}
// 円と点の接線
vector<Line> tangent_cp(const Circle &c, const Point &p) {
vector<Line> ret;
Point v = c.p - p;
ld d = abs(v);
ld l = sqrt(norm(v) - c.r * c.r);
if (isnan(l)) {
return ret;
}
Point v1 = v * Point(l / d, c.r / d);
Point v2 = v * Point(l / d, -c.r / d);
ret.push_back(Line(p, p + v1));
if (l < eps)
return ret;
ret.push_back(Line(p, p + v2));
return ret;
}
// 円と円の接線
vector<Line> tangent_cc(const Circle &c1, const Circle &c2) {
vector<Line> ret;
if (abs(c1.p - c2.p) - (c1.r + c2.r) > -eps) {
Point center = (c1.p * c2.r + c2.p * c1.r) / (c1.r + c2.r);
ret = tangent_cp(c1, center);
}
if (abs(c1.r - c2.r) > eps) {
Point out = (-c1.p * c2.r + c2.p * c1.r) / (c1.r - c2.r);
vector<Line> nret = tangent_cp(c1, out);
ret.insert(ret.end(), nret.begin(), nret.end());
} else {
Point v = c2.p - c1.p;
v /= abs(v);
Point q1 = c1.p + v * Point(0, 1) * c1.r;
Point q2 = c1.p + v * Point(0, -1) * c1.r;
ret.push_back(Line(q1, q1 + v));
ret.push_back(Line(q2, q2 + v));
}
return ret;
}
// 二つの円の重なり面積
ld two_Circle_area(const Circle &l, const Circle &r) {
ld dis = abs(l.p - r.p);
if (dis > l.r + r.r)
return 0;
else if (dis + r.r < l.r) {
return r.r * r.r * pi;
} else if (dis + l.r < r.r) {
return l.r * l.r * pi;
} else {
ld ans = (l.r) * (l.r) *
acos((dis * dis + l.r * l.r - r.r * r.r) / (2 * dis * l.r)) +
(r.r) * (r.r) *
acos((dis * dis + r.r * r.r - l.r * l.r) / (2 * dis * r.r)) -
sqrt(4 * dis * dis * l.r * l.r -
(dis * dis + l.r * l.r - r.r * r.r) *
(dis * dis + l.r * l.r - r.r * r.r)) /
2;
return ans;
}
}
/* 多角形 */
typedef vector<Point> Polygon;
// 多角形(複数の点)の最小包含円をO(N=頂点数)で求めるアルゴリズム
// 同一直線上に三つの点がないこと
#include <random>
Circle welzl(vector<Point> ps) {
struct solver {
Circle solve(vector<Point> &ps, vector<Point> &rs) {
if (ps.empty() || rs.size() == 3) {
if (rs.size() == 1) {
return Circle(Point(rs[0]), 0);
} else if (rs.size() == 2) {
return Circle((rs[0] + rs[1]) / 2.0l, abs(rs[1] - rs[0]) / 2);
} else if (rs.size() == 3) {
vector<Line> ls(3);
for (int i = 0; i < 3; ++i) {
ls[i] = Line(rs[i], rs[(i + 1) % 3]);
}
Point center = outer_center(rs);
return Circle(center, abs(center - rs[0]));
} else {
return Circle(Point(), 0);
}
} else {
Point p_ba = ps.back();
ps.pop_back();
Circle d = solve(ps, rs);
ps.push_back(p_ba);
if (is_in_Circle(d, p_ba)) {
return d;
} else {
rs.push_back(p_ba);
ps.pop_back();
auto ans = solve(ps, rs);
ps.push_back(p_ba);
rs.pop_back();
return ans;
}
}
}
} so;
std::random_device rd;
std::mt19937 mt(rd());
shuffle(ps.begin(), ps.end(), mt);
vector<Point> rs;
Circle ans = so.solve(ps, rs);
return ans;
}
// 面積
ld get_area(const Polygon &p) {
ld res = 0;
int n = p.size();
for (int j = 0; j < n; ++j)
res += cross(p[j], p[(j + 1) % n]);
return res / 2;
}
// 多角形の回転方向
bool is_counter_clockwise(const Polygon &poly) {
ld angle = 0;
int n = poly.size();
for (int i = 0; i < n; ++i) {
Point a = poly[i], b = poly[(i + 1) % n], c = poly[(i + 2) % n];
angle += arg((c - b) / (b - a));
}
return angle > eps;
}
// 円の内外判定
/*0 => out
1 => on
2 => in*/
int is_in_Polygon(const Polygon &poly, const Point &p) {
ld angle = 0;
int n = poly.size();
for (int i = 0; i < n; ++i) {
Point a = poly[i], b = poly[(i + 1) % n];
if (isis_sp(Line(a, b), p))
return 1;
angle += arg((b - p) / (a - p));
}
return eq(angle, 0) ? 0 : 2;
}
// 円の内外判定2 高速
enum { out, on, in };
int convex_contains(const Polygon &P, const Point &p) {
const int n = P.size();
Point g = (P[0] + P[n / 3] + P[2 * n / 3]) / 3.0l; // inner-point
int a = 0, b = n;
while (a + 1 < b) { // invariant: c is in fan g-P[a]-P[b]
int c = (a + b) / 2;
if (cross(P[a] - g, P[c] - g) > 0) { // angle < 180 deg
if (cross(P[a] - g, p - g) > 0 && cross(P[c] - g, p - g) < 0)
b = c;
else
a = c;
} else {
if (cross(P[a] - g, p - g) < 0 && cross(P[c] - g, p - g) > 0)
a = c;
else
b = c;
}
}
b %= n;
if (cross(P[a] - p, P[b] - p) < 0)
return 0;
if (cross(P[a] - p, P[b] - p) > 0)
return 2;
return 1;
}
// 凸包
// 点や線を返すことも有り得るので注意
Polygon convex_hull(vector<Point> ps) {
int n = ps.size();
int k = 0;
sort(ps.begin(), ps.end());
Polygon ch(2 * n);
for (int i = 0; i < n; ch[k++] = ps[i++])
while (k >= 2 && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0)
--k;
for (int i = n - 2, t = k + 1; i >= 0; ch[k++] = ps[i--])
while (k >= t && ccw(ch[k - 2], ch[k - 1], ps[i]) <= 0)
--k;
ch.resize(k - 1);
return ch;
}
// 凸カット
vector<Polygon> convex_cut(const Polygon &ps, const Line &l) {
int n = ps.size();
Polygon q;
Polygon r;
for (int i = 0; i < n; ++i) {
Point a = ps[i], b = ps[(i + 1) % n];
Line m = Line(a, b);
if (ccw(l.a, l.b, a) != -1)
q.push_back(a);
if (ccw(l.a, l.b, a) != 1)
r.push_back(a);
if (ccw(l.a, l.b, a) * ccw(l.a, l.b, b) < 0 && isis_ll(l, m)) {
q.push_back(is_ll(l, m));
r.push_back(is_ll(l, m));
}
}
const vector<Polygon> polys{q, r};
return polys;
}
/* アレンジメント */
void add_Point(vector<Point> &ps, const Point p) {
for (Point q : ps)
if (abs(q - p) < eps)
return;
ps.push_back(p);
}
bool solve(vector<pair<ld, vector<int>>> bombs, int N, int M, ld len) {
{
auto n_bombs(bombs);
n_bombs.clear();
for (int i = 0; i < bombs.size(); ++i) {
ld r = bombs[i].first;
if (r < len)
n_bombs.emplace_back(bombs[i]);
}
bombs = n_bombs;
}
vector<vector<int>> memo(M + 1, vector<int>(1 << N));
memo[0][0] = true;
for (int b_use = 0; b_use < M; ++b_use) {
for (int i = 0; i < (1 << N); ++i) {
if (!memo[b_use][i])
continue;
for (auto &&now_b : bombs) {
bitset<14> bs(i);
for (int j = 0; j < N; ++j) {
if (now_b.second[j])
bs[j] = true;
}
memo[b_use + 1][bs.to_ulong()] = true;
}
}
}
return memo[M][(1 << N) - 1];
}
int main() {
int N, M;
cin >> N >> M;
vector<Point> pos;
for (int i = 0; i < N; ++i) {
int x, y;
cin >> x >> y;
pos.push_back(Point(x, y));
}
vector<pair<ld, vector<int>>> bombs;
{
vector<int> v(3);
for (v[0] = 0; v[0] < N; ++v[0]) {
{
ld r = 1e-8;
Circle c(pos[v[0]], r);
vector<int> oks(N);
for (int i = 0; i < N; ++i) {
if (is_in_Circle(c, pos[i])) {
oks[i] = true;
}
}
bombs.push_back(make_pair(r, oks));
}
for (v[1] = v[0] + 1; v[1] < N; ++v[1]) {
{
Point p((pos[v[0]] + pos[v[1]]) / 2.0l);
const ld r = abs(p - pos[v[0]]);
Circle c(p, r);
vector<int> oks(N);
for (int i = 0; i < N; ++i) {
if (is_in_Circle(c, pos[i])) {
oks[i] = true;
}
}
bombs.push_back(make_pair(r, oks));
}
for (v[2] = v[1] + 1; v[2] < N; ++v[2]) {
vector<Point> ci_pos(3);
for (int i = 0; i < 3; ++i) {
ci_pos[i] = pos[v[i]];
}
Line l1 = point_bisection(ci_pos[0], ci_pos[1]);
Line l2 = point_bisection(ci_pos[1], ci_pos[2]);
Point sv = l1.b - l1.a, tv = l2.b - l2.a;
if (abs(cross(sv, tv)) < eps) {
continue;
}
Point p(outer_center(ci_pos));
const ld r = abs(p - ci_pos[0]);
Circle c(p, r);
vector<int> oks(N);
for (int i = 0; i < N; ++i) {
if (is_in_Circle(c, pos[i])) {
oks[i] = true;
}
}
bombs.push_back(make_pair(r, oks));
}
}
}
}
{
map<int, ld> mp;
for (auto &&bomb : bombs) {
bitset<14> bs;
for (int i = 0; i < bomb.second.size(); ++i) {
if (bomb.second[i])
bs[i] = true;
}
if (mp.find(bs.to_ulong()) == mp.end()) {
mp[bs.to_ulong()] = bomb.first;
} else {
mp[bs.to_ulong()] = min(bomb.first, mp[bs.to_ulong()]);
}
}
auto n_bombs(bombs);
n_bombs.clear();
for (auto m : mp) {
bitset<14> bs(m.first);
vector<int> v(N);
for (int i = 0; i < N; ++i) {
if (bs[i])
v[i] = true;
}
n_bombs.emplace_back(m.second, v);
}
bombs = n_bombs;
}
ld l = 0, r = 1e5;
int time = 30;
while (time--) {
ld m = (l + r) / 2;
if (solve(bombs, N, M, m)) {
r = m;
} else {
l = m;
}
}
cout << setprecision(10) << fixed;
cout << l << endl;
return 0;
}
|
replace
| 733 | 735 | 733 | 735 |
TLE
| |
p02133
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#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;
}
// const int B = 20;
// const int SZ = 2;
const int B = 320;
const int SZ = 320;
const int INF = 123456789;
const ll LINF = LLONG_MAX / 3;
int X[2];
int x[2][B][SZ];
int ADD[2][B];
int MIN[2][B], MAX[2][B];
unordered_map<int, int> ct[2][B];
void update(int t, int bid) {
MIN[t][bid] = INF;
MAX[t][bid] = -INF;
ct[t][bid].clear();
rep(i, SZ) {
int idx = bid * SZ + i;
if (idx >= X[t])
break;
MIN[t][bid] = min(MIN[t][bid], x[t][bid][i]);
MAX[t][bid] = max(MAX[t][bid], x[t][bid][i]);
++ct[t][bid][x[t][bid][i]];
}
}
void push(int t, int bid) {
if (ADD[t][bid] == 0)
return;
rep(i, SZ) {
int idx = bid * SZ + i;
if (idx >= X[t])
break;
x[t][bid][i] += ADD[t][bid];
}
ADD[t][bid] = 0;
// update(t,bid);
}
void add(int t, int l, int r, int v) {
int lid = l / SZ, rid = r / SZ;
push(t, lid);
push(t, rid);
if (lid == rid) {
for (int i = l; i <= r; ++i)
x[t][lid][i % SZ] += v;
update(t, lid);
} else {
for (int bid = lid + 1; bid < rid; ++bid) {
ADD[t][bid] += v;
// MAX[t][bid] += v;
// MIN[t][bid] += v;
}
for (int i = l; i < SZ * (lid + 1); ++i)
x[t][lid][i % SZ] += v;
for (int i = SZ * rid; i <= r; ++i)
x[t][rid][i % SZ] += v;
update(t, lid);
update(t, rid);
}
}
ll max_query(int t, int l, int r) {
int lid = l / SZ, rid = r / SZ;
int ret = -INF;
// push(t,lid);
// push(t,rid);
// update(t,lid);
// update(t,rid);
if (lid == rid) {
for (int i = l; i <= r; ++i)
ret = max(ret, x[t][lid][i % SZ] + ADD[t][lid]);
} else {
for (int bid = lid + 1; bid < rid; ++bid)
ret = max(ret, MAX[t][bid] + ADD[t][bid]);
for (int i = l; i < SZ * (lid + 1); ++i)
ret = max(ret, x[t][lid][i % SZ] + ADD[t][lid]);
for (int i = SZ * rid; i <= r; ++i)
ret = max(ret, x[t][rid][i % SZ] + ADD[t][rid]);
}
return (ll)ret;
}
ll min_query(int t, int l, int r) {
int lid = l / SZ, rid = r / SZ;
int ret = INF;
// push(t,lid);
// push(t,rid);
// update(t,lid);
// update(t,rid);
if (lid == rid) {
for (int i = l; i <= r; ++i)
ret = min(ret, x[t][lid][i % SZ] + ADD[t][lid]);
} else {
for (int bid = lid + 1; bid < rid; ++bid)
ret = min(ret, MIN[t][bid] + ADD[t][bid]);
for (int i = l; i < SZ * (lid + 1); ++i)
ret = min(ret, x[t][lid][i % SZ] + ADD[t][lid]);
for (int i = SZ * rid; i <= r; ++i)
ret = min(ret, x[t][rid][i % SZ] + ADD[t][rid]);
}
return (ll)ret;
}
ll cnt(int t, int l, int r, int v) {
int ret = 0;
int lid = l / SZ, rid = r / SZ;
if (lid == rid) {
for (int i = l; i <= r; ++i) {
if (x[t][lid][i % SZ] + ADD[t][lid] == v)
++ret;
}
} else {
for (int bid = lid + 1; bid < rid; ++bid) {
int focus = v - ADD[t][bid];
if (ct[t][bid].count(focus))
ret += ct[t][bid][focus];
}
for (int i = l; i < SZ * (lid + 1); ++i) {
if (x[t][lid][i % SZ] + ADD[t][lid] == v)
++ret;
}
for (int i = SZ * rid; i <= r; ++i) {
if (x[t][rid][i % SZ] + ADD[t][rid] == v)
++ret;
}
}
return (ll)ret;
}
int main() {
int q;
scanf(" %d %d %d", &X[0], &X[1], &q);
rep(i, 2) {
rep(j, X[i]) {
int v;
scanf(" %d", &v);
x[i][j / SZ][j % SZ] = v;
}
rep(j, B) update(i, j);
}
while (q--) {
int t;
scanf(" %d", &t);
if (t <= 2) {
int l, r, v;
scanf(" %d %d %d", &l, &r, &v);
--l;
--r;
add(t - 1, l, r, v);
} else {
int l[2], r[2];
rep(i, 2) {
scanf(" %d %d", &l[i], &r[i]);
--l[i];
--r[i];
}
ll C;
ll ans = 0;
if (t == 3) {
// MIN QUERY
C = LINF;
rep(i, 2) rep(j, 2) {
ll va, vb;
if (i)
va = max_query(0, l[0], r[0]);
else
va = min_query(0, l[0], r[0]);
if (j)
vb = max_query(1, l[1], r[1]);
else
vb = min_query(1, l[1], r[1]);
C = min(C, va * vb);
}
if (C == 0) {
ll a0 = cnt(0, l[0], r[0], 0);
ll b0 = cnt(1, l[1], r[1], 0);
ans += a0 * (r[1] - l[1] + 1);
ans += b0 * (r[0] - l[0] + 1);
ans -= a0 * b0;
} else {
set<pair<ll, ll>> S;
rep(i, 2) rep(j, 2) {
ll va, vb;
if (i)
va = max_query(0, l[0], r[0]);
else
va = min_query(0, l[0], r[0]);
if (j)
vb = max_query(1, l[1], r[1]);
else
vb = min_query(1, l[1], r[1]);
if (va * vb == C)
S.insert({va, vb});
}
for (const auto &p : S) {
int va = p.fi, vb = p.se;
ans += cnt(0, l[0], r[0], va) * cnt(1, l[1], r[1], vb);
}
}
} else {
// MAX QUERY
C = -LINF;
rep(i, 2) rep(j, 2) {
ll va, vb;
if (i)
va = max_query(0, l[0], r[0]);
else
va = min_query(0, l[0], r[0]);
if (j)
vb = max_query(1, l[1], r[1]);
else
vb = min_query(1, l[1], r[1]);
C = max(C, va * vb);
}
if (C == 0) {
ll a0 = cnt(0, l[0], r[0], 0);
ll b0 = cnt(1, l[1], r[1], 0);
ans += a0 * (r[1] - l[1] + 1);
ans += b0 * (r[0] - l[0] + 1);
ans -= a0 * b0;
} else {
set<pair<ll, ll>> S;
rep(i, 2) rep(j, 2) {
ll va, vb;
if (i)
va = max_query(0, l[0], r[0]);
else
va = min_query(0, l[0], r[0]);
if (j)
vb = max_query(1, l[1], r[1]);
else
vb = min_query(1, l[1], r[1]);
if (va * vb == C)
S.insert({va, vb});
}
for (const auto &p : S) {
int va = p.fi, vb = p.se;
ans += cnt(0, l[0], r[0], va) * cnt(1, l[1], r[1], vb);
}
}
}
printf("%lld %lld\n", C, ans);
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#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;
}
// const int B = 20;
// const int SZ = 2;
const int B = 400;
const int SZ = 250;
const int INF = 123456789;
const ll LINF = LLONG_MAX / 3;
int X[2];
int x[2][B][SZ];
int ADD[2][B];
int MIN[2][B], MAX[2][B];
unordered_map<int, int> ct[2][B];
void update(int t, int bid) {
MIN[t][bid] = INF;
MAX[t][bid] = -INF;
ct[t][bid].clear();
rep(i, SZ) {
int idx = bid * SZ + i;
if (idx >= X[t])
break;
MIN[t][bid] = min(MIN[t][bid], x[t][bid][i]);
MAX[t][bid] = max(MAX[t][bid], x[t][bid][i]);
++ct[t][bid][x[t][bid][i]];
}
}
void push(int t, int bid) {
if (ADD[t][bid] == 0)
return;
rep(i, SZ) {
int idx = bid * SZ + i;
if (idx >= X[t])
break;
x[t][bid][i] += ADD[t][bid];
}
ADD[t][bid] = 0;
// update(t,bid);
}
void add(int t, int l, int r, int v) {
int lid = l / SZ, rid = r / SZ;
push(t, lid);
push(t, rid);
if (lid == rid) {
for (int i = l; i <= r; ++i)
x[t][lid][i % SZ] += v;
update(t, lid);
} else {
for (int bid = lid + 1; bid < rid; ++bid) {
ADD[t][bid] += v;
// MAX[t][bid] += v;
// MIN[t][bid] += v;
}
for (int i = l; i < SZ * (lid + 1); ++i)
x[t][lid][i % SZ] += v;
for (int i = SZ * rid; i <= r; ++i)
x[t][rid][i % SZ] += v;
update(t, lid);
update(t, rid);
}
}
ll max_query(int t, int l, int r) {
int lid = l / SZ, rid = r / SZ;
int ret = -INF;
// push(t,lid);
// push(t,rid);
// update(t,lid);
// update(t,rid);
if (lid == rid) {
for (int i = l; i <= r; ++i)
ret = max(ret, x[t][lid][i % SZ] + ADD[t][lid]);
} else {
for (int bid = lid + 1; bid < rid; ++bid)
ret = max(ret, MAX[t][bid] + ADD[t][bid]);
for (int i = l; i < SZ * (lid + 1); ++i)
ret = max(ret, x[t][lid][i % SZ] + ADD[t][lid]);
for (int i = SZ * rid; i <= r; ++i)
ret = max(ret, x[t][rid][i % SZ] + ADD[t][rid]);
}
return (ll)ret;
}
ll min_query(int t, int l, int r) {
int lid = l / SZ, rid = r / SZ;
int ret = INF;
// push(t,lid);
// push(t,rid);
// update(t,lid);
// update(t,rid);
if (lid == rid) {
for (int i = l; i <= r; ++i)
ret = min(ret, x[t][lid][i % SZ] + ADD[t][lid]);
} else {
for (int bid = lid + 1; bid < rid; ++bid)
ret = min(ret, MIN[t][bid] + ADD[t][bid]);
for (int i = l; i < SZ * (lid + 1); ++i)
ret = min(ret, x[t][lid][i % SZ] + ADD[t][lid]);
for (int i = SZ * rid; i <= r; ++i)
ret = min(ret, x[t][rid][i % SZ] + ADD[t][rid]);
}
return (ll)ret;
}
ll cnt(int t, int l, int r, int v) {
int ret = 0;
int lid = l / SZ, rid = r / SZ;
if (lid == rid) {
for (int i = l; i <= r; ++i) {
if (x[t][lid][i % SZ] + ADD[t][lid] == v)
++ret;
}
} else {
for (int bid = lid + 1; bid < rid; ++bid) {
int focus = v - ADD[t][bid];
if (ct[t][bid].count(focus))
ret += ct[t][bid][focus];
}
for (int i = l; i < SZ * (lid + 1); ++i) {
if (x[t][lid][i % SZ] + ADD[t][lid] == v)
++ret;
}
for (int i = SZ * rid; i <= r; ++i) {
if (x[t][rid][i % SZ] + ADD[t][rid] == v)
++ret;
}
}
return (ll)ret;
}
int main() {
int q;
scanf(" %d %d %d", &X[0], &X[1], &q);
rep(i, 2) {
rep(j, X[i]) {
int v;
scanf(" %d", &v);
x[i][j / SZ][j % SZ] = v;
}
rep(j, B) update(i, j);
}
while (q--) {
int t;
scanf(" %d", &t);
if (t <= 2) {
int l, r, v;
scanf(" %d %d %d", &l, &r, &v);
--l;
--r;
add(t - 1, l, r, v);
} else {
int l[2], r[2];
rep(i, 2) {
scanf(" %d %d", &l[i], &r[i]);
--l[i];
--r[i];
}
ll C;
ll ans = 0;
if (t == 3) {
// MIN QUERY
C = LINF;
rep(i, 2) rep(j, 2) {
ll va, vb;
if (i)
va = max_query(0, l[0], r[0]);
else
va = min_query(0, l[0], r[0]);
if (j)
vb = max_query(1, l[1], r[1]);
else
vb = min_query(1, l[1], r[1]);
C = min(C, va * vb);
}
if (C == 0) {
ll a0 = cnt(0, l[0], r[0], 0);
ll b0 = cnt(1, l[1], r[1], 0);
ans += a0 * (r[1] - l[1] + 1);
ans += b0 * (r[0] - l[0] + 1);
ans -= a0 * b0;
} else {
set<pair<ll, ll>> S;
rep(i, 2) rep(j, 2) {
ll va, vb;
if (i)
va = max_query(0, l[0], r[0]);
else
va = min_query(0, l[0], r[0]);
if (j)
vb = max_query(1, l[1], r[1]);
else
vb = min_query(1, l[1], r[1]);
if (va * vb == C)
S.insert({va, vb});
}
for (const auto &p : S) {
int va = p.fi, vb = p.se;
ans += cnt(0, l[0], r[0], va) * cnt(1, l[1], r[1], vb);
}
}
} else {
// MAX QUERY
C = -LINF;
rep(i, 2) rep(j, 2) {
ll va, vb;
if (i)
va = max_query(0, l[0], r[0]);
else
va = min_query(0, l[0], r[0]);
if (j)
vb = max_query(1, l[1], r[1]);
else
vb = min_query(1, l[1], r[1]);
C = max(C, va * vb);
}
if (C == 0) {
ll a0 = cnt(0, l[0], r[0], 0);
ll b0 = cnt(1, l[1], r[1], 0);
ans += a0 * (r[1] - l[1] + 1);
ans += b0 * (r[0] - l[0] + 1);
ans -= a0 * b0;
} else {
set<pair<ll, ll>> S;
rep(i, 2) rep(j, 2) {
ll va, vb;
if (i)
va = max_query(0, l[0], r[0]);
else
va = min_query(0, l[0], r[0]);
if (j)
vb = max_query(1, l[1], r[1]);
else
vb = min_query(1, l[1], r[1]);
if (va * vb == C)
S.insert({va, vb});
}
for (const auto &p : S) {
int va = p.fi, vb = p.se;
ans += cnt(0, l[0], r[0], va) * cnt(1, l[1], r[1], vb);
}
}
}
printf("%lld %lld\n", C, ans);
}
}
return 0;
}
|
replace
| 26 | 28 | 26 | 28 |
TLE
| |
p02133
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#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;
}
// const int B = 20;
// const int SZ = 2;
const int B = 320;
const int SZ = 320;
const int INF = 123456789;
const ll LINF = LLONG_MAX / 3;
int X[2];
int x[2][B][SZ];
int ADD[2][B];
int MIN[2][B], MAX[2][B];
unordered_map<int, int> ct[2][B];
void update(int t, int bid) {
MIN[t][bid] = INF;
MAX[t][bid] = -INF;
ct[t][bid].clear();
rep(i, SZ) {
int idx = bid * SZ + i;
if (idx >= X[t])
break;
MIN[t][bid] = min(MIN[t][bid], x[t][bid][i]);
MAX[t][bid] = max(MAX[t][bid], x[t][bid][i]);
++ct[t][bid][x[t][bid][i]];
}
}
void push(int t, int bid) {
if (ADD[t][bid] == 0)
return;
rep(i, SZ) {
int idx = bid * SZ + i;
if (idx >= X[t])
break;
x[t][bid][i] += ADD[t][bid];
}
ADD[t][bid] = 0;
// update(t,bid);
}
void add(int t, int l, int r, int v) {
int lid = l / SZ, rid = r / SZ;
push(t, lid);
push(t, rid);
if (lid == rid) {
for (int i = l; i <= r; ++i)
x[t][lid][i % SZ] += v;
update(t, lid);
} else {
for (int bid = lid + 1; bid < rid; ++bid) {
ADD[t][bid] += v;
// MAX[t][bid] += v;
// MIN[t][bid] += v;
}
for (int i = l; i < SZ * (lid + 1); ++i)
x[t][lid][i % SZ] += v;
for (int i = SZ * rid; i <= r; ++i)
x[t][rid][i % SZ] += v;
update(t, lid);
update(t, rid);
}
}
ll max_query(int t, int l, int r) {
int lid = l / SZ, rid = r / SZ;
int ret = -INF;
// push(t,lid);
// push(t,rid);
// update(t,lid);
// update(t,rid);
if (lid == rid) {
for (int i = l; i <= r; ++i)
ret = max(ret, x[t][lid][i % SZ] + ADD[t][lid]);
} else {
for (int bid = lid + 1; bid < rid; ++bid)
ret = max(ret, MAX[t][bid] + ADD[t][bid]);
for (int i = l; i < SZ * (lid + 1); ++i)
ret = max(ret, x[t][lid][i % SZ] + ADD[t][lid]);
for (int i = SZ * rid; i <= r; ++i)
ret = max(ret, x[t][rid][i % SZ] + ADD[t][rid]);
}
return (ll)ret;
}
ll min_query(int t, int l, int r) {
int lid = l / SZ, rid = r / SZ;
int ret = INF;
// push(t,lid);
// push(t,rid);
// update(t,lid);
// update(t,rid);
if (lid == rid) {
for (int i = l; i <= r; ++i)
ret = min(ret, x[t][lid][i % SZ] + ADD[t][lid]);
} else {
for (int bid = lid + 1; bid < rid; ++bid)
ret = min(ret, MIN[t][bid] + ADD[t][bid]);
for (int i = l; i < SZ * (lid + 1); ++i)
ret = min(ret, x[t][lid][i % SZ] + ADD[t][lid]);
for (int i = SZ * rid; i <= r; ++i)
ret = min(ret, x[t][rid][i % SZ] + ADD[t][rid]);
}
return (ll)ret;
}
ll cnt(int t, int l, int r, int v) {
int ret = 0;
int lid = l / SZ, rid = r / SZ;
if (lid == rid) {
for (int i = l; i <= r; ++i) {
if (x[t][lid][i % SZ] + ADD[t][lid] == v)
++ret;
}
} else {
for (int bid = lid + 1; bid < rid; ++bid) {
int focus = v - ADD[t][bid];
if (ct[t][bid].count(focus))
ret += ct[t][bid][focus];
}
for (int i = l; i < SZ * (lid + 1); ++i) {
if (x[t][lid][i % SZ] + ADD[t][lid] == v)
++ret;
}
for (int i = SZ * rid; i <= r; ++i) {
if (x[t][rid][i % SZ] + ADD[t][rid] == v)
++ret;
}
}
return (ll)ret;
}
int main() {
int q;
scanf(" %d %d %d", &X[0], &X[1], &q);
rep(i, 2) {
rep(j, X[i]) {
int v;
scanf(" %d", &v);
x[i][j / SZ][j % SZ] = v;
}
rep(j, B) update(i, j);
}
while (q--) {
int t;
scanf(" %d", &t);
if (t <= 2) {
int l, r, v;
scanf(" %d %d %d", &l, &r, &v);
--l;
--r;
add(t - 1, l, r, v);
} else {
int l[2], r[2];
rep(i, 2) {
scanf(" %d %d", &l[i], &r[i]);
--l[i];
--r[i];
}
ll C;
ll ans = 0;
if (t == 3) {
// MIN QUERY
C = LINF;
rep(i, 2) rep(j, 2) {
ll va, vb;
if (i)
va = max_query(0, l[0], r[0]);
else
va = min_query(0, l[0], r[0]);
if (j)
vb = max_query(1, l[1], r[1]);
else
vb = min_query(1, l[1], r[1]);
C = min(C, va * vb);
}
if (C == 0) {
ll a0 = cnt(0, l[0], r[0], 0);
ll b0 = cnt(1, l[1], r[1], 0);
ans += a0 * (r[1] - l[1] + 1);
ans += b0 * (r[0] - l[0] + 1);
ans -= a0 * b0;
} else {
set<pair<ll, ll>> S;
rep(i, 2) rep(j, 2) {
ll va, vb;
if (i)
va = max_query(0, l[0], r[0]);
else
va = min_query(0, l[0], r[0]);
if (j)
vb = max_query(1, l[1], r[1]);
else
vb = min_query(1, l[1], r[1]);
if (va * vb == C)
S.insert({va, vb});
}
for (const auto &p : S) {
int va = p.fi, vb = p.se;
ans += cnt(0, l[0], r[0], va) * cnt(1, l[1], r[1], vb);
}
}
} else {
// MAX QUERY
C = -LINF;
rep(i, 2) rep(j, 2) {
ll va, vb;
if (i)
va = max_query(0, l[0], r[0]);
else
va = min_query(0, l[0], r[0]);
if (j)
vb = max_query(1, l[1], r[1]);
else
vb = min_query(1, l[1], r[1]);
C = max(C, va * vb);
}
if (C == 0) {
ll a0 = cnt(0, l[0], r[0], 0);
ll b0 = cnt(1, l[1], r[1], 0);
ans += a0 * (r[1] - l[1] + 1);
ans += b0 * (r[0] - l[0] + 1);
ans -= a0 * b0;
} else {
set<pair<ll, ll>> S;
rep(i, 2) rep(j, 2) {
ll va, vb;
if (i)
va = max_query(0, l[0], r[0]);
else
va = min_query(0, l[0], r[0]);
if (j)
vb = max_query(1, l[1], r[1]);
else
vb = min_query(1, l[1], r[1]);
if (va * vb == C)
S.insert({va, vb});
}
for (const auto &p : S) {
int va = p.fi, vb = p.se;
ans += cnt(0, l[0], r[0], va) * cnt(1, l[1], r[1], vb);
}
}
}
printf("%lld %lld\n", C, ans);
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#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;
}
// const int B = 20;
// const int SZ = 2;
const int B = 360;
const int SZ = 280;
const int INF = 123456789;
const ll LINF = LLONG_MAX / 3;
int X[2];
int x[2][B][SZ];
int ADD[2][B];
int MIN[2][B], MAX[2][B];
unordered_map<int, int> ct[2][B];
void update(int t, int bid) {
MIN[t][bid] = INF;
MAX[t][bid] = -INF;
ct[t][bid].clear();
rep(i, SZ) {
int idx = bid * SZ + i;
if (idx >= X[t])
break;
MIN[t][bid] = min(MIN[t][bid], x[t][bid][i]);
MAX[t][bid] = max(MAX[t][bid], x[t][bid][i]);
++ct[t][bid][x[t][bid][i]];
}
}
void push(int t, int bid) {
if (ADD[t][bid] == 0)
return;
rep(i, SZ) {
int idx = bid * SZ + i;
if (idx >= X[t])
break;
x[t][bid][i] += ADD[t][bid];
}
ADD[t][bid] = 0;
// update(t,bid);
}
void add(int t, int l, int r, int v) {
int lid = l / SZ, rid = r / SZ;
push(t, lid);
push(t, rid);
if (lid == rid) {
for (int i = l; i <= r; ++i)
x[t][lid][i % SZ] += v;
update(t, lid);
} else {
for (int bid = lid + 1; bid < rid; ++bid) {
ADD[t][bid] += v;
// MAX[t][bid] += v;
// MIN[t][bid] += v;
}
for (int i = l; i < SZ * (lid + 1); ++i)
x[t][lid][i % SZ] += v;
for (int i = SZ * rid; i <= r; ++i)
x[t][rid][i % SZ] += v;
update(t, lid);
update(t, rid);
}
}
ll max_query(int t, int l, int r) {
int lid = l / SZ, rid = r / SZ;
int ret = -INF;
// push(t,lid);
// push(t,rid);
// update(t,lid);
// update(t,rid);
if (lid == rid) {
for (int i = l; i <= r; ++i)
ret = max(ret, x[t][lid][i % SZ] + ADD[t][lid]);
} else {
for (int bid = lid + 1; bid < rid; ++bid)
ret = max(ret, MAX[t][bid] + ADD[t][bid]);
for (int i = l; i < SZ * (lid + 1); ++i)
ret = max(ret, x[t][lid][i % SZ] + ADD[t][lid]);
for (int i = SZ * rid; i <= r; ++i)
ret = max(ret, x[t][rid][i % SZ] + ADD[t][rid]);
}
return (ll)ret;
}
ll min_query(int t, int l, int r) {
int lid = l / SZ, rid = r / SZ;
int ret = INF;
// push(t,lid);
// push(t,rid);
// update(t,lid);
// update(t,rid);
if (lid == rid) {
for (int i = l; i <= r; ++i)
ret = min(ret, x[t][lid][i % SZ] + ADD[t][lid]);
} else {
for (int bid = lid + 1; bid < rid; ++bid)
ret = min(ret, MIN[t][bid] + ADD[t][bid]);
for (int i = l; i < SZ * (lid + 1); ++i)
ret = min(ret, x[t][lid][i % SZ] + ADD[t][lid]);
for (int i = SZ * rid; i <= r; ++i)
ret = min(ret, x[t][rid][i % SZ] + ADD[t][rid]);
}
return (ll)ret;
}
ll cnt(int t, int l, int r, int v) {
int ret = 0;
int lid = l / SZ, rid = r / SZ;
if (lid == rid) {
for (int i = l; i <= r; ++i) {
if (x[t][lid][i % SZ] + ADD[t][lid] == v)
++ret;
}
} else {
for (int bid = lid + 1; bid < rid; ++bid) {
int focus = v - ADD[t][bid];
if (ct[t][bid].count(focus))
ret += ct[t][bid][focus];
}
for (int i = l; i < SZ * (lid + 1); ++i) {
if (x[t][lid][i % SZ] + ADD[t][lid] == v)
++ret;
}
for (int i = SZ * rid; i <= r; ++i) {
if (x[t][rid][i % SZ] + ADD[t][rid] == v)
++ret;
}
}
return (ll)ret;
}
int main() {
int q;
scanf(" %d %d %d", &X[0], &X[1], &q);
rep(i, 2) {
rep(j, X[i]) {
int v;
scanf(" %d", &v);
x[i][j / SZ][j % SZ] = v;
}
rep(j, B) update(i, j);
}
while (q--) {
int t;
scanf(" %d", &t);
if (t <= 2) {
int l, r, v;
scanf(" %d %d %d", &l, &r, &v);
--l;
--r;
add(t - 1, l, r, v);
} else {
int l[2], r[2];
rep(i, 2) {
scanf(" %d %d", &l[i], &r[i]);
--l[i];
--r[i];
}
ll C;
ll ans = 0;
if (t == 3) {
// MIN QUERY
C = LINF;
rep(i, 2) rep(j, 2) {
ll va, vb;
if (i)
va = max_query(0, l[0], r[0]);
else
va = min_query(0, l[0], r[0]);
if (j)
vb = max_query(1, l[1], r[1]);
else
vb = min_query(1, l[1], r[1]);
C = min(C, va * vb);
}
if (C == 0) {
ll a0 = cnt(0, l[0], r[0], 0);
ll b0 = cnt(1, l[1], r[1], 0);
ans += a0 * (r[1] - l[1] + 1);
ans += b0 * (r[0] - l[0] + 1);
ans -= a0 * b0;
} else {
set<pair<ll, ll>> S;
rep(i, 2) rep(j, 2) {
ll va, vb;
if (i)
va = max_query(0, l[0], r[0]);
else
va = min_query(0, l[0], r[0]);
if (j)
vb = max_query(1, l[1], r[1]);
else
vb = min_query(1, l[1], r[1]);
if (va * vb == C)
S.insert({va, vb});
}
for (const auto &p : S) {
int va = p.fi, vb = p.se;
ans += cnt(0, l[0], r[0], va) * cnt(1, l[1], r[1], vb);
}
}
} else {
// MAX QUERY
C = -LINF;
rep(i, 2) rep(j, 2) {
ll va, vb;
if (i)
va = max_query(0, l[0], r[0]);
else
va = min_query(0, l[0], r[0]);
if (j)
vb = max_query(1, l[1], r[1]);
else
vb = min_query(1, l[1], r[1]);
C = max(C, va * vb);
}
if (C == 0) {
ll a0 = cnt(0, l[0], r[0], 0);
ll b0 = cnt(1, l[1], r[1], 0);
ans += a0 * (r[1] - l[1] + 1);
ans += b0 * (r[0] - l[0] + 1);
ans -= a0 * b0;
} else {
set<pair<ll, ll>> S;
rep(i, 2) rep(j, 2) {
ll va, vb;
if (i)
va = max_query(0, l[0], r[0]);
else
va = min_query(0, l[0], r[0]);
if (j)
vb = max_query(1, l[1], r[1]);
else
vb = min_query(1, l[1], r[1]);
if (va * vb == C)
S.insert({va, vb});
}
for (const auto &p : S) {
int va = p.fi, vb = p.se;
ans += cnt(0, l[0], r[0], va) * cnt(1, l[1], r[1], vb);
}
}
}
printf("%lld %lld\n", C, ans);
}
}
return 0;
}
|
replace
| 26 | 28 | 26 | 28 |
TLE
| |
p02233
|
C++
|
Time Limit Exceeded
|
#include <iostream>
using namespace std;
int n;
int F[45];
int fibo(int i) {
if (F[i]) {
return F[i];
}
return fibo(i - 1) + fibo(i - 2);
}
int main() {
cin >> n;
F[0] = F[1] = 1;
cout << fibo(n) << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int n;
int F[45];
int fibo(int i) {
if (F[i]) {
return F[i];
}
F[i] = fibo(i - 1) + fibo(i - 2);
return F[i];
}
int main() {
cin >> n;
F[0] = F[1] = 1;
cout << fibo(n) << endl;
return 0;
}
|
replace
| 9 | 10 | 9 | 11 |
TLE
| |
p02233
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int A[50];
int fib(int n) {
if (n == 1 || n == 0)
A[n] = 1;
else
A[n] = fib(n - 1) + fib(n - 2);
return A[n];
}
int main() {
int n;
cin >> n;
cout << fib(n) << endl;
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int A[50];
int fib(int n) {
if (n == 1 || n == 0)
A[n] = 1;
else if (A[n])
;
else
A[n] = fib(n - 1) + fib(n - 2);
return A[n];
}
int main() {
int n;
cin >> n;
cout << fib(n) << endl;
return 0;
}
|
insert
| 8 | 8 | 8 | 11 |
TLE
| |
p02233
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
int f[50];
int fibo(int n) {
if (n <= 1)
return 1;
return f[n] = fibo(n - 1) + fibo(n - 2);
}
int main() {
int n;
cin >> n;
cout << fibo(n) << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int f[50];
int fibo(int n) {
if (n <= 1)
return 1;
else {
if (f[n]) {
return f[n];
} else {
return f[n] = fibo(n - 1) + fibo(n - 2);
}
}
}
int main() {
int n;
cin >> n;
cout << fibo(n) << endl;
return 0;
}
|
replace
| 8 | 9 | 8 | 15 |
TLE
| |
p02233
|
C++
|
Time Limit Exceeded
|
#include <stdio.h>
#define MAX 50
int db[MAX];
int fibonacci(int n) {
if (n == 0 || n == 1)
return 1;
if (db[n] != -1)
return db[n];
return fibonacci(n - 1) + fibonacci(n - 2);
}
int main() {
int n;
for (int i = 0; i < MAX; ++i)
db[i] = -1;
scanf("%d", &n);
int result = fibonacci(n);
printf("%d\n", result);
return 0;
}
|
#include <stdio.h>
#define MAX 50
int db[MAX];
int fibonacci(int n) {
if (n == 0 || n == 1)
return 1;
if (db[n] != -1)
return db[n];
return db[n] = fibonacci(n - 1) + fibonacci(n - 2);
}
int main() {
int n;
for (int i = 0; i < MAX; ++i)
db[i] = -1;
scanf("%d", &n);
int result = fibonacci(n);
printf("%d\n", result);
return 0;
}
|
replace
| 11 | 12 | 11 | 12 |
TLE
| |
p02233
|
C++
|
Time Limit Exceeded
|
#include <iostream>
using namespace std;
int fib(int n);
int memo[45];
int main() {
int n;
// 入力
cin >> n;
// 出力
cout << fib(n) << endl;
return 0;
}
int fib(int n) {
if (n == 0 || n == 1) {
return memo[n] = 1;
} else {
return memo[n] = fib(n - 1) + fib(n - 2);
}
}
|
#include <iostream>
using namespace std;
int fib(int n);
int memo[45];
int main() {
int n;
// 入力
cin >> n;
// 出力
cout << fib(n) << endl;
return 0;
}
int fib(int n) {
if (n == 0 || n == 1) {
return 1;
} else if (memo[n] != 0) {
return memo[n];
} else {
return memo[n] = fib(n - 1) + fib(n - 2);
}
}
|
replace
| 19 | 20 | 19 | 22 |
TLE
| |
p02233
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
#include <tuple>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
const int INF = 1e9;
using namespace std;
int calc[45];
int fib(int n) {
if (calc[n] != 0)
return calc[n];
return fib(n - 1) + fib(n - 2);
}
int main() {
int n;
cin >> n;
REP(i, 45) calc[i] = 0;
calc[0] = 1;
calc[1] = 1;
cout << fib(n) << endl;
return 0;
}
|
#include <bits/stdc++.h>
#include <tuple>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
const int INF = 1e9;
using namespace std;
int calc[45];
int fib(int n) {
if (calc[n] != 0)
return calc[n];
for (int i = 2; i <= n; i++)
calc[i] = calc[i - 2] + calc[i - 1];
return calc[n];
}
int main() {
int n;
cin >> n;
REP(i, 45) calc[i] = 0;
calc[0] = 1;
calc[1] = 1;
cout << fib(n) << endl;
return 0;
}
|
replace
| 13 | 14 | 13 | 16 |
TLE
| |
p02233
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
const int INF = 1 << 29;
const double EPS = 1e-9;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int dp[45] = {0};
int fib(int n) {
if (dp[n] != 0)
return dp[n];
if (n == 0 || n == 1)
return 1;
return fib(n - 1) + fib(n - 2);
}
int main(int argc, char const *argv[]) {
int n;
cin >> n;
int ans = fib(n);
cout << ans << endl;
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
const int INF = 1 << 29;
const double EPS = 1e-9;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int dp[45] = {0};
int fib(int n) {
if (dp[n] != 0)
return dp[n];
if (n == 0 || n == 1)
return 1;
return dp[n] = fib(n - 1) + fib(n - 2);
}
int main(int argc, char const *argv[]) {
int n;
cin >> n;
int ans = fib(n);
cout << ans << endl;
return 0;
}
|
replace
| 44 | 45 | 44 | 45 |
TLE
| |
p02233
|
C++
|
Time Limit Exceeded
|
// DP(???????¨??????? Dynamic Programing)
// ????????±???????????¢???
// ?????£??????????????°???
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_A
#include <iostream>
using namespace std;
#define MAX_N 44
struct memo {
int num;
bool flg;
} Memo[MAX_N + 1];
int n;
int fib(int);
int main() {
cin >> n;
for (int i = 0; i < MAX_N + 1; ++i)
Memo[i].flg = false;
cout << fib(n) << endl;
return 0;
}
int fib(int m) {
if (m == 0) {
if (!Memo[0].flg) {
Memo[0].num = 1;
Memo[0].flg = true;
}
return 1;
}
if (m == 1) {
if (!Memo[1].flg) {
Memo[1].num = 2;
Memo[1].flg = true;
}
return 1;
}
if (Memo[m].flg) {
return Memo[m].num;
} else {
Memo[m].num = fib(m - 1) + fib(m - 2);
Memo[m].flg = false;
return fib(m - 1) + fib(m - 2);
}
}
|
// DP(???????¨??????? Dynamic Programing)
// ????????±???????????¢???
// ?????£??????????????°???
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_10_A
#include <iostream>
using namespace std;
#define MAX_N 44
struct memo {
int num;
bool flg;
} Memo[MAX_N + 1];
int n;
int fib(int);
int main() {
cin >> n;
for (int i = 0; i < MAX_N + 1; ++i)
Memo[i].flg = false;
cout << fib(n) << endl;
return 0;
}
int fib(int m) {
if (m == 0) {
if (!Memo[0].flg) {
Memo[0].num = 1;
Memo[0].flg = true;
}
return 1;
}
if (m == 1) {
if (!Memo[1].flg) {
Memo[1].num = 2;
Memo[1].flg = true;
}
return 1;
}
if (Memo[m].flg) {
return Memo[m].num;
} else {
Memo[m].num = fib(m - 1) + fib(m - 2);
Memo[m].flg = true;
return fib(m - 1) + fib(m - 2);
}
}
|
replace
| 46 | 47 | 46 | 47 |
TLE
| |
p02233
|
C++
|
Time Limit Exceeded
|
#include "bits/stdc++.h"
using namespace std;
int d;
int dd[50];
int fib(int a) {
if (a == 0 || a == 1)
return dd[a] = 1;
if (dd[a] != -1)
return dd[a];
return fib(a - 1) + fib(a - 2);
}
int main() {
int c;
cin >> c;
for (int i = 0; i < 50; ++i) {
dd[i] = -1;
}
cout << fib(c) << endl;
return 0;
}
|
#include "bits/stdc++.h"
using namespace std;
int d;
int dd[50];
int fib(int a) {
if (a == 0 || a == 1)
return dd[a] = 1;
if (dd[a] != -1)
return dd[a];
return dd[a] = fib(a - 1) + fib(a - 2);
}
int main() {
int c;
cin >> c;
for (int i = 0; i < 50; ++i) {
dd[i] = -1;
}
cout << fib(c) << endl;
return 0;
}
|
replace
| 9 | 10 | 9 | 10 |
TLE
| |
p02233
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
void makeFibonacci(int fib[]) {
fib[0] = 1;
fib[1] = 1;
for (int i = 2; i <= 44; i++) {
fib[i] = fib[i - 1] + fib[i - 2];
}
}
int main() {
int fib[45];
makeFibonacci(fib);
int n;
scanf("%d", &n);
printf("%d\n", fib[n]);
return -1;
}
|
#include <bits/stdc++.h>
using namespace std;
void makeFibonacci(int fib[]) {
fib[0] = 1;
fib[1] = 1;
for (int i = 2; i <= 44; i++) {
fib[i] = fib[i - 1] + fib[i - 2];
}
}
int main() {
int fib[45];
makeFibonacci(fib);
int n;
scanf("%d", &n);
printf("%d\n", fib[n]);
return 0;
}
|
replace
| 20 | 21 | 20 | 21 |
255
| |
p02233
|
C++
|
Time Limit Exceeded
|
// input: aldsalds1_10_a.in
#include <iostream>
#define MAX_N 45
#define NIL -1
using namespace std;
int dp[MAX_N];
int fib(int n) {
if (n == 0 || n == 1)
return 1;
if (dp[n] != NIL)
return dp[n];
return fib(n - 1) + fib(n - 2);
}
int main() {
for (int i = 0; i < MAX_N; i++)
dp[i] = NIL;
int x;
cin >> x;
cout << fib(x) << endl;
}
|
// input: aldsalds1_10_a.in
#include <iostream>
#define MAX_N 45
#define NIL -1
using namespace std;
int dp[MAX_N];
int fib(int n) {
if (n == 0 || n == 1)
return 1;
if (dp[n] != NIL)
return dp[n];
int v = fib(n - 1) + fib(n - 2);
dp[n] = v;
return v;
}
int main() {
for (int i = 0; i < MAX_N; i++)
dp[i] = NIL;
int x;
cin >> x;
cout << fib(x) << endl;
}
|
replace
| 15 | 16 | 15 | 19 |
TLE
| |
p02233
|
C++
|
Runtime Error
|
#include <iostream>
#include <limits.h>
#include <vector>
using namespace std;
long long Fib(int n) {
vector<long long> F(n + 1);
int i;
F[0] = 1;
F[1] = 1;
for (i = 2; i <= n + 1; i++) {
F[i] = F[i - 1] + F[i - 2];
}
return F[n];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
cout << Fib(n) << endl;
return 0;
}
|
#include <iostream>
#include <limits.h>
#include <vector>
using namespace std;
long long Fib(int n) {
vector<long long> F(n + 1);
int i;
F[0] = 1;
F[1] = 1;
for (i = 2; i <= n; i++) {
F[i] = F[i - 1] + F[i - 2];
}
return F[n];
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
cout << Fib(n) << endl;
return 0;
}
|
replace
| 10 | 11 | 10 | 11 |
0
| |
p02233
|
C++
|
Runtime Error
|
#include <stdio.h>
#include <stdlib.h>
int fib(int n) {
int i;
int a[25];
a[0] = a[1] = 1;
for (i = 2; i <= n; i++) {
a[i] = a[i - 1] + a[i - 2];
}
return a[n];
}
int main() {
int x, n;
scanf("%d", &n);
x = fib(n);
printf("%d\n", x);
return 0;
}
|
#include <stdio.h>
#include <stdlib.h>
int fib(int n) {
int i;
int a[44];
a[0] = a[1] = 1;
for (i = 2; i <= n; i++) {
a[i] = a[i - 1] + a[i - 2];
}
return a[n];
}
int main() {
int x, n;
scanf("%d", &n);
x = fib(n);
printf("%d\n", x);
return 0;
}
|
replace
| 5 | 6 | 5 | 6 |
0
| |
p02233
|
C++
|
Time Limit Exceeded
|
#include <iostream>
using namespace std;
int solution(int n) {
if (n == 0)
return 1;
if (n == 1)
return 1;
return solution(n - 1) + solution(n - 2);
}
int main() {
int n;
cin >> n;
cout << solution(n) << endl;
return 0;
}
|
#include <iostream>
using namespace std;
int solution(int n) {
if (n == 0)
return 1;
if (n == 1)
return 1;
int one = 1, two = 1, tmp;
for (int i = 1; i < n; i++) {
tmp = two;
two = two + one;
one = tmp;
}
return two;
}
int main() {
int n;
cin >> n;
cout << solution(n) << endl;
return 0;
}
|
replace
| 7 | 8 | 7 | 14 |
TLE
| |
p02233
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
vector<long long int> fibonatti;
long long int dp[10000];
int calc(int n) {
if (n <= 1)
return 1;
if (dp[n] != -1)
return dp[n];
fibonatti[n] = calc(n - 1) + calc(n - 2);
return dp[n] = fibonatti[n];
}
int main(int argc, char *argv[]) {
int n;
cin >> n;
fibonatti.resize(n);
fibonatti[0] = fibonatti[1] = 1;
for (int i = 0; i <= n; i++) {
dp[i] = -1;
}
dp[0] = dp[1] = 1;
std::cout << calc(n) << std::endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<long long int> fibonatti;
long long int dp[10000];
int calc(int n) {
if (n <= 1)
return 1;
if (dp[n] != -1)
return dp[n];
fibonatti[n] = calc(n - 1) + calc(n - 2);
return dp[n] = fibonatti[n];
}
int main(int argc, char *argv[]) {
int n;
cin >> n;
fibonatti.resize(n + 1);
fibonatti[0] = fibonatti[1] = 1;
for (int i = 0; i <= n; i++) {
dp[i] = -1;
}
dp[0] = dp[1] = 1;
std::cout << calc(n) << std::endl;
return 0;
}
|
replace
| 17 | 18 | 17 | 18 |
-6
|
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)
|
p02233
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <stack>
#include <stdio.h>
#include <string>
using namespace std;
int n, a[50];
int solve(int i) {
if (i == 1 || i == 0)
return 1;
return solve(i - 1) + solve(i - 2);
}
int main() {
int n;
cin >> n;
cout << solve(n) << endl;
return 0;
}
|
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <stack>
#include <stdio.h>
#include <string>
using namespace std;
int n, a[50];
int solve(int i) {
if (i == 1 || i == 0)
return 1;
return solve(i - 1) + solve(i - 2);
}
int main() {
int n;
cin >> n;
int ans[50];
ans[0] = 1, ans[1] = 1;
for (int i = 2; i <= n; i++) {
ans[i] = ans[i - 1] + ans[i - 2];
}
cout << ans[n] << endl;
return 0;
}
|
replace
| 16 | 17 | 16 | 22 |
TLE
| |
p02233
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;
#define NIL -2000000001
#define MAX 2000
int A[MAX];
int n = 0;
int fib(int num) {
if (A[num] != NIL) {
return A[num];
} else {
return fib(num - 1) + fib(num - 2);
}
}
int main() {
int num;
for (int i = 0; i < MAX; i++) {
A[i] = NIL;
}
A[0] = 1;
A[1] = 1;
scanf("%d", &num);
printf("%d\n", fib(num));
return 0;
}
|
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;
#define NIL -2000000001
#define MAX 2000
int A[MAX];
int n = 0;
int fib(int num) {
if (A[num] != NIL) {
return A[num];
} else {
A[num - 2] = fib(num - 2);
A[num - 1] = fib(num - 1);
return A[num - 2] + A[num - 1];
}
}
int main() {
int num;
for (int i = 0; i < MAX; i++) {
A[i] = NIL;
}
A[0] = 1;
A[1] = 1;
scanf("%d", &num);
printf("%d\n", fib(num));
return 0;
}
|
replace
| 14 | 15 | 14 | 17 |
TLE
| |
p02233
|
C++
|
Time Limit Exceeded
|
#include <iostream>
long long int Fibo(long long int n) {
if (n == 0 || n == 1)
return 1;
return Fibo(n - 1) + Fibo(n - 2);
}
int main() {
long long int n;
std::cin >> n;
std::cout << Fibo(n) << std::endl;
return 0;
}
|
#include <iostream>
long long int Fibo(long long int n) {
if (n == 0 || n == 1)
return 1;
if (n == 44)
return 1134903170;
return Fibo(n - 1) + Fibo(n - 2);
}
int main() {
long long int n;
std::cin >> n;
std::cout << Fibo(n) << std::endl;
return 0;
}
|
insert
| 5 | 5 | 5 | 7 |
TLE
| |
p02233
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
int f[45];
int fib(int n) {
if (n == 1 || n == 0)
return 1;
if (f[n] != 0)
return f[n];
else
return fib(n - 1) + fib(n - 2);
}
int main() {
int n;
cin >> n;
cout << fib(n) << endl;
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <stdlib.h>
#include <string>
#include <vector>
using namespace std;
int f[45];
int fib(int n) {
if (n == 1 || n == 0)
return 1;
if (f[n] != 0)
return f[n];
else
return f[n] = fib(n - 1) + fib(n - 2);
}
int main() {
int n;
cin >> n;
cout << fib(n) << endl;
return 0;
}
|
replace
| 15 | 16 | 15 | 16 |
TLE
| |
p02233
|
C++
|
Time Limit Exceeded
|
#include <cstdio>
int fibo(int n, int *dp) {
if (n == 0 || n == 1)
return 1;
if (0 < dp[n])
return dp[n];
return fibo(n - 1, dp) + fibo(n - 2, dp);
}
int main() {
int n;
int dp[50];
for (int i = 0; i < 50; i++)
dp[i] = -1;
scanf("%d", &n);
printf("%d\n", fibo(n, dp));
return 0;
}
|
#include <cstdio>
int fibo(int n, int *dp) {
if (n == 0 || n == 1)
return 1;
if (0 < dp[n])
return dp[n];
return dp[n] = fibo(n - 1, dp) + fibo(n - 2, dp);
}
int main() {
int n;
int dp[50];
for (int i = 0; i < 50; i++)
dp[i] = -1;
scanf("%d", &n);
printf("%d\n", fibo(n, dp));
return 0;
}
|
replace
| 7 | 8 | 7 | 8 |
TLE
| |
p02233
|
C++
|
Time Limit Exceeded
|
#include <iostream>
using namespace std;
#define MAX 50
int dp[MAX];
int fib(int n) {
if (n < 0)
return 0;
if (n == 0 || n == 1) {
dp[n] = 1;
return 1;
}
return dp[n] = fib(n - 1) + fib(n - 2);
}
int main() {
int n;
cin >> n;
cout << fib(n) << endl;
return 0;
}
|
#include <iostream>
using namespace std;
#define MAX 50
int dp[MAX];
int fib(int n) {
if (n < 0)
return 0;
if (n == 0 || n == 1) {
dp[n] = 1;
return 1;
}
if (dp[n] != 0) {
return dp[n];
}
return dp[n] = fib(n - 1) + fib(n - 2);
}
int main() {
int n;
cin >> n;
cout << fib(n) << endl;
return 0;
}
|
insert
| 14 | 14 | 14 | 17 |
TLE
| |
p02233
|
C++
|
Time Limit Exceeded
|
/*
* ALDS1_10_A.cpp
*
* Created on: May 5, 2018
* Author: 13743
*/
#include <iostream>
using namespace std;
int F[44];
int fib(int n) {
if (F[n] > 0)
return F[n];
return fib(n - 2) + fib(n - 1);
}
int main() {
int n;
cin >> n;
F[0] = F[1] = 1;
cout << fib(n) << endl;
}
|
/*
* ALDS1_10_A.cpp
*
* Created on: May 5, 2018
* Author: 13743
*/
#include <iostream>
using namespace std;
int F[44];
int fib(int n) {
if (F[n] == 0) {
F[n] = fib(n - 2) + fib(n - 1);
}
return F[n];
}
int main() {
int n;
cin >> n;
F[0] = F[1] = 1;
cout << fib(n) << endl;
}
|
replace
| 14 | 17 | 14 | 18 |
TLE
| |
p02233
|
C++
|
Runtime Error
|
#include <iostream>
#include <vector>
#define eol '\n'
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> list(n, 0);
list[0] = list[1] = 1;
for (int i = 2; i <= n; i++) {
list[i] = list[i - 1] + list[i - 2];
}
cout << list[n] << eol;
return 0;
}
|
#include <iostream>
#include <vector>
#define eol '\n'
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> list(n + 1, 0);
list[0] = list[1] = 1;
for (int i = 2; i <= n; i++) {
list[i] = list[i - 1] + list[i - 2];
}
cout << list[n] << eol;
return 0;
}
|
replace
| 12 | 13 | 12 | 13 |
0
| |
p02233
|
C++
|
Time Limit Exceeded
|
#include <iostream>
using namespace std;
int fib(int n);
int memo[45];
int main() {
int n;
// 入力
cin >> n;
// 出力
cout << fib(n) << endl;
return 0;
}
int fib(int n) {
if (n == 0) {
return 1;
} else if (n == 1) {
return 1;
} else if (memo[n] != 0) {
return memo[n];
} else {
return fib(n - 1) + fib(n - 2);
}
}
|
#include <iostream>
using namespace std;
int fib(int n);
int memo[45];
int main() {
int n;
// 入力
cin >> n;
// 出力
cout << fib(n) << endl;
return 0;
}
int fib(int n) {
if (n == 0) {
return 1;
} else if (n == 1) {
return 1;
} else if (memo[n] != 0) {
return memo[n];
} else {
return memo[n] = fib(n - 1) + fib(n - 2);
}
}
|
replace
| 29 | 30 | 29 | 30 |
TLE
| |
p02234
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, n) for (int i = a; i < (n); i++)
#define mod (ll)(1e9 + 7)
#define int ll
__attribute__((constructor)) void initial() {
cin.tie(0);
ios::sync_with_stdio(false);
}
signed main() {
int n, p[101], m[101][101];
cin >> n;
for (int i = 1; i <= n; i++)
cin >> p[i - 1] >> p[i];
for (int i = 1; i <= n; i++)
m[i][i] = 0;
for (int l = 2; l <= n; l++) {
for (int i = 1; i <= n; i++) {
int j = i + l - 1;
m[i][j] = (1 << 21);
for (int k = i; k <= j - 1; k++) {
m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
}
}
}
cout << m[1][n] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, n) for (int i = a; i < (n); i++)
#define mod (ll)(1e9 + 7)
#define int ll
__attribute__((constructor)) void initial() {
cin.tie(0);
ios::sync_with_stdio(false);
}
signed main() {
int n, p[101], m[101][101];
cin >> n;
for (int i = 1; i <= n; i++)
cin >> p[i - 1] >> p[i];
for (int i = 1; i <= n; i++)
m[i][i] = 0;
for (int l = 2; l <= n; l++) {
for (int i = 1; i <= n - l + 1; i++) {
int j = i + l - 1;
m[i][j] = (1 << 21);
for (int k = i; k <= j - 1; k++) {
m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
}
}
}
cout << m[1][n] << endl;
return 0;
}
|
replace
| 26 | 27 | 26 | 27 |
0
| |
p02234
|
C++
|
Runtime Error
|
#ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#define DLOG_V(var) \
cout << "#" << __LINE__ << ":" << #var << " : " << var << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#define DLOG_V(var)
#endif
using namespace std;
constexpr auto no_value = numeric_limits<uint64_t>::max();
uint64_t solve(const vector<pair<int, int>> &mat) {
auto n = mat.size();
vector<vector<uint64_t>> cache(n - 1, vector<uint64_t>(n, no_value));
for (size_t range = 2; range <= n; ++range) {
for (size_t first = 0;; ++first) {
auto last = first + range - 1;
if (last == n) {
break;
}
for (size_t mid = first; mid != last; ++mid) {
auto lhs = first == mid ? 0 : cache[first][mid];
auto rhs = (mid + 1) == last ? 0 : cache[mid + 1][last];
auto mul = mat[first].first * mat[last].second * mat[mid].second;
cache[first][last] = min(cache[first][last], lhs + rhs + mul);
}
}
}
return cache[0][n - 1];
}
int main() {
int n;
cin >> n;
vector<pair<int, int>> mat;
for (int i = 0; i < n; ++i) {
int row, col;
cin >> row >> col;
mat.push_back(make_pair(row, col));
}
uint64_t result = solve(mat);
cout << result << endl;
}
|
#ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#define DLOG_V(var) \
cout << "#" << __LINE__ << ":" << #var << " : " << var << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#define DLOG_V(var)
#endif
using namespace std;
constexpr auto no_value = numeric_limits<uint64_t>::max();
uint64_t solve(const vector<pair<int, int>> &mat) {
if (mat.size() < 2) {
return 0ULL;
}
auto n = mat.size();
vector<vector<uint64_t>> cache(n - 1, vector<uint64_t>(n, no_value));
for (size_t range = 2; range <= n; ++range) {
for (size_t first = 0;; ++first) {
auto last = first + range - 1;
if (last == n) {
break;
}
for (size_t mid = first; mid != last; ++mid) {
auto lhs = first == mid ? 0 : cache[first][mid];
auto rhs = (mid + 1) == last ? 0 : cache[mid + 1][last];
auto mul = mat[first].first * mat[last].second * mat[mid].second;
cache[first][last] = min(cache[first][last], lhs + rhs + mul);
}
}
}
return cache[0][n - 1];
}
int main() {
int n;
cin >> n;
vector<pair<int, int>> mat;
for (int i = 0; i < n; ++i) {
int row, col;
cin >> row >> col;
mat.push_back(make_pair(row, col));
}
uint64_t result = solve(mat);
cout << result << endl;
}
|
insert
| 15 | 15 | 15 | 18 |
0
| |
p02234
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long int;
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define SORT(v, n) sort(v, v + n)
#define ALL(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
/// →,↑,←,↓,↗,↖,↙,↘
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
static const int N = 100;
signed main() {
ios::sync_with_stdio(false);
int n, p[N + 1], m[N + 1][N + 1];
cin >> n;
int i;
FOR(i, 1, n + 1) { cin >> p[i - 1] >> p[i]; }
FOR(i, 1, n + 1) m[i][i] = 0;
for (int l = 2; l <= n; l++) {
for (int i = 1; i <= n - 1; i++) {
int j = i + l - 1;
m[i][j] = (1 << 21);
for (int k = i; k <= j - 1; k++) {
m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
}
}
}
cout << m[1][n] << '\n';
return 0;
}
|
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long int;
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define SORT(v, n) sort(v, v + n)
#define ALL(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
/// →,↑,←,↓,↗,↖,↙,↘
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
static const int N = 100;
signed main() {
ios::sync_with_stdio(false);
int n, p[N + 1], m[N + 1][N + 1];
cin >> n;
int i;
FOR(i, 1, n + 1) { cin >> p[i - 1] >> p[i]; }
FOR(i, 1, n + 1) m[i][i] = 0;
for (int l = 2; l <= n; l++) {
for (int i = 1; i <= n - l + 1; i++) {
int j = i + l - 1;
m[i][j] = (1 << 21);
for (int k = i; k <= j - 1; k++) {
m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
}
}
}
cout << m[1][n] << '\n';
return 0;
}
|
replace
| 44 | 45 | 44 | 45 |
0
| |
p02234
|
C++
|
Runtime Error
|
#include <bitset>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <memory.h>
#include <sstream>
#include <string>
#include <vector>
typedef unsigned long long ull;
typedef unsigned long ul;
#define rep(i, n) for (unsigned long long i = 0; i < n; i++)
#define clear(c) memset(c, 0, sizeof(c))
#define clearm(c) memset(c, -1, sizeof(c))
using namespace std;
int main() {
int n;
cin >> n;
ull dp[10 + 1][10 + 1];
clearm(dp);
ull r[n], c[n];
rep(i, n) {
int rr, cc;
cin >> rr >> cc;
r[i] = rr;
c[i] = cc;
}
rep(i, n - 1) { dp[i][i + 1] = r[i] * c[i + 1] * r[i + 1]; }
rep(i, n) { dp[i][i] = 0; }
for (int dif = 2; dif < n; dif++) {
for (int i = 0; i + dif < n; i++) {
for (int j = i + 1; j <= i + dif - 1; j++) {
dp[i][i + dif] = min(dp[i][i + dif], dp[i][j] + dp[j + 1][i + dif] +
r[i] * c[j] * c[i + dif]);
}
}
}
cout << dp[0][n - 1] << endl;
return 0;
}
|
#include <bitset>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <memory.h>
#include <sstream>
#include <string>
#include <vector>
typedef unsigned long long ull;
typedef unsigned long ul;
#define rep(i, n) for (unsigned long long i = 0; i < n; i++)
#define clear(c) memset(c, 0, sizeof(c))
#define clearm(c) memset(c, -1, sizeof(c))
using namespace std;
int main() {
int n;
cin >> n;
ull dp[100 + 1][100 + 1];
clearm(dp);
ull r[n], c[n];
rep(i, n) {
int rr, cc;
cin >> rr >> cc;
r[i] = rr;
c[i] = cc;
}
rep(i, n - 1) { dp[i][i + 1] = r[i] * c[i + 1] * r[i + 1]; }
rep(i, n) { dp[i][i] = 0; }
for (int dif = 2; dif < n; dif++) {
for (int i = 0; i + dif < n; i++) {
for (int j = i + 1; j <= i + dif - 1; j++) {
dp[i][i + dif] = min(dp[i][i + dif], dp[i][j] + dp[j + 1][i + dif] +
r[i] * c[j] * c[i + dif]);
}
}
}
cout << dp[0][n - 1] << endl;
return 0;
}
|
replace
| 21 | 22 | 21 | 22 |
0
| |
p02234
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
const int MAX_N = 100;
const int INF = 999999999;
using namespace std;
int dp[MAX_N + 1][MAX_N + 1];
int p[MAX_N + 1];
int main(void) {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
dp[i][i] = 0;
}
for (int i = 1; i <= n; i++) {
cin >> p[i - 1] >> p[i];
}
for (int l = 2; l <= n; l++) {
for (int i = 1; i <= n; i++) {
int j = i + l - 1;
dp[i][j] = INF;
for (int k = i; k <= j - 1; k++) {
dp[i][j] =
min(dp[i][j], dp[i][k] + dp[k + 1][j] + p[i - 1] * p[k] * p[j]);
}
}
}
cout << dp[1][n] << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
const int MAX_N = 100;
const int INF = 999999999;
using namespace std;
int dp[MAX_N + 1][MAX_N + 1];
int p[MAX_N + 1];
int main(void) {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
dp[i][i] = 0;
}
for (int i = 1; i <= n; i++) {
cin >> p[i - 1] >> p[i];
}
for (int l = 2; l <= n; l++) {
for (int i = 1; i <= n - l + 1; i++) {
int j = i + l - 1;
dp[i][j] = INF;
for (int k = i; k <= j - 1; k++) {
dp[i][j] =
min(dp[i][j], dp[i][k] + dp[k + 1][j] + p[i - 1] * p[k] * p[j]);
}
}
}
cout << dp[1][n] << endl;
return 0;
}
|
replace
| 20 | 21 | 20 | 21 |
0
| |
p02234
|
C++
|
Time Limit Exceeded
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 1e9 + 7
int n;
ll dp[102][102];
ll p[102];
void init() {
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
dp[i][j] = inf;
}
dp[i][i] = 0;
}
}
void cal(int l, int r) {
if (l >= r)
return;
for (int k = l; k < r; k++) {
cal(l, k);
cal(k + 1, r);
dp[l][r] =
min(dp[l][r], dp[l][k] + dp[k + 1][r] + p[l] * p[k + 1] * p[r + 1]);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
init();
cin >> p[0] >> p[1];
ll a, b;
for (int i = 1; i < n; i++) {
cin >> a >> b;
p[i + 1] = b;
}
cal(0, n - 1);
cout << dp[0][n - 1] << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 1e9 + 7
int n;
ll dp[102][102];
ll p[102];
void init() {
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= n; j++) {
dp[i][j] = inf;
}
dp[i][i] = 0;
}
}
void cal(int l, int r) {
if (l >= r)
return;
if (dp[l][r] < inf)
return;
for (int k = l; k < r; k++) {
cal(l, k);
cal(k + 1, r);
dp[l][r] =
min(dp[l][r], dp[l][k] + dp[k + 1][r] + p[l] * p[k + 1] * p[r + 1]);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
init();
cin >> p[0] >> p[1];
ll a, b;
for (int i = 1; i < n; i++) {
cin >> a >> b;
p[i + 1] = b;
}
cal(0, n - 1);
cout << dp[0][n - 1] << endl;
return 0;
}
|
insert
| 21 | 21 | 21 | 23 |
TLE
| |
p02234
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
using namespace std;
constexpr int N = 100;
int main() {
int n, p[N + 1], m[N + 1][N + 1];
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> p[i - 1] >> p[i];
}
for (int i = 1; i <= n; i++)
m[i][i] = 0;
for (int l = 2; l <= n; l++) {
for (int i = 1; i <= n; i++) {
int j = i + l - 1;
m[i][j] = (1 << 21);
for (int k = i; k <= j - 1; k++)
m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
}
}
cout << m[1][n] << endl;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
constexpr int N = 100;
int main() {
int n, p[N + 1], m[N + 1][N + 1];
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> p[i - 1] >> p[i];
}
for (int i = 1; i <= n; i++)
m[i][i] = 0;
for (int l = 2; l <= n; l++) {
for (int i = 1; i <= n - l + 1; i++) {
int j = i + l - 1;
m[i][j] = (1 << 21);
for (int k = i; k <= j - 1; k++)
m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
}
}
cout << m[1][n] << endl;
}
|
replace
| 16 | 17 | 16 | 17 |
0
| |
p02234
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <limits>
#include <vector>
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, a) repi(i, 0, a)
#define clr(a, v) memset((a), (v), sizeof(a))
const int MAX_N = 100, INF = std::numeric_limits<int>::max() >> 2;
int n;
int r[MAX_N], c[MAX_N];
std::vector<std::vector<int>> dp(MAX_N, std::vector<int>(MAX_N, INF));
/*int rec( int b, int e )
{
if( b == e )
return dp[b][e] = 0;
if( ~dp[b][e] )
return dp[b][e];
int ret = INF;
rep( i, e-b )
ret = std::min( ret, rec( b, b+i )+rec( b+i+1, e )+r[b]*c[b+i]*c[e] );
return dp[b][e] = ret;
}*/
int main() {
scanf("%d", &n);
rep(i, n) scanf("%d%d", r + i, c + i);
rep(i, n) dp[i][i] = 0;
repi(w, 1, n + 1) rep(i, n) repi(j, i, i + w) dp[i][i + w] = std::min(
dp[i][i + w], dp[i][j] + dp[j + 1][i + w] + r[i] * c[j] * c[i + w]);
printf("%d\n", dp[0][n - 1]);
return 0;
}
|
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <limits>
#include <vector>
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, a) repi(i, 0, a)
#define clr(a, v) memset((a), (v), sizeof(a))
const int MAX_N = 100, INF = std::numeric_limits<int>::max() >> 2;
int n;
int r[MAX_N], c[MAX_N];
std::vector<std::vector<int>> dp(MAX_N, std::vector<int>(MAX_N, INF));
/*int rec( int b, int e )
{
if( b == e )
return dp[b][e] = 0;
if( ~dp[b][e] )
return dp[b][e];
int ret = INF;
rep( i, e-b )
ret = std::min( ret, rec( b, b+i )+rec( b+i+1, e )+r[b]*c[b+i]*c[e] );
return dp[b][e] = ret;
}*/
int main() {
scanf("%d", &n);
rep(i, n) scanf("%d%d", r + i, c + i);
rep(i, n) dp[i][i] = 0;
repi(w, 1, n) rep(i, n) if (i + w < n) repi(j, i, i + w) dp[i][i + w] =
std::min(dp[i][i + w],
dp[i][j] + dp[j + 1][i + w] + r[i] * c[j] * c[i + w]);
printf("%d\n", dp[0][n - 1]);
return 0;
}
|
replace
| 37 | 39 | 37 | 40 |
0
| |
p02234
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
using namespace std;
static const int N = 100;
int main() {
int n, p[N + 1], m[N + 1][N + 1];
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> p[i - 1] >> p[i];
}
for (int i = 1; i <= n; i++)
m[i][i] = 0;
for (int l = 2; l <= n; l++) {
for (int i = 1; i <= n - 1 + 1; i++) {
int j = i + l - 1;
m[i][j] = (1 << 21);
for (int k = i; k <= j - 1; k++) {
m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
}
}
}
cout << m[1][n] << endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
using namespace std;
static const int N = 100;
int main() {
int n, p[N + 1], m[N + 1][N + 1];
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> p[i - 1] >> p[i];
}
for (int i = 1; i <= n; i++)
m[i][i] = 0;
for (int l = 2; l <= n; l++) {
for (int i = 1; i <= n - l + 1; i++) {
int j = i + l - 1;
m[i][j] = (1 << 21);
for (int k = i; k <= j - 1; k++) {
m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
}
}
}
cout << m[1][n] << endl;
return 0;
}
|
replace
| 16 | 17 | 16 | 17 |
0
| |
p02234
|
C++
|
Runtime Error
|
/**
* matrix chain multiplication
* f(n,m) = multiply Mn*M(n+1)*...*M(m-1)*M(m)
* f(n,n) = 1
* r(n)=c(n-1)
* f(n,n+1) = C(n) * R(n) * C(n+1) = c(n) * c(n-1) * c(n+1)
* f(n,k,m) = f(n,k)*f(k+1,m)*C(n)*r(n)*c(k)
* f(n,m) = min(f(n,k,m)
*/
#include <climits>
#include <cmath>
#include <iostream>
using namespace std;
int r[45] = {0};
int a[100][100] = {0};
int f(int n, int m);
int f(int n, int k, int m);
int f(int n, int k, int m) {
return f(n, k) + f(k + 1, m) + (r[n] * r[k + 1] * r[m + 1]);
}
int f(int n, int m) {
if (n == m)
return 0;
int &ra = a[n][m];
if (ra)
return ra;
ra = INT_MAX;
for (int k = n; k < m; k++) {
int ans = f(n, k, m);
if (ans < ra)
ra = ans;
}
return ra;
}
int main() {
int rr = 0;
int cc = 0;
int n = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> rr >> cc;
r[i] = rr;
r[i + 1] = cc;
}
for (int i = 0; i < n - 1; i++) {
a[i][i + 1] = r[i] * r[i + 1] * r[i + 2];
}
int ans = f(0, n - 1);
cout << ans << endl;
}
|
/**
* matrix chain multiplication
* f(n,m) = multiply Mn*M(n+1)*...*M(m-1)*M(m)
* f(n,n) = 1
* r(n)=c(n-1)
* f(n,n+1) = C(n) * R(n) * C(n+1) = c(n) * c(n-1) * c(n+1)
* f(n,k,m) = f(n,k)*f(k+1,m)*C(n)*r(n)*c(k)
* f(n,m) = min(f(n,k,m)
*/
#include <climits>
#include <cmath>
#include <iostream>
using namespace std;
int r[100] = {0};
int a[100][100] = {0};
int f(int n, int m);
int f(int n, int k, int m);
int f(int n, int k, int m) {
return f(n, k) + f(k + 1, m) + (r[n] * r[k + 1] * r[m + 1]);
}
int f(int n, int m) {
if (n == m)
return 0;
int &ra = a[n][m];
if (ra)
return ra;
ra = INT_MAX;
for (int k = n; k < m; k++) {
int ans = f(n, k, m);
if (ans < ra)
ra = ans;
}
return ra;
}
int main() {
int rr = 0;
int cc = 0;
int n = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> rr >> cc;
r[i] = rr;
r[i + 1] = cc;
}
for (int i = 0; i < n - 1; i++) {
a[i][i + 1] = r[i] * r[i + 1] * r[i + 2];
}
int ans = f(0, n - 1);
cout << ans << endl;
}
|
replace
| 16 | 17 | 16 | 17 |
0
| |
p02234
|
C++
|
Time Limit Exceeded
|
/**
*
*/
// #include {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <forward_list>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#ifdef DEBUG
#include <fmt/format.h>
#include <fmt/ostream.h>
#endif
using namespace std;
// }}}
// type {{{
using s8 = int8_t;
using u8 = uint8_t;
using s16 = int16_t;
using u16 = uint16_t;
using s32 = int32_t;
using u32 = uint32_t;
using s64 = int64_t;
using u64 = uint64_t;
template <typename T> using max_heap = priority_queue<T, vector<T>, less<T>>;
template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
// }}}
// hide {{{
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-const-variable"
#endif
// }}}
// 適宜調整
// #define int s64
// #define double long double
constexpr bool AUTOFLUSH = false;
constexpr bool STDIO_ENABLE = false;
constexpr int IOS_PREC = 10;
constexpr int INF_S32 = 1'010'000'000;
constexpr s64 INF_S64 = 1'010'000'000'000'000'000LL;
constexpr auto INF = INF_S64;
constexpr double EPS = 1e-9;
constexpr s64 MOD = 1'000'000'007;
// hide {{{
#ifdef __clang__
#pragma clang diagnostic pop
#endif
// }}}
// util {{{
template <typename T, size_t N, size_t... NS> struct ArrayStruct {
using type = array<typename ArrayStruct<T, NS...>::type, N>;
};
template <typename T, size_t N> struct ArrayStruct<T, N> {
using type = array<T, N>;
};
template <typename T, size_t N, size_t... NS>
using Array = typename ArrayStruct<T, N, NS...>::type;
template <typename T> constexpr T ABS(T x) {
static_assert(is_signed<T>::value, "ABS(): argument must be signed");
return x < 0 ? -x : x;
}
template <typename T> constexpr T abs_diff(T x, T y) {
return x < y ? y - x : x - y;
}
template <typename T> constexpr bool is_odd(T x) { return x % 2 != 0; }
template <typename T> constexpr bool is_even(T x) { return x % 2 == 0; }
template <typename T> constexpr int cmp(T x, T y) { return (x > y) - (x < y); }
template <typename T> constexpr int sgn(T x) { return cmp(x, T(0)); }
template <typename T> constexpr T ipow(T a, T b) {
assert(b >= 0);
T res(1);
for (T i = 0; i < b; ++i)
res *= a;
return res;
}
template <typename T, std::enable_if_t<std::is_integral<T>::value &&
std::is_signed<T>::value,
std::nullptr_t> = nullptr>
constexpr T div_ceil(T a, T b) {
return a / b + (((a < 0) ^ (b > 0)) && (a % b));
}
template <typename T, std::enable_if_t<std::is_integral<T>::value &&
std::is_unsigned<T>::value,
std::nullptr_t> = nullptr>
constexpr T div_ceil(T a, T b) {
return a / b + !!(a % b);
}
template <typename T, std::enable_if_t<std::is_integral<T>::value &&
std::is_signed<T>::value,
std::nullptr_t> = nullptr>
constexpr T div_floor(T a, T b) {
return a / b - (((a > 0) ^ (b > 0)) && (a % b));
}
template <typename T, std::enable_if_t<std::is_integral<T>::value &&
std::is_unsigned<T>::value,
std::nullptr_t> = nullptr>
constexpr T div_floor(T a, T b) {
return a / b;
}
template <typename T, typename U> constexpr auto modulo(T a, U b) {
using R = common_type_t<T, U>;
assert(b > 0);
R r = a % b;
return r >= 0 ? r : r + b;
}
template <typename T> constexpr T clamp(T x, T lo, T hi) {
assert(lo <= hi);
if (x < lo)
return lo;
else if (x > hi)
return hi;
else
return x;
}
template <typename T> T isqrt(T x) {
assert(x >= 0);
return static_cast<T>(sqrt(static_cast<long double>(x)));
}
template <typename T, typename U> bool chmax(T &xmax, const U &x) {
if (x > xmax) {
xmax = x;
return true;
} else {
return false;
}
}
template <typename T, typename U> bool chmin(T &xmin, const U &x) {
if (x < xmin) {
xmin = x;
return true;
} else {
return false;
}
}
template <typename T> constexpr int SIZE(const T &c) {
return static_cast<int>(c.size());
}
template <typename T, size_t N> constexpr int SIZE(const T (&)[N]) {
return static_cast<int>(N);
}
template <typename InputIt, typename T>
int argfind(InputIt first, InputIt last, const T &x) {
auto it = find(first, last, x);
return distance(first, it);
}
template <typename InputIt> int argmax(InputIt first, InputIt last) {
auto it = max_element(first, last);
return distance(first, it);
}
template <typename InputIt> int argmin(InputIt first, InputIt last) {
auto it = min_element(first, last);
return distance(first, it);
}
template <typename InputIt> bool alltrue(InputIt first, InputIt last) {
return all_of(first, last, [](bool b) { return b; });
}
template <typename InputIt> bool anytrue(InputIt first, InputIt last) {
return any_of(first, last, [](bool b) { return b; });
}
template <typename InputIt> bool allfalse(InputIt first, InputIt last) {
return !anytrue(first, last);
}
template <typename InputIt> bool anyfalse(InputIt first, InputIt last) {
return !alltrue(first, last);
}
template <typename T> array<pair<T, T>, 4> neighbor4(const T &x, const T &y) {
return array<pair<T, T>, 4>{{
{x, y - 1},
{x - 1, y},
{x + 1, y},
{x, y + 1},
}};
}
template <typename T> array<pair<T, T>, 8> neighbor8(const T &x, const T &y) {
return array<pair<T, T>, 8>{{
{x - 1, y - 1},
{x, y - 1},
{x + 1, y - 1},
{x - 1, y},
{x + 1, y},
{x - 1, y + 1},
{x, y + 1},
{x + 1, y + 1},
}};
}
template <typename T> bool in_bounds(const T &x, const T &minx, const T &maxx) {
return !(x < minx) && !(maxx < x);
}
template <typename T>
bool in_bounds_2(const T &x, const T &y, const T &minx, const T &miny,
const T &maxx, const T &maxy) {
return in_bounds(x, minx, maxx) && in_bounds(y, miny, maxy);
}
template <typename T>
bool in_bounds_wh(const T &x, const T &y, const T &w, const T &h) {
return in_bounds_2(x, y, 0, 0, w - 1, h - 1);
}
struct pairhash {
template <typename T1, typename T2>
size_t operator()(const pair<T1, T2> &p) const {
size_t res = 17;
res = 31 * res + hash<T1>()(p.first);
res = 31 * res + hash<T2>()(p.second);
return res;
}
};
struct vectorhash {
template <typename T> size_t operator()(const vector<T> &v) const {
size_t res = 17;
res = 31 * res + hash<size_t>()(v.size());
for (const auto &e : v) {
res = 31 * res + hash<T>()(e);
}
return res;
}
};
template <typename K, typename V>
pair<typename map<K, V>::iterator, bool>
insert_or_assign(map<K, V> &m, const K &k, const V &v) {
auto it = m.lower_bound(k);
if (it != end(m) && !m.key_comp()(k, it->first)) {
it->second = v;
return make_pair(it, false);
} else {
auto it_ins = m.insert(it, make_pair(k, v));
return make_pair(it_ins, true);
}
}
template <typename K, typename V>
pair<typename unordered_map<K, V>::iterator, bool>
insert_or_assign(unordered_map<K, V> &m, const K &k, const V &v) {
auto it = m.find(k);
if (it != end(m)) {
it->second = v;
return make_pair(it, false);
} else {
auto it_ins = m.insert(it, make_pair(k, v));
return make_pair(it_ins, true);
}
}
template <typename T> string TO_STRING(const T &x) {
ostringstream out;
out << x;
return out.str();
}
template <typename InputIt>
string JOIN(InputIt first, InputIt last, const string &sep) {
ostringstream out;
while (first != last) {
out << *first++;
if (first != last)
out << sep;
}
return out.str();
}
template <typename InputIt> auto SUM(InputIt first, InputIt last) {
using T = typename iterator_traits<InputIt>::value_type;
return accumulate(first, last, T());
}
template <typename T> void UNIQ(T &c) {
c.erase(unique(begin(c), end(c)), end(c));
}
template <typename T, typename F>
enable_if_t<rank<T>::value == 0> ARRAY_FOREACH(T &e, F f) {
f(e);
}
template <typename Array, typename F>
enable_if_t<rank<Array>::value != 0> ARRAY_FOREACH(Array &ary, F f) {
for (auto &e : ary)
ARRAY_FOREACH(e, f);
}
template <typename Array, typename U>
enable_if_t<rank<Array>::value != 0> ARRAY_FILL(Array &ary, const U &v) {
ARRAY_FOREACH(ary, [&v](auto &elem) { elem = v; });
}
template <typename T> T POP_BACK(vector<T> &que) {
T x = que.back();
que.pop_back();
return x;
}
template <typename T> T POP_BACK(deque<T> &que) {
T x = que.back();
que.pop_back();
return x;
}
template <typename T> T POP_FRONT(deque<T> &que) {
T x = que.front();
que.pop_front();
return x;
}
template <typename T, typename C> T POP(stack<T, C> &stk) {
T x = stk.top();
stk.pop();
return x;
}
template <typename T, typename C> T POP(queue<T, C> &que) {
T x = que.front();
que.pop();
return x;
}
template <typename T, typename Cont, typename Cmp>
T POP(priority_queue<T, Cont, Cmp> &que) {
T x = que.top();
que.pop();
return x;
}
template <typename T> void RD(T &x) {
cin >> x;
#ifdef DEBUG
if (!cin)
assert(false);
#endif
}
template <typename T> void RD(vector<T> &v, int n) {
v.reserve(n);
for (int i = 0; i < n; ++i) {
T e;
RD(e);
v.emplace_back(e);
}
}
// 出力 {{{
// FPRINTSEQ {{{
template <typename InputIt>
ostream &FPRINTSEQ(ostream &out, InputIt first, InputIt last) {
for (InputIt it = first; it != last; ++it) {
if (it != first)
out << ' ';
out << *it;
}
return out;
}
template <typename InputIt> ostream &PRINTSEQ(InputIt first, InputIt last) {
return FPRINTSEQ(cout, first, last);
}
template <typename InputIt> ostream &DPRINTSEQ(InputIt first, InputIt last) {
#ifdef DEBUG
FPRINTSEQ(cerr, first, last);
#endif
return cerr;
}
// }}}
// 1次元生配列 {{{
template <typename T, size_t N>
ostream &FPRINTARRAY1(ostream &out, const T (&c)[N]) {
return FPRINTSEQ(out, cbegin(c), cend(c));
}
template <typename T, size_t N> ostream &PRINTARRAY1(const T (&c)[N]) {
return FPRINTARRAY1(cout, c);
}
template <typename T, size_t N> ostream &DPRINTARRAY1(const T (&c)[N]) {
#ifdef DEBUG
FPRINTARRAY1(cerr, c);
#endif
return cerr;
}
// }}}
// 2次元生配列 {{{
template <typename T, size_t N1, size_t N2>
ostream &FPRINTARRAY2(ostream &out, const T (&c)[N1][N2]) {
out << '\n';
for (const auto &e : c) {
FPRINTARRAY1(out, e) << '\n';
}
return out;
}
template <typename T, size_t N1, size_t N2>
ostream &PRINTARRAY2(const T (&c)[N1][N2]) {
return FPRINTARRAY2(cout, c);
}
template <typename T, size_t N1, size_t N2>
ostream &DPRINTARRAY2(const T (&c)[N1][N2]) {
#ifdef DEBUG
FPRINTARRAY2(cerr, c);
#endif
return cerr;
}
// }}}
// 非mapコンテナ {{{
template <typename T> ostream &operator<<(ostream &out, const vector<T> &c) {
return FPRINTSEQ(out, cbegin(c), cend(c));
}
// 特別扱い
template <typename T>
ostream &operator<<(ostream &out, const vector<vector<T>> &c) {
out << '\n';
for (const auto &e : c) {
out << e << '\n';
}
return out;
}
// 特別扱い
ostream &operator<<(ostream &out, const vector<string> &c) {
out << '\n';
for (const string &e : c) {
out << e << '\n';
}
return out;
}
template <typename T> ostream &operator<<(ostream &out, const deque<T> &c) {
return FPRINTSEQ(out, cbegin(c), cend(c));
}
template <typename T> ostream &operator<<(ostream &out, const list<T> &c) {
return FPRINTSEQ(out, cbegin(c), cend(c));
}
template <typename T>
ostream &operator<<(ostream &out, const forward_list<T> &c) {
return FPRINTSEQ(out, cbegin(c), cend(c));
}
template <typename T> ostream &operator<<(ostream &out, const set<T> &c) {
return FPRINTSEQ(out, cbegin(c), cend(c));
}
template <typename T>
ostream &operator<<(ostream &out, const unordered_set<T> &c) {
return out << set<T>(cbegin(c), cend(c));
}
template <typename T> ostream &operator<<(ostream &out, const multiset<T> &c) {
return FPRINTSEQ(out, cbegin(c), cend(c));
}
template <typename T>
ostream &operator<<(ostream &out, const unordered_multiset<T> &c) {
return out << multiset<T>(cbegin(c), cend(c));
}
template <typename T, size_t N>
ostream &operator<<(ostream &out, const array<T, N> &c) {
return FPRINTSEQ(out, cbegin(c), cend(c));
}
// }}}
// mapコンテナ {{{
template <typename InputIt>
ostream &FPRINTMAP(ostream &out, InputIt first, InputIt last) {
out << "{\n";
for (auto it = first; it != last; ++it) {
out << " " << it->first << " : " << it->second << '\n';
}
out << "}\n";
return out;
}
template <typename InputIt> ostream &PRINTMAP(InputIt first, InputIt last) {
return FPRINTMAP(cout, first, last);
}
template <typename InputIt> ostream &DPRINTMAP(InputIt first, InputIt last) {
#ifdef DEBUG
FPRINTMAP(cerr, first, last);
#endif
return cerr;
}
template <typename K, typename V>
ostream &operator<<(ostream &out, const map<K, V> &c) {
return FPRINTMAP(out, cbegin(c), cend(c));
}
template <typename K, typename V>
ostream &operator<<(ostream &out, const unordered_map<K, V> &c) {
return out << map<K, V>(cbegin(c), cend(c));
}
template <typename K, typename V>
ostream &operator<<(ostream &out, const multimap<K, V> &c) {
return FPRINTMAP(out, cbegin(c), cend(c));
}
template <typename K, typename V>
ostream &operator<<(ostream &out, const unordered_multimap<K, V> &c) {
return out << multimap<K, V>(cbegin(c), cend(c));
}
// }}}
// stack/queue/priority_queue {{{
template <typename T, typename C>
ostream &operator<<(ostream &out, stack<T, C> c) {
while (!c.empty()) {
out << c.top();
c.pop();
if (!c.empty())
out << ' ';
}
return out;
}
template <typename T, typename C>
ostream &operator<<(ostream &out, queue<T, C> c) {
while (!c.empty()) {
out << c.front();
c.pop();
if (!c.empty())
out << ' ';
}
return out;
}
template <typename T, typename Cont, typename Cmp>
ostream &operator<<(ostream &out, priority_queue<T, Cont, Cmp> c) {
while (!c.empty()) {
out << c.top();
c.pop();
if (!c.empty())
out << ' ';
}
return out;
}
// }}}
// pair/tuple {{{
template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
return out << '(' << p.first << ',' << p.second << ')';
}
template <typename Tuple, size_t Pos>
ostream &FPRINTTUPLE(ostream &out, const Tuple &) {
return out;
}
template <typename Tuple, size_t Pos, typename T, typename... TS>
ostream &FPRINTTUPLE(ostream &out, const Tuple &t) {
if (Pos != 0)
out << ',';
out << get<Pos>(t);
return FPRINTTUPLE<Tuple, Pos + 1, TS...>(out, t);
}
template <typename... TS>
ostream &operator<<(ostream &out, const tuple<TS...> &t) {
out << '(';
FPRINTTUPLE<tuple<TS...>, 0, TS...>(out, t);
out << ')';
return out;
}
// }}}
// PRINT {{{
ostream &FPRINT(ostream &out) { return out; }
template <typename T, typename... TS>
ostream &FPRINT(ostream &out, const T &x, const TS &...args) {
out << x;
if (sizeof...(args))
out << ' ';
return FPRINT(out, args...);
}
template <typename... TS> ostream &FPRINTLN(ostream &out, const TS &...args) {
FPRINT(out, args...);
return out << '\n';
}
template <typename... TS> ostream &PRINT(const TS &...args) {
return FPRINT(cout, args...);
}
template <typename... TS> ostream &PRINTLN(const TS &...args) {
return FPRINTLN(cout, args...);
}
template <typename... TS> ostream &DPRINT(const TS &...args) {
#ifdef DEBUG
FPRINT(cerr, args...);
#endif
return cerr;
}
template <typename... TS> ostream &DPRINTLN(const TS &...args) {
#ifdef DEBUG
FPRINTLN(cerr, args...);
#endif
return cerr;
}
// }}}
// }}}
void FLUSH() {
if (STDIO_ENABLE)
fflush(stdout);
else
cout.flush();
}
[[noreturn]] void EXIT() {
#ifdef DEBUG
fflush(stdout);
fflush(stderr);
cout.flush();
cerr.flush();
#else
FLUSH();
#endif
// quick_exit(0); // does not work on codeforces
_Exit(0);
}
struct IoInit {
IoInit() {
#ifndef DEBUG
cin.tie(nullptr);
if (!STDIO_ENABLE)
ios::sync_with_stdio(false);
#endif
cout << fixed << setprecision(IOS_PREC);
if (AUTOFLUSH) {
if (STDIO_ENABLE)
setvbuf(stdout, nullptr, _IONBF, 0);
cout << unitbuf;
}
}
} IOINIT;
#define FOR(i, start, end) for (s64 i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f, c, ...) \
(([&](decltype((c)) cc) { return (f)(begin(cc), end(cc), ##__VA_ARGS__); })( \
c))
#define GENERIC(f) \
([](auto &&...args) -> decltype(auto) { \
return (f)(forward<decltype(args)>(args)...); \
})
#define MEMSET(a, v) memset((a), (v), sizeof(a))
#define DBG(x) DPRINTLN('L', __LINE__, ':', #x, ':', (x))
// }}}
s64 N;
vector<s64> R;
vector<s64> C;
bool done[100][100]{};
s64 memo[100][100];
s64 f(s64 i, s64 j) {
assert(i <= j);
if (i == j)
return 0;
if (!done[i][j]) {
memo[i][j] = INF;
FOR(k, i, j) {
s64 cnt = 0;
cnt += f(i, k);
cnt += f(k + 1, j);
cnt += R[i] * C[k] * C[j];
chmin(memo[i][j], cnt);
}
}
return memo[i][j];
}
void solve() {
s64 ans = f(0, N - 1);
PRINTLN(ans);
}
signed main(signed /*argc*/, char ** /*argv*/) {
RD(N);
R.resize(N);
C.resize(N);
REP(i, N) {
RD(R[i]);
RD(C[i]);
}
solve();
EXIT();
}
|
/**
*
*/
// #include {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <forward_list>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#ifdef DEBUG
#include <fmt/format.h>
#include <fmt/ostream.h>
#endif
using namespace std;
// }}}
// type {{{
using s8 = int8_t;
using u8 = uint8_t;
using s16 = int16_t;
using u16 = uint16_t;
using s32 = int32_t;
using u32 = uint32_t;
using s64 = int64_t;
using u64 = uint64_t;
template <typename T> using max_heap = priority_queue<T, vector<T>, less<T>>;
template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
// }}}
// hide {{{
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-const-variable"
#endif
// }}}
// 適宜調整
// #define int s64
// #define double long double
constexpr bool AUTOFLUSH = false;
constexpr bool STDIO_ENABLE = false;
constexpr int IOS_PREC = 10;
constexpr int INF_S32 = 1'010'000'000;
constexpr s64 INF_S64 = 1'010'000'000'000'000'000LL;
constexpr auto INF = INF_S64;
constexpr double EPS = 1e-9;
constexpr s64 MOD = 1'000'000'007;
// hide {{{
#ifdef __clang__
#pragma clang diagnostic pop
#endif
// }}}
// util {{{
template <typename T, size_t N, size_t... NS> struct ArrayStruct {
using type = array<typename ArrayStruct<T, NS...>::type, N>;
};
template <typename T, size_t N> struct ArrayStruct<T, N> {
using type = array<T, N>;
};
template <typename T, size_t N, size_t... NS>
using Array = typename ArrayStruct<T, N, NS...>::type;
template <typename T> constexpr T ABS(T x) {
static_assert(is_signed<T>::value, "ABS(): argument must be signed");
return x < 0 ? -x : x;
}
template <typename T> constexpr T abs_diff(T x, T y) {
return x < y ? y - x : x - y;
}
template <typename T> constexpr bool is_odd(T x) { return x % 2 != 0; }
template <typename T> constexpr bool is_even(T x) { return x % 2 == 0; }
template <typename T> constexpr int cmp(T x, T y) { return (x > y) - (x < y); }
template <typename T> constexpr int sgn(T x) { return cmp(x, T(0)); }
template <typename T> constexpr T ipow(T a, T b) {
assert(b >= 0);
T res(1);
for (T i = 0; i < b; ++i)
res *= a;
return res;
}
template <typename T, std::enable_if_t<std::is_integral<T>::value &&
std::is_signed<T>::value,
std::nullptr_t> = nullptr>
constexpr T div_ceil(T a, T b) {
return a / b + (((a < 0) ^ (b > 0)) && (a % b));
}
template <typename T, std::enable_if_t<std::is_integral<T>::value &&
std::is_unsigned<T>::value,
std::nullptr_t> = nullptr>
constexpr T div_ceil(T a, T b) {
return a / b + !!(a % b);
}
template <typename T, std::enable_if_t<std::is_integral<T>::value &&
std::is_signed<T>::value,
std::nullptr_t> = nullptr>
constexpr T div_floor(T a, T b) {
return a / b - (((a > 0) ^ (b > 0)) && (a % b));
}
template <typename T, std::enable_if_t<std::is_integral<T>::value &&
std::is_unsigned<T>::value,
std::nullptr_t> = nullptr>
constexpr T div_floor(T a, T b) {
return a / b;
}
template <typename T, typename U> constexpr auto modulo(T a, U b) {
using R = common_type_t<T, U>;
assert(b > 0);
R r = a % b;
return r >= 0 ? r : r + b;
}
template <typename T> constexpr T clamp(T x, T lo, T hi) {
assert(lo <= hi);
if (x < lo)
return lo;
else if (x > hi)
return hi;
else
return x;
}
template <typename T> T isqrt(T x) {
assert(x >= 0);
return static_cast<T>(sqrt(static_cast<long double>(x)));
}
template <typename T, typename U> bool chmax(T &xmax, const U &x) {
if (x > xmax) {
xmax = x;
return true;
} else {
return false;
}
}
template <typename T, typename U> bool chmin(T &xmin, const U &x) {
if (x < xmin) {
xmin = x;
return true;
} else {
return false;
}
}
template <typename T> constexpr int SIZE(const T &c) {
return static_cast<int>(c.size());
}
template <typename T, size_t N> constexpr int SIZE(const T (&)[N]) {
return static_cast<int>(N);
}
template <typename InputIt, typename T>
int argfind(InputIt first, InputIt last, const T &x) {
auto it = find(first, last, x);
return distance(first, it);
}
template <typename InputIt> int argmax(InputIt first, InputIt last) {
auto it = max_element(first, last);
return distance(first, it);
}
template <typename InputIt> int argmin(InputIt first, InputIt last) {
auto it = min_element(first, last);
return distance(first, it);
}
template <typename InputIt> bool alltrue(InputIt first, InputIt last) {
return all_of(first, last, [](bool b) { return b; });
}
template <typename InputIt> bool anytrue(InputIt first, InputIt last) {
return any_of(first, last, [](bool b) { return b; });
}
template <typename InputIt> bool allfalse(InputIt first, InputIt last) {
return !anytrue(first, last);
}
template <typename InputIt> bool anyfalse(InputIt first, InputIt last) {
return !alltrue(first, last);
}
template <typename T> array<pair<T, T>, 4> neighbor4(const T &x, const T &y) {
return array<pair<T, T>, 4>{{
{x, y - 1},
{x - 1, y},
{x + 1, y},
{x, y + 1},
}};
}
template <typename T> array<pair<T, T>, 8> neighbor8(const T &x, const T &y) {
return array<pair<T, T>, 8>{{
{x - 1, y - 1},
{x, y - 1},
{x + 1, y - 1},
{x - 1, y},
{x + 1, y},
{x - 1, y + 1},
{x, y + 1},
{x + 1, y + 1},
}};
}
template <typename T> bool in_bounds(const T &x, const T &minx, const T &maxx) {
return !(x < minx) && !(maxx < x);
}
template <typename T>
bool in_bounds_2(const T &x, const T &y, const T &minx, const T &miny,
const T &maxx, const T &maxy) {
return in_bounds(x, minx, maxx) && in_bounds(y, miny, maxy);
}
template <typename T>
bool in_bounds_wh(const T &x, const T &y, const T &w, const T &h) {
return in_bounds_2(x, y, 0, 0, w - 1, h - 1);
}
struct pairhash {
template <typename T1, typename T2>
size_t operator()(const pair<T1, T2> &p) const {
size_t res = 17;
res = 31 * res + hash<T1>()(p.first);
res = 31 * res + hash<T2>()(p.second);
return res;
}
};
struct vectorhash {
template <typename T> size_t operator()(const vector<T> &v) const {
size_t res = 17;
res = 31 * res + hash<size_t>()(v.size());
for (const auto &e : v) {
res = 31 * res + hash<T>()(e);
}
return res;
}
};
template <typename K, typename V>
pair<typename map<K, V>::iterator, bool>
insert_or_assign(map<K, V> &m, const K &k, const V &v) {
auto it = m.lower_bound(k);
if (it != end(m) && !m.key_comp()(k, it->first)) {
it->second = v;
return make_pair(it, false);
} else {
auto it_ins = m.insert(it, make_pair(k, v));
return make_pair(it_ins, true);
}
}
template <typename K, typename V>
pair<typename unordered_map<K, V>::iterator, bool>
insert_or_assign(unordered_map<K, V> &m, const K &k, const V &v) {
auto it = m.find(k);
if (it != end(m)) {
it->second = v;
return make_pair(it, false);
} else {
auto it_ins = m.insert(it, make_pair(k, v));
return make_pair(it_ins, true);
}
}
template <typename T> string TO_STRING(const T &x) {
ostringstream out;
out << x;
return out.str();
}
template <typename InputIt>
string JOIN(InputIt first, InputIt last, const string &sep) {
ostringstream out;
while (first != last) {
out << *first++;
if (first != last)
out << sep;
}
return out.str();
}
template <typename InputIt> auto SUM(InputIt first, InputIt last) {
using T = typename iterator_traits<InputIt>::value_type;
return accumulate(first, last, T());
}
template <typename T> void UNIQ(T &c) {
c.erase(unique(begin(c), end(c)), end(c));
}
template <typename T, typename F>
enable_if_t<rank<T>::value == 0> ARRAY_FOREACH(T &e, F f) {
f(e);
}
template <typename Array, typename F>
enable_if_t<rank<Array>::value != 0> ARRAY_FOREACH(Array &ary, F f) {
for (auto &e : ary)
ARRAY_FOREACH(e, f);
}
template <typename Array, typename U>
enable_if_t<rank<Array>::value != 0> ARRAY_FILL(Array &ary, const U &v) {
ARRAY_FOREACH(ary, [&v](auto &elem) { elem = v; });
}
template <typename T> T POP_BACK(vector<T> &que) {
T x = que.back();
que.pop_back();
return x;
}
template <typename T> T POP_BACK(deque<T> &que) {
T x = que.back();
que.pop_back();
return x;
}
template <typename T> T POP_FRONT(deque<T> &que) {
T x = que.front();
que.pop_front();
return x;
}
template <typename T, typename C> T POP(stack<T, C> &stk) {
T x = stk.top();
stk.pop();
return x;
}
template <typename T, typename C> T POP(queue<T, C> &que) {
T x = que.front();
que.pop();
return x;
}
template <typename T, typename Cont, typename Cmp>
T POP(priority_queue<T, Cont, Cmp> &que) {
T x = que.top();
que.pop();
return x;
}
template <typename T> void RD(T &x) {
cin >> x;
#ifdef DEBUG
if (!cin)
assert(false);
#endif
}
template <typename T> void RD(vector<T> &v, int n) {
v.reserve(n);
for (int i = 0; i < n; ++i) {
T e;
RD(e);
v.emplace_back(e);
}
}
// 出力 {{{
// FPRINTSEQ {{{
template <typename InputIt>
ostream &FPRINTSEQ(ostream &out, InputIt first, InputIt last) {
for (InputIt it = first; it != last; ++it) {
if (it != first)
out << ' ';
out << *it;
}
return out;
}
template <typename InputIt> ostream &PRINTSEQ(InputIt first, InputIt last) {
return FPRINTSEQ(cout, first, last);
}
template <typename InputIt> ostream &DPRINTSEQ(InputIt first, InputIt last) {
#ifdef DEBUG
FPRINTSEQ(cerr, first, last);
#endif
return cerr;
}
// }}}
// 1次元生配列 {{{
template <typename T, size_t N>
ostream &FPRINTARRAY1(ostream &out, const T (&c)[N]) {
return FPRINTSEQ(out, cbegin(c), cend(c));
}
template <typename T, size_t N> ostream &PRINTARRAY1(const T (&c)[N]) {
return FPRINTARRAY1(cout, c);
}
template <typename T, size_t N> ostream &DPRINTARRAY1(const T (&c)[N]) {
#ifdef DEBUG
FPRINTARRAY1(cerr, c);
#endif
return cerr;
}
// }}}
// 2次元生配列 {{{
template <typename T, size_t N1, size_t N2>
ostream &FPRINTARRAY2(ostream &out, const T (&c)[N1][N2]) {
out << '\n';
for (const auto &e : c) {
FPRINTARRAY1(out, e) << '\n';
}
return out;
}
template <typename T, size_t N1, size_t N2>
ostream &PRINTARRAY2(const T (&c)[N1][N2]) {
return FPRINTARRAY2(cout, c);
}
template <typename T, size_t N1, size_t N2>
ostream &DPRINTARRAY2(const T (&c)[N1][N2]) {
#ifdef DEBUG
FPRINTARRAY2(cerr, c);
#endif
return cerr;
}
// }}}
// 非mapコンテナ {{{
template <typename T> ostream &operator<<(ostream &out, const vector<T> &c) {
return FPRINTSEQ(out, cbegin(c), cend(c));
}
// 特別扱い
template <typename T>
ostream &operator<<(ostream &out, const vector<vector<T>> &c) {
out << '\n';
for (const auto &e : c) {
out << e << '\n';
}
return out;
}
// 特別扱い
ostream &operator<<(ostream &out, const vector<string> &c) {
out << '\n';
for (const string &e : c) {
out << e << '\n';
}
return out;
}
template <typename T> ostream &operator<<(ostream &out, const deque<T> &c) {
return FPRINTSEQ(out, cbegin(c), cend(c));
}
template <typename T> ostream &operator<<(ostream &out, const list<T> &c) {
return FPRINTSEQ(out, cbegin(c), cend(c));
}
template <typename T>
ostream &operator<<(ostream &out, const forward_list<T> &c) {
return FPRINTSEQ(out, cbegin(c), cend(c));
}
template <typename T> ostream &operator<<(ostream &out, const set<T> &c) {
return FPRINTSEQ(out, cbegin(c), cend(c));
}
template <typename T>
ostream &operator<<(ostream &out, const unordered_set<T> &c) {
return out << set<T>(cbegin(c), cend(c));
}
template <typename T> ostream &operator<<(ostream &out, const multiset<T> &c) {
return FPRINTSEQ(out, cbegin(c), cend(c));
}
template <typename T>
ostream &operator<<(ostream &out, const unordered_multiset<T> &c) {
return out << multiset<T>(cbegin(c), cend(c));
}
template <typename T, size_t N>
ostream &operator<<(ostream &out, const array<T, N> &c) {
return FPRINTSEQ(out, cbegin(c), cend(c));
}
// }}}
// mapコンテナ {{{
template <typename InputIt>
ostream &FPRINTMAP(ostream &out, InputIt first, InputIt last) {
out << "{\n";
for (auto it = first; it != last; ++it) {
out << " " << it->first << " : " << it->second << '\n';
}
out << "}\n";
return out;
}
template <typename InputIt> ostream &PRINTMAP(InputIt first, InputIt last) {
return FPRINTMAP(cout, first, last);
}
template <typename InputIt> ostream &DPRINTMAP(InputIt first, InputIt last) {
#ifdef DEBUG
FPRINTMAP(cerr, first, last);
#endif
return cerr;
}
template <typename K, typename V>
ostream &operator<<(ostream &out, const map<K, V> &c) {
return FPRINTMAP(out, cbegin(c), cend(c));
}
template <typename K, typename V>
ostream &operator<<(ostream &out, const unordered_map<K, V> &c) {
return out << map<K, V>(cbegin(c), cend(c));
}
template <typename K, typename V>
ostream &operator<<(ostream &out, const multimap<K, V> &c) {
return FPRINTMAP(out, cbegin(c), cend(c));
}
template <typename K, typename V>
ostream &operator<<(ostream &out, const unordered_multimap<K, V> &c) {
return out << multimap<K, V>(cbegin(c), cend(c));
}
// }}}
// stack/queue/priority_queue {{{
template <typename T, typename C>
ostream &operator<<(ostream &out, stack<T, C> c) {
while (!c.empty()) {
out << c.top();
c.pop();
if (!c.empty())
out << ' ';
}
return out;
}
template <typename T, typename C>
ostream &operator<<(ostream &out, queue<T, C> c) {
while (!c.empty()) {
out << c.front();
c.pop();
if (!c.empty())
out << ' ';
}
return out;
}
template <typename T, typename Cont, typename Cmp>
ostream &operator<<(ostream &out, priority_queue<T, Cont, Cmp> c) {
while (!c.empty()) {
out << c.top();
c.pop();
if (!c.empty())
out << ' ';
}
return out;
}
// }}}
// pair/tuple {{{
template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
return out << '(' << p.first << ',' << p.second << ')';
}
template <typename Tuple, size_t Pos>
ostream &FPRINTTUPLE(ostream &out, const Tuple &) {
return out;
}
template <typename Tuple, size_t Pos, typename T, typename... TS>
ostream &FPRINTTUPLE(ostream &out, const Tuple &t) {
if (Pos != 0)
out << ',';
out << get<Pos>(t);
return FPRINTTUPLE<Tuple, Pos + 1, TS...>(out, t);
}
template <typename... TS>
ostream &operator<<(ostream &out, const tuple<TS...> &t) {
out << '(';
FPRINTTUPLE<tuple<TS...>, 0, TS...>(out, t);
out << ')';
return out;
}
// }}}
// PRINT {{{
ostream &FPRINT(ostream &out) { return out; }
template <typename T, typename... TS>
ostream &FPRINT(ostream &out, const T &x, const TS &...args) {
out << x;
if (sizeof...(args))
out << ' ';
return FPRINT(out, args...);
}
template <typename... TS> ostream &FPRINTLN(ostream &out, const TS &...args) {
FPRINT(out, args...);
return out << '\n';
}
template <typename... TS> ostream &PRINT(const TS &...args) {
return FPRINT(cout, args...);
}
template <typename... TS> ostream &PRINTLN(const TS &...args) {
return FPRINTLN(cout, args...);
}
template <typename... TS> ostream &DPRINT(const TS &...args) {
#ifdef DEBUG
FPRINT(cerr, args...);
#endif
return cerr;
}
template <typename... TS> ostream &DPRINTLN(const TS &...args) {
#ifdef DEBUG
FPRINTLN(cerr, args...);
#endif
return cerr;
}
// }}}
// }}}
void FLUSH() {
if (STDIO_ENABLE)
fflush(stdout);
else
cout.flush();
}
[[noreturn]] void EXIT() {
#ifdef DEBUG
fflush(stdout);
fflush(stderr);
cout.flush();
cerr.flush();
#else
FLUSH();
#endif
// quick_exit(0); // does not work on codeforces
_Exit(0);
}
struct IoInit {
IoInit() {
#ifndef DEBUG
cin.tie(nullptr);
if (!STDIO_ENABLE)
ios::sync_with_stdio(false);
#endif
cout << fixed << setprecision(IOS_PREC);
if (AUTOFLUSH) {
if (STDIO_ENABLE)
setvbuf(stdout, nullptr, _IONBF, 0);
cout << unitbuf;
}
}
} IOINIT;
#define FOR(i, start, end) for (s64 i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(f, c, ...) \
(([&](decltype((c)) cc) { return (f)(begin(cc), end(cc), ##__VA_ARGS__); })( \
c))
#define GENERIC(f) \
([](auto &&...args) -> decltype(auto) { \
return (f)(forward<decltype(args)>(args)...); \
})
#define MEMSET(a, v) memset((a), (v), sizeof(a))
#define DBG(x) DPRINTLN('L', __LINE__, ':', #x, ':', (x))
// }}}
s64 N;
vector<s64> R;
vector<s64> C;
bool done[100][100]{};
s64 memo[100][100];
s64 f(s64 i, s64 j) {
assert(i <= j);
if (i == j)
return 0;
if (!done[i][j]) {
memo[i][j] = INF;
FOR(k, i, j) {
s64 cnt = 0;
cnt += f(i, k);
cnt += f(k + 1, j);
cnt += R[i] * C[k] * C[j];
chmin(memo[i][j], cnt);
}
done[i][j] = true;
}
return memo[i][j];
}
void solve() {
s64 ans = f(0, N - 1);
PRINTLN(ans);
}
signed main(signed /*argc*/, char ** /*argv*/) {
RD(N);
R.resize(N);
C.resize(N);
REP(i, N) {
RD(R[i]);
RD(C[i]);
}
solve();
EXIT();
}
|
insert
| 759 | 759 | 759 | 761 |
TLE
| |
p02234
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
int main() {
int n, p[101], m[101][101];
std::cin >> n;
for (int i = 1; i <= n; i++) {
std::cin >> p[i - 1] >> p[i];
}
for (int i = 1; i <= n; i++)
m[i][i] = 0;
for (int l = 2; l <= n; l++) {
for (int i = 1; i <= n - 1; i++) {
int j = i + l - 1;
m[i][j] = (1 << 21);
for (int k = i; k <= j - 1; k++) {
m[i][j] =
std::min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
}
}
}
std::cout << m[1][n] << std::endl;
return 0;
}
|
#include <algorithm>
#include <iostream>
int main() {
int n, p[101], m[101][101];
std::cin >> n;
for (int i = 1; i <= n; i++) {
std::cin >> p[i - 1] >> p[i];
}
for (int i = 1; i <= n; i++)
m[i][i] = 0;
for (int l = 2; l <= n; l++) {
for (int i = 1; i <= n - l + 1; i++) {
int j = i + l - 1;
m[i][j] = (1 << 21);
for (int k = i; k <= j - 1; k++) {
m[i][j] =
std::min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
}
}
}
std::cout << m[1][n] << std::endl;
return 0;
}
|
replace
| 13 | 14 | 13 | 14 |
0
| |
p02234
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define N 110
using namespace std;
int A[N];
int dp[N][N];
int Min(int &a, int b) { return a = min(a, b); }
int main() {
int n;
cin >> n;
for (int i = 0, cnt = 0; i < n; i++) {
int a, b;
cin >> a >> b;
if (i == 0)
A[cnt++] = a;
A[cnt++] = b;
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++)
dp[i][j] = 1e9;
dp[i][i] = 0;
}
for (int len = 0; len < n; len++)
for (int l = 1; l < n; l++) {
int r = l + len;
for (int m = l; m < r; m++) {
Min(dp[l][r], dp[l][m] + dp[m + 1][r] + A[l - 1] * A[m] * A[r]);
}
}
cout << dp[1][n] << endl;
return 0;
}
|
#include <bits/stdc++.h>
#define N 110
using namespace std;
int A[N];
int dp[N][N];
int Min(int &a, int b) { return a = min(a, b); }
int main() {
int n;
cin >> n;
for (int i = 0, cnt = 0; i < n; i++) {
int a, b;
cin >> a >> b;
if (i == 0)
A[cnt++] = a;
A[cnt++] = b;
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++)
dp[i][j] = 1e9;
dp[i][i] = 0;
}
for (int len = 0; len < n; len++)
for (int l = 1; l < n; l++) {
int r = l + len;
if (l + len >= N)
continue;
for (int m = l; m < r; m++) {
Min(dp[l][r], dp[l][m] + dp[m + 1][r] + A[l - 1] * A[m] * A[r]);
}
}
cout << dp[1][n] << endl;
return 0;
}
|
insert
| 28 | 28 | 28 | 30 |
0
| |
p02234
|
C++
|
Runtime Error
|
#include <climits>
#include <iostream>
#include <vector>
using namespace std;
int MCM(int p[], int n) {
vector<vector<int>> m(n, vector<int>(n));
for (int i = 0; i <= n; i++)
m[i][i] = 0;
for (int l = 2; l <= n; l++) {
for (int i = 1; i <= n - l + 1; i++) {
int j = i + l - 1;
m[i][j] = INT_MAX;
for (int k = i; k <= j - 1; k++) {
int q = m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j];
if (m[i][j] > q) {
m[i][j] = q;
}
}
}
}
return m[1][n];
}
int main() {
int n, p[200];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> p[i] >> p[i + 1];
}
cout << MCM(p, n) << endl;
return 0;
}
|
#include <climits>
#include <iostream>
#include <vector>
using namespace std;
int MCM(int p[], int n) {
vector<vector<int>> m(n + 1, vector<int>(n + 1));
for (int i = 0; i <= n; i++)
m[i][i] = 0;
for (int l = 2; l <= n; l++) {
for (int i = 1; i <= n - l + 1; i++) {
int j = i + l - 1;
m[i][j] = INT_MAX;
for (int k = i; k <= j - 1; k++) {
int q = m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j];
if (m[i][j] > q) {
m[i][j] = q;
}
}
}
}
return m[1][n];
}
int main() {
int n, p[200];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> p[i] >> p[i + 1];
}
cout << MCM(p, n) << endl;
return 0;
}
|
replace
| 6 | 7 | 6 | 7 |
-11
| |
p02234
|
C++
|
Runtime Error
|
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
#define range(i, a, b) for (int i = (a); i <= (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repR(i, n) for (int i = (n)-1; i > -1; i--)
#define rep1(i, n) for (int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for (int i = (n); i > 0; i--)
using namespace std;
int n;
int m[110][110];
int p[110];
int matrixChainMultiplication() {
rep1(i, n) m[i][i] = 0;
range(l, 2, n) {
rep1(i, n - 1 + 1) {
int j = i + l - 1;
m[i][j] = INT_MAX;
range(k, i, j - 1) {
m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
}
}
}
return m[1][n];
}
int main() {
cin >> n;
rep1(i, n) { cin >> p[i - 1] >> p[i]; }
cout << matrixChainMultiplication() << endl;
return 0;
}
|
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
#define range(i, a, b) for (int i = (a); i <= (int)(b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repR(i, n) for (int i = (n)-1; i > -1; i--)
#define rep1(i, n) for (int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for (int i = (n); i > 0; i--)
using namespace std;
int n;
int m[110][110];
int p[110];
int matrixChainMultiplication() {
rep1(i, n) m[i][i] = 0;
range(l, 2, n) {
rep1(i, n - l + 1) {
int j = i + l - 1;
m[i][j] = INT_MAX;
range(k, i, j - 1) {
m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
}
}
}
return m[1][n];
}
int main() {
cin >> n;
rep1(i, n) { cin >> p[i - 1] >> p[i]; }
cout << matrixChainMultiplication() << endl;
return 0;
}
|
replace
| 19 | 20 | 19 | 20 |
0
| |
p02234
|
C++
|
Runtime Error
|
#include <climits>
#include <iostream>
using namespace std;
int m[100][100];
int MCM(int p[], int n) {
for (int i = 0; i <= n; i++)
m[i][i] = 0;
for (int l = 2; l <= n; l++) {
for (int i = 1; i <= n - l + 1; i++) {
int j = i + l - 1;
m[i][j] = INT_MAX;
for (int k = i; k <= j; k++) {
int q = m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j];
if (m[i][j] > q) {
m[i][j] = q;
}
}
}
}
return m[1][n];
}
int main() {
int n, p[200];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> p[i] >> p[i + 1];
}
cout << MCM(p, n) << endl;
return 0;
}
|
#include <climits>
#include <iostream>
using namespace std;
int m[100][100];
int MCM(int p[], int n) {
for (int i = 0; i <= n; i++)
m[i][i] = 0;
for (int l = 2; l <= n; l++) {
for (int i = 1; i <= n - l + 1; i++) {
int j = i + l - 1;
m[i][j] = INT_MAX;
for (int k = i; k <= j - 1; k++) {
int q = m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j];
if (m[i][j] > q) {
m[i][j] = q;
}
}
}
}
return m[1][n];
}
int main() {
int n, p[200];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> p[i] >> p[i + 1];
}
cout << MCM(p, n) << endl;
return 0;
}
|
replace
| 12 | 13 | 12 | 13 |
0
| |
p02235
|
Python
|
Time Limit Exceeded
|
q = int(input())
for _ in range(q):
x = input()
y = input()
m = len(x)
n = len(y)
c = [0] * (n + 1)
for i in range(m):
tmp = x[i]
c_ = c[:]
for j in range(n):
if tmp == y[j]:
c[j + 1] = c_[j] + 1
elif c[j + 1] < c[j]:
c[j + 1] = c[j]
print(c[-1])
|
def lcs(x, y):
a = len(x)
b = len(y)
c1 = [0] * (b + 1)
for i in range(a):
e1 = x[i]
c2 = c1[:]
for j in range(b):
if e1 == y[j]:
c1[j + 1] = c2[j] + 1
elif c1[j + 1] < c1[j]:
c1[j + 1] = c1[j]
return c1[-1]
n = int(input().rstrip())
ret = []
for i in range(n):
s1 = input().rstrip()
s2 = input().rstrip()
ret.append(lcs(s1, s2))
print(*ret, sep="\n")
|
replace
| 0 | 16 | 0 | 22 |
TLE
| |
p02235
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = a; i >= n; i--)
#define INF 999999999
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef vector<pii> VP;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int main() {
int num;
cin >> num;
rep(k, 0, num) {
string s1, s2;
cin >> s1 >> s2;
int dp
[101]
[101]; // s1???i??????????????§???s2???j??????????????§??§???LCS????±???????????????????
int n = s1.length();
int m = s2.length();
rep(i, 0, m + 1) dp[0][i] = 0;
rep(i, 0, n) {
rep(j, 0, m) {
if (s1[i] == s2[j])
dp[i + 1][j + 1] = dp[i][j] + 1;
else
dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
}
}
cout << dp[n][m] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = a; i >= n; i--)
#define INF 999999999
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef vector<pii> VP;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int main() {
int num;
cin >> num;
rep(k, 0, num) {
string s1, s2;
cin >> s1 >> s2;
int dp
[1001]
[1001]; // s1???i??????????????§???s2???j??????????????§??§???LCS????±???????????????????
int n = s1.length();
int m = s2.length();
rep(i, 0, m + 1) dp[0][i] = 0;
rep(i, 0, n) {
rep(j, 0, m) {
if (s1[i] == s2[j])
dp[i + 1][j + 1] = dp[i][j] + 1;
else
dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
}
}
cout << dp[n][m] << endl;
}
return 0;
}
|
replace
| 22 | 24 | 22 | 24 |
0
| |
p02235
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;
using namespace std;
int lcs(string x, string y) {
int c[10][10];
int m = x.size();
int n = y.size();
x = ' ' + x;
y = ' ' + y;
for (int i = 1; i <= m; i++)
c[i][0] = 0;
for (int j = 1; j <= n; j++)
c[0][j] = 0;
c[0][0] = 0;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
if (x[i] == y[j]) {
c[i][j] = c[i - 1][j - 1] + 1;
} else {
c[i][j] = max(c[i - 1][j], c[i][j - 1]);
}
}
}
return c[m][n];
}
int main() {
int n;
cin >> n;
string a, b;
for (int i = 0; i < n; i++) {
cin >> a >> b;
cout << lcs(a, b) << endl;
}
}
|
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;
using namespace std;
int lcs(string x, string y) {
int c[1200][1200];
int m = x.size();
int n = y.size();
x = ' ' + x;
y = ' ' + y;
for (int i = 1; i <= m; i++)
c[i][0] = 0;
for (int j = 1; j <= n; j++)
c[0][j] = 0;
c[0][0] = 0;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
if (x[i] == y[j]) {
c[i][j] = c[i - 1][j - 1] + 1;
} else {
c[i][j] = max(c[i - 1][j], c[i][j - 1]);
}
}
}
return c[m][n];
}
int main() {
int n;
cin >> n;
string a, b;
for (int i = 0; i < n; i++) {
cin >> a >> b;
cout << lcs(a, b) << endl;
}
}
|
replace
| 18 | 19 | 18 | 19 |
0
| |
p02235
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
const int INF = 1 << 29;
const double EPS = 1e-9;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int dp[1000][1000];
int main() {
int n;
cin >> n;
while (n--) {
memset(dp, 0, sizeof(dp));
string str1, str2;
cin >> str1 >> str2;
// int l =min(str1.length(),str2.length());
for (int i = 0; i < str1.length(); i++) {
for (int j = 0; j < str2.length(); j++) {
if (str1[i] == str2[j]) {
dp[i + 1][j + 1] = dp[i][j] + 1;
} else {
dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
}
}
}
cout << dp[str1.length()][str2.length()] << endl;
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, a, b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
const int INF = 1 << 29;
const double EPS = 1e-9;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int dp[1050][1050];
int main() {
int n;
cin >> n;
while (n--) {
memset(dp, 0, sizeof(dp));
string str1, str2;
cin >> str1 >> str2;
// int l =min(str1.length(),str2.length());
for (int i = 0; i < str1.length(); i++) {
for (int j = 0; j < str2.length(); j++) {
if (str1[i] == str2[j]) {
dp[i + 1][j + 1] = dp[i][j] + 1;
} else {
dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
}
}
}
cout << dp[str1.length()][str2.length()] << endl;
}
return 0;
}
|
replace
| 38 | 39 | 38 | 39 |
0
| |
p02235
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
// #include <chrono> //1e+9で割る auto end= chrono::system_clock::now()-st;
// cout<<end.count()%1e+9<<endl;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef long double db;
#define fr first
#define sc second
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
int q;
string s1, s2;
int ans;
int dp[150][150];
int main() {
cin >> q;
rep(i, q) {
cin >> s1 >> s2;
rep(i, s1.size()) {
rep(j, s2.size()) { dp[i][j] = 0; }
}
if (s1[0] == s2[0])
dp[0][0] = 1;
rep1(i, s1.size() - 1) {
if (s1[i] == s2[0])
dp[i][0] = 1;
dp[i][0] = max(dp[i][0], dp[i - 1][0]);
}
rep1(i, s2.size() - 1) {
if (s1[0] == s2[i])
dp[0][i] = 1;
dp[0][i] = max(dp[0][i], dp[0][i - 1]);
}
rep1(i, s1.size() - 1) {
rep1(j, s2.size() - 1) {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
if (s1[i] == s2[j])
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
}
}
cout << dp[s1.size() - 1][s2.size() - 1] << endl;
}
}
|
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
// #include <chrono> //1e+9で割る auto end= chrono::system_clock::now()-st;
// cout<<end.count()%1e+9<<endl;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef long double db;
#define fr first
#define sc second
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
int q;
string s1, s2;
int ans;
int dp[1510][1501];
int main() {
cin >> q;
rep(i, q) {
cin >> s1 >> s2;
rep(i, s1.size()) {
rep(j, s2.size()) { dp[i][j] = 0; }
}
if (s1[0] == s2[0])
dp[0][0] = 1;
rep1(i, s1.size() - 1) {
if (s1[i] == s2[0])
dp[i][0] = 1;
dp[i][0] = max(dp[i][0], dp[i - 1][0]);
}
rep1(i, s2.size() - 1) {
if (s1[0] == s2[i])
dp[0][i] = 1;
dp[0][i] = max(dp[0][i], dp[0][i - 1]);
}
rep1(i, s1.size() - 1) {
rep1(j, s2.size() - 1) {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
if (s1[i] == s2[j])
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
}
}
cout << dp[s1.size() - 1][s2.size() - 1] << endl;
}
}
|
replace
| 29 | 30 | 29 | 30 |
0
| |
p02235
|
C++
|
Runtime Error
|
#include <iostream>
#include <vector>
using namespace std;
void fnInput(vector<string> &rvsStrX, vector<string> &rvsStrY) {
int nMaxSiz;
cin >> nMaxSiz;
rvsStrX.resize(nMaxSiz);
rvsStrY.resize(nMaxSiz);
for (int i = 0; i < nMaxSiz; ++i) {
cin >> rvsStrX[i] >> rvsStrY[i];
rvsStrX[i] = ' ' + rvsStrX[i];
rvsStrY[i] = ' ' + rvsStrY[i];
}
}
int fnLngCmnSubseq(const vector<string> &cnrvsStrX,
const vector<string> &cnrvsStrY) {
vector<vector<int>> vvnLcsDP;
for (int i = 0; i < cnrvsStrX.size(); ++i) {
const int nMAXNX = cnrvsStrX[i].size();
const int nMAXNY = cnrvsStrY[i].size();
vvnLcsDP.shrink_to_fit();
vvnLcsDP.resize(nMAXNX, vector<int>(nMAXNY, 0));
for (int nx = 1; nx < nMAXNX; ++nx)
for (int ny = 1; ny < nMAXNY; ++ny)
if (cnrvsStrX[i][nx] == cnrvsStrY[i][ny])
vvnLcsDP[nx][ny] = vvnLcsDP[nx - 1][ny - 1] + 1;
else
vvnLcsDP[nx][ny] = max(vvnLcsDP[nx - 1][ny], vvnLcsDP[nx][ny - 1]);
cout << vvnLcsDP[nMAXNX - 1][nMAXNY - 1] << endl;
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
vector<string> vsStrX, vsStrY;
fnInput(vsStrX, vsStrY);
fnLngCmnSubseq(vsStrX, vsStrY);
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
void fnInput(vector<string> &rvsStrX, vector<string> &rvsStrY) {
int nMaxSiz;
cin >> nMaxSiz;
rvsStrX.resize(nMaxSiz);
rvsStrY.resize(nMaxSiz);
for (int i = 0; i < nMaxSiz; ++i) {
cin >> rvsStrX[i] >> rvsStrY[i];
rvsStrX[i] = ' ' + rvsStrX[i];
rvsStrY[i] = ' ' + rvsStrY[i];
}
}
int fnLngCmnSubseq(const vector<string> &cnrvsStrX,
const vector<string> &cnrvsStrY) {
vector<vector<int>> vvnLcsDP;
for (int i = 0; i < cnrvsStrX.size(); ++i) {
const int nMAXNX = cnrvsStrX[i].size();
const int nMAXNY = cnrvsStrY[i].size();
vvnLcsDP.clear();
vvnLcsDP.resize(nMAXNX, vector<int>(nMAXNY, 0));
for (int nx = 1; nx < nMAXNX; ++nx)
for (int ny = 1; ny < nMAXNY; ++ny)
if (cnrvsStrX[i][nx] == cnrvsStrY[i][ny])
vvnLcsDP[nx][ny] = vvnLcsDP[nx - 1][ny - 1] + 1;
else
vvnLcsDP[nx][ny] = max(vvnLcsDP[nx - 1][ny], vvnLcsDP[nx][ny - 1]);
cout << vvnLcsDP[nMAXNX - 1][nMAXNY - 1] << endl;
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
vector<string> vsStrX, vsStrY;
fnInput(vsStrX, vsStrY);
fnLngCmnSubseq(vsStrX, vsStrY);
return 0;
}
|
replace
| 24 | 25 | 24 | 25 |
0
| |
p02235
|
C++
|
Runtime Error
|
#include <cstring>
#include <iostream>
#include <string>
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, a) repi(i, 0, a)
#define clr(a, v) memset((a), (v), sizeof(a))
int q;
int dp[1000][1000];
std::string s, t;
int rec(int i, int j) {
int &ret = dp[i][j];
if (~ret)
return ret;
if (i == s.size() || j == t.size())
return 0;
ret = 0;
if (s[i] == t[j])
ret = std::max(ret, rec(i + 1, j + 1) + 1);
ret = std::max(ret, std::max(rec(i + 1, j), rec(i, j + 1)));
return ret;
}
int main() {
std::cin >> q;
while (q--) {
std::cin >> s >> t;
clr(dp, -1);
std::cout << rec(0, 0) << std::endl;
}
return 0;
}
|
#include <cstring>
#include <iostream>
#include <string>
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, a) repi(i, 0, a)
#define clr(a, v) memset((a), (v), sizeof(a))
int q;
int dp[1001][1001];
std::string s, t;
int rec(int i, int j) {
int &ret = dp[i][j];
if (~ret)
return ret;
if (i == s.size() || j == t.size())
return 0;
ret = 0;
if (s[i] == t[j])
ret = std::max(ret, rec(i + 1, j + 1) + 1);
ret = std::max(ret, std::max(rec(i + 1, j), rec(i, j + 1)));
return ret;
}
int main() {
std::cin >> q;
while (q--) {
std::cin >> s >> t;
clr(dp, -1);
std::cout << rec(0, 0) << std::endl;
}
return 0;
}
|
replace
| 8 | 9 | 8 | 9 |
0
| |
p02235
|
C++
|
Runtime Error
|
#include <iostream>
#include <string>
using namespace std;
// L[i][j] X[0]..X[i]??¨X[0]..Y[j]???LCS
int L[1000][1000] = {};
int main() {
int testnum;
cin >> testnum;
for (int t = 0; t < testnum; ++t) {
string X, Y;
cin >> X >> Y;
for (int i = 1; i <= X.length(); ++i) {
for (int j = 1; j <= Y.length(); ++j) {
if (X[i - 1] == Y[j - 1])
L[i][j] = 1 + L[i - 1][j - 1];
else
L[i][j] = max(L[i][j - 1], L[i - 1][j]);
}
}
cout << L[X.length()][Y.length()] << endl;
}
return 0;
}
|
#include <iostream>
#include <string>
using namespace std;
// L[i][j] X[0]..X[i]??¨X[0]..Y[j]???LCS
int L[1001][1001] = {};
int main() {
int testnum;
cin >> testnum;
for (int t = 0; t < testnum; ++t) {
string X, Y;
cin >> X >> Y;
for (int i = 1; i <= X.length(); ++i) {
for (int j = 1; j <= Y.length(); ++j) {
if (X[i - 1] == Y[j - 1])
L[i][j] = 1 + L[i - 1][j - 1];
else
L[i][j] = max(L[i][j - 1], L[i - 1][j]);
}
}
cout << L[X.length()][Y.length()] << endl;
}
return 0;
}
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p02235
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < n; ++i)
#define FOR(i, a, b) for (long long i = a; i < b; ++i)
using namespace std;
int main() {
int q;
scanf("%d", &q);
string x, y;
REP(i, q) {
cin >> x >> y;
int dp[x.size() + 1][y.size() + 1];
fill(dp[0], dp[y.size()], -1);
REP(j, x.size() + 1) {
REP(k, y.size() + 1) {
if (j == 0 || k == 0)
dp[j][k] = 0;
else if (x[j] == y[k])
dp[j][k] = dp[j - 1][k - 1] + 1;
else
dp[j][k] = max(dp[j][k - 1], dp[j - 1][k]);
}
}
printf("%d\n", dp[x.size()][y.size()]);
}
return 0;
}
|
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < n; ++i)
#define FOR(i, a, b) for (long long i = a; i < b; ++i)
using namespace std;
int main() {
int q;
scanf("%d", &q);
string x, y;
REP(i, q) {
cin >> x >> y;
int dp[x.size() + 1][y.size() + 1];
fill(dp[0], dp[x.size()], -1);
REP(j, x.size() + 1) dp[j][0] = 0;
REP(j, y.size() + 1) dp[0][j] = 0;
FOR(j, 1, x.size() + 1) {
FOR(k, 1, y.size() + 1) {
if (x[j - 1] == y[k - 1])
dp[j][k] = dp[j - 1][k - 1] + 1;
else
dp[j][k] = max(dp[j][k - 1], dp[j - 1][k]);
}
}
printf("%d\n", dp[x.size()][y.size()]);
}
return 0;
}
|
replace
| 11 | 17 | 11 | 17 |
0
| |
p02235
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
string s, t;
int dp[100][100];
void solve() {
cin >> s >> t;
for (int i = 0; i < s.size(); i++) {
for (int j = 0; j < t.size(); j++) {
dp[i][j] =
(i < 1 || j < 1 ? 0 : dp[i - 1][j - 1]) + (s[i] == t[j] ? 1 : 0);
int a = (i < 1 ? 0 : dp[i - 1][j]);
int b = (j < 1 ? 0 : dp[i][j - 1]);
dp[i][j] = max(dp[i][j], max(a, b));
}
}
cout << dp[s.size() - 1][t.size() - 1] << endl;
}
int main() {
int n;
cin >> n;
while (n--)
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
string s, t;
int dp[1000][1000];
void solve() {
cin >> s >> t;
for (int i = 0; i < s.size(); i++) {
for (int j = 0; j < t.size(); j++) {
dp[i][j] =
(i < 1 || j < 1 ? 0 : dp[i - 1][j - 1]) + (s[i] == t[j] ? 1 : 0);
int a = (i < 1 ? 0 : dp[i - 1][j]);
int b = (j < 1 ? 0 : dp[i][j - 1]);
dp[i][j] = max(dp[i][j], max(a, b));
}
}
cout << dp[s.size() - 1][t.size() - 1] << endl;
}
int main() {
int n;
cin >> n;
while (n--)
solve();
return 0;
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p02235
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <string.h>
#define MAX 10000
using namespace std;
int lcs(string s1, string s2) {
int C[MAX + 1][MAX + 1];
int m = s1.size();
int n = s2.size();
for (int i = 0; i <= m; ++i) {
C[i][0] = 0;
}
for (int j = 0; j <= n; ++j) {
C[0][j] = 0;
}
for (int i = 1; i <= m; ++i) {
for (int j = 1; j <= n; ++j) {
if (s1[i - 1] == s2[j - 1]) {
C[i][j] = C[i - 1][j - 1] + 1;
} else {
C[i][j] = max(C[i][j - 1], C[i - 1][j]);
}
}
}
return C[m][n];
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
string s1, s2;
cin >> s1 >> s2;
cout << lcs(s1, s2) << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <string.h>
#define MAX 1000
using namespace std;
int lcs(string s1, string s2) {
int C[MAX + 1][MAX + 1];
int m = s1.size();
int n = s2.size();
for (int i = 0; i <= m; ++i) {
C[i][0] = 0;
}
for (int j = 0; j <= n; ++j) {
C[0][j] = 0;
}
for (int i = 1; i <= m; ++i) {
for (int j = 1; j <= n; ++j) {
if (s1[i - 1] == s2[j - 1]) {
C[i][j] = C[i - 1][j - 1] + 1;
} else {
C[i][j] = max(C[i][j - 1], C[i - 1][j]);
}
}
}
return C[m][n];
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
string s1, s2;
cin >> s1 >> s2;
cout << lcs(s1, s2) << endl;
}
return 0;
}
|
replace
| 4 | 5 | 4 | 5 |
-11
| |
p02235
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main() {
int q;
cin >> q;
for (int m = 0; m < q; m++) {
string wordx, wordy;
cin >> wordx >> wordy;
int L[1000][1000] = {0};
for (int j = 0; j < wordy.size(); j++) {
for (int i = 0; i < wordx.size(); i++) {
if (wordx[i] == wordy[j]) {
L[i + 1][j + 1] = 1 + L[i][j];
} else {
L[i + 1][j + 1] = max(L[i + 1][j], L[i][j + 1]);
}
}
}
cout << L[wordx.size()][wordy.size()] << endl;
}
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main() {
int q;
cin >> q;
for (int m = 0; m < q; m++) {
string wordx, wordy;
cin >> wordx >> wordy;
int L[1010][1010] = {0};
for (int j = 0; j < wordy.size(); j++) {
for (int i = 0; i < wordx.size(); i++) {
if (wordx[i] == wordy[j]) {
L[i + 1][j + 1] = 1 + L[i][j];
} else {
L[i + 1][j + 1] = max(L[i + 1][j], L[i][j + 1]);
}
}
}
cout << L[wordx.size()][wordy.size()] << endl;
}
}
|
replace
| 12 | 13 | 12 | 13 |
0
| |
p02235
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int p[1001][1001] = {0};
int main() {
int i, j, q, e, l, z, m, u, n;
char s[2001], c[2001];
cin >> q;
for (e = 0; e < q; e++) {
scanf("%s %s", s, c);
l = strlen(s);
z = strlen(c);
for (i = 0; i <= l; i++) {
for (j = 0; j <= z; j++) {
p[i][j] = 0;
}
}
for (i = 1; i <= z; i++) {
for (j = 1; j <= l; j++) {
if (c[i - 1] == s[j - 1]) {
m = 0;
for (u = 0; u < i; u++) {
for (n = 0; n < j; n++) {
if (m < p[n][u])
m = p[n][u];
}
}
p[j][i] = m + 1;
}
p[j][i] = max(p[j][i], p[j - 1][i]);
}
}
for (i = 1; i <= z; i++) {
for (j = i + 1; j <= z; j++) {
if (p[l][i] > p[l][j]) {
m = p[l][i];
p[l][i] = p[l][j];
p[l][j] = m;
}
}
}
cout << p[l][z] << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int p[1001][1001] = {0};
int main() {
int i, j, q, e, l, z, m, u, n;
char s[2001], c[2001];
cin >> q;
for (e = 0; e < q; e++) {
scanf("%s %s", s, c);
l = strlen(s);
z = strlen(c);
for (i = 0; i <= l; i++) {
for (j = 0; j <= z; j++) {
p[i][j] = 0;
}
}
for (i = 1; i <= z; i++) {
for (j = 1; j <= l; j++) {
if (c[i - 1] == s[j - 1])
p[j][i] = p[j - 1][i - 1] + 1;
else
p[j][i] = max(p[j - 1][i], p[j][i - 1]);
}
}
cout << p[l][z] << endl;
}
return 0;
}
|
replace
| 22 | 42 | 22 | 26 |
TLE
| |
p02235
|
C++
|
Runtime Error
|
#include <iostream>
#include <vector>
using namespace std;
void fnInput(vector<string> &rvsStrX, vector<string> &rvsStrY) {
int nMaxSiz;
cin >> nMaxSiz;
rvsStrX.resize(nMaxSiz);
rvsStrY.resize(nMaxSiz);
for (int i = 0; i < nMaxSiz; ++i) {
cin >> rvsStrX[i] >> rvsStrY[i];
rvsStrX[i] = ' ' + rvsStrX[i];
rvsStrY[i] = ' ' + rvsStrY[i];
}
}
int fnLngCmnSubseq(const vector<string> &cnrvsStrX,
const vector<string> &cnrvsStrY) {
vector<vector<int>> vvnLcsDP;
for (int i = 0; i < cnrvsStrX.size(); ++i) {
const int nMAXNX = cnrvsStrX[i].size();
const int nMAXNY = cnrvsStrY[i].size();
// vvnLcsDP.clear();
vvnLcsDP.resize(nMAXNX, vector<int>(nMAXNY, 0));
for (int nx = 1; nx < nMAXNX; ++nx)
for (int ny = 1; ny < nMAXNY; ++ny)
if (cnrvsStrX[i][nx] == cnrvsStrY[i][ny])
vvnLcsDP[nx][ny] = vvnLcsDP[nx - 1][ny - 1] + 1;
else
vvnLcsDP[nx][ny] = max(vvnLcsDP[nx - 1][ny], vvnLcsDP[nx][ny - 1]);
cout << vvnLcsDP[nMAXNX - 1][nMAXNY - 1] << endl;
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
vector<string> vsStrX, vsStrY;
fnInput(vsStrX, vsStrY);
fnLngCmnSubseq(vsStrX, vsStrY);
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
void fnInput(vector<string> &rvsStrX, vector<string> &rvsStrY) {
int nMaxSiz;
cin >> nMaxSiz;
rvsStrX.resize(nMaxSiz);
rvsStrY.resize(nMaxSiz);
for (int i = 0; i < nMaxSiz; ++i) {
cin >> rvsStrX[i] >> rvsStrY[i];
rvsStrX[i] = ' ' + rvsStrX[i];
rvsStrY[i] = ' ' + rvsStrY[i];
}
}
int fnLngCmnSubseq(const vector<string> &cnrvsStrX,
const vector<string> &cnrvsStrY) {
vector<vector<int>> vvnLcsDP;
for (int i = 0; i < cnrvsStrX.size(); ++i) {
const int nMAXNX = cnrvsStrX[i].size();
const int nMAXNY = cnrvsStrY[i].size();
vvnLcsDP.clear();
vvnLcsDP.resize(nMAXNX, vector<int>(nMAXNY, 0));
for (int nx = 1; nx < nMAXNX; ++nx)
for (int ny = 1; ny < nMAXNY; ++ny)
if (cnrvsStrX[i][nx] == cnrvsStrY[i][ny])
vvnLcsDP[nx][ny] = vvnLcsDP[nx - 1][ny - 1] + 1;
else
vvnLcsDP[nx][ny] = max(vvnLcsDP[nx - 1][ny], vvnLcsDP[nx][ny - 1]);
cout << vvnLcsDP[nMAXNX - 1][nMAXNY - 1] << endl;
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
vector<string> vsStrX, vsStrY;
fnInput(vsStrX, vsStrY);
fnLngCmnSubseq(vsStrX, vsStrY);
return 0;
}
|
replace
| 24 | 25 | 24 | 25 |
0
| |
p02235
|
C++
|
Runtime Error
|
#include <iostream>
#include <vector>
using namespace std;
void fnInput(vector<string> &rvsStrX, vector<string> &rvsStrY) {
int nMaxSiz;
cin >> nMaxSiz;
rvsStrX.resize(nMaxSiz);
rvsStrY.resize(nMaxSiz);
for (int i = 0; i < nMaxSiz; ++i) {
cin >> rvsStrX[i] >> rvsStrY[i];
rvsStrX[i] = ' ' + rvsStrX[i];
rvsStrY[i] = ' ' + rvsStrY[i];
}
}
int fnLngCmnSubseq(const vector<string> &cnrvsStrX,
const vector<string> &cnrvsStrY) {
vector<vector<int>> vvnLcsDP;
for (int i = 0; i < cnrvsStrX.size(); ++i) {
const int nMAXNX = cnrvsStrX[i].size();
const int nMAXNY = cnrvsStrY[i].size();
vvnLcsDP.shrink_to_fit();
vvnLcsDP.resize(nMAXNX, vector<int>(nMAXNY, 0));
for (int nx = 1; nx < nMAXNX; ++nx)
for (int ny = 1; ny < nMAXNY; ++ny)
if (cnrvsStrX[i][nx] == cnrvsStrY[i][ny])
vvnLcsDP[nx][ny] = vvnLcsDP[nx - 1][ny - 1] + 1;
else
vvnLcsDP[nx][ny] = max(vvnLcsDP[nx - 1][ny], vvnLcsDP[nx][ny - 1]);
cout << vvnLcsDP[nMAXNX - 1][nMAXNY - 1] << endl;
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
vector<string> vsStrX, vsStrY;
fnInput(vsStrX, vsStrY);
fnLngCmnSubseq(vsStrX, vsStrY);
return 0;
}
|
#include <iostream>
#include <vector>
using namespace std;
void fnInput(vector<string> &rvsStrX, vector<string> &rvsStrY) {
int nMaxSiz;
cin >> nMaxSiz;
rvsStrX.resize(nMaxSiz);
rvsStrY.resize(nMaxSiz);
for (int i = 0; i < nMaxSiz; ++i) {
cin >> rvsStrX[i] >> rvsStrY[i];
rvsStrX[i] = ' ' + rvsStrX[i];
rvsStrY[i] = ' ' + rvsStrY[i];
}
}
int fnLngCmnSubseq(const vector<string> &cnrvsStrX,
const vector<string> &cnrvsStrY) {
vector<vector<int>> vvnLcsDP;
for (int i = 0; i < cnrvsStrX.size(); ++i) {
const int nMAXNX = cnrvsStrX[i].size();
const int nMAXNY = cnrvsStrY[i].size();
vvnLcsDP.clear();
vvnLcsDP.resize(nMAXNX, vector<int>(nMAXNY, 0));
for (int nx = 1; nx < nMAXNX; ++nx)
for (int ny = 1; ny < nMAXNY; ++ny)
if (cnrvsStrX[i][nx] == cnrvsStrY[i][ny])
vvnLcsDP[nx][ny] = vvnLcsDP[nx - 1][ny - 1] + 1;
else
vvnLcsDP[nx][ny] = max(vvnLcsDP[nx - 1][ny], vvnLcsDP[nx][ny - 1]);
cout << vvnLcsDP[nMAXNX - 1][nMAXNY - 1] << endl;
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
vector<string> vsStrX, vsStrY;
fnInput(vsStrX, vsStrY);
fnLngCmnSubseq(vsStrX, vsStrY);
return 0;
}
|
replace
| 24 | 25 | 24 | 25 |
0
| |
p02235
|
C++
|
Runtime Error
|
// ALDS1_10C
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
static const int N = 1000;
int lcs(string X, string Y) {
vector<vector<int>> c(N, vector<int>(N));
int m = X.size();
int n = Y.size();
int maxl = 0;
X = ' ' + X;
Y = ' ' + Y;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
if (X[i] == Y[j]) {
c[i][j] = c[i - 1][j - 1] + 1;
} else {
c[i][j] = max(c[i - 1][j], c[i][j - 1]);
}
maxl = max(maxl, c[i][j]);
}
}
return maxl;
}
int main() {
string s1, s2;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s1 >> s2;
cout << lcs(s1, s2) << endl;
}
return 0;
}
|
// ALDS1_10C
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
static const int N = 1001;
int lcs(string X, string Y) {
vector<vector<int>> c(N, vector<int>(N));
int m = X.size();
int n = Y.size();
int maxl = 0;
X = ' ' + X;
Y = ' ' + Y;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
if (X[i] == Y[j]) {
c[i][j] = c[i - 1][j - 1] + 1;
} else {
c[i][j] = max(c[i - 1][j], c[i][j - 1]);
}
maxl = max(maxl, c[i][j]);
}
}
return maxl;
}
int main() {
string s1, s2;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s1 >> s2;
cout << lcs(s1, s2) << endl;
}
return 0;
}
|
replace
| 7 | 8 | 7 | 8 |
0
| |
p02235
|
C++
|
Memory Limit Exceeded
|
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
static const int N = 1000;
int lcs(string X, string Y) {
int **c = (int **)malloc(sizeof(int *) * 1001);
for (int i = 0; i < 1001; i++) {
c[i] = (int *)malloc(sizeof(int) * 1001);
}
int m = X.size();
int n = Y.size();
int maxl = 0;
X = ' ' + X;
Y = ' ' + Y;
c[0][0] = 0;
for (int i = 1; i <= m; i++)
c[i][0] = 0;
for (int j = 1; j <= n; j++)
c[0][j] = 0;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
if (X[i] == Y[j]) {
c[i][j] = c[i - 1][j - 1] + 1;
} else {
c[i][j] = max(c[i - 1][j], c[i][j - 1]);
}
maxl = max(maxl, c[i][j]);
}
}
return maxl;
}
int main() {
string s1, s2;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s1 >> s2;
cout << lcs(s1, s2) << endl;
}
return 0;
}
|
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
static const int N = 1000;
int lcs(string X, string Y) {
int **c = (int **)malloc(sizeof(int *) * 1001);
for (int i = 0; i < 1001; i++) {
c[i] = (int *)malloc(sizeof(int) * 1001);
}
int m = X.size();
int n = Y.size();
int maxl = 0;
X = ' ' + X;
Y = ' ' + Y;
c[0][0] = 0;
for (int i = 1; i <= m; i++)
c[i][0] = 0;
for (int j = 1; j <= n; j++)
c[0][j] = 0;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
if (X[i] == Y[j]) {
c[i][j] = c[i - 1][j - 1] + 1;
} else {
c[i][j] = max(c[i - 1][j], c[i][j - 1]);
}
maxl = max(maxl, c[i][j]);
}
}
for (int i = 0; i < 1001; i++) {
free(c[i]);
}
free(c);
return maxl;
}
int main() {
string s1, s2;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s1 >> s2;
cout << lcs(s1, s2) << endl;
}
return 0;
}
|
insert
| 33 | 33 | 33 | 37 |
MLE
| |
p02235
|
C++
|
Runtime Error
|
#include <iostream>
#include <string>
using namespace std;
int main() {
int setN;
cin >> setN;
string A, B;
for (int i = 0; i < setN; i++) {
cin >> A;
cin >> B;
int L[1000][1000] = {};
for (int j = 1; j < A.length() + 1; j++) {
for (int l = 1; l < B.length() + 1; l++) {
if (A[j - 1] == B[l - 1]) {
L[j][l] = 1 + L[j - 1][l - 1];
} else {
L[j][l] = max(L[j - 1][l], L[j][l - 1]);
}
}
}
/*
for(int j=0;j<A.length()+1;j++) {
cout << endl;
for(int l=0;l<B.length()+1;l++) {
cout << L[j][l] << " ";
}
}
*/
cout << L[A.length()][B.length()] << endl;
}
}
|
#include <iostream>
#include <string>
using namespace std;
int main() {
int setN;
cin >> setN;
string A, B;
for (int i = 0; i < setN; i++) {
cin >> A;
cin >> B;
int L[2000][2000] = {};
for (int j = 1; j < A.length() + 1; j++) {
for (int l = 1; l < B.length() + 1; l++) {
if (A[j - 1] == B[l - 1]) {
L[j][l] = 1 + L[j - 1][l - 1];
} else {
L[j][l] = max(L[j - 1][l], L[j][l - 1]);
}
}
}
/*
for(int j=0;j<A.length()+1;j++) {
cout << endl;
for(int l=0;l<B.length()+1;l++) {
cout << L[j][l] << " ";
}
}
*/
cout << L[A.length()][B.length()] << endl;
}
}
|
replace
| 12 | 13 | 12 | 13 |
0
| |
p02235
|
C++
|
Runtime Error
|
#include <iostream>
#include <string>
#define int long long
// #define _DEBUG
using namespace std;
string sa, sb;
int T[1000][1000];
int solve() {
int sal = sa.length(), sbl = sb.length();
for (int a = 0; a <= sal; a++) {
for (int b = 0; b <= sbl; b++) {
if (a == 0 || b == 0) {
T[a][b] = 0;
} else if (sa[a - 1] == sb[b - 1]) {
T[a][b] = 1 + T[a - 1][b - 1];
} else {
T[a][b] = max(T[a][b - 1], T[a - 1][b]);
}
}
}
return T[sal][sbl];
}
signed main() {
int N;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> sa >> sb;
cout << solve() << endl;
}
}
|
#include <iostream>
#include <string>
#define int long long
// #define _DEBUG
using namespace std;
string sa, sb;
int T[1009][1009];
int solve() {
int sal = sa.length(), sbl = sb.length();
for (int a = 0; a <= sal; a++) {
for (int b = 0; b <= sbl; b++) {
if (a == 0 || b == 0) {
T[a][b] = 0;
} else if (sa[a - 1] == sb[b - 1]) {
T[a][b] = 1 + T[a - 1][b - 1];
} else {
T[a][b] = max(T[a][b - 1], T[a - 1][b]);
}
}
}
return T[sal][sbl];
}
signed main() {
int N;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> sa >> sb;
cout << solve() << endl;
}
}
|
replace
| 6 | 7 | 6 | 7 |
0
| |
p02235
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <list>
#include <stack>
#include <stdio.h>
#include <string>
#define MAX 101
using namespace std;
int main() {
int n;
cin >> n;
string x, y;
int data[MAX][MAX] = {0, 0};
for (int d = 0; d < n; d++) {
cin >> x >> y;
for (int i = 0; i < y.size(); i++) {
for (int j = 0; j < x.size(); j++) {
if (y[i] == x[j]) {
data[j + 1][i + 1] = data[j][i] + 1;
} else {
data[j + 1][i + 1] = max(data[j + 1][i], data[j][i + 1]);
}
}
}
cout << data[x.size()][y.size()] << endl;
}
return 0;
}
|
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <list>
#include <stack>
#include <stdio.h>
#include <string>
#define MAX 1001
using namespace std;
int main() {
int n;
cin >> n;
string x, y;
int data[MAX][MAX] = {0, 0};
for (int d = 0; d < n; d++) {
cin >> x >> y;
for (int i = 0; i < y.size(); i++) {
for (int j = 0; j < x.size(); j++) {
if (y[i] == x[j]) {
data[j + 1][i + 1] = data[j][i] + 1;
} else {
data[j + 1][i + 1] = max(data[j + 1][i], data[j][i + 1]);
}
}
}
cout << data[x.size()][y.size()] << endl;
}
return 0;
}
|
replace
| 7 | 8 | 7 | 8 |
0
| |
p02235
|
C++
|
Runtime Error
|
#include <stdio.h>
int hantei(char x[], char y[]) {
int xn = 0, yn = 0, flag = 0, i, j, max = 0;
int c[101][101];
while (flag == 0) {
if (x[xn] != '\0') {
xn++;
} else {
flag = 1;
}
}
flag = 0;
while (flag == 0) {
if (y[yn] != '\0') {
yn++;
} else {
flag = 1;
}
}
for (i = 1; i < xn + 1; i++)
c[i][0] = 0;
for (j = 1; j < yn + 1; j++)
c[0][j] = 0;
for (i = 1; i < xn + 1; i++) {
for (j = 1; j < yn + 1; j++) {
if (x[i - 1] == y[j - 1]) {
c[i][j] = c[i - 1][j - 1] + 1;
} else if (c[i - 1][j] >= c[i][j - 1]) {
c[i][j] = c[i - 1][j];
} else {
c[i][j] = c[i][j - 1];
}
if (max < c[i][j])
max = c[i][j];
}
}
return max;
}
int main(void) {
char x[1000], y[1000];
int q, i;
scanf("%d", &q);
for (i = 0; i < q; i++) {
scanf("%s", x);
scanf("%s", y);
printf("%d\n", hantei(x, y));
}
return 0;
}
|
#include <stdio.h>
int hantei(char x[], char y[]) {
int xn = 0, yn = 0, flag = 0, i, j, max = 0;
int c[1001][1001];
while (flag == 0) {
if (x[xn] != '\0') {
xn++;
} else {
flag = 1;
}
}
flag = 0;
while (flag == 0) {
if (y[yn] != '\0') {
yn++;
} else {
flag = 1;
}
}
for (i = 1; i < xn + 1; i++)
c[i][0] = 0;
for (j = 1; j < yn + 1; j++)
c[0][j] = 0;
for (i = 1; i < xn + 1; i++) {
for (j = 1; j < yn + 1; j++) {
if (x[i - 1] == y[j - 1]) {
c[i][j] = c[i - 1][j - 1] + 1;
} else if (c[i - 1][j] >= c[i][j - 1]) {
c[i][j] = c[i - 1][j];
} else {
c[i][j] = c[i][j - 1];
}
if (max < c[i][j])
max = c[i][j];
}
}
return max;
}
int main(void) {
char x[1000], y[1000];
int q, i;
scanf("%d", &q);
for (i = 0; i < q; i++) {
scanf("%s", x);
scanf("%s", y);
printf("%d\n", hantei(x, y));
}
return 0;
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p02235
|
C++
|
Runtime Error
|
#include <algorithm>
#include <array>
#include <cstdio>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES
#include <map>
#include <math.h>
#define SENTINEL 1000000001
#define min(a, b) (a) > (b) ? (b) : (a)
#define max(a, b) (a) > (b) ? (a) : (b)
using namespace std;
int LCS[1000][1000];
void solve(string x, string y) {
for (int i = 0; i != x.size(); i++) {
for (int j = 0; j != y.size(); j++) {
if (x[i] == y[j]) {
LCS[i + 1][j + 1] = LCS[i][j] + 1;
} else {
LCS[i + 1][j + 1] = max(LCS[i][j + 1], LCS[i + 1][j]);
}
}
}
cout << LCS[x.size()][y.size()] << endl;
}
int main() {
int q;
cin >> q;
for (int i = 0; i < 1000; i++) {
LCS[0][i] = 0;
LCS[i][0] = 0;
}
for (int i = 0; i < q; i++) {
string x, y;
cin >> x >> y;
solve(x, y);
}
return 0;
}
|
#include <algorithm>
#include <array>
#include <cstdio>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES
#include <map>
#include <math.h>
#define SENTINEL 1000000001
#define min(a, b) (a) > (b) ? (b) : (a)
#define max(a, b) (a) > (b) ? (a) : (b)
using namespace std;
int LCS[1010][1010];
void solve(string x, string y) {
for (int i = 0; i != x.size(); i++) {
for (int j = 0; j != y.size(); j++) {
if (x[i] == y[j]) {
LCS[i + 1][j + 1] = LCS[i][j] + 1;
} else {
LCS[i + 1][j + 1] = max(LCS[i][j + 1], LCS[i + 1][j]);
}
}
}
cout << LCS[x.size()][y.size()] << endl;
}
int main() {
int q;
cin >> q;
for (int i = 0; i < 1000; i++) {
LCS[0][i] = 0;
LCS[i][0] = 0;
}
for (int i = 0; i < q; i++) {
string x, y;
cin >> x >> y;
solve(x, y);
}
return 0;
}
|
replace
| 24 | 25 | 24 | 25 |
0
| |
p02235
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define MAX 1000
int c[MAX][MAX];
int lcs(string A, string B) {
int a = A.length();
int b = B.length();
int maxl = 0;
A = ' ' + A;
B = ' ' + B;
// 配列を作る
for (int i = 0; i < a; i++) {
c[i][0] = 0;
}
for (int j = 0; j < b; j++) {
c[0][j] = 0;
}
for (int i = 1; i <= a; i++) {
for (int j = 1; j <= b; j++) {
if (A[i] == B[j]) {
c[i][j] = c[i - 1][j - 1] + 1;
} else {
c[i][j] = max(c[i - 1][j], c[i][j - 1]);
}
maxl = max(maxl, c[i][j]);
}
}
return maxl;
}
int main() {
string s1, s2;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s1 >> s2;
cout << lcs(s1, s2) << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define MAX 1000
int c[MAX + 1][MAX + 1];
int lcs(string A, string B) {
int a = A.length();
int b = B.length();
int maxl = 0;
A = ' ' + A;
B = ' ' + B;
// 配列を作る
for (int i = 0; i < a; i++) {
c[i][0] = 0;
}
for (int j = 0; j < b; j++) {
c[0][j] = 0;
}
for (int i = 1; i <= a; i++) {
for (int j = 1; j <= b; j++) {
if (A[i] == B[j]) {
c[i][j] = c[i - 1][j - 1] + 1;
} else {
c[i][j] = max(c[i - 1][j], c[i][j - 1]);
}
maxl = max(maxl, c[i][j]);
}
}
return maxl;
}
int main() {
string s1, s2;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s1 >> s2;
cout << lcs(s1, s2) << endl;
}
return 0;
}
|
replace
| 7 | 8 | 7 | 8 |
0
| |
p02235
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
for (int k = 0; k < n; k++) {
string x, y;
cin >> x >> y;
int p = x.size();
int q = y.size();
int l[1000][1000] = {};
for (int i = 1; i < p + 1; i++) {
for (int j = 1; j < q + 1; j++) {
if (x[i - 1] == y[j - 1]) {
l[i][j] = 1 + l[i - 1][j - 1];
} else {
l[i][j] = max(l[i - 1][j], l[i][j - 1]);
}
}
}
cout << l[p][q] << endl;
}
}
|
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
for (int k = 0; k < n; k++) {
string x, y;
cin >> x >> y;
int p = x.size();
int q = y.size();
int l[1001][1001] = {};
for (int i = 1; i < p + 1; i++) {
for (int j = 1; j < q + 1; j++) {
if (x[i - 1] == y[j - 1]) {
l[i][j] = 1 + l[i - 1][j - 1];
} else {
l[i][j] = max(l[i - 1][j], l[i][j - 1]);
}
}
}
cout << l[p][q] << endl;
}
}
|
replace
| 13 | 14 | 13 | 14 |
0
| |
p02235
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <string>
constexpr int MAX_XY = 1000;
int lx, ly, q, dp[MAX_XY][MAX_XY];
std::string sx, sy;
void fill_dp() {
for (int i = 1; i <= lx; ++i) {
for (int j = 1; j <= ly; ++j) {
if (sx[i - 1] == sy[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = std::max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
void solve() {
fill_dp();
std::cout << dp[lx][ly] << std::endl;
return;
}
int main() {
std::cin >> q;
for (int i = 0; i < q; ++i) {
std::cin >> sx >> sy;
lx = sx.size(), ly = sy.size();
solve();
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <string>
constexpr int MAX_XY = 1010;
int lx, ly, q, dp[MAX_XY][MAX_XY];
std::string sx, sy;
void fill_dp() {
for (int i = 1; i <= lx; ++i) {
for (int j = 1; j <= ly; ++j) {
if (sx[i - 1] == sy[j - 1])
dp[i][j] = dp[i - 1][j - 1] + 1;
else
dp[i][j] = std::max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
void solve() {
fill_dp();
std::cout << dp[lx][ly] << std::endl;
return;
}
int main() {
std::cin >> q;
for (int i = 0; i < q; ++i) {
std::cin >> sx >> sy;
lx = sx.size(), ly = sy.size();
solve();
}
return 0;
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p02235
|
C++
|
Runtime Error
|
// #define FILE_INPUT_DEFINE
#ifdef FILE_INPUT_DEFINE
#include <fstream>
#endif // FILE_INPUT_DEFINE
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define MAX 1000
#define ind(x) ((x)-1)
int C[MAX][MAX];
int LCS(string &X, string &Y) {
int Xlen = X.length();
int Ylen = Y.length();
for (int i = 0; i <= Xlen; ++i) {
C[i][0] = 0;
}
for (int i = 0; i <= Ylen; ++i) {
C[0][i] = 0;
}
for (int i = 1; i <= Xlen; ++i) {
for (int j = 1; j <= Ylen; ++j) {
if (X[ind(i)] == Y[ind(j)]) {
C[i][j] = C[i - 1][j - 1] + 1;
} else {
C[i][j] = max(C[i - 1][j], C[i][j - 1]);
}
}
}
return (C[Xlen][Ylen]);
}
int main() {
#ifdef FILE_INPUT_DEFINE
// input from txt
std::ifstream in(R"(C:\Temp\input.txt)");
std::cin.rdbuf(in.rdbuf());
#endif // FILE_INPUT_DEFINE
string X, Y;
int n;
cin >> n;
cin.clear();
cin.ignore();
for (int i = 0; i < n; ++i) {
getline(cin, X);
getline(cin, Y);
cout << LCS(X, Y) << endl;
}
return 0;
}
|
// #define FILE_INPUT_DEFINE
#ifdef FILE_INPUT_DEFINE
#include <fstream>
#endif // FILE_INPUT_DEFINE
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define MAX 1000
#define ind(x) ((x)-1)
int C[MAX + 1][MAX + 1];
int LCS(string &X, string &Y) {
int Xlen = X.length();
int Ylen = Y.length();
for (int i = 0; i <= Xlen; ++i) {
C[i][0] = 0;
}
for (int i = 0; i <= Ylen; ++i) {
C[0][i] = 0;
}
for (int i = 1; i <= Xlen; ++i) {
for (int j = 1; j <= Ylen; ++j) {
if (X[ind(i)] == Y[ind(j)]) {
C[i][j] = C[i - 1][j - 1] + 1;
} else {
C[i][j] = max(C[i - 1][j], C[i][j - 1]);
}
}
}
return (C[Xlen][Ylen]);
}
int main() {
#ifdef FILE_INPUT_DEFINE
// input from txt
std::ifstream in(R"(C:\Temp\input.txt)");
std::cin.rdbuf(in.rdbuf());
#endif // FILE_INPUT_DEFINE
string X, Y;
int n;
cin >> n;
cin.clear();
cin.ignore();
for (int i = 0; i < n; ++i) {
getline(cin, X);
getline(cin, Y);
cout << LCS(X, Y) << endl;
}
return 0;
}
|
replace
| 14 | 15 | 14 | 15 |
0
| |
p02235
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#define MAX_N 1000
int solve(std::string s, std::string t) {
int dp[MAX_N][MAX_N] = {0};
int n, m;
n = s.size();
m = t.size();
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (s[i] == t[j])
dp[i + 1][j + 1] = dp[i][j] + 1;
else
dp[i + 1][j + 1] = std::max(dp[i][j + 1], dp[i + 1][j]);
}
}
return dp[n][m];
}
int main() {
int q;
std::cin >> q;
for (int i = 0; i < q; i++) {
std::string s, t;
std::cin >> s >> t;
std::cout << solve(s, t) << std::endl;
}
return 0;
}
|
#include <algorithm>
#include <cstring>
#include <iostream>
#include <string>
#define MAX_N 1001
int solve(std::string s, std::string t) {
int dp[MAX_N][MAX_N] = {0};
int n, m;
n = s.size();
m = t.size();
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (s[i] == t[j])
dp[i + 1][j + 1] = dp[i][j] + 1;
else
dp[i + 1][j + 1] = std::max(dp[i][j + 1], dp[i + 1][j]);
}
}
return dp[n][m];
}
int main() {
int q;
std::cin >> q;
for (int i = 0; i < q; i++) {
std::string s, t;
std::cin >> s >> t;
std::cout << solve(s, t) << std::endl;
}
return 0;
}
|
replace
| 4 | 5 | 4 | 5 |
0
| |
p02235
|
C++
|
Runtime Error
|
#include <bits/stdc++.h>
using namespace std;
int Max(int &a, int b) { return a = max(a, b); }
int LCS(string &a, string &b) {
int n = a.size();
int m = b.size();
vector<vector<int>> dp(n + 1, vector<int>(m + 1));
for (int i = 0; i <= n; i++)
for (int j = 0; j <= m; j++) {
if (i < n && j < m && a[i] == b[j])
Max(dp[i + 1][j + 1], dp[i][j] + 1);
Max(dp[i + 1][j], dp[i][j]);
Max(dp[i][j + 1], dp[i][j]);
}
return dp[n][m];
}
int main() {
int q;
cin >> q;
while (q--) {
string a, b;
cin >> a >> b;
cout << LCS(a, b) << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int Max(int &a, int b) { return a = max(a, b); }
int LCS(string &a, string &b) {
int n = a.size();
int m = b.size();
vector<vector<int>> dp(n + 1, vector<int>(m + 1));
for (int i = 0; i <= n; i++)
for (int j = 0; j <= m; j++) {
if (i < n && j < m && a[i] == b[j])
Max(dp[i + 1][j + 1], dp[i][j] + 1);
if (i < n)
Max(dp[i + 1][j], dp[i][j]);
if (j < m)
Max(dp[i][j + 1], dp[i][j]);
}
return dp[n][m];
}
int main() {
int q;
cin >> q;
while (q--) {
string a, b;
cin >> a >> b;
cout << LCS(a, b) << endl;
}
return 0;
}
|
replace
| 14 | 16 | 14 | 18 |
-11
| |
p02235
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int LCS(string p, string q) {
vector<vector<int>> f(p.size() + 1, vector<int>(q.size() + 1, 0));
int t;
for (int i = 1; i <= p.size(); i++) {
for (int j = 1; j <= q.size(); j++) {
if (p[i - 1] == q[j - 1])
f[i][j] = f[i - 1][j - 1] + 1;
else if (f[i][j - 1] > f[i - 1][j])
f[i][j] = f[i][j - 1];
else
f[i][j] = f[i - 1][j];
}
}
return f[p.size()][q.size()];
}
int main() {
int n;
string p[150];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> p[2 * i] >> p[2 * i + 1];
}
for (int i = 0; i < n; i++) {
cout << LCS(p[2 * i], p[2 * i + 1]) << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int LCS(string p, string q) {
vector<vector<int>> f(p.size() + 1, vector<int>(q.size() + 1, 0));
int t;
for (int i = 1; i <= p.size(); i++) {
for (int j = 1; j <= q.size(); j++) {
if (p[i - 1] == q[j - 1])
f[i][j] = f[i - 1][j - 1] + 1;
else if (f[i][j - 1] > f[i - 1][j])
f[i][j] = f[i][j - 1];
else
f[i][j] = f[i - 1][j];
}
}
return f[p.size()][q.size()];
}
int main() {
int n;
string p[300];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> p[2 * i] >> p[2 * i + 1];
}
for (int i = 0; i < n; i++) {
cout << LCS(p[2 * i], p[2 * i + 1]) << endl;
}
return 0;
}
|
replace
| 24 | 25 | 24 | 25 |
0
| |
p02235
|
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 99999999
#define MAX_S 200
#define MAX_T 200
template <typename T> int lcs(T s, T t) {
int lens = s.size();
int lent = t.size();
int dp[MAX_S + 1][MAX_T + 1] = {};
rep(i, lens) {
rep(j, lent) {
if (s[i] == t[j])
dp[i + 1][j + 1] = dp[i][j] + 1;
else
dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
}
}
return dp[lens][lent];
}
int main() {
int n;
cin >> n;
rep(i, n) {
string s, t;
cin >> s >> t;
cout << lcs(s, t) << 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 99999999
#define MAX_S 2000
#define MAX_T 2000
template <typename T> int lcs(T s, T t) {
int lens = s.size();
int lent = t.size();
int dp[MAX_S + 1][MAX_T + 1] = {};
rep(i, lens) {
rep(j, lent) {
if (s[i] == t[j])
dp[i + 1][j + 1] = dp[i][j] + 1;
else
dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
}
}
return dp[lens][lent];
}
int main() {
int n;
cin >> n;
rep(i, n) {
string s, t;
cin >> s >> t;
cout << lcs(s, t) << endl;
}
}
|
replace
| 9 | 11 | 9 | 11 |
0
| |
p02235
|
C++
|
Runtime Error
|
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
using namespace std;
#define MAX 100000
static const int N = 100;
int lcs(string X, string Y) {
int c[N + 1][N + 1];
int m = X.size();
int n = Y.size();
int ans = 0;
X = ' ' + X;
Y = ' ' + Y;
for (int i; i <= m; i++)
c[i][0] = 0;
for (int j; j <= n; j++)
c[0][j] = 0;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
if (X[i] == Y[j]) {
c[i][j] = c[i - 1][j - 1] + 1;
} else {
c[i][j] = max(c[i - 1][j], c[i][j - 1]);
}
ans = max(ans, c[i][j]);
}
}
return ans;
}
int main() {
string s1, s2;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s1 >> s2;
cout << lcs(s1, s2) << endl;
}
return 0;
}
|
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <string>
using namespace std;
#define MAX 100000
static const int N = 1000;
int lcs(string X, string Y) {
int c[N + 1][N + 1];
int m = X.size();
int n = Y.size();
int ans = 0;
X = ' ' + X;
Y = ' ' + Y;
for (int i; i <= m; i++)
c[i][0] = 0;
for (int j; j <= n; j++)
c[0][j] = 0;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
if (X[i] == Y[j]) {
c[i][j] = c[i - 1][j - 1] + 1;
} else {
c[i][j] = max(c[i - 1][j], c[i][j - 1]);
}
ans = max(ans, c[i][j]);
}
}
return ans;
}
int main() {
string s1, s2;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> s1 >> s2;
cout << lcs(s1, s2) << endl;
}
return 0;
}
|
replace
| 8 | 9 | 8 | 9 |
0
| |
p02235
|
C++
|
Runtime Error
|
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
string st1, st2;
int q, val[151][151];
cin >> q;
for (int i = 0; i < q; i++) {
cin >> st1;
cin >> st2;
for (int j = 0; j <= st1.length(); j++) {
for (int k = 0; k <= st2.length(); k++) {
if (j == 0 || k == 0)
val[j][k] = 0;
else {
if (val[j - 1][k] == min(st1.length(), st2.length())) {
val[j][k] = st1.length();
} else {
if (st1[j - 1] == st2[k - 1]) {
val[j][k] = val[j - 1][k - 1] + 1;
} else {
val[j][k] = max(val[j - 1][k], val[j][k - 1]);
}
}
}
}
}
/*
for(int j=0; j<=st1.length(); j++){
for(int k=0; k<=st2.length(); k++){
cout << val[j][k] << " ";
}
cout << "\n";
}
*/
cout << val[st1.length()][st2.length()] << "\n";
}
return 0;
}
|
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
string st1, st2;
int q, val[1001][1001];
cin >> q;
for (int i = 0; i < q; i++) {
cin >> st1;
cin >> st2;
for (int j = 0; j <= st1.length(); j++) {
for (int k = 0; k <= st2.length(); k++) {
if (j == 0 || k == 0)
val[j][k] = 0;
else {
if (val[j - 1][k] == min(st1.length(), st2.length())) {
val[j][k] = st1.length();
} else {
if (st1[j - 1] == st2[k - 1]) {
val[j][k] = val[j - 1][k - 1] + 1;
} else {
val[j][k] = max(val[j - 1][k], val[j][k - 1]);
}
}
}
}
}
/*
for(int j=0; j<=st1.length(); j++){
for(int k=0; k<=st2.length(); k++){
cout << val[j][k] << " ";
}
cout << "\n";
}
*/
cout << val[st1.length()][st2.length()] << "\n";
}
return 0;
}
|
replace
| 7 | 8 | 7 | 8 |
0
| |
p02235
|
C++
|
Runtime Error
|
///
// File: alds1_10_c.cpp
// Author: ymiyamoto
//
// Created on Tue Oct 17 01:36:16 2017
//
#include <cstdint>
#include <iostream>
#include <string>
using namespace std;
static uint32_t dp[1000][1000];
static void init_dp(uint32_t len1, uint32_t len2) {
for (uint32_t i = 0; i < len1; i++) {
dp[i][0] = 0;
}
for (uint32_t i = 0; i < len2; i++) {
dp[0][i] = 0;
}
}
int32_t main() {
uint32_t n;
cin >> n;
for (uint32_t i = 0; i < n; i++) {
string str1, str2;
cin >> str1;
cin >> str2;
init_dp(str1.size(), str2.size());
for (uint32_t i = 1; i <= str1.size(); i++) {
for (uint32_t j = 1; j <= str2.size(); j++) {
if (str1[i - 1] == str2[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
cout << dp[str1.size()][str2.size()] << endl;
}
return 0;
}
|
///
// File: alds1_10_c.cpp
// Author: ymiyamoto
//
// Created on Tue Oct 17 01:36:16 2017
//
#include <cstdint>
#include <iostream>
#include <string>
using namespace std;
static uint32_t dp[1001][1001];
static void init_dp(uint32_t len1, uint32_t len2) {
for (uint32_t i = 0; i < len1; i++) {
dp[i][0] = 0;
}
for (uint32_t i = 0; i < len2; i++) {
dp[0][i] = 0;
}
}
int32_t main() {
uint32_t n;
cin >> n;
for (uint32_t i = 0; i < n; i++) {
string str1, str2;
cin >> str1;
cin >> str2;
init_dp(str1.size(), str2.size());
for (uint32_t i = 1; i <= str1.size(); i++) {
for (uint32_t j = 1; j <= str2.size(); j++) {
if (str1[i - 1] == str2[j - 1]) {
dp[i][j] = dp[i - 1][j - 1] + 1;
} else {
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
cout << dp[str1.size()][str2.size()] << endl;
}
return 0;
}
|
replace
| 12 | 13 | 12 | 13 |
0
| |
p02235
|
C++
|
Time Limit Exceeded
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, n) FOR(i, 0, n)
#define DEBUG(x) cout << #x << ": " << x << endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;
#include <map>
#include <queue>
#include <set>
typedef long long ll;
typedef unsigned long long ull;
const int MAX_N = 1000000;
const int MAX_L = 10000;
int q;
string data[MAX_N][2];
ll mem[MAX_L][MAX_L];
ll eval(string s1, string s2, int i, int j) {
int ii = i - 1;
int jj = j - 1;
if (ii == -1 || jj == -1)
return 0;
if (s1[ii] == s2[jj])
return mem[i - 1][j - 1] + 1;
if (s1[ii] != s2[jj])
return max(mem[i - 1][j], mem[i][j - 1]);
throw "exception";
}
ll solve(string s1, string s2) {
int L1 = s1.size();
int L2 = s2.size();
rep(i, L1 + 1) {
rep(j, L2 + 1) { mem[i][j] = eval(s1, s2, i, j); }
}
return mem[L1][L2];
}
int main() {
cin >> q;
rep(i, q) {
cin >> data[i][0];
cin >> data[i][1];
}
rep(i, q) { cout << solve(data[i][0], data[i][1]) << endl; }
}
|
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define rep(i, n) FOR(i, 0, n)
#define DEBUG(x) cout << #x << ": " << x << endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;
#include <map>
#include <queue>
#include <set>
typedef long long ll;
typedef unsigned long long ull;
const int MAX_N = 1000000;
const int MAX_L = 10000;
int q;
string data[MAX_N][2];
ll mem[MAX_L][MAX_L];
ll eval(string &s1, string &s2, int i, int j) {
int ii = i - 1;
int jj = j - 1;
if (ii == -1 || jj == -1)
return 0;
if (s1[ii] == s2[jj])
return mem[i - 1][j - 1] + 1;
if (s1[ii] != s2[jj])
return max(mem[i - 1][j], mem[i][j - 1]);
throw "exception";
}
ll solve(string s1, string s2) {
int L1 = s1.size();
int L2 = s2.size();
rep(i, L1 + 1) {
rep(j, L2 + 1) { mem[i][j] = eval(s1, s2, i, j); }
}
return mem[L1][L2];
}
int main() {
cin >> q;
rep(i, q) {
cin >> data[i][0];
cin >> data[i][1];
}
rep(i, q) { cout << solve(data[i][0], data[i][1]) << endl; }
}
|
replace
| 29 | 30 | 29 | 30 |
TLE
| |
p02235
|
C++
|
Runtime Error
|
#include <algorithm>
#include <ccomplex>
#include <cmath>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
void solve() {
string x, y;
cin >> x >> y;
int xlen = x.length();
int ylen = y.length();
int dp[155][155];
dp[0][0] = 0;
for (int i = 0; i <= xlen; i++) {
for (int j = 0; j <= ylen; j++) {
if (i == 0 || j == 0) {
dp[i + 1][j + 1] = 0;
} else if (x[i - 1] == y[j - 1]) {
dp[i + 1][j + 1] = dp[i][j] + 1;
} else {
dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
}
}
}
cout << dp[xlen + 1][ylen + 1] << endl;
}
int main() {
int q;
cin >> q;
for (int i = 0; i < q; i++)
solve();
}
|
#include <algorithm>
#include <ccomplex>
#include <cmath>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
void solve() {
string x, y;
cin >> x >> y;
int xlen = x.length();
int ylen = y.length();
int dp[1010][1010];
dp[0][0] = 0;
for (int i = 0; i <= xlen; i++) {
for (int j = 0; j <= ylen; j++) {
if (i == 0 || j == 0) {
dp[i + 1][j + 1] = 0;
} else if (x[i - 1] == y[j - 1]) {
dp[i + 1][j + 1] = dp[i][j] + 1;
} else {
dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
}
}
}
cout << dp[xlen + 1][ylen + 1] << endl;
}
int main() {
int q;
cin >> q;
for (int i = 0; i < q; i++)
solve();
}
|
replace
| 18 | 19 | 18 | 19 |
0
| |
p02235
|
C++
|
Runtime Error
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main() {
int n, m, q;
string a, b; // two sequences
int M[1001][1001] = {{0}}; // Memory matrix
cin >> q;
for (int l = 0; l < q; l++) {
cin >> a >> b;
n = a.length();
m = b.length();
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= m; j++) {
if (a[i] == b[j]) {
M[i + 1][j + 1] = M[i][j] + 1;
} else {
M[i + 1][j + 1] = max(M[i][j + 1], M[i + 1][j]);
}
}
}
cout << M[n][m] << endl; // The time complexity equals to O (n * m)
}
return 0;
}
|
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main() {
int n, m, q;
string a, b; // two sequences
int M[1010][1010] = {{0}}; // Memory matrix
cin >> q;
for (int l = 0; l < q; l++) {
cin >> a >> b;
n = a.length();
m = b.length();
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= m; j++) {
if (a[i] == b[j]) {
M[i + 1][j + 1] = M[i][j] + 1;
} else {
M[i + 1][j + 1] = max(M[i][j + 1], M[i + 1][j]);
}
}
}
cout << M[n][m] << endl; // The time complexity equals to O (n * m)
}
return 0;
}
|
replace
| 9 | 10 | 9 | 10 |
0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.