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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02713 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
int k;
cin >> k;
int ans = 0;
for (int a = 1; a <= k; a++)
for (int b = 1; b <= k; b++)
for (int c = 1; c <= k; c++) {
int mx = 0;
mx = max(a, b);
mx = max(mx, c);
for (int i = mx; i >= 1; i--) {
if (a % i == 0 && b % i == 0 & c % i == 0) {
ans += i;
break;
}
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
int k;
cin >> k;
int ans = 0;
for (int a = 1; a <= k; a++)
for (int b = 1; b <= k; b++)
for (int c = 1; c <= k; c++) {
int mx = 0;
mx = min(a, b);
mx = min(mx, c);
for (int i = mx; i >= 1; i--) {
if (a % i == 0 && b % i == 0 & c % i == 0) {
ans += i;
break;
}
}
}
cout << ans << endl;
}
| replace | 15 | 17 | 15 | 17 | TLE | |
p02713 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define mod 1000000007
#define mp make_pair
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0
using namespace std;
using ll = long long;
using pii = pair<int, int>;
// 最大公約数
ll gcd(ll a, ll b) { return b ? gcd(b, a) : a; }
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
ll ans = 0;
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= n; j++) {
for (ll k = 1; k <= n; k++) {
ans += gcd(gcd(i, j), k);
}
}
}
cout << ans;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define mod 1000000007
#define mp make_pair
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0
using namespace std;
using ll = long long;
using pii = pair<int, int>;
// 最大公約数
ll gcd(ll a, ll b) { return b ? gcd(b, a %= b) : a; }
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin >> n;
ll ans = 0;
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= n; j++) {
for (ll k = 1; k <= n; k++) {
ans += gcd(gcd(i, j), k);
}
}
}
cout << ans;
return 0;
} | replace | 21 | 22 | 21 | 22 | TLE | |
p02713 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int K;
cin >> K;
int A = 0;
for (int i = 1; i <= K; i++) {
for (int j = 1; j <= K; j++) {
for (int k = 1; k <= K; k++) {
for (int l = K; l >= 1; l--) {
if (i % l == 0 && j % l == 0 && k % l == 0) {
A += l;
break;
}
}
}
}
}
cout << A << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int K;
cin >> K;
int A = 0;
for (int i = 1; i <= K; i++) {
for (int j = 1; j <= K; j++) {
for (int k = 1; k <= K; k++) {
int B = min(i, j);
B = min(B, k);
for (int l = B; l >= 1; l--) {
if (i % l == 0 && j % l == 0 && k % l == 0) {
A += l;
break;
}
}
}
}
}
cout << A << endl;
}
| replace | 11 | 12 | 11 | 14 | TLE | |
p02713 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define mp make_pair
#define pb push_back
#define ll long long
#define kl k << 1
#define kr k << 1 | 1
using namespace std;
inline ll read() {
ll s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
s = s * 10 + ch - '0', ch = getchar();
return s * w;
}
void put1() { puts("YES"); }
void put2() { puts("NO"); }
void put3() { puts("-1"); }
ll qp(ll a, ll b, ll p) {
ll ans = 1;
while (b) {
if (b & 1) {
ans = (ans * a) % p;
--b;
}
a = (a * a) % p;
b >>= 1;
}
return ans % p;
}
const int manx = 1e5 + 5;
const int mo = 998244353;
map<pair<ll, ll>, ll> gc;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
ll n = read(), ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
ll x, y;
if (gc[mp(i, j)])
x = gc[mp(i, j)];
else
x = gc[mp(i, j)] = gcd(i, j);
if (gc[mp(x, k)])
y = gc[mp(x, k)];
else
y = gc[mp(x, k)] = gcd(x, k);
ans += y;
}
}
}
cout << ans;
return 0;
}
| #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define mp make_pair
#define pb push_back
#define ll long long
#define kl k << 1
#define kr k << 1 | 1
using namespace std;
inline ll read() {
ll s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-')
w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
s = s * 10 + ch - '0', ch = getchar();
return s * w;
}
void put1() { puts("YES"); }
void put2() { puts("NO"); }
void put3() { puts("-1"); }
ll qp(ll a, ll b, ll p) {
ll ans = 1;
while (b) {
if (b & 1) {
ans = (ans * a) % p;
--b;
}
a = (a * a) % p;
b >>= 1;
}
return ans % p;
}
const int manx = 1e5 + 5;
const int mo = 998244353;
map<pair<ll, ll>, ll> gc;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
ll n = read(), ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
ll x = gcd(i, j);
ll y = gcd(x, k);
ans += y;
}
}
}
cout << ans;
return 0;
}
| replace | 54 | 63 | 54 | 56 | TLE | |
p02713 | Python | Time Limit Exceeded | from math import gcd
from functools import reduce
def gcd_kai(*numbers):
return reduce(gcd, numbers)
K = int(input())
ans = 0
for i in range(K):
for j in range(K):
for k in range(K):
ans += gcd_kai(i + 1, j + 1, k + 1)
print(ans)
| from math import gcd
from functools import reduce
def gcd_kai(*numbers):
return reduce(gcd, numbers)
K = int(input())
ans = 1
if K == 1:
next
else:
ans += (K - 1) * K * 3
ans_sub = 0
for i in range(2, K):
for j in range(i + 1, K + 1):
for k in range(i, K + 1):
ans_sub += gcd_kai(i, j, k)
ans += ans_sub * 3
for i in range(2, K + 1):
ans += i
print(ans)
| replace | 9 | 14 | 9 | 22 | TLE | |
p02713 | Python | Time Limit Exceeded | import itertools
import math
def gcd(a: int, b: int, c: int) -> int:
return math.gcd(math.gcd(a, b), c)
def main() -> None:
k = int(input())
s = sum(gcd(a, b, c) for a, b, c in itertools.product(range(1, k + 1), repeat=3))
print(s)
if __name__ == "__main__":
main()
| import itertools
import math
def gcd(a: int, b: int, c: int) -> int:
return math.gcd(math.gcd(a, b), c)
def main() -> None:
k = int(input())
one_to_k = range(1, k + 1)
s1 = sum(one_to_k)
s2 = sum(math.gcd(a, b) for a, b in itertools.combinations(one_to_k, 2))
s3 = sum(gcd(a, b, c) for a, b, c in itertools.combinations(one_to_k, 3))
print(s1 + 6 * s2 + 6 * s3)
if __name__ == "__main__":
main()
| replace | 11 | 13 | 11 | 16 | TLE | |
p02713 | Python | Runtime Error | import math
k = int(input())
ans = 0
for a in range(k):
for b in range(k):
d = math.gcd(a + 1, b + 1)
for c in range(k):
ans += math(d, c + 1)
print(ans)
| import math
k = int(input())
ans = 0
for a in range(k):
for b in range(k):
d = math.gcd(a + 1, b + 1)
for c in range(k):
ans += math.gcd(d, c + 1)
print(ans)
| replace | 9 | 10 | 9 | 10 | TypeError: 'module' object is not callable | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02713/Python/s321209057.py", line 9, in <module>
ans += math(d, c + 1)
TypeError: 'module' object is not callable
|
p02713 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
int e(int x, int y) {
if (x < y)
swap(x, y);
int r;
while (true) {
r = x % y;
if (r == 0)
return y;
x = y;
y = r;
}
return 0;
}
int main() {
int k;
cin >> k;
int sum = 0;
rep(i, k) {
rep(j, k) {
rep(l, k) {
int a = e(i, j);
int b = e(a, l);
sum += b;
}
}
}
cout << sum << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
int e(int x, int y) {
if (x < y)
swap(x, y);
int r;
while (true) {
r = x % y;
if (r == 0)
return y;
x = y;
y = r;
}
return 0;
}
int main() {
int k;
cin >> k;
int sum = 0;
rep(i, k) {
rep(j, k) {
rep(l, k) {
int a = e(i, j);
int b = e(a, l);
sum += b;
}
}
}
cout << sum << endl;
}
| replace | 2 | 3 | 2 | 3 | -8 | |
p02713 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b, int c) {
for (int i = 200; i >= 1; i--) {
if (a % i == 0 && b % i == 0 && c % i == 0)
return i;
}
}
int main() {
int k;
cin >> k;
long long sum = 0;
for (int i = 1; i <= k; i++)
for (int j = 1; j <= k; j++)
for (int k1 = 1; k1 <= k; k1++) {
sum += gcd(i, j, k1);
}
cout << sum;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b, int c) {
if (a < b)
swap(a, b);
int r = 0, ans = 0;
while (1) {
r = a % b;
if (r == 0) {
ans = b;
break;
} else {
a = b;
b = r;
}
}
if (ans > c)
swap(ans, c);
while (1) {
r = ans % c;
if (r == 0) {
return c;
} else {
ans = c;
c = r;
}
}
}
int main() {
int k;
cin >> k;
long long sum = 0;
for (int i = 1; i <= k; i++)
for (int j = 1; j <= k; j++)
for (int k1 = 1; k1 <= k; k1++) {
sum += gcd(i, j, k1);
}
cout << sum;
return 0;
} | replace | 3 | 6 | 3 | 26 | TLE | |
p02713 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <math.h>
#define PI 3.14159265358979323846264338327950L
#define ll long long
using namespace std;
int solve(int i, int j) {
int result = 1;
for (int k = 2; k <= min(i, j); k++) {
if (i % k == 0 && j % k == 0) {
result = k;
}
}
return result;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int k;
cin >> k;
ll sum = 0;
for (int i = 1; i <= k; i++) {
for (int j = 1; j <= k; j++) {
for (int k = 1; k <= k; k++) {
sum += solve(solve(i, j), k);
}
}
}
cout << sum << "\n";
}
| #include <bits/stdc++.h>
#include <math.h>
#define PI 3.14159265358979323846264338327950L
#define ll long long
using namespace std;
int solve(int i, int j) {
int result = 1;
for (int k = 2; k <= min(i, j); k++) {
if (i % k == 0 && j % k == 0) {
result = k;
}
}
return result;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int k;
cin >> k;
ll sum = 0;
for (int i = 1; i <= k; i++) {
for (int j = 1; j <= k; j++) {
for (int m = 1; m <= k; m++) {
sum += solve(solve(i, j), m);
}
}
}
cout << sum << "\n";
}
| replace | 26 | 28 | 26 | 28 | TLE | |
p02713 | C++ | Runtime Error | #include <iostream>
#define ll long long int
using namespace std;
ll gcd2(int a, int b) {
if (a % b == 0)
return b;
if (a < b) {
int tmp = a;
a = b;
b = tmp;
}
return gcd2(b, a % b);
}
ll gcd3(int a, int b, int c) { return gcd2(gcd2(a, b), c); }
int main(void) {
ll K, sum = 0;
cin >> K;
for (int i = 1; i <= K; i++) {
for (int j = 1; j <= K; j++) {
for (int k = 1; k <= K; k++) {
sum += gcd3(i, j, k);
}
}
}
cout << sum << endl;
return 0;
}
| #include <iostream>
#define ll long long int
using namespace std;
ll gcd2(int a, int b) {
if (a % b == 0)
return b;
return gcd2(b, a % b);
}
ll gcd3(int a, int b, int c) { return gcd2(gcd2(a, b), c); }
int main(void) {
ll K, sum = 0;
cin >> K;
for (int i = 1; i <= K; i++) {
for (int j = 1; j <= K; j++) {
for (int k = 1; k <= K; k++) {
sum += gcd3(i, j, k);
}
}
}
cout << sum << endl;
return 0;
}
| delete | 8 | 13 | 8 | 8 | -8 | |
p02713 | C++ | Time Limit Exceeded | #include "bits/stdc++.h"
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define INF 1000000009
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
#define REP(i, a, b) for (int i = a; i <= b; i++)
int main(int argc, char const *argv[]) {
map<pair<int, pair<int, int>>, int> mp;
int n;
cin >> n;
int gcd = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
if (!mp[{i, {j, k}}]) {
mp[{i, {j, k}}] = 1;
// mp[{j,{i,k}}]=1;
// mp[{k,{i,j}}]=1;
// cout<<i<<' '<<j<<' '<<k<<endl;
gcd += __gcd(i, __gcd(j, k));
}
}
}
}
cout << gcd << endl;
return 0;
} | #include "bits/stdc++.h"
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define INF 1000000009
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
#define REP(i, a, b) for (int i = a; i <= b; i++)
int main(int argc, char const *argv[]) {
map<pair<int, pair<int, int>>, int> mp;
int n;
cin >> n;
int gcd = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
gcd += __gcd(i, __gcd(j, k));
}
}
}
cout << gcd << endl;
return 0;
} | replace | 20 | 27 | 20 | 22 | TLE | |
p02713 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <map>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int euclid(int i, int j) {
if (i % j == 0)
return j;
euclid(j, i % j);
}
int main() {
int K;
cin >> K;
long long sum = 0;
for (int a = 1; a <= K; a++) {
for (int b = 1; b <= K; b++) {
for (int c = 1; c <= K; c++) {
int tmp = euclid(max(a, b), min(a, b));
sum += euclid(max(tmp, c), min(tmp, c));
}
}
}
cout << sum << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <map>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int euclid(int i, int j) {
if (i % j == 0)
return j;
return euclid(j, i % j);
}
int main() {
int K;
cin >> K;
long long sum = 0;
for (int a = 1; a <= K; a++) {
for (int b = 1; b <= K; b++) {
for (int c = 1; c <= K; c++) {
int tmp = euclid(max(a, b), min(a, b));
sum += euclid(max(tmp, c), min(tmp, c));
}
}
}
cout << sum << endl;
return 0;
}
| replace | 15 | 16 | 15 | 16 | 0 | |
p02713 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) {
if (x % y == 0)
return y;
else
return gcd(y, x % y);
}
int gcd2(int x, int y, int z) { return gcd(x, gcd(y, z)); }
int main() {
int n;
cin >> n;
long long ans = 0;
for (int i; i < n; i++)
for (int j; j < n; j++)
for (int k; k < n; k++)
ans += gcd2(i, j, k);
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) {
if (x % y == 0)
return y;
else
return gcd(y, x % y);
}
int gcd2(int x, int y, int z) { return gcd(x, gcd(y, z)); }
int main() {
int n;
cin >> n;
long long ans = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
for (int k = 1; k <= n; k++)
ans += gcd2(i, j, k);
cout << ans << endl;
} | replace | 15 | 18 | 15 | 18 | 0 | |
p02713 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for ((i) = 0; (i) < (n); (i)++)
typedef long long ll;
typedef pair<int, int> P;
ll gcd(ll a, ll b, ll c) {
ll i = 0;
ll n = 0;
n = min({a, b, c});
rep(i, n) {
if (a % (n - i) == 0 && b % (n - i) == 0 && c % (n - i) == 0) {
return n - i;
}
}
return 1;
}
int main() {
ll n, i, j, k;
cin >> n;
ll s1 = 0;
rep(i, n) rep(j, n) rep(k, n) s1 += gcd(i + 1, j + 1, k + 1);
cout << s1;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for ((i) = 0; (i) < (n); (i)++)
typedef long long ll;
typedef pair<int, int> P;
ll gcd(ll a, ll b, ll c) {
ll i = 0;
ll n = 0;
n = min({a, b, c});
rep(i, n) {
if (a % (n - i) == 0 && b % (n - i) == 0 && c % (n - i) == 0) {
return n - i;
}
}
return 1;
}
int main() {
ll n, i, j, k;
cin >> n;
ll s1 = 0;
rep(i, n) rep(j, n) rep(k, n) {
if (i == j && j == k)
s1 += i + 1;
if (i > j && j > k)
s1 += 6 * gcd(i + 1, j + 1, k + 1);
if (i > j && j == k)
s1 += 3 * gcd(i + 1, j + 1, k + 1);
if (i == j && j > k)
s1 += 3 * gcd(i + 1, j + 1, k + 1);
}
cout << s1;
return 0;
} | replace | 21 | 22 | 21 | 31 | TLE | |
p02713 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vpi = vector<pii>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpl = vector<pll>;
using vs = vector<string>;
int gcd(int a, int b) {
if (a % b == 0) {
return b;
} else {
gcd(b, a % b);
}
}
int main() {
int n;
cin >> n;
ll sun = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
for (int k = 1; k <= n; k++) {
sun += gcd(gcd(i, j), k);
}
cout << sun << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vpi = vector<pii>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpl = vector<pll>;
using vs = vector<string>;
int gcd(int a, int b) {
if (a % b == 0) {
return b;
} else {
return gcd(b, a % b);
}
}
int main() {
int n;
cin >> n;
ll sun = 0;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++)
for (int k = 1; k <= n; k++) {
sun += gcd(gcd(i, j), k);
}
cout << sun << endl;
return 0;
}
| replace | 19 | 20 | 19 | 20 | 0 | |
p02713 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
using namespace std;
#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e9 + 7;
int gcd(int a, int b) {
if (a % b == 0)
return b;
return gcd(b, a % b);
}
int main() {
int k;
cin >> k;
ll sum = 0;
for (int a = 1; a <= k; a++) {
for (int b = 1; b <= k; k++) {
// int g = gcd(a,b);
for (int c = 1; c <= k; c++) {
sum += gcd(gcd(a, b), c);
}
}
}
cout << sum << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
using namespace std;
#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e9 + 7;
int gcd(int a, int b) {
if (a % b == 0)
return b;
return gcd(b, a % b);
}
int main() {
int k;
cin >> k;
ll sum = 0;
for (int a = 1; a <= k; a++) {
for (int b = 1; b <= k; b++) {
// int g = gcd(a,b);
for (int c = 1; c <= k; c++) {
sum += gcd(gcd(a, b), c);
}
}
}
cout << sum << endl;
return 0;
}
| replace | 46 | 47 | 46 | 47 | TLE | |
p02713 | C++ | Runtime Error | #include "bits/stdc++.h"
#define rep(i, N) for (int i = 0; i < N; i++)
#define int long long
#define INF 1e10
using namespace std;
int gcd(int p, int q) {
if (p % q == 0)
return q;
return gcd(q, p % q);
}
signed main(void) {
int K;
int ans = 0;
cin >> K;
rep(a, K) {
rep(b, K) {
rep(c, K) { ans += gcd(gcd(a, b), c); }
}
}
cout << ans << endl;
return 0;
} | #include "bits/stdc++.h"
#define rep(i, N) for (int i = 0; i < N; i++)
#define int long long
#define INF 1e10
using namespace std;
int gcd(int p, int q) {
if (p % q == 0)
return q;
return gcd(q, p % q);
}
signed main(void) {
int K;
int ans = 0;
cin >> K;
rep(a, K) {
rep(b, K) {
rep(c, K) { ans += gcd(gcd(a + 1, b + 1), c + 1); }
}
}
cout << ans << endl;
return 0;
} | replace | 23 | 24 | 23 | 24 | -8 | |
p02713 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int gcd(int x, int y) {
for (int i = max(x, y); i > 0; i--) {
if (x % i == 0 && y % i == 0)
return i;
}
}
int main() {
int K;
cin >> K;
int A[K][K];
for (int i = 0; i < K; i++) {
for (int j = 0; j < K; j++) {
A[i][j] = gcd(i + 1, j + 1);
}
}
int B[K][K][K];
for (int i = 0; i < K; i++) {
for (int j = 0; j < K; j++) {
for (int k = 0; k < K; k++) {
B[i][j][k] = gcd(A[i][j], k + 1);
}
}
}
int sum = 0;
for (int i = 0; i < K; i++) {
for (int j = 0; j < K; j++) {
for (int k = 0; k < K; k++) {
sum += B[i][j][k];
}
}
}
cout << sum << endl;
}
| #include <iostream>
using namespace std;
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
int main() {
int K;
cin >> K;
int A[K][K];
for (int i = 0; i < K; i++) {
for (int j = 0; j < K; j++) {
A[i][j] = gcd(i + 1, j + 1);
}
}
int B[K][K][K];
for (int i = 0; i < K; i++) {
for (int j = 0; j < K; j++) {
for (int k = 0; k < K; k++) {
B[i][j][k] = gcd(A[i][j], k + 1);
}
}
}
int sum = 0;
for (int i = 0; i < K; i++) {
for (int j = 0; j < K; j++) {
for (int k = 0; k < K; k++) {
sum += B[i][j][k];
}
}
}
cout << sum << endl;
}
| replace | 3 | 9 | 3 | 4 | TLE | |
p02713 | C++ | Time Limit Exceeded | #include <cmath>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int cal_gcd(int a, int b);
int main() {
int k;
ll sum = 0;
cin >> k;
for (int i = 1; i <= k; i++) {
for (int j = 1; j <= k; j++) {
for (int l = 1; l <= k; l++) {
sum += cal_gcd(i, cal_gcd(j, l));
}
}
}
cout << sum << endl;
return 0;
}
int cal_gcd(int a, int b) {
int buf = 0;
if (a < b) {
buf = b;
b = a;
a = buf;
}
if (a % b == 0)
return b;
cal_gcd(a % b, b);
}
| #include <cmath>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int cal_gcd(int a, int b);
int main() {
int k;
ll sum = 0;
cin >> k;
for (int i = 1; i <= k; i++) {
for (int j = 1; j <= k; j++) {
for (int l = 1; l <= k; l++) {
sum += cal_gcd(i, cal_gcd(j, l));
}
}
}
cout << sum << endl;
return 0;
}
int cal_gcd(int a, int b) {
int buf = 0;
if (a < b) {
buf = b;
b = a;
a = buf;
}
if (a % b == 0)
return b;
return cal_gcd(a % b, b);
}
| replace | 35 | 36 | 35 | 36 | TLE | |
p02713 | C++ | Time Limit Exceeded | #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <deque> // deque
#include <iostream> // cout, endl, cin
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
using namespace std;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define REP1(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
int gcd(int a, int b, int c) {
int ma, ret;
ma = max(a, max(b, c));
for (int i = ma; i > 0; i--) {
if (a % i == 0 && b % i == 0 && c % i == 0) {
ret = i;
break;
}
}
return ret;
}
int main(void) {
int K, i, j, k, g;
long long int sum = 0;
cin >> K;
REP1(i, 1, K) {
REP1(j, 1, K) {
REP1(k, 1, K) {
g = gcd(i, j, k);
sum += g;
}
}
}
cout << sum << endl;
} | #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <deque> // deque
#include <iostream> // cout, endl, cin
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
using namespace std;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define REP1(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
int gcd(int a, int b, int c) {
int ma, ret;
ma = min(a, min(b, c));
for (int i = ma; i > 0; i--) {
if (a % i == 0 && b % i == 0 && c % i == 0) {
ret = i;
break;
}
}
return ret;
}
int main(void) {
int K, i, j, k, g;
long long int sum = 0;
cin >> K;
REP1(i, 1, K) {
REP1(j, 1, K) {
REP1(k, 1, K) {
g = gcd(i, j, k);
sum += g;
}
}
}
cout << sum << endl;
} | replace | 26 | 27 | 26 | 27 | TLE | |
p02713 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
int gcd(int x, int y) {
if (x % y == 0) {
return y;
}
int k = x % y;
gcd(y, k);
}
int main() {
int k;
cin >> k;
ll ans = 0;
for (int i = 1; i <= k; i++) {
for (int j = 1; j <= k; j++) {
for (int s = 1; s <= k; s++) {
int f = gcd(i, j);
int t = gcd(s, f);
ans += t;
}
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
int gcd(int x, int y) {
if (x % y == 0) {
return y;
}
int k = x % y;
return gcd(y, k);
}
int main() {
int k;
cin >> k;
ll ans = 0;
for (int i = 1; i <= k; i++) {
for (int j = 1; j <= k; j++) {
for (int s = 1; s <= k; s++) {
int f = gcd(i, j);
int t = gcd(s, f);
ans += t;
}
}
}
cout << ans << endl;
} | replace | 14 | 15 | 14 | 15 | 0 | |
p02713 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (a < b) {
int r = b;
b = a;
a = r;
}
if (a % b == 0)
return b;
else
return gcd(b, a % b);
}
int gcd2(int a, int b, int c) { return gcd(a, gcd(b, c)); }
int main() {
long int k, ans = 0;
cin >> k;
for (int a = 0; a < k; a++) {
for (int b = 0; b < k; b++) {
for (int c = 0; c < k; c++) {
ans += gcd2(a, b, c);
}
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (a < b) {
int r = b;
b = a;
a = r;
}
if (a % b == 0)
return b;
else
return gcd(b, a % b);
}
int gcd2(int a, int b, int c) { return gcd(a, gcd(b, c)); }
int main() {
long int k, ans = 0;
cin >> k;
for (int a = 1; a < k + 1; a++) {
for (int b = 1; b < k + 1; b++) {
for (int c = 1; c < k + 1; c++) {
ans += gcd2(a, b, c);
}
}
}
cout << ans << endl;
}
| replace | 17 | 20 | 17 | 20 | -8 | |
p02713 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll a, b, c, i, j, k, l, m, n, ans, tmp, hoge, fuga, piyo;
ll x[10010], y[10010];
string s, str;
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; i++) {
m = gcd(i, j);
for (int k = 1; k <= n; i++) {
ans += gcd(m, k);
}
}
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll a, b, c, i, j, k, l, m, n, ans, tmp, hoge, fuga, piyo;
ll x[10010], y[10010];
string s, str;
int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 1; k <= n; k++) {
ans += gcd(i, gcd(j, k));
}
}
}
cout << ans;
return 0;
} | replace | 10 | 14 | 10 | 13 | TLE | |
p02713 | C++ | Time Limit Exceeded | /*
Coded and Decoded by : Yash Kapoor
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair
#define pll pair<ll, ll>
#define vl vector<ll>
#define sl set<ll>
#define vll vector<pll>
#define ml map<ll, ll>
#define mll map<pll, ll>
#define all(a) a.begin(), a.end()
#define x first
#define y second
#define sz(x) (ll) x.size()
#define dl '\n'
// #define why (ll)1000000007
#define why (ll)998244353
#define lp(i, a, b) for (ll i = a; i < b; ++i)
#define lpr(i, a, b) for (ll i = a; i >= b; i--)
#define lpd(i, x) for (auto i : x)
#define ios \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
ll inf = 1e18;
ld pi = 3.141592653589;
ll mod = why;
ll fast_power(ll base, ll power, ll mod) {
ll result = 1;
while (power) {
if (power % 2)
result = (result * base) % mod;
base = (base * base) % mod;
power /= 2;
}
return result;
}
ll inverse(ll base, ll mod) { return fast_power(base, mod - 2, mod); }
ll solve() {
ll k, sum = 0;
cin >> k;
lp(i, 1, k + 1) {
lp(j, 1, k + 1) {
lp(l, 1, k + 1) { sum += __gcd(i, __gcd(j, l)); }
}
}
cout << sum;
}
int main() {
ios ll t = 1;
// cin>>t;
while (t--) {
solve();
}
} | /*
Coded and Decoded by : Yash Kapoor
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair
#define pll pair<ll, ll>
#define vl vector<ll>
#define sl set<ll>
#define vll vector<pll>
#define ml map<ll, ll>
#define mll map<pll, ll>
#define all(a) a.begin(), a.end()
#define x first
#define y second
#define sz(x) (ll) x.size()
#define dl '\n'
// #define why (ll)1000000007
#define why (ll)998244353
#define lp(i, a, b) for (ll i = a; i < b; ++i)
#define lpr(i, a, b) for (ll i = a; i >= b; i--)
#define lpd(i, x) for (auto i : x)
#define ios \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
ll inf = 1e18;
ld pi = 3.141592653589;
ll mod = why;
ll fast_power(ll base, ll power, ll mod) {
ll result = 1;
while (power) {
if (power % 2)
result = (result * base) % mod;
base = (base * base) % mod;
power /= 2;
}
return result;
}
ll inverse(ll base, ll mod) { return fast_power(base, mod - 2, mod); }
ll solve() {
ll k, sum = 0;
cin >> k;
lp(i, 1, k + 1) {
lp(j, 1, k + 1) {
lp(l, 1, k + 1) { sum += __gcd(i, __gcd(j, l)); }
}
}
cout << sum;
return 0;
}
int main() {
ios ll t = 1;
// cin>>t;
while (t--) {
solve();
}
}
| insert | 58 | 58 | 58 | 59 | TLE | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
int main() {
int n;
cin >> n;
if (n <= 3) {
cout << 0 << endl;
return 0;
}
string s;
cin >> s;
vector<int> r;
vector<int> g;
vector<int> b;
for (int i = 0; i < n; i++) {
if (s[i] == 'R') {
r.push_back(i);
} else if (s[i] == 'G') {
g.push_back(i);
} else {
b.push_back(i);
}
}
set<vector<int>> check;
// cout << r.size() << endl;
// cout << g.size() << endl;
// cout << b.size() << endl;
// cout << (int)r.size() * (int)b.size() * (int) g.size() << endl;
ll sum = (ll)r.size() * (ll)b.size() * (ll)g.size();
for (int i = 0; i < (int)r.size(); i++) {
for (int j = 0; j < (int)g.size(); j++) {
int rg = r[i] + g[j];
if (rg % 2 == 1) {
continue;
}
if (rg / 2 > b.back()) {
break;
}
sum -= (int)(binary_search(b.begin(), b.end(), rg / 2));
}
}
for (int i = 0; i < (int)r.size(); i++) {
for (int j = 0; j < (int)b.size(); j++) {
int rb = r[i] + b[j];
if (rb % 2 == 1) {
continue;
}
if (rb / 2 > g.back()) {
break;
}
sum -= (int)(binary_search(g.begin(), g.end(), rb / 2));
}
}
for (int i = 0; i < (int)g.size(); i++) {
for (int j = 0; j < (int)b.size(); j++) {
int gb = g[i] + b[j];
if (gb % 2 == 1) {
continue;
}
if (gb / 2 > r.back()) {
break;
}
sum -= (int)(binary_search(r.begin(), r.end(), gb / 2));
}
}
cout << sum << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
int main() {
int n;
cin >> n;
if (n <= 3) {
cout << 0 << endl;
return 0;
}
string s;
cin >> s;
vector<int> r;
vector<int> g;
vector<int> b;
for (int i = 0; i < n; i++) {
if (s[i] == 'R') {
r.push_back(i);
} else if (s[i] == 'G') {
g.push_back(i);
} else {
b.push_back(i);
}
}
set<vector<int>> check;
// cout << r.size() << endl;
// cout << g.size() << endl;
// cout << b.size() << endl;
// cout << (int)r.size() * (int)b.size() * (int) g.size() << endl;
ll sum = (ll)r.size() * (ll)b.size() * (ll)g.size();
if (sum == 0) {
cout << sum << endl;
return 0;
}
for (int i = 0; i < (int)r.size(); i++) {
for (int j = 0; j < (int)g.size(); j++) {
int rg = r[i] + g[j];
if (rg % 2 == 1) {
continue;
}
if (rg / 2 > b.back()) {
break;
}
sum -= (int)(binary_search(b.begin(), b.end(), rg / 2));
}
}
for (int i = 0; i < (int)r.size(); i++) {
for (int j = 0; j < (int)b.size(); j++) {
int rb = r[i] + b[j];
if (rb % 2 == 1) {
continue;
}
if (rb / 2 > g.back()) {
break;
}
sum -= (int)(binary_search(g.begin(), g.end(), rb / 2));
}
}
for (int i = 0; i < (int)g.size(); i++) {
for (int j = 0; j < (int)b.size(); j++) {
int gb = g[i] + b[j];
if (gb % 2 == 1) {
continue;
}
if (gb / 2 > r.back()) {
break;
}
sum -= (int)(binary_search(r.begin(), r.end(), gb / 2));
}
}
cout << sum << endl;
return 0;
}
| insert | 46 | 46 | 46 | 50 | 0 | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int n, a[4001];
char s[4001];
int s1[4001], s2[4001], s3[4001];
long long ans;
int main() {
scanf("%d", &n);
cin >> s;
for (int i = 0; i < n; ++i) {
if (s[i] == 'R')
a[i + 1] = 1;
else if (s[i] == 'G')
a[i + 1] = 2;
else
a[i + 1] = 3;
}
for (int i = 1; i <= n; ++i) {
if (a[i] == 1) {
s1[i] = s1[i - 1] + 1;
s2[i] = s2[i - 1], s3[i] = s3[i - 1];
} else if (a[i] == 2) {
s2[i] = s2[i - 1] + 1;
s1[i] = s1[i - 1], s3[i] = s3[i - 1];
} else {
s1[i] = s1[i - 1];
s2[i] = s2[i - 1];
s3[i] = s3[i - 1] + 1;
}
}
for (int i = 1; i <= n - 2; ++i) {
for (int j = i + 1; j < n; ++j) {
int N = j - i;
if (a[j] == a[i])
continue;
if (a[i] + a[j] == 3)
ans += s3[n] - s3[j] - (a[j + N] == 3);
else if (a[i] + a[j] == 4)
ans += s2[n] - s2[j] - (a[j + N] == 2);
else if (a[i] + a[j] == 5)
ans += s1[n] - s1[j] - (a[j + N] == 1);
}
}
printf("%lld\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int n, a[40001];
char s[40001];
int s1[40001], s2[40010], s3[40001];
long long ans;
int main() {
scanf("%d", &n);
cin >> s;
for (int i = 0; i < n; ++i) {
if (s[i] == 'R')
a[i + 1] = 1;
else if (s[i] == 'G')
a[i + 1] = 2;
else
a[i + 1] = 3;
}
for (int i = 1; i <= n; ++i) {
if (a[i] == 1) {
s1[i] = s1[i - 1] + 1;
s2[i] = s2[i - 1], s3[i] = s3[i - 1];
} else if (a[i] == 2) {
s2[i] = s2[i - 1] + 1;
s1[i] = s1[i - 1], s3[i] = s3[i - 1];
} else {
s1[i] = s1[i - 1];
s2[i] = s2[i - 1];
s3[i] = s3[i - 1] + 1;
}
}
for (int i = 1; i <= n - 2; ++i) {
for (int j = i + 1; j < n; ++j) {
int N = j - i;
if (a[j] == a[i])
continue;
if (a[i] + a[j] == 3)
ans += s3[n] - s3[j] - (a[j + N] == 3);
else if (a[i] + a[j] == 4)
ans += s2[n] - s2[j] - (a[j + N] == 2);
else if (a[i] + a[j] == 5)
ans += s1[n] - s1[j] - (a[j + N] == 1);
}
}
printf("%lld\n", ans);
return 0;
} | replace | 2 | 5 | 2 | 5 | 0 | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(ri, n) for (int ri = (int)(n - 1); ri >= 0; ri--)
#define rep2(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri, x, n) for (int ri = (int)(n - 1); ri >= (int)(x); ri--)
#define repit(itr, x) for (auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr, x) for (auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;
int fc(const vector<int> &v, int i, int j) {
int res = v.size() - (lower_bound(ALL(v), j) - v.begin());
int t = j - i;
t += j;
if (*lower_bound(ALL(v), t) == t)
res--;
return res;
}
int main() {
int n;
cin >> n;
string s;
cin >> s;
vector<vector<int>> v(3, vector<int>());
rep(i, s.size()) {
if (s.at(i) == 'R')
s.at(i) = 0;
if (s.at(i) == 'G')
s.at(i) = 1;
if (s.at(i) == 'B')
s.at(i) = 2;
}
ll ans = 0;
rep(i, n) v.at(s.at(i)).push_back(i);
rep(i, n) rep2(j, i + 1, n) {
if (s.at(i) == s.at(j))
continue;
rep(l, 3) {
if (s.at(i) != l && s.at(j) != l)
ans += fc(v.at(l), i, j);
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(ri, n) for (int ri = (int)(n - 1); ri >= 0; ri--)
#define rep2(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri, x, n) for (int ri = (int)(n - 1); ri >= (int)(x); ri--)
#define repit(itr, x) for (auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr, x) for (auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;
int fc(const vector<int> &v, int i, int j) {
int res = v.size() - (lower_bound(ALL(v), j) - v.begin());
int t = j - i;
t += j;
auto itr = lower_bound(ALL(v), t);
if (itr != v.end() && *itr == t)
res--;
return res;
}
int main() {
int n;
cin >> n;
string s;
cin >> s;
vector<vector<int>> v(3, vector<int>());
rep(i, s.size()) {
if (s.at(i) == 'R')
s.at(i) = 0;
if (s.at(i) == 'G')
s.at(i) = 1;
if (s.at(i) == 'B')
s.at(i) = 2;
}
ll ans = 0;
rep(i, n) v.at(s.at(i)).push_back(i);
rep(i, n) rep2(j, i + 1, n) {
if (s.at(i) == s.at(j))
continue;
rep(l, 3) {
if (s.at(i) != l && s.at(j) != l)
ans += fc(v.at(l), i, j);
}
}
cout << ans << endl;
return 0;
} | replace | 15 | 16 | 15 | 17 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <iostream>
#include <string>
using namespace std;
int main() {
int N;
string S;
cin >> N;
cin >> S;
int sum = 0;
for (int i = 1; i < N - 1; i++) {
for (int j = i + 1; j < N; j++) {
if (S[i - 1] != S[j - 1]) {
for (int k = j + 1; k <= N; k++) {
if (S[k - 1] != S[i - 1] && S[k - 1] != S[j - 1]) {
if ((j - i) != (k - j)) {
sum++;
}
}
}
}
}
}
cout << sum << endl;
} | #include <iostream>
#include <string>
using namespace std;
int main() {
int N;
string S;
cin >> N >> S;
int count_r = 0;
int count_g = 0;
int count_b = 0;
for (int i = 0; i < N; i++) {
if (S[i] == 'R') {
count_r++;
}
if (S[i] == 'G') {
count_g++;
}
if (S[i] == 'B') {
count_b++;
}
}
int64_t sum = count_r * count_g * count_b;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j + (j - i) < N; j++) {
int k = j + (j - i);
if (S[i] != S[j] && S[j] != S[k] && S[k] != S[i]) {
sum--;
}
}
}
cout << sum << endl;
} | replace | 7 | 20 | 7 | 28 | TLE | |
p02714 | C++ | Runtime Error | #define _USE_MATH_DEFINES
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
using ll = long long;
using namespace std;
// LLONG_MAX = 90^18
#define int long long
#define CONTAINS(v, n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a) + (size))
#define REMOVE(v, a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v, a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v, a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No"); }
void Yes() { cout << "Yes"; }
void No() { cout << "No"; }
int N;
char S[4010];
int r_cnt[4010];
int g_cnt[4010];
int b_cnt[4010];
signed main() {
cin >> N;
cin >> S;
int r = 0;
int g = 0;
int b = 0;
for (int i = N - 1; i >= 0; i--) {
if (S[i] == 'R')
r++;
if (S[i] == 'G')
g++;
if (S[i] == 'B')
b++;
r_cnt[i] = r;
g_cnt[i] = g;
b_cnt[i] = b;
}
int sum = 0;
for (int i = 0; i < N - 2; i++) {
for (int j = i + 1; j < N - 1; j++) {
int sub = j - i;
int k = j + sub;
if ((S[i] == 'R' && S[j] == 'G') || (S[i] == 'G' && S[j] == 'R')) {
if (S[k] == 'B') {
sum--;
}
sum += b_cnt[j + 1];
}
if ((S[i] == 'R' && S[j] == 'B') || (S[i] == 'B' && S[j] == 'R')) {
if (S[k] == 'G') {
sum--;
}
sum += g_cnt[j + 1];
}
if ((S[i] == 'B' && S[j] == 'G') || (S[i] == 'G' && S[j] == 'B')) {
if (S[k] == 'R') {
sum--;
}
sum += r_cnt[j + 1];
}
}
}
cout << sum << endl;
}
| #define _USE_MATH_DEFINES
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <tuple>
#include <vector>
using ll = long long;
using namespace std;
// LLONG_MAX = 90^18
#define int long long
#define CONTAINS(v, n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a) + (size))
#define REMOVE(v, a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v, a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v, a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No"); }
void Yes() { cout << "Yes"; }
void No() { cout << "No"; }
int N;
char S[4010];
int r_cnt[4010];
int g_cnt[4010];
int b_cnt[4010];
signed main() {
cin >> N;
cin >> S;
int r = 0;
int g = 0;
int b = 0;
for (int i = N - 1; i >= 0; i--) {
if (S[i] == 'R')
r++;
if (S[i] == 'G')
g++;
if (S[i] == 'B')
b++;
r_cnt[i] = r;
g_cnt[i] = g;
b_cnt[i] = b;
}
int sum = 0;
for (int i = 0; i < N - 2; i++) {
for (int j = i + 1; j < N - 1; j++) {
int sub = j - i;
int k = j + sub;
if (k >= N)
k = 4000;
if ((S[i] == 'R' && S[j] == 'G') || (S[i] == 'G' && S[j] == 'R')) {
if (S[k] == 'B') {
sum--;
}
sum += b_cnt[j + 1];
}
if ((S[i] == 'R' && S[j] == 'B') || (S[i] == 'B' && S[j] == 'R')) {
if (S[k] == 'G') {
sum--;
}
sum += g_cnt[j + 1];
}
if ((S[i] == 'B' && S[j] == 'G') || (S[i] == 'G' && S[j] == 'B')) {
if (S[k] == 'R') {
sum--;
}
sum += r_cnt[j + 1];
}
}
}
cout << sum << endl;
}
| insert | 68 | 68 | 68 | 70 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define srt(i) sort(i.begin(), i.end())
#define rvt(i) sort(i.begin(), i.end(), greater<int>())
int main() {
int n;
string s;
cin >> n >> s;
int ans = 0;
for (int i = 1; i <= n - 2; i++)
for (int j = i + 1; j <= n - 1; j++)
for (int k = j + 1; k <= n; k++) {
if (j - i == k - j)
continue;
if (s.at(i - 1) != s.at(j - 1) && s.at(i - 1) != s.at(k - 1) &&
s.at(j - 1) != s.at(k - 1))
ans++;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define srt(i) sort(i.begin(), i.end())
#define rvt(i) sort(i.begin(), i.end(), greater<int>())
int main() {
int n;
string s;
cin >> n >> s;
int64_t r, g, b;
r = 0;
g = 0;
b = 0;
rep(i, n) {
if (s.at(i) == 'R')
r++;
if (s.at(i) == 'G')
g++;
if (s.at(i) == 'B')
b++;
}
int64_t ans = r * g * b;
for (int i = 0; i < n; i++) {
for (int t = 1; t <= n; t++) {
if (i + 2 * t >= n)
continue;
char first = s.at(i);
char second = s.at(i + t);
char third = s.at(i + 2 * t);
if (first != second && first != third && second != third)
ans--;
}
}
cout << ans << endl;
} | replace | 16 | 26 | 16 | 44 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
const long long INF = (long long)1e18 + 1;
#define DIV 1000000007
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
#ifdef TEST
chrono::system_clock::time_point start, end;
start = chrono::system_clock::now();
#endif
long idx = 0;
long N;
cin >> N;
string S;
cin >> S;
ll total = 0;
vector<long> R;
vector<long> G;
vector<long> B;
for (size_t i = 0; i < N; i++) {
if (S[i] == 'R')
R.push_back(i);
else if (S[i] == 'G')
G.push_back(i);
else if (S[i] == 'B')
B.push_back(i);
}
ll out_of_rule = 0;
for (size_t i = 0; i < R.size(); i++) {
for (size_t j = 0; j < G.size(); j++) {
ll index = abs(R[i] - G[j]);
cerr << R[i] << "," << G[j] << ":" << index << endl;
if (index % 2 == 0 && S[min(R[i], G[j]) + index / 2] == 'B')
out_of_rule++;
if (max(R[i], G[j]) + index < N && S[max(R[i], G[j]) + index] == 'B')
out_of_rule++;
if (min(R[i], G[j]) - index >= 0 && S[min(R[i], G[j]) - index] == 'B')
out_of_rule++;
}
}
cout << R.size() * G.size() * B.size() - out_of_rule << endl;
#ifdef TEST
end = chrono::system_clock::now();
cerr << static_cast<double>(
chrono::duration_cast<chrono::microseconds>(end - start).count() /
1000.0)
<< "[ms]" << endl;
#endif
return 0;
} | #include <algorithm>
#include <bitset>
#include <chrono>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = long long;
const long long INF = (long long)1e18 + 1;
#define DIV 1000000007
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
#ifdef TEST
chrono::system_clock::time_point start, end;
start = chrono::system_clock::now();
#endif
long idx = 0;
long N;
cin >> N;
string S;
cin >> S;
ll total = 0;
vector<long> R;
vector<long> G;
vector<long> B;
for (size_t i = 0; i < N; i++) {
if (S[i] == 'R')
R.push_back(i);
else if (S[i] == 'G')
G.push_back(i);
else if (S[i] == 'B')
B.push_back(i);
}
ll out_of_rule = 0;
for (size_t i = 0; i < R.size(); i++) {
for (size_t j = 0; j < G.size(); j++) {
ll index = abs(R[i] - G[j]);
// cerr << R[i] << "," << G[j] << ":" << index << endl;
if (index % 2 == 0 && S[min(R[i], G[j]) + index / 2] == 'B')
out_of_rule++;
if (max(R[i], G[j]) + index < N && S[max(R[i], G[j]) + index] == 'B')
out_of_rule++;
if (min(R[i], G[j]) - index >= 0 && S[min(R[i], G[j]) - index] == 'B')
out_of_rule++;
}
}
cout << R.size() * G.size() * B.size() - out_of_rule << endl;
#ifdef TEST
end = chrono::system_clock::now();
cerr << static_cast<double>(
chrono::duration_cast<chrono::microseconds>(end - start).count() /
1000.0)
<< "[ms]" << endl;
#endif
return 0;
} | replace | 45 | 46 | 45 | 46 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
#define ull unsigned long long
#define max 998244353 // 1000000007
ll gcd(ll a, ll b) {
if (a < b)
swap(a, b);
while (ll r = a % b)
a = b, b = r;
return b;
}
class mod {
public:
ll val;
mod(ll v) { val = v % max; }
mod() { val = 0; }
void operator-=(const mod &v) {
val -= v.val;
if (val < 0)
val += max;
}
void operator+=(const mod &v) {
if (val + v.val >= max)
val -= max;
val += v.val;
}
void operator+=(ll &v) {
if (val + v >= max)
val -= max;
val += v;
}
void operator*=(const mod &v) {
val *= v.val;
val %= max;
}
void operator*=(ll &v) {
val *= v;
val %= max;
}
ll modinv(ll a) {
ll b = max, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= max;
if (u < 0)
u += max;
return u;
}
void operator/=(const mod &v) {
val *= modinv(v.val);
val %= max;
}
void operator/=(ll &v) {
val *= modinv(v);
val %= max;
}
};
int func(int a, int b) {
if (a < b)
return func(b, a);
int r;
while (r = a % b) {
a = b;
b = r;
}
return b;
}
int main() {
int n;
cin >> n;
vector<int> s(n), r(n), g(n), b(n);
int nr = 0, ng = 0, nb = 0;
for (int i = 0; i < n; i++) {
char c;
cin >> c;
if (c == 'R')
s[i] = 1, r[nr++] = i;
else if (c == 'G')
s[i] = 2, g[ng++] = i;
else
s[i] = 4, b[nb++] = i;
}
ll re = 0;
for (int i = 0; i < n - 2; i++)
for (int j = i + 1; j < n - 1; j++)
if (s[i] == s[j])
continue;
else
for (int k = j + 1; k < n; k++)
if (j - i != k - j && s[i] + s[j] + s[k] == 7)
re++;
printf("%lld", re);
return 0;
} | #include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
#define ull unsigned long long
#define max 998244353 // 1000000007
ll gcd(ll a, ll b) {
if (a < b)
swap(a, b);
while (ll r = a % b)
a = b, b = r;
return b;
}
class mod {
public:
ll val;
mod(ll v) { val = v % max; }
mod() { val = 0; }
void operator-=(const mod &v) {
val -= v.val;
if (val < 0)
val += max;
}
void operator+=(const mod &v) {
if (val + v.val >= max)
val -= max;
val += v.val;
}
void operator+=(ll &v) {
if (val + v >= max)
val -= max;
val += v;
}
void operator*=(const mod &v) {
val *= v.val;
val %= max;
}
void operator*=(ll &v) {
val *= v;
val %= max;
}
ll modinv(ll a) {
ll b = max, u = 1, v = 0;
while (b) {
ll t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= max;
if (u < 0)
u += max;
return u;
}
void operator/=(const mod &v) {
val *= modinv(v.val);
val %= max;
}
void operator/=(ll &v) {
val *= modinv(v);
val %= max;
}
};
int func(int a, int b) {
if (a < b)
return func(b, a);
int r;
while (r = a % b) {
a = b;
b = r;
}
return b;
}
int main() {
int n;
cin >> n;
vector<int> s(n), r(n), g(n), b(n);
int nr = 0, ng = 0, nb = 0;
for (int i = 0; i < n; i++) {
char c;
cin >> c;
if (c == 'R')
s[i] = 1, r[nr++] = i;
else if (c == 'G')
s[i] = 2, g[ng++] = i;
else
s[i] = 4, b[nb++] = i;
}
ll re = 0;
for (int i = 0; i < n - 2; i++)
for (int j = i + 1; j < n - 1; j++)
if (s[i] == s[j])
continue;
// j以上の数から探索
else {
int k;
int target = 2 * j - i;
bool had = false;
if (s[i] + s[j] == 3) {
// b
k = lower_bound(b.begin(), b.begin() + nb, j + 1) - b.begin();
re += (nb - k);
if (binary_search(b.begin() + k, b.begin() + nb, target))
re--;
} else if (s[i] + s[j] == 5) {
// g
k = lower_bound(g.begin(), g.begin() + ng, j + 1) - g.begin();
re += (ng - k);
if (binary_search(g.begin() + k, g.begin() + ng, target))
re--;
} else {
// r
k = lower_bound(r.begin(), r.begin() + nr, j + 1) - r.begin();
re += (nr - k);
if (binary_search(r.begin() + k, r.begin() + nr, target))
re--;
}
}
printf("%lld", re);
return 0;
} | replace | 125 | 129 | 125 | 151 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <numeric>
#include <stdlib.h>
#include <type_traits>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
int c = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n - 1; j++) {
for (int k = j + 1; k <= n - 1; k++) {
if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k] &&
(j - i) != (k - j)) {
c++;
}
}
}
}
cout << c;
return 0;
} | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <numeric>
#include <stdlib.h>
#include <type_traits>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
unsigned long long int c = 0;
long long int cr = 0;
long long int cg = 0;
long long int cb = 0;
for (int i = 0; i < n; i++) {
switch (s[i]) {
case 'R':
cr++;
break;
case 'G':
cg++;
break;
case 'B':
cb++;
break;
}
}
c = cr * cg * cb;
for (int j = 0; j < n - 2; j++) {
for (int k = j + 1; k < n - 1; k++) {
if (s[j] != s[k] && s[k] != s[2 * k - j] && s[j] != s[2 * k - j] &&
(2 * k - j) < n) {
c--;
}
}
}
cout << c;
return 0;
} | replace | 17 | 25 | 17 | 40 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define INF 2e9
#define rep(i, n, m) for (int i = n; i < m; i++)
using namespace std;
int main() {
int n;
string s;
vector<int> R, G, B;
cin >> n >> s;
rep(i, 0, n) {
switch (s[i]) {
case 'R':
R.push_back(i + 1);
break;
case 'G':
G.push_back(i + 1);
break;
case 'B':
B.push_back(i + 1);
break;
}
}
int ans = 0;
for (int i : R)
for (int j : G)
for (int k : B) {
vector<int> a = {i, j, k};
sort(a.begin(), a.end());
if (2 * a[1] != a[0] + a[2])
ans++;
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define INF 2e9
#define rep(i, n, m) for (int i = n; i < m; i++)
using namespace std;
int main() {
int n;
string s;
vector<int> R, G, B;
cin >> n >> s;
rep(i, 0, n) {
switch (s[i]) {
case 'R':
R.push_back(i + 1);
break;
case 'G':
G.push_back(i + 1);
break;
case 'B':
B.push_back(i + 1);
break;
}
}
long long int ans;
ans = R.size() * G.size() * B.size();
rep(i, 0, n) rep(j, i, n) {
int k = 2 * j - i;
if (j <= k && k < n)
if (s[i] != s[j] && s[k] != s[j] && s[i] != s[k])
ans--;
}
cout << ans << endl;
return 0;
}
| replace | 34 | 43 | 34 | 42 | TLE | |
p02714 | Python | Time Limit Exceeded | N = int(input())
S = input()
ans = 0
for i in range(N - 2):
for j in range(i + 1, N - 1):
if S[j] != S[i]:
for k in range(j + 1, N):
if j - i != k - j and S[k] != S[i] and S[k] != S[j]:
ans += 1
print(ans)
| def main():
N = int(input())
S = input()
ans = S.count("R") * S.count("G") * S.count("B")
for i in range(N):
for d in range(N - 1):
j = i + d
k = j + d
if k < N and S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
ans -= 1
print(ans)
main()
| replace | 0 | 10 | 0 | 14 | TLE | |
p02714 | C++ | Runtime Error | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pii> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vector<pair<ll, ll>>> vvpll;
typedef vector<bool> vb;
typedef map<int, int> mii;
typedef map<char, int> mci;
typedef map<ll, ll> mll;
#define FIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define all(x) x.begin(), x.end()
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define F first
#define S second
#define left (node << 1)
#define right (node << 1) + 1
// #define mod 998244353
#define mod 1000000007
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) \
cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
#define trace4(x, y, z, t) \
cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << " | " << #t << ": " << t << endl
#define trace5(x, y, z, t, u) \
cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << " | " << #t << ": " << t << " | " << #u << ": " << u << endl
#define trace6(x, y, z, t, u, v) \
cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << " | " << #t << ": " << t << " | " << #u << ": " << u << " | " \
<< #v << ": " << v << endl
#define repa(i, sta, end, inc) for (int i = sta; i <= end; i += inc)
#define repb(i, sta, end, inc) for (int i = sta; i >= end; i -= inc)
ll power(ll x, ll y, ll z) {
ll res = 1;
x %= z;
while (y) {
if (y & 1) {
res = res * x % z;
}
x = x * x % z;
y /= 2;
}
return res % z;
}
ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
const int N = 2 * 100000 + 1;
const int inf = (1 << 30);
void solve() {
int n;
string s;
cin >> n >> s;
vi r, g, b;
repa(i, 0, n - 1, 1) {
if (s[i] == 'R') {
r.pb(i);
} else if (s[i] == 'G') {
g.pb(i);
} else {
b.pb(i);
}
}
ll ans = 0;
repa(i, 0, r.size() - 1, 1) {
int ri = r[i];
int id = ub(all(g), ri) - g.begin();
if (id != g.size()) {
repa(j, id, g.size() - 1, 1) {
int gj = g[j];
int id_ = ub(all(b), gj) - b.begin();
if (id_ != b.size()) {
ans += b.size() - id_;
if (bs(all(b), 2 * gj - ri))
ans--;
}
}
}
}
repa(i, 0, r.size() - 1, 1) {
int ri = r[i];
int id = ub(all(b), ri) - b.begin();
if (id != b.size()) {
repa(j, id, b.size() - 1, 1) {
int bj = b[j];
int id_ = ub(all(g), bj) - g.begin();
if (id_ != g.size()) {
ans += g.size() - id_;
if (bs(all(g), 2 * bj - ri))
ans--;
}
}
}
}
repa(i, 0, g.size() - 1, 1) {
int gi = g[i];
int id = ub(all(r), gi) - r.begin();
if (id != r.size()) {
repa(j, id, r.size() - 1, 1) {
int rj = r[j];
int id_ = ub(all(b), rj) - b.begin();
if (id_ != b.size()) {
ans += b.size() - id_;
if (bs(all(b), 2 * rj - gi))
ans--;
}
}
}
}
repa(i, 0, g.size() - 1, 1) {
int gi = g[i];
int id = ub(all(b), gi) - b.begin();
if (id != b.size()) {
repa(j, id, b.size() - 1, 1) {
int bj = b[j];
int id_ = ub(all(r), bj) - r.begin();
if (id_ != r.size()) {
ans += r.size() - id_;
if (bs(all(r), 2 * bj - gi))
ans--;
}
}
}
}
repa(i, 0, b.size() - 1, 1) {
int bi = b[i];
int id = ub(all(g), bi) - g.begin();
if (id != g.size()) {
repa(j, id, g.size() - 1, 1) {
int gj = g[j];
int id_ = ub(all(r), gj) - r.begin();
if (id_ != r.size()) {
ans += r.size() - id_;
if (bs(all(r), 2 * gj - bi))
ans--;
}
}
}
}
repa(i, 0, b.size() - 1, 1) {
int bi = b[i];
int id = ub(all(r), bi) - r.begin();
if (id != r.size()) {
repa(j, id, r.size() - 1, 1) {
int rj = r[j];
int id_ = ub(all(g), rj) - g.begin();
if (id_ != g.size()) {
ans += g.size() - id_;
if (bs(all(g), 2 * rj - bi))
ans--;
}
}
}
}
cout << ans << endl;
}
int main() {
FIO;
int T = 1;
// cin >> T;
repa(i, 1, T, 1) { solve(); }
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pii> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vector<pair<ll, ll>>> vvpll;
typedef vector<bool> vb;
typedef map<int, int> mii;
typedef map<char, int> mci;
typedef map<ll, ll> mll;
#define FIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define all(x) x.begin(), x.end()
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define F first
#define S second
#define left (node << 1)
#define right (node << 1) + 1
// #define mod 998244353
#define mod 1000000007
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) \
cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
#define trace4(x, y, z, t) \
cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << " | " << #t << ": " << t << endl
#define trace5(x, y, z, t, u) \
cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << " | " << #t << ": " << t << " | " << #u << ": " << u << endl
#define trace6(x, y, z, t, u, v) \
cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << " | " << #t << ": " << t << " | " << #u << ": " << u << " | " \
<< #v << ": " << v << endl
#define repa(i, sta, end, inc) for (int i = sta; i <= end; i += inc)
#define repb(i, sta, end, inc) for (int i = sta; i >= end; i -= inc)
ll power(ll x, ll y, ll z) {
ll res = 1;
x %= z;
while (y) {
if (y & 1) {
res = res * x % z;
}
x = x * x % z;
y /= 2;
}
return res % z;
}
ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
const int N = 2 * 100000 + 1;
const int inf = (1 << 30);
void solve() {
int n;
string s;
cin >> n >> s;
vi r, g, b;
repa(i, 0, n - 1, 1) {
if (s[i] == 'R') {
r.pb(i);
} else if (s[i] == 'G') {
g.pb(i);
} else {
b.pb(i);
}
}
ll ans = 0;
if (r.size())
repa(i, 0, r.size() - 1, 1) {
int ri = r[i];
if (g.size()) {
int id = ub(all(g), ri) - g.begin();
if (id != g.size()) {
repa(j, id, g.size() - 1, 1) {
int gj = g[j];
if (b.size()) {
int id_ = ub(all(b), gj) - b.begin();
if (id_ != b.size()) {
ans += b.size() - id_;
if (bs(all(b), 2 * gj - ri))
ans--;
}
}
}
}
}
}
if (r.size())
repa(i, 0, r.size() - 1, 1) {
int ri = r[i];
if (b.size()) {
int id = ub(all(b), ri) - b.begin();
if (id != b.size()) {
repa(j, id, b.size() - 1, 1) {
int bj = b[j];
if (g.size()) {
int id_ = ub(all(g), bj) - g.begin();
if (id_ != g.size()) {
ans += g.size() - id_;
if (bs(all(g), 2 * bj - ri))
ans--;
}
}
}
}
}
}
if (g.size())
repa(i, 0, g.size() - 1, 1) {
int gi = g[i];
if (r.size()) {
int id = ub(all(r), gi) - r.begin();
if (id != r.size()) {
repa(j, id, r.size() - 1, 1) {
int rj = r[j];
if (b.size()) {
int id_ = ub(all(b), rj) - b.begin();
if (id_ != b.size()) {
ans += b.size() - id_;
if (bs(all(b), 2 * rj - gi))
ans--;
}
}
}
}
}
}
if (g.size())
repa(i, 0, g.size() - 1, 1) {
int gi = g[i];
if (b.size()) {
int id = ub(all(b), gi) - b.begin();
if (id != b.size()) {
repa(j, id, b.size() - 1, 1) {
int bj = b[j];
if (r.size()) {
int id_ = ub(all(r), bj) - r.begin();
if (id_ != r.size()) {
ans += r.size() - id_;
if (bs(all(r), 2 * bj - gi))
ans--;
}
}
}
}
}
}
if (b.size())
repa(i, 0, b.size() - 1, 1) {
int bi = b[i];
if (g.size()) {
int id = ub(all(g), bi) - g.begin();
if (id != g.size()) {
repa(j, id, g.size() - 1, 1) {
int gj = g[j];
if (r.size()) {
int id_ = ub(all(r), gj) - r.begin();
if (id_ != r.size()) {
ans += r.size() - id_;
if (bs(all(r), 2 * gj - bi))
ans--;
}
}
}
}
}
}
if (b.size())
repa(i, 0, b.size() - 1, 1) {
int bi = b[i];
if (r.size()) {
int id = ub(all(r), bi) - r.begin();
if (id != r.size()) {
repa(j, id, r.size() - 1, 1) {
int rj = r[j];
if (g.size()) {
int id_ = ub(all(g), rj) - g.begin();
if (id_ != g.size()) {
ans += g.size() - id_;
if (bs(all(g), 2 * rj - bi))
ans--;
}
}
}
}
}
}
cout << ans << endl;
}
int main() {
FIO;
int T = 1;
// cin >> T;
repa(i, 1, T, 1) { solve(); }
return 0;
}
| replace | 89 | 179 | 89 | 209 | 0 | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxx = 4e3 + 7;
int n;
char s[maxx];
int num[maxx];
vector<int> vec[maxx];
LL cnt[maxx];
bool vis[maxx];
LL chk(int a, int b, int c) {
LL res = 0;
for (int i = 0; i < vec[a].size(); i++) {
for (int j = 0; j < vec[b].size(); j++) {
int id_a = vec[a][i];
int id_b = vec[b][j];
if (id_b > id_a) {
int id_nxt = id_b + (id_b - id_a);
if (num[id_nxt] == c)
res++;
}
}
}
return res;
}
int main() {
scanf("%d", &n);
scanf("%s", s + 1);
for (int i = 1; i <= n; i++) {
if (s[i] == 'B')
num[i] = 1;
else if (s[i] == 'G')
num[i] = 2;
else if (s[i] == 'R')
num[i] = 3;
}
for (int i = 1; i <= n; i++) {
vec[num[i]].push_back(i);
cnt[num[i]]++;
}
LL ans = cnt[1] * cnt[2] * cnt[3];
ans -= chk(1, 2, 3);
ans -= chk(1, 3, 2);
ans -= chk(2, 1, 3);
ans -= chk(2, 3, 1);
ans -= chk(3, 1, 2);
ans -= chk(3, 2, 1);
printf("%lld\n", ans);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxx = 4e3 + 7;
int n;
char s[maxx];
int num[maxx];
vector<int> vec[maxx];
LL cnt[maxx];
bool vis[maxx];
LL chk(int a, int b, int c) {
LL res = 0;
for (int i = 0; i < vec[a].size(); i++) {
for (int j = 1; vec[a][i] + 2 * j <= n; j++) {
if (num[vec[a][i] + j] == b && num[vec[a][i] + 2 * j] == c)
res++;
}
}
return res;
}
int main() {
scanf("%d", &n);
scanf("%s", s + 1);
for (int i = 1; i <= n; i++) {
if (s[i] == 'B')
num[i] = 1;
else if (s[i] == 'G')
num[i] = 2;
else if (s[i] == 'R')
num[i] = 3;
}
for (int i = 1; i <= n; i++) {
vec[num[i]].push_back(i);
cnt[num[i]]++;
}
LL ans = cnt[1] * cnt[2] * cnt[3];
ans -= chk(1, 2, 3);
ans -= chk(1, 3, 2);
ans -= chk(2, 1, 3);
ans -= chk(2, 3, 1);
ans -= chk(3, 1, 2);
ans -= chk(3, 2, 1);
printf("%lld\n", ans);
return 0;
} | replace | 14 | 22 | 14 | 17 | 0 | |
p02714 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
long long ans = 0;
cin >> N;
vector<int> r(0), g(0), b(0);
vector<char> c(N);
for (int i = 0; i < N; i++) {
cin >> c.at(i);
if (c.at(i) == 'R') {
r.push_back(i + 1);
} else if (c.at(i) == 'G') {
g.push_back(i + 1);
} else {
b.push_back(i + 1);
}
}
vector<int> a(2);
sort(b.begin(), b.end());
ans = r.size() * g.size() * b.size();
int temp;
for (int i = 0; i < r.size(); i++) {
for (int j = 0; j < g.size(); j++) {
a.at(0) = r.at(i);
a.at(1) = g.at(j);
sort(a.begin(), a.end());
temp = 2 * a.at(1) - a.at(0);
if (temp > b.at((b.size() - 1) / 2) && temp <= b.at(b.size() - 1)) {
for (int k = (b.size() - 1) / 2; k < b.size(); k++) {
if (b.at(k) == temp) {
ans--;
break;
}
}
} else if (temp <= b.at((b.size() - 1) / 2) && temp >= b.at(0)) {
for (int k = (b.size() - 1) / 2; k > -1; k--) {
if (b.at(k) == temp) {
ans--;
break;
}
}
}
temp = a.at(1) + a.at(0);
if (temp > 2 * b.at((b.size() - 1) / 2) &&
temp <= 2 * b.at(b.size() - 1)) {
for (int k = (b.size() - 1) / 2; k < b.size(); k++) {
if (2 * b.at(k) == temp) {
ans--;
break;
}
}
} else if (temp <= 2 * b.at((b.size() - 1) / 2) && temp >= 2 * b.at(0)) {
for (int k = (b.size() - 1) / 2; k > -1; k--) {
if (2 * b.at(k) == temp) {
ans--;
break;
}
}
}
temp = 2 * a.at(0) - a.at(1);
if (temp > b.at((b.size() - 1) / 2) && temp <= b.at(b.size() - 1)) {
for (int k = (b.size() - 1) / 2; k < b.size(); k++) {
if (b.at(k) == temp) {
ans--;
break;
}
}
} else if (temp <= b.at((b.size() - 1) / 2) && temp >= b.at(0)) {
for (int k = (b.size() - 1) / 2; k > -1; k--) {
if (b.at(k) == temp) {
ans--;
break;
}
}
}
}
}
cout << ans;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
long long ans = 0;
cin >> N;
vector<int> r(0), g(0), b(0);
vector<char> c(N);
for (int i = 0; i < N; i++) {
cin >> c.at(i);
if (c.at(i) == 'R') {
r.push_back(i + 1);
} else if (c.at(i) == 'G') {
g.push_back(i + 1);
} else {
b.push_back(i + 1);
}
}
vector<int> a(2);
sort(b.begin(), b.end());
ans = r.size() * g.size() * b.size();
int temp;
for (int i = 0; i < r.size(); i++) {
if (b.size() == 0) {
break;
}
for (int j = 0; j < g.size(); j++) {
a.at(0) = r.at(i);
a.at(1) = g.at(j);
sort(a.begin(), a.end());
temp = 2 * a.at(1) - a.at(0);
if (temp > b.at((b.size() - 1) / 2) && temp <= b.at(b.size() - 1)) {
for (int k = (b.size() - 1) / 2; k < b.size(); k++) {
if (b.at(k) == temp) {
ans--;
break;
}
}
} else if (temp <= b.at((b.size() - 1) / 2) && temp >= b.at(0)) {
for (int k = (b.size() - 1) / 2; k > -1; k--) {
if (b.at(k) == temp) {
ans--;
break;
}
}
}
temp = a.at(1) + a.at(0);
if (temp > 2 * b.at((b.size() - 1) / 2) &&
temp <= 2 * b.at(b.size() - 1)) {
for (int k = (b.size() - 1) / 2; k < b.size(); k++) {
if (2 * b.at(k) == temp) {
ans--;
break;
}
}
} else if (temp <= 2 * b.at((b.size() - 1) / 2) && temp >= 2 * b.at(0)) {
for (int k = (b.size() - 1) / 2; k > -1; k--) {
if (2 * b.at(k) == temp) {
ans--;
break;
}
}
}
temp = 2 * a.at(0) - a.at(1);
if (temp > b.at((b.size() - 1) / 2) && temp <= b.at(b.size() - 1)) {
for (int k = (b.size() - 1) / 2; k < b.size(); k++) {
if (b.at(k) == temp) {
ans--;
break;
}
}
} else if (temp <= b.at((b.size() - 1) / 2) && temp >= b.at(0)) {
for (int k = (b.size() - 1) / 2; k > -1; k--) {
if (b.at(k) == temp) {
ans--;
break;
}
}
}
}
}
cout << ans;
} | insert | 29 | 29 | 29 | 32 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <deque> // deque
#include <functional>
#include <iomanip>
#include <iostream> // cout, endl, cin
#include <map> // map
#include <math.h>
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
using namespace std;
#define ll long long
using vt = ll; // ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for (vt i = (vt)(s); i < (vt)(n); i++)
#define all(v) v.begin(), v.end()
#define P pair<ll, ll>
const ll MOD = 1000000007;
int main() {
ll n;
string s;
cin >> n >> s;
vector<ll> r, g, b;
rep(i, n) {
if (s.at(i) == 'R')
r.push_back(i);
else if (s.at(i) == 'G')
g.push_back(i);
else
b.push_back(i);
}
if (r.empty() || g.empty() || b.empty()) {
cout << 0;
return 0;
}
ll ans = r.size() * g.size() * b.size();
for (auto i : r) {
for (auto j : g) {
for (auto k : b) {
if (i < k && j < k && abs(i - j) < k - max(i, j))
break;
vector<ll> v = {i, j, k};
sort(all(v));
if (v.at(2) - v.at(1) == v.at(1) - v.at(0))
ans--;
}
}
}
cout << ans;
return 0;
} | #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <deque> // deque
#include <functional>
#include <iomanip>
#include <iostream> // cout, endl, cin
#include <map> // map
#include <math.h>
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
using namespace std;
#define ll long long
using vt = ll; // ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for (vt i = (vt)(s); i < (vt)(n); i++)
#define all(v) v.begin(), v.end()
#define P pair<ll, ll>
const ll MOD = 1000000007;
int main() {
ll n;
string s;
cin >> n >> s;
vector<ll> r, g, b;
rep(i, n) {
if (s.at(i) == 'R')
r.push_back(i);
else if (s.at(i) == 'G')
g.push_back(i);
else
b.push_back(i);
}
if (r.empty() || g.empty() || b.empty()) {
cout << 0;
return 0;
}
ll ans = r.size() * g.size() * b.size();
for (auto i : r) {
for (auto j : g) {
ll x = max(i, j);
ll y = min(i, j);
if (binary_search(all(b), y - (x - y)))
ans--;
if (binary_search(all(b), x + (x - y)))
ans--;
if ((x - y) % 2 == 0) {
if (binary_search(all(b), y + (x - y) / 2))
ans--;
}
}
}
cout << ans;
return 0;
} | replace | 50 | 56 | 50 | 58 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順
int main() {
int N;
string S;
cin >> N >> S;
vector<int> R;
vector<int> G;
vector<int> B;
rep(i, N) {
switch (S.at(i)) {
case 'R':
R.push_back(i);
break;
case 'G':
G.push_back(i);
break;
case 'B':
B.push_back(i);
break;
}
}
ll sum = 0;
rep(i, R.size()) {
rep(j, G.size()) {
rep(k, B.size()) {
int r = R.at(i);
int g = G.at(j);
int b = B.at(k);
if (r > g)
swap(r, g);
if (g > b)
swap(g, b);
if (r > g)
swap(r, g);
if (g - r == b - g)
continue;
sum++;
}
}
}
cout << sum << endl;
} | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
using ll = int64_t;
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順
int main() {
int N;
string S;
cin >> N >> S;
vector<int> R;
vector<int> G;
vector<int> B;
rep(i, N) {
switch (S.at(i)) {
case 'R':
R.push_back(i);
break;
case 'G':
G.push_back(i);
break;
case 'B':
B.push_back(i);
break;
}
}
ll sum = 0;
rep(i, R.size()) {
rep(j, G.size()) {
int r = R.at(i);
int b = G.at(j);
if (b < r)
swap(b, r);
int d = b - r;
int e = B.size();
if (find(B.begin(), B.end(), b + d) != B.end())
e--;
if (find(B.begin(), B.end(), r - d) != B.end())
e--;
if ((b + r) % 2 == 0)
if (find(B.begin(), B.end(), (b + r) / 2) != B.end())
e--;
sum += e;
}
}
cout << sum << endl;
} | replace | 30 | 44 | 30 | 44 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include <algorithm> //sort,二分探索,など
#include <bitset> //固定長bit集合
#include <cmath> //pow,logなど
#include <complex> //複素数
#include <deque> //両端アクセスのキュー
#include <functional> //sortのgreater
#include <iomanip> //setprecision(浮動小数点の出力の誤差)
#include <iostream> //入出力
#include <map> //map(辞書)
#include <numeric> //iota(整数列の生成),gcdとlcm(c++17)
#include <queue> //キュー
#include <set> //集合
#include <stack> //スタック
#include <string> //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility> //pair
#include <vector> //可変長配列
using namespace std;
typedef long long ll;
// マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 // 10^12
#define MOD 10000007 // 10^9+7
#define MAXR 100000 // 10^5:最大のrange(素数列挙などで使用)
int main(void) {
int n;
cin >> n;
string s;
cin >> s;
vector<int> a, b, c;
REP(i, n) {
if (s[i] == 'R')
a.push_back(i + 1);
if (s[i] == 'G')
b.push_back(i + 1);
if (s[i] == 'B')
c.push_back(i + 1);
}
ll sum = 0;
// cout << a.size() << "," << b.size() << "," << c.size() << endl;
REP(i, a.size()) {
REP(j, b.size()) {
REP(k, c.size()) {
if (a[i] < b[j]) {
if (b[j] < c[k]) { // c, b, a
if (c[k] - b[j] == b[j] - a[i])
continue;
}
if (c[k] < a[i]) { // b, a, c
if (b[j] - a[i] == a[i] - c[k])
continue;
}
if (b[j] > c[k] && c[k] > a[i]) { // b, c, a
if (b[j] - c[k] == c[k] - a[i])
continue;
}
} else {
if (a[i] < c[k]) { // c, a, b
if (c[k] - a[i] == a[i] - b[j])
continue;
}
if (b[j] > c[k]) { // a, b, c
if (a[i] - b[j] == b[j] - c[k])
continue;
}
if (a[i] > c[k] && c[k] > b[j]) { // a, c, b
if (a[i] - c[k] == c[k] - b[j])
continue;
}
}
sum++;
}
}
}
cout << sum << endl;
return 0;
}
| #include <algorithm> //sort,二分探索,など
#include <bitset> //固定長bit集合
#include <cmath> //pow,logなど
#include <complex> //複素数
#include <deque> //両端アクセスのキュー
#include <functional> //sortのgreater
#include <iomanip> //setprecision(浮動小数点の出力の誤差)
#include <iostream> //入出力
#include <map> //map(辞書)
#include <numeric> //iota(整数列の生成),gcdとlcm(c++17)
#include <queue> //キュー
#include <set> //集合
#include <stack> //スタック
#include <string> //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility> //pair
#include <vector> //可変長配列
using namespace std;
typedef long long ll;
// マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 // 10^12
#define MOD 10000007 // 10^9+7
#define MAXR 100000 // 10^5:最大のrange(素数列挙などで使用)
int main(void) {
int n;
cin >> n;
string s;
cin >> s;
vector<int> a, b, c;
REP(i, n) {
if (s[i] == 'R')
a.push_back(i + 1);
if (s[i] == 'G')
b.push_back(i + 1);
if (s[i] == 'B')
c.push_back(i + 1);
}
ll sum = a.size() * b.size() * c.size();
// とびとびのものを数えて引く
for (int i = 1; i < n; i++) {
for (int j = 0; j + i + i < n; j++) {
if (s[j] == s[j + i] || s[j + i] == s[j + i + i] || s[j] == s[j + i + i])
continue;
sum--;
}
}
cout << sum << endl;
return 0;
}
| replace | 48 | 82 | 48 | 56 | TLE | |
p02714 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
typedef char SINT8;
typedef short SINT16;
typedef int SINT32;
typedef long long SINT64;
typedef double DOUBLE;
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) > (0) ? (a) : -(a))
#define rep(i, a, b) for (SINT64(i) = SINT64(a); (i) < SINT64(b); (i)++)
#define rrep(i, a, b) for (SINT64(i) = SINT64(a); (i) >= SINT64(b); (i)--)
#define put(a) cout << (a) << endl
#define puts(a) cout << (a) << " "
#define putr(a) \
rep(testIncrement, 0, a.size()) { puts(a[testIncrement]); } \
cout << endl
#define INF 1000000001
#define MOD 1000000007
#define INF64 1000000000000000001
#define F first
#define S second
#define Pii pair<SINT32, SINT32>
#define Pll pair<SINT64, SINT64>
#define Piii pair<SINT32, pair<SINT32, SINT32>>
#define Plll pair<SINT64, pair<SINT64, SINT64>>
#define Vll(a, b, c) vector<vector<SINT64>> (a)((b),vector<SINT64>((c))
#define Vlll(a, b, c, d) vector<vector<vector<SINT64>>> (a)((b),vector<vector<SINT64>>((c),vector<SINT64>((d)))
using namespace std;
int main() {
SINT64 N;
cin >> N;
string s;
cin >> s;
vector<SINT64> r;
vector<SINT64> g;
vector<SINT64> b;
rep(i, 0, N) {
if (s[i] == 'R') {
r.emplace_back(i);
} else if (s[i] == 'G') {
g.emplace_back(i);
} else {
b.emplace_back(i);
}
}
priority_queue<SINT64, vector<SINT64>, greater<SINT64>> q; // 宣言
rep(i, 0, r.size()) {
rep(j, 0, g.size()) {
if (((r[i] + g[j]) % 2) == 0) {
q.push((r[i] + g[j]) / 2);
}
if (r[i] > g[j]) {
SINT64 buf = r[i] - g[j];
if ((r[i] + buf) < N) {
q.push(r[i] + buf);
}
if ((g[j] - buf) >= 0) {
q.push(g[j] - buf);
}
} else {
SINT64 buf = g[j] - r[i];
if ((g[j] + buf) < N) {
q.push(g[j] + buf);
}
if ((r[i] - buf) >= 0) {
q.push(r[i] - buf);
}
}
}
}
SINT64 ans = g.size() * r.size() * b.size();
SINT64 ct = q.top();
q.pop(); // 先頭データ削除
rep(i, 0, b.size()) {
while (1) {
if (ct == b[i]) {
ans--;
}
if (ct > b[i])
break;
if (q.size() == 0) {
put(ans);
return 0;
}
ct = q.top();
q.pop();
}
}
put(ans);
return 0;
}
// vector<vector<SINT64>> data(N,vector<SINT64>(N));
////2次元配列 vector<vector<vector<SINT64>>>
//data(N,vector<vector<SINT64>>(N,vector<SINT64>(N))); //3次元配列
// Vll(data,N,N); //2次元配列
// Vlll(data,N,N,N); //3次元配列
// sort(data.begin(),data.end());
// sort(data.begin(),data.end(),std::greater<SINT64>());
// __gcd(A,B);
// reverse(data.begin(),data.end());
// 関数へのvectorポインタ渡し
// void dfs(SINT64 poi, SINT64 d, vector<vector<Pll>>& data) {
// }
/* 複数条件ソート
bool sortcompare(Pll A, Pll B) {
if(A.F == B.F){
return A.S > B.S;
} else {
return A.F < B.F;
}
}
sort(data.begin(),data.end(),sortcompare);
*/
// タプル
// vector<tuple<SINT64,SINT64,SINT64>> edges;
// edges.emplace_back(a,b,c);
// cout << get<0>(edges[i]);
// cout << get<1>(edges[i]);
// cout << get<2>(edges[i]);
// sort(begin(edges), end(edges)); //ソート
// data.emplace_back(BUF); //後ろに追加
// data.erase(std::unique(data.begin(), data.end()), data.end());
// //ソート後に使用 同じ値を消す
// data.insert(data.begin() + X, 0); //X番目の要素に0を挿入
// 隣接リスト
// vector<vector<SINT64>> data(N);
// data[ A ].emplace_back( B );
// 両端キュー
// deque<SINT64> data;
// data.emplace_front(buf); //先頭挿入
// lower_boundは値がなければ最大値(.size())を返す
// posi = lower_bound(data.begin(),data.end(), X) - data.begin();
// // X以上を探す posi = lower_bound(data.begin(),data.end(),make_pair(X,0)) -
// data.begin(); //pair
/* 文字列回転
string N;
cin >> N;
N = N[N.length()-1] + N.substr(0,N.length()-1);
s = to_string(i); //ストリング変換
*/
/* 文字列合成
string N,M;
cin >> N >> M;
SINT64 ans = 0;
ans = stoi(N+M);
*/
/* 文字列変更
string s; cin >> s;
rep(i,0,s.length()) {
s[i] = (((s[i]-'A' + N) % 26) + 'A');
}
put(s);
*/
/*
//ワーシャルフロイド
vector<vector<SINT64>> dist(N,vector<SINT64>(N,INF64));
rep(i,0,N) {
dist[i][i] = 0;
}
rep(k,0,N) {
rep(i,0,N) {
rep(j,0,N) {
dist[i][j] = MIN(dist[i][j],
dist[i][k]+dist[k][j]);
}
}
}
*/
/* 優先度付きキュー
priority_queue<SINT64, vector<SINT64>, greater<SINT64>> bufq;
//小さいほうから取り出せる priority_queue<SINT64, vector<SINT64>> bufq;
//大きいほうから取り出せる
bufq.push(X); //X を挿入
bufq.top(); //先頭データ読み
bufq.pop(); //先頭データ削除
*/
/* キュー
queue<SINT64> bufq; //宣言
bufq.push(0); //挿入
bufq.front(); //先頭データ読み
bufq.pop(); //先頭データ削除
*/
/* SET コンテナ
set<SINT64> data;
data.insert(X); //X を挿入
data.erase(data.begin()); //先頭を削除
data.erase(--data.end()); //末尾を削除
*data.begin(); //先頭要素にアクセス
*data.rbegin(); //末尾要素にアクセス
//全表示
set<SINT64>::iterator it; //イテレータを用意
for(it = data.begin(); it != data.end(); it++) {
cout << *it << " ";
}
cout << endl;
//N番目を一部表示
set<SINT64>::iterator it; // イテレータを用意
it = data.begin();
rep (i,0,N) {
it++;
}
cout << *it << endl;
*/
/* map
map<string,SINT32> mp;
SINT32 N = 0;
SINT32 mx = 0;
cin >> N;
for (SINT32 i = 0; i < N; i++) {
string s;
cin >> s;
mp[s]++;
}
for(auto it=mp.begin();it!=mp.end();it++) {
mx=max(mx,it->second);
}
//abc146E
map<SINT64,SINT64> mp;
rep(i,0,N+1) {
ans += mp[rui[i]];
mp[rui[i]]++;
bufq.push(rui[i]);
if (bufq.size() == M) {
mp[bufq.front()]--;
bufq.pop();
}
}
*/
/*
//順列全表示
//sortしてからでないと全列挙にならない
sort(data.begin(),data.end());
do {
cout << buf << endl;
rep(i,0,R) {
cout << data[i] << " ";
}
cout << endl;
} while (next_permutation(data.begin(),data.end()));
*/
/* bit数数え上げ
SINT64 bits64(SINT64 bits)
{
bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}
*/
// bitシフトのLONG対応
// ans += (1L<<50);
// 桁指定表示
// ans = ans * M_PI;
// cout << setprecision(15) << ans << endl;
// 桁数0埋め
// cout << std::setfill('0') << std::right << std::setw(2) << 5; //05
// 2次元累積和
/*
vector<vector<SINT64>> data(H,vector<SINT64>(W));
vector<vector<SINT64>> rui(H+1,vector<SINT64>(W+1));
rep(i,0,H) {
rep(j,0,W) {
cin >> data[i][j];
}
}
rep(i,1,H+1) {
rep(j,1,W+1) {
rui[i][j] = data[i-1][j-1] + rui[i][j-1];
}
}
rep(i,1,H+1) {
rep(j,1,W+1) {
rui[i][j] += rui[i-1][j];
}
}
*/
// 逆元 コンビネーション
/*
SINT64 modpow(SINT64 a, SINT64 p) {
if (p == 0) return 1;
if (p % 2 == 0) {
//pが偶数の時
SINT64 halfP = p / 2;
SINT64 half = modpow(a, halfP);
//a^(p/2) をhalfとして、half*halfを計算
return half * half % MOD;
} else {
//pが奇数の時は、偶数にするために1減らす
return a * modpow(a, p - 1) % MOD;
}
}
SINT64 calcComb(SINT64 a, SINT64 b) {
SINT64 Mul = 1;
SINT64 Div = 1;
SINT64 ans = 0;
if (b > a - b) {
return calcComb(a, a - b);
}
rep(i,0,b) {
Mul *= (a - i);
Div *= (i + 1);
Mul %= MOD;
Div %= MOD;
}
ans = Mul * modpow(Div, MOD - 2) % MOD;
return ans;
}
*/
/* UNION FIND
class UnionFind {
public:
vector<SINT64> parent;
UnionFind(SINT64 N) {
parent = vector<SINT64>(N+10, -1); //少し多めに
}
SINT64 root(SINT64 A) {
if (parent[A] < 0) {
return A;
} else {
parent[A] = root(parent[A]);
return parent[A];
}
}
SINT64 size(SINT64 A) {
return parent[root(A)] * (-1);
}
bool judge(SINT64 A, SINT64 B) {
A = root(A);
B = root(B);
if (A == B) {
return true; //同じグループ
} else {
return false; //違うグループ
}
}
void connect(SINT64 A, SINT64 B) {
A = root(A);
B = root(B);
if (A != B) {
if (size(A) < size(B)) {
swap(A, B);
}
parent[A] += parent[B];
parent[B] = A;
}
}
};
UnionFind uni(N);
*/
/* セグ木
class SegTree {
private:
SINT64 size;
vector<SINT64> node;
SINT64 jugdement(SINT64 a, SINT64 b) {
SINT64 ans = 0;
ans = a+b;
return ans;
}
public:
//コンストラクタ
SegTree(vector<SINT64> data) {
SINT64 ori_size;
ori_size = data.size();
size = 1;
while (size < ori_size) {
size *= 2;
}
node.resize(2*size-1, 0);
rep(i,0,ori_size) {
node[size-1+i] = data[i];
}
rrep(i,size-2,0) {
node[i] = jugdement(node[2*i+1], node[2*i+2]);
}
}
//データ更新
void update(SINT64 x, SINT64 val) {
x += (size - 1);
node[x] = val+node[x];
while(x > 0) {
x = (x - 1) / 2;
node[x] = jugdement(node[2*x+1], node[2*x+2]);
}
}
//データ取得 [a,b)
SINT64 getdata(SINT64 a, SINT64 b, SINT64 k = 0, SINT64 l = 0, SINT64 r
= -1) { if (r < 0) { r = size;
}
//要求範囲外
if ((r <= a) || (b <= l)) {
return 0;
}
//完全要求区間内
if ((a <= l) && (r <= b)) {
return node[k];
}
SINT64 vl = getdata(a, b, 2*k+1, l, (l+r)/2);
SINT64 vr = getdata(a, b, 2*k+2, (l+r)/2, r);
return jugdement(vl, vr);
}
//表示
void disp() {
rep(i,0,size) {
puts(node[size-1+i]);
} cout << endl;
}
void alldisp() {
SINT64 cnt = 0;
SINT64 end = 2;
while (1) {
puts(node[cnt]);
if (cnt == end-2) {
end *= 2;
cout << endl;
}
cnt++;
if (cnt == size*2-1) {
break;
}
}
}
};
SegTree seg(N);
*/
/* 最大フロー最小カット
class Dinic {
struct EDGE {
SINT64 to;
SINT64 cap;
SINT64 rev;
};
vector<vector<EDGE>> G;
vector<SINT64> level;
vector<SINT64> root;
SINT64 N;
public:
Dinic(SINT64 n) {
N = n;
G.resize(N);
level.resize(N);
}
void add(SINT64 a, SINT64 b, SINT64 cap) {
G[a].emplace_back((EDGE){b,cap,(SINT64)G[b].size()});
G[b].emplace_back((EDGE){a,0,(SINT64)G[a].size()-1});
}
void bfs(SINT64 s) {
level[s] = 0;
queue<SINT64> q;
q.push(s);
while(q.size() != 0) {
SINT64 buf = q.front();
q.pop();
rep(i,0,G[buf].size()) {
EDGE now = G[buf][i];
if ((now.cap > 0) && (level[now.to] == -1)) {
level[now.to] = level[buf]+1;
q.push(now.to);
}
}
}
}
SINT64 dfs(SINT64 now, SINT64 g, SINT64 flow) {
if (now == g) return flow;
rep(i,root[now],G[now].size()) {
EDGE buf = G[now][i];
root[now] = i;
//dsf進捗更新 if ((buf.cap > 0) && (level[buf.to] > level[now])) { SINT64 mi =
MIN(buf.cap,flow); SINT64 nowf = dfs(buf.to,g,mi); if (nowf > 0) { G[now][i].cap
-= nowf; //順経路に容量削減 G[buf.to][buf.rev].cap +=
nowf; //逆経路に容量追加 return nowf;
//今回探索のFLOW追加数
}
}
}
return 0;
}
SINT64 act(SINT64 s, SINT64 g) {
SINT64 cnt = 0;
//最大FLOWカウント if (s == g) return cnt;
//スタート=ゴールは例外 while(1) { level.assign(N,-1);
//sからの最短距離初期化 root.assign(N,0);
//dsf進捗初期化 bfs(s); if (level[g] == -1) break;
//gへ到達不可 while(1) { SINT64 flow; flow = dfs(s,g,INF64); if (flow == 0)
break; cnt += flow;
}
}
return cnt;
}
};
*/
/* ダイクストラ
class Dijkstra {
vector<vector<Pll>> G;
vector<SINT64> dist;
public:
Dijkstra(SINT64 n) {
G.resize(n);
dist.resize(n, INF64);
}
void add(SINT64 a, SINT64 b, SINT64 cost) {
G[a].emplace_back(Pll(b,cost));
}
void form(SINT64 s) {
priority_queue<Pll, vector<Pll>, greater<Pll>> q;
q.push(Pll(0,s));
//cost,位置 while(q.size() != 0) { Pll now = q.top(); q.pop(); if (dist[now.S]
== INF64) { dist[now.S] = now.F; rep(i,0,G[now.S].size()) { Pll buf =
G[now.S][i]; if (dist[buf.F] == INF64) { q.push(Pll(buf.S+now.F,buf.F));
}
}
}
}
}
//form()で構築したsからの距離を返す
SINT64 get_dist(SINT64 a) {
if (dist[a] == INF64) {
return -1; //到達不可
} else {
return dist[a];
}
}
};
*/
/* LCA
class Lca {
vector<vector<SINT64>> G;
vector<vector<SINT64>> D; //ダブリング
vector<SINT64> depth;
SINT64 N;
SINT64 LOG_N;
public:
Lca(SINT64 n) {
N = n;
LOG_N = floor(log2(N));
G.resize(N);
D.resize(N);
depth.resize(N,-1);
}
void add(SINT64 a, SINT64 b) {
G[a].emplace_back(b);
G[b].emplace_back(a);
}
void bfs(SINT64 s) {
depth[s] = 0;
D[s].emplace_back(-1);
queue<SINT64> q;
q.push(s);
while(q.size() != 0) {
SINT64 now = q.front();
q.pop();
rep(i,0,G[now].size()) {
SINT64 next = G[now][i];
if (depth[next] == -1) {
depth[next] = depth[now]+1;
D[next].emplace_back(now);
q.push(next);
}
}
}
}
//頂点のsからのダブリング構築
void form(SINT64 s) {
bfs(s);
rep(i,1,LOG_N+1) {
rep(j,0,N) {
SINT64 buf = D[j][i-1];
if (buf == -1) {
D[j].emplace_back(-1);
} else {
D[j].emplace_back(D[buf][i-1]);
}
}
}
}
//aのx上の頂点を求める
SINT64 get(SINT64 a, SINT64 x) {
rrep(i,LOG_N,0) {
if (((x >> i) & 1) == 1) {
a = D[a][i];
if (a == -1) return -1;
}
}
return a;
}
//aとbの共通祖先を求める
SINT64 get_lca(SINT64 a, SINT64 b) {
if (depth[a] < depth[b]) swap(a,b);
SINT64 diff = depth[a] - depth[b];
a = get(a,diff);
//aのx上の頂点を求める if (a == b) return a; rrep(i,LOG_N,0) { if (D[a][i] !=
D[b][i]) { a = D[a][i]; b = D[b][i];
}
}
return D[a][0];
}
//aとbの共通祖先までの距離の合計を求める
SINT64 get_dist(SINT64 a, SINT64 b) {
SINT64 buf = get_lca(a,b);
return depth[a] + depth[b] - depth[buf]*2;
}
};
*/
/* ベルマンフォード
class Bellman {
struct EDGE {
SINT64 from;
SINT64 to;
SINT64 cost;
};
vector<EDGE> edges;
vector<SINT64> dist;
SINT64 N;
public:
Bellman(SINT64 n) {
N = n;
dist.resize(n, INF64);
}
void add(SINT64 from, SINT64 to, SINT64 cost) {
edges.emplace_back((EDGE){from,to,cost});
}
//sで構築したt迄の距離取得
SINT64 get_dist(SINT64 t) {
//到達不可はINF64
return dist[t];
}
//構築
//負の閉路無し : 0
//負の閉路有り : 1
//負の閉路有るが目的地gの更新は停止 : 2
SINT64 form(SINT64 s, SINT64 g) {
dist[s] = 0;
SINT64 cnt = 0;
SINT64 check = 0;
while(1) {
SINT64 renew = 0;
rep(i,0,edges.size()) {
EDGE e = edges[i];
if (dist[e.from] != INF64) {
if (dist[e.to] > dist[e.from] + e.cost)
{ renew = 1; dist[e.to] = dist[e.from] + e.cost;
}
}
}
if (renew == 0) return 0;
//N回更新後のgの距離と 2N回更新後のgの距離を比較
if (cnt == N) check = dist[g];
if (cnt > 2*N) {
if (check == dist[g]) return 2;
return 1;
}
cnt++;
}
}
};
*/
/*コンビネーション
class Comb {
vector<SINT64> base;
SINT64 N;
public:
Comb (SINT64 n) {
N = n+5;
base.resize(N);
base[0] = 1;
rep(i,1,N) {
base[i] = base[i-1]*i;
base[i] %= MOD;
}
}
SINT64 get_comb(SINT64 a, SINT64 b) {
SINT64 ans = 0;
SINT64 aa = base[a] * modpow(base[a-b], MOD - 2) % MOD;
ans = aa * modpow(base[b], MOD - 2) % MOD;
return ans;
}
SINT64 modpow(SINT64 a, SINT64 p) {
if (p == 0) return 1;
if (p % 2 == 0) {
SINT64 halfP = p / 2;
SINT64 half = modpow(a, halfP);
return half * half % MOD;
} else {
return a * modpow(a, p - 1) % MOD;
}
}
};
*/
/* SUFFIX ARRAY
class SuffixArray {
private:
vector<string> array; // サフィックスアレイ
vector<SINT64> lcp; // LCP
vector<SINT64> sais; // SA IS
string str;
public:
// コンストラクタ
SuffixArray (string s) {
str = s;
vector<SINT64> Vstr;
rep(i,0,str.length()) {
Vstr.emplace_back(str[i]);
}
sais_act(Vstr, sais, 255); // SAIS実行
// lcp_act(); //
隣り合うSUFFIXの先頭から同じ長さを算出
// suffix array 文字列作成
// array.resize(str.length());
// rep(i,0,array.size()) {
// array[i] = str.substr(sais[i]);
// }
// rep(i,0,array.size()) {put(array[i]);} // 表示用
}
// LCP作成
void lcp_act(void) {
lcp.resize(str.length());
vector<SINT64> buffer(str.length());
rep(i,0,str.length()) {
buffer[sais[i]] = i;
}
SINT64 cnt = 0;
rep(i,0,str.length()) {
if (buffer[i] >= str.length()-1) {
cnt = 0;
} else {
SINT64 a = buffer[i];
SINT64 b = buffer[i]+1;
while(1) {
if (cnt >= str.length() - sais[a])
break; if (cnt >= str.length() - sais[a]) break;
if (str[sais[a]+cnt] ==
str[sais[b]+cnt]) { cnt++; } else { break;
}
}
}
lcp[buffer[i]] = cnt;
if (cnt != 0) cnt--;
}
}
// 引数の文字列が何個含まれるか算出
SINT64 get_cnt(string t) {
SINT64 low,high;
SINT64 L,R;
L = -1;
R = str.length();
while(R-L > 1) {
SINT64 M = (R+L)/2;
string buf = str.substr(sais[M]);
if (buf.length() > t.length()) {
buf = buf.substr(0,t.length());
}
if (buf > t) {R = M;} else {L = M;}
}
high = R;
L = -1;
R = str.length();
while(R-L > 1) {
SINT64 M = (R+L)/2;
string buf = str.substr(sais[M]);
if (buf >= t) {R = M;} else {L = M;}
}
low = R;
return high - low;
}
// SAIS実行
void sais_act(vector<SINT64>& Vstr, vector<SINT64>& r_sais, SINT64 type)
{ Vstr.push_back(0); //
番兵追加 vector<SINT64> lms_seed; // LMS
ソート前 vector<SINT64> lms_sort; // LMS
ソート後 vector<SINT64> lms_long(Vstr.size(),0); // LMS 長さ
vector<SINT64> lms_type(Vstr.size(),1); // 0:L 1:S 2:LMS
vector<SINT64> lms_posi(Vstr.size(),-1); //
LMS内での位置
SINT64 len = 0;
// L S LMS判定 初期値は全てS
rrep(i,Vstr.size()-2,0) {
len++;
if (Vstr[i] > Vstr[i+1]) {
lms_type[i] = 0;
// L if (lms_type[i+1] == 1) {
lms_type[i+1] = 2;
// LMS lms_long[i+1] = len; // LMSの長さ格納 len = 1;
}
}
if (Vstr[i] == Vstr[i+1]) lms_type[i] = lms_type[i+1];
// 右と同じ
}
SINT64 cnt = 0;
rep(i,0,Vstr.size()) {
if (lms_type[i] == 2) lms_seed.emplace_back(i);
if (lms_type[i] == 2) lms_posi[i] = cnt++;
}
// Induced Sort初回
vector<SINT64> bucket;
// Induced Sort初回結果格納用 induced_sort(Vstr, lms_seed, bucket, lms_type,
type);
// lms_sortにLMSのソートを格納
rrep(i,Vstr.size()-1,0) {
if ((bucket[i] != -1) && (lms_type[bucket[i]] == 2)) {
lms_sort.emplace_back(bucket[i]);
}
}
SINT64 ok = 0; // 再帰必要性判定 SINT64 rank = 1;
// 再帰用文字 vector<SINT64> next(lms_sort.size(), 1); // 再帰用文字列
rrep(i,lms_sort.size()-2,0) {
SINT64 A = lms_long[lms_sort[i]];
SINT64 B = lms_long[lms_sort[i+1]];
if (A == B) {
SINT64 ck = 0;
rep(j,0,A) {
if (Vstr[lms_sort[i]+j] != Vstr[lms_sort[i+1]+j]) {
ck = 1;
break;
}
}
if (ck == 0) {
ok = 1; // 再帰必要
} else {
rank++;
}
} else {
rank++;
}
next[lms_posi[lms_sort[i]]] = rank;
}
if (ok == 1) {
vector<SINT64> recursive;
sais_act(next, recursive, rank+1);
rep(i,0,recursive.size()) {
lms_sort[recursive.size()-i-1] =
lms_seed[recursive[i]];
}
}
// SORT済みLMSでInduced Sorting
r_sais.resize(Vstr.size(),-1);
induced_sort(Vstr, lms_sort, r_sais, lms_type, type);
r_sais.erase(r_sais.begin()); // 番兵削除
}
// induced_sort
void induced_sort(vector<SINT64>& Vstr, vector<SINT64>& seed,
vector<SINT64>& bucket_sort, vector<SINT64>& lms_type, SINT64 type) {
vector<SINT64> bucket_cnt(type,0); //
バケット 文字種ごとの数 vector<SINT64> bucket_st(type,0);
// バケット 文字種の開始位置
vector<SINT64> bucket_end(type,0); //
バケット 文字種の終了位置 vector<SINT64> bucket_pre(Vstr.size(),-1); //
バケット 初回格納用 vector<SINT64> cnt1(type,0); vector<SINT64> cnt2(type,0);
vector<SINT64> cnt3(type,0);
bucket_sort.resize(Vstr.size(),-1);
// バケットソート位置作成
rep(i,0,Vstr.size()) bucket_cnt[Vstr[i]]++;
// 個数作成
rep(i,1,type) bucket_st[i] = bucket_st[i-1] + bucket_cnt[i-1];
// 開始位置
rep(i,0,type) bucket_end[i] = bucket_st[i] + bucket_cnt[i]-1;
// 終了位置
// LMSをbucket_preに格納
rep(i,0,seed.size()) {
SINT64 no = seed[i];
bucket_pre[bucket_end[Vstr[no]] - cnt1[Vstr[no]]] = no;
cnt1[Vstr[no]]++;
}
// Lをbucket_sortに格納
rep(i,0,Vstr.size()) {
if ((bucket_pre[i] != -1) && (bucket_pre[i] != 0)) {
if (lms_type[bucket_pre[i]-1] == 0) {
// -1がLの場合 SINT64 buf = Vstr[bucket_pre[i]-1]; bucket_pre [bucket_st[buf] +
cnt2[buf]] = bucket_pre[i]-1; bucket_sort[bucket_st[buf] + cnt2[buf]] =
bucket_pre[i]-1; cnt2[buf]++;
}
}
}
// Sをbucket_sortに格納
bucket_sort[0] = Vstr.size()-1;
// 番兵追加 rrep(i,Vstr.size()-1,0) { if ((bucket_sort[i] != -1) &&
(bucket_sort[i] != 0)) { if (lms_type[bucket_sort[i]-1] != 0) { //
-1がS(LMS)の場合 SINT64 buf = Vstr[bucket_sort[i]-1];
bucket_sort[bucket_end[buf] - cnt3[buf]]
= bucket_sort[i]-1; cnt3[buf]++;
}
}
}
}
};
*/
| #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
typedef char SINT8;
typedef short SINT16;
typedef int SINT32;
typedef long long SINT64;
typedef double DOUBLE;
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) > (0) ? (a) : -(a))
#define rep(i, a, b) for (SINT64(i) = SINT64(a); (i) < SINT64(b); (i)++)
#define rrep(i, a, b) for (SINT64(i) = SINT64(a); (i) >= SINT64(b); (i)--)
#define put(a) cout << (a) << endl
#define puts(a) cout << (a) << " "
#define putr(a) \
rep(testIncrement, 0, a.size()) { puts(a[testIncrement]); } \
cout << endl
#define INF 1000000001
#define MOD 1000000007
#define INF64 1000000000000000001
#define F first
#define S second
#define Pii pair<SINT32, SINT32>
#define Pll pair<SINT64, SINT64>
#define Piii pair<SINT32, pair<SINT32, SINT32>>
#define Plll pair<SINT64, pair<SINT64, SINT64>>
#define Vll(a, b, c) vector<vector<SINT64>> (a)((b),vector<SINT64>((c))
#define Vlll(a, b, c, d) vector<vector<vector<SINT64>>> (a)((b),vector<vector<SINT64>>((c),vector<SINT64>((d)))
using namespace std;
int main() {
SINT64 N;
cin >> N;
string s;
cin >> s;
vector<SINT64> r;
vector<SINT64> g;
vector<SINT64> b;
rep(i, 0, N) {
if (s[i] == 'R') {
r.emplace_back(i);
} else if (s[i] == 'G') {
g.emplace_back(i);
} else {
b.emplace_back(i);
}
}
priority_queue<SINT64, vector<SINT64>, greater<SINT64>> q; // 宣言
rep(i, 0, r.size()) {
rep(j, 0, g.size()) {
if (((r[i] + g[j]) % 2) == 0) {
q.push((r[i] + g[j]) / 2);
}
if (r[i] > g[j]) {
SINT64 buf = r[i] - g[j];
if ((r[i] + buf) < N) {
q.push(r[i] + buf);
}
if ((g[j] - buf) >= 0) {
q.push(g[j] - buf);
}
} else {
SINT64 buf = g[j] - r[i];
if ((g[j] + buf) < N) {
q.push(g[j] + buf);
}
if ((r[i] - buf) >= 0) {
q.push(r[i] - buf);
}
}
}
}
SINT64 ans = g.size() * r.size() * b.size();
if (q.size() == 0) {
put(ans);
return 0;
}
SINT64 ct = q.top();
q.pop(); // 先頭データ削除
rep(i, 0, b.size()) {
while (1) {
if (ct == b[i]) {
ans--;
}
if (ct > b[i])
break;
if (q.size() == 0) {
put(ans);
return 0;
}
ct = q.top();
q.pop();
}
}
put(ans);
return 0;
}
// vector<vector<SINT64>> data(N,vector<SINT64>(N));
////2次元配列 vector<vector<vector<SINT64>>>
//data(N,vector<vector<SINT64>>(N,vector<SINT64>(N))); //3次元配列
// Vll(data,N,N); //2次元配列
// Vlll(data,N,N,N); //3次元配列
// sort(data.begin(),data.end());
// sort(data.begin(),data.end(),std::greater<SINT64>());
// __gcd(A,B);
// reverse(data.begin(),data.end());
// 関数へのvectorポインタ渡し
// void dfs(SINT64 poi, SINT64 d, vector<vector<Pll>>& data) {
// }
/* 複数条件ソート
bool sortcompare(Pll A, Pll B) {
if(A.F == B.F){
return A.S > B.S;
} else {
return A.F < B.F;
}
}
sort(data.begin(),data.end(),sortcompare);
*/
// タプル
// vector<tuple<SINT64,SINT64,SINT64>> edges;
// edges.emplace_back(a,b,c);
// cout << get<0>(edges[i]);
// cout << get<1>(edges[i]);
// cout << get<2>(edges[i]);
// sort(begin(edges), end(edges)); //ソート
// data.emplace_back(BUF); //後ろに追加
// data.erase(std::unique(data.begin(), data.end()), data.end());
// //ソート後に使用 同じ値を消す
// data.insert(data.begin() + X, 0); //X番目の要素に0を挿入
// 隣接リスト
// vector<vector<SINT64>> data(N);
// data[ A ].emplace_back( B );
// 両端キュー
// deque<SINT64> data;
// data.emplace_front(buf); //先頭挿入
// lower_boundは値がなければ最大値(.size())を返す
// posi = lower_bound(data.begin(),data.end(), X) - data.begin();
// // X以上を探す posi = lower_bound(data.begin(),data.end(),make_pair(X,0)) -
// data.begin(); //pair
/* 文字列回転
string N;
cin >> N;
N = N[N.length()-1] + N.substr(0,N.length()-1);
s = to_string(i); //ストリング変換
*/
/* 文字列合成
string N,M;
cin >> N >> M;
SINT64 ans = 0;
ans = stoi(N+M);
*/
/* 文字列変更
string s; cin >> s;
rep(i,0,s.length()) {
s[i] = (((s[i]-'A' + N) % 26) + 'A');
}
put(s);
*/
/*
//ワーシャルフロイド
vector<vector<SINT64>> dist(N,vector<SINT64>(N,INF64));
rep(i,0,N) {
dist[i][i] = 0;
}
rep(k,0,N) {
rep(i,0,N) {
rep(j,0,N) {
dist[i][j] = MIN(dist[i][j],
dist[i][k]+dist[k][j]);
}
}
}
*/
/* 優先度付きキュー
priority_queue<SINT64, vector<SINT64>, greater<SINT64>> bufq;
//小さいほうから取り出せる priority_queue<SINT64, vector<SINT64>> bufq;
//大きいほうから取り出せる
bufq.push(X); //X を挿入
bufq.top(); //先頭データ読み
bufq.pop(); //先頭データ削除
*/
/* キュー
queue<SINT64> bufq; //宣言
bufq.push(0); //挿入
bufq.front(); //先頭データ読み
bufq.pop(); //先頭データ削除
*/
/* SET コンテナ
set<SINT64> data;
data.insert(X); //X を挿入
data.erase(data.begin()); //先頭を削除
data.erase(--data.end()); //末尾を削除
*data.begin(); //先頭要素にアクセス
*data.rbegin(); //末尾要素にアクセス
//全表示
set<SINT64>::iterator it; //イテレータを用意
for(it = data.begin(); it != data.end(); it++) {
cout << *it << " ";
}
cout << endl;
//N番目を一部表示
set<SINT64>::iterator it; // イテレータを用意
it = data.begin();
rep (i,0,N) {
it++;
}
cout << *it << endl;
*/
/* map
map<string,SINT32> mp;
SINT32 N = 0;
SINT32 mx = 0;
cin >> N;
for (SINT32 i = 0; i < N; i++) {
string s;
cin >> s;
mp[s]++;
}
for(auto it=mp.begin();it!=mp.end();it++) {
mx=max(mx,it->second);
}
//abc146E
map<SINT64,SINT64> mp;
rep(i,0,N+1) {
ans += mp[rui[i]];
mp[rui[i]]++;
bufq.push(rui[i]);
if (bufq.size() == M) {
mp[bufq.front()]--;
bufq.pop();
}
}
*/
/*
//順列全表示
//sortしてからでないと全列挙にならない
sort(data.begin(),data.end());
do {
cout << buf << endl;
rep(i,0,R) {
cout << data[i] << " ";
}
cout << endl;
} while (next_permutation(data.begin(),data.end()));
*/
/* bit数数え上げ
SINT64 bits64(SINT64 bits)
{
bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}
*/
// bitシフトのLONG対応
// ans += (1L<<50);
// 桁指定表示
// ans = ans * M_PI;
// cout << setprecision(15) << ans << endl;
// 桁数0埋め
// cout << std::setfill('0') << std::right << std::setw(2) << 5; //05
// 2次元累積和
/*
vector<vector<SINT64>> data(H,vector<SINT64>(W));
vector<vector<SINT64>> rui(H+1,vector<SINT64>(W+1));
rep(i,0,H) {
rep(j,0,W) {
cin >> data[i][j];
}
}
rep(i,1,H+1) {
rep(j,1,W+1) {
rui[i][j] = data[i-1][j-1] + rui[i][j-1];
}
}
rep(i,1,H+1) {
rep(j,1,W+1) {
rui[i][j] += rui[i-1][j];
}
}
*/
// 逆元 コンビネーション
/*
SINT64 modpow(SINT64 a, SINT64 p) {
if (p == 0) return 1;
if (p % 2 == 0) {
//pが偶数の時
SINT64 halfP = p / 2;
SINT64 half = modpow(a, halfP);
//a^(p/2) をhalfとして、half*halfを計算
return half * half % MOD;
} else {
//pが奇数の時は、偶数にするために1減らす
return a * modpow(a, p - 1) % MOD;
}
}
SINT64 calcComb(SINT64 a, SINT64 b) {
SINT64 Mul = 1;
SINT64 Div = 1;
SINT64 ans = 0;
if (b > a - b) {
return calcComb(a, a - b);
}
rep(i,0,b) {
Mul *= (a - i);
Div *= (i + 1);
Mul %= MOD;
Div %= MOD;
}
ans = Mul * modpow(Div, MOD - 2) % MOD;
return ans;
}
*/
/* UNION FIND
class UnionFind {
public:
vector<SINT64> parent;
UnionFind(SINT64 N) {
parent = vector<SINT64>(N+10, -1); //少し多めに
}
SINT64 root(SINT64 A) {
if (parent[A] < 0) {
return A;
} else {
parent[A] = root(parent[A]);
return parent[A];
}
}
SINT64 size(SINT64 A) {
return parent[root(A)] * (-1);
}
bool judge(SINT64 A, SINT64 B) {
A = root(A);
B = root(B);
if (A == B) {
return true; //同じグループ
} else {
return false; //違うグループ
}
}
void connect(SINT64 A, SINT64 B) {
A = root(A);
B = root(B);
if (A != B) {
if (size(A) < size(B)) {
swap(A, B);
}
parent[A] += parent[B];
parent[B] = A;
}
}
};
UnionFind uni(N);
*/
/* セグ木
class SegTree {
private:
SINT64 size;
vector<SINT64> node;
SINT64 jugdement(SINT64 a, SINT64 b) {
SINT64 ans = 0;
ans = a+b;
return ans;
}
public:
//コンストラクタ
SegTree(vector<SINT64> data) {
SINT64 ori_size;
ori_size = data.size();
size = 1;
while (size < ori_size) {
size *= 2;
}
node.resize(2*size-1, 0);
rep(i,0,ori_size) {
node[size-1+i] = data[i];
}
rrep(i,size-2,0) {
node[i] = jugdement(node[2*i+1], node[2*i+2]);
}
}
//データ更新
void update(SINT64 x, SINT64 val) {
x += (size - 1);
node[x] = val+node[x];
while(x > 0) {
x = (x - 1) / 2;
node[x] = jugdement(node[2*x+1], node[2*x+2]);
}
}
//データ取得 [a,b)
SINT64 getdata(SINT64 a, SINT64 b, SINT64 k = 0, SINT64 l = 0, SINT64 r
= -1) { if (r < 0) { r = size;
}
//要求範囲外
if ((r <= a) || (b <= l)) {
return 0;
}
//完全要求区間内
if ((a <= l) && (r <= b)) {
return node[k];
}
SINT64 vl = getdata(a, b, 2*k+1, l, (l+r)/2);
SINT64 vr = getdata(a, b, 2*k+2, (l+r)/2, r);
return jugdement(vl, vr);
}
//表示
void disp() {
rep(i,0,size) {
puts(node[size-1+i]);
} cout << endl;
}
void alldisp() {
SINT64 cnt = 0;
SINT64 end = 2;
while (1) {
puts(node[cnt]);
if (cnt == end-2) {
end *= 2;
cout << endl;
}
cnt++;
if (cnt == size*2-1) {
break;
}
}
}
};
SegTree seg(N);
*/
/* 最大フロー最小カット
class Dinic {
struct EDGE {
SINT64 to;
SINT64 cap;
SINT64 rev;
};
vector<vector<EDGE>> G;
vector<SINT64> level;
vector<SINT64> root;
SINT64 N;
public:
Dinic(SINT64 n) {
N = n;
G.resize(N);
level.resize(N);
}
void add(SINT64 a, SINT64 b, SINT64 cap) {
G[a].emplace_back((EDGE){b,cap,(SINT64)G[b].size()});
G[b].emplace_back((EDGE){a,0,(SINT64)G[a].size()-1});
}
void bfs(SINT64 s) {
level[s] = 0;
queue<SINT64> q;
q.push(s);
while(q.size() != 0) {
SINT64 buf = q.front();
q.pop();
rep(i,0,G[buf].size()) {
EDGE now = G[buf][i];
if ((now.cap > 0) && (level[now.to] == -1)) {
level[now.to] = level[buf]+1;
q.push(now.to);
}
}
}
}
SINT64 dfs(SINT64 now, SINT64 g, SINT64 flow) {
if (now == g) return flow;
rep(i,root[now],G[now].size()) {
EDGE buf = G[now][i];
root[now] = i;
//dsf進捗更新 if ((buf.cap > 0) && (level[buf.to] > level[now])) { SINT64 mi =
MIN(buf.cap,flow); SINT64 nowf = dfs(buf.to,g,mi); if (nowf > 0) { G[now][i].cap
-= nowf; //順経路に容量削減 G[buf.to][buf.rev].cap +=
nowf; //逆経路に容量追加 return nowf;
//今回探索のFLOW追加数
}
}
}
return 0;
}
SINT64 act(SINT64 s, SINT64 g) {
SINT64 cnt = 0;
//最大FLOWカウント if (s == g) return cnt;
//スタート=ゴールは例外 while(1) { level.assign(N,-1);
//sからの最短距離初期化 root.assign(N,0);
//dsf進捗初期化 bfs(s); if (level[g] == -1) break;
//gへ到達不可 while(1) { SINT64 flow; flow = dfs(s,g,INF64); if (flow == 0)
break; cnt += flow;
}
}
return cnt;
}
};
*/
/* ダイクストラ
class Dijkstra {
vector<vector<Pll>> G;
vector<SINT64> dist;
public:
Dijkstra(SINT64 n) {
G.resize(n);
dist.resize(n, INF64);
}
void add(SINT64 a, SINT64 b, SINT64 cost) {
G[a].emplace_back(Pll(b,cost));
}
void form(SINT64 s) {
priority_queue<Pll, vector<Pll>, greater<Pll>> q;
q.push(Pll(0,s));
//cost,位置 while(q.size() != 0) { Pll now = q.top(); q.pop(); if (dist[now.S]
== INF64) { dist[now.S] = now.F; rep(i,0,G[now.S].size()) { Pll buf =
G[now.S][i]; if (dist[buf.F] == INF64) { q.push(Pll(buf.S+now.F,buf.F));
}
}
}
}
}
//form()で構築したsからの距離を返す
SINT64 get_dist(SINT64 a) {
if (dist[a] == INF64) {
return -1; //到達不可
} else {
return dist[a];
}
}
};
*/
/* LCA
class Lca {
vector<vector<SINT64>> G;
vector<vector<SINT64>> D; //ダブリング
vector<SINT64> depth;
SINT64 N;
SINT64 LOG_N;
public:
Lca(SINT64 n) {
N = n;
LOG_N = floor(log2(N));
G.resize(N);
D.resize(N);
depth.resize(N,-1);
}
void add(SINT64 a, SINT64 b) {
G[a].emplace_back(b);
G[b].emplace_back(a);
}
void bfs(SINT64 s) {
depth[s] = 0;
D[s].emplace_back(-1);
queue<SINT64> q;
q.push(s);
while(q.size() != 0) {
SINT64 now = q.front();
q.pop();
rep(i,0,G[now].size()) {
SINT64 next = G[now][i];
if (depth[next] == -1) {
depth[next] = depth[now]+1;
D[next].emplace_back(now);
q.push(next);
}
}
}
}
//頂点のsからのダブリング構築
void form(SINT64 s) {
bfs(s);
rep(i,1,LOG_N+1) {
rep(j,0,N) {
SINT64 buf = D[j][i-1];
if (buf == -1) {
D[j].emplace_back(-1);
} else {
D[j].emplace_back(D[buf][i-1]);
}
}
}
}
//aのx上の頂点を求める
SINT64 get(SINT64 a, SINT64 x) {
rrep(i,LOG_N,0) {
if (((x >> i) & 1) == 1) {
a = D[a][i];
if (a == -1) return -1;
}
}
return a;
}
//aとbの共通祖先を求める
SINT64 get_lca(SINT64 a, SINT64 b) {
if (depth[a] < depth[b]) swap(a,b);
SINT64 diff = depth[a] - depth[b];
a = get(a,diff);
//aのx上の頂点を求める if (a == b) return a; rrep(i,LOG_N,0) { if (D[a][i] !=
D[b][i]) { a = D[a][i]; b = D[b][i];
}
}
return D[a][0];
}
//aとbの共通祖先までの距離の合計を求める
SINT64 get_dist(SINT64 a, SINT64 b) {
SINT64 buf = get_lca(a,b);
return depth[a] + depth[b] - depth[buf]*2;
}
};
*/
/* ベルマンフォード
class Bellman {
struct EDGE {
SINT64 from;
SINT64 to;
SINT64 cost;
};
vector<EDGE> edges;
vector<SINT64> dist;
SINT64 N;
public:
Bellman(SINT64 n) {
N = n;
dist.resize(n, INF64);
}
void add(SINT64 from, SINT64 to, SINT64 cost) {
edges.emplace_back((EDGE){from,to,cost});
}
//sで構築したt迄の距離取得
SINT64 get_dist(SINT64 t) {
//到達不可はINF64
return dist[t];
}
//構築
//負の閉路無し : 0
//負の閉路有り : 1
//負の閉路有るが目的地gの更新は停止 : 2
SINT64 form(SINT64 s, SINT64 g) {
dist[s] = 0;
SINT64 cnt = 0;
SINT64 check = 0;
while(1) {
SINT64 renew = 0;
rep(i,0,edges.size()) {
EDGE e = edges[i];
if (dist[e.from] != INF64) {
if (dist[e.to] > dist[e.from] + e.cost)
{ renew = 1; dist[e.to] = dist[e.from] + e.cost;
}
}
}
if (renew == 0) return 0;
//N回更新後のgの距離と 2N回更新後のgの距離を比較
if (cnt == N) check = dist[g];
if (cnt > 2*N) {
if (check == dist[g]) return 2;
return 1;
}
cnt++;
}
}
};
*/
/*コンビネーション
class Comb {
vector<SINT64> base;
SINT64 N;
public:
Comb (SINT64 n) {
N = n+5;
base.resize(N);
base[0] = 1;
rep(i,1,N) {
base[i] = base[i-1]*i;
base[i] %= MOD;
}
}
SINT64 get_comb(SINT64 a, SINT64 b) {
SINT64 ans = 0;
SINT64 aa = base[a] * modpow(base[a-b], MOD - 2) % MOD;
ans = aa * modpow(base[b], MOD - 2) % MOD;
return ans;
}
SINT64 modpow(SINT64 a, SINT64 p) {
if (p == 0) return 1;
if (p % 2 == 0) {
SINT64 halfP = p / 2;
SINT64 half = modpow(a, halfP);
return half * half % MOD;
} else {
return a * modpow(a, p - 1) % MOD;
}
}
};
*/
/* SUFFIX ARRAY
class SuffixArray {
private:
vector<string> array; // サフィックスアレイ
vector<SINT64> lcp; // LCP
vector<SINT64> sais; // SA IS
string str;
public:
// コンストラクタ
SuffixArray (string s) {
str = s;
vector<SINT64> Vstr;
rep(i,0,str.length()) {
Vstr.emplace_back(str[i]);
}
sais_act(Vstr, sais, 255); // SAIS実行
// lcp_act(); //
隣り合うSUFFIXの先頭から同じ長さを算出
// suffix array 文字列作成
// array.resize(str.length());
// rep(i,0,array.size()) {
// array[i] = str.substr(sais[i]);
// }
// rep(i,0,array.size()) {put(array[i]);} // 表示用
}
// LCP作成
void lcp_act(void) {
lcp.resize(str.length());
vector<SINT64> buffer(str.length());
rep(i,0,str.length()) {
buffer[sais[i]] = i;
}
SINT64 cnt = 0;
rep(i,0,str.length()) {
if (buffer[i] >= str.length()-1) {
cnt = 0;
} else {
SINT64 a = buffer[i];
SINT64 b = buffer[i]+1;
while(1) {
if (cnt >= str.length() - sais[a])
break; if (cnt >= str.length() - sais[a]) break;
if (str[sais[a]+cnt] ==
str[sais[b]+cnt]) { cnt++; } else { break;
}
}
}
lcp[buffer[i]] = cnt;
if (cnt != 0) cnt--;
}
}
// 引数の文字列が何個含まれるか算出
SINT64 get_cnt(string t) {
SINT64 low,high;
SINT64 L,R;
L = -1;
R = str.length();
while(R-L > 1) {
SINT64 M = (R+L)/2;
string buf = str.substr(sais[M]);
if (buf.length() > t.length()) {
buf = buf.substr(0,t.length());
}
if (buf > t) {R = M;} else {L = M;}
}
high = R;
L = -1;
R = str.length();
while(R-L > 1) {
SINT64 M = (R+L)/2;
string buf = str.substr(sais[M]);
if (buf >= t) {R = M;} else {L = M;}
}
low = R;
return high - low;
}
// SAIS実行
void sais_act(vector<SINT64>& Vstr, vector<SINT64>& r_sais, SINT64 type)
{ Vstr.push_back(0); //
番兵追加 vector<SINT64> lms_seed; // LMS
ソート前 vector<SINT64> lms_sort; // LMS
ソート後 vector<SINT64> lms_long(Vstr.size(),0); // LMS 長さ
vector<SINT64> lms_type(Vstr.size(),1); // 0:L 1:S 2:LMS
vector<SINT64> lms_posi(Vstr.size(),-1); //
LMS内での位置
SINT64 len = 0;
// L S LMS判定 初期値は全てS
rrep(i,Vstr.size()-2,0) {
len++;
if (Vstr[i] > Vstr[i+1]) {
lms_type[i] = 0;
// L if (lms_type[i+1] == 1) {
lms_type[i+1] = 2;
// LMS lms_long[i+1] = len; // LMSの長さ格納 len = 1;
}
}
if (Vstr[i] == Vstr[i+1]) lms_type[i] = lms_type[i+1];
// 右と同じ
}
SINT64 cnt = 0;
rep(i,0,Vstr.size()) {
if (lms_type[i] == 2) lms_seed.emplace_back(i);
if (lms_type[i] == 2) lms_posi[i] = cnt++;
}
// Induced Sort初回
vector<SINT64> bucket;
// Induced Sort初回結果格納用 induced_sort(Vstr, lms_seed, bucket, lms_type,
type);
// lms_sortにLMSのソートを格納
rrep(i,Vstr.size()-1,0) {
if ((bucket[i] != -1) && (lms_type[bucket[i]] == 2)) {
lms_sort.emplace_back(bucket[i]);
}
}
SINT64 ok = 0; // 再帰必要性判定 SINT64 rank = 1;
// 再帰用文字 vector<SINT64> next(lms_sort.size(), 1); // 再帰用文字列
rrep(i,lms_sort.size()-2,0) {
SINT64 A = lms_long[lms_sort[i]];
SINT64 B = lms_long[lms_sort[i+1]];
if (A == B) {
SINT64 ck = 0;
rep(j,0,A) {
if (Vstr[lms_sort[i]+j] != Vstr[lms_sort[i+1]+j]) {
ck = 1;
break;
}
}
if (ck == 0) {
ok = 1; // 再帰必要
} else {
rank++;
}
} else {
rank++;
}
next[lms_posi[lms_sort[i]]] = rank;
}
if (ok == 1) {
vector<SINT64> recursive;
sais_act(next, recursive, rank+1);
rep(i,0,recursive.size()) {
lms_sort[recursive.size()-i-1] =
lms_seed[recursive[i]];
}
}
// SORT済みLMSでInduced Sorting
r_sais.resize(Vstr.size(),-1);
induced_sort(Vstr, lms_sort, r_sais, lms_type, type);
r_sais.erase(r_sais.begin()); // 番兵削除
}
// induced_sort
void induced_sort(vector<SINT64>& Vstr, vector<SINT64>& seed,
vector<SINT64>& bucket_sort, vector<SINT64>& lms_type, SINT64 type) {
vector<SINT64> bucket_cnt(type,0); //
バケット 文字種ごとの数 vector<SINT64> bucket_st(type,0);
// バケット 文字種の開始位置
vector<SINT64> bucket_end(type,0); //
バケット 文字種の終了位置 vector<SINT64> bucket_pre(Vstr.size(),-1); //
バケット 初回格納用 vector<SINT64> cnt1(type,0); vector<SINT64> cnt2(type,0);
vector<SINT64> cnt3(type,0);
bucket_sort.resize(Vstr.size(),-1);
// バケットソート位置作成
rep(i,0,Vstr.size()) bucket_cnt[Vstr[i]]++;
// 個数作成
rep(i,1,type) bucket_st[i] = bucket_st[i-1] + bucket_cnt[i-1];
// 開始位置
rep(i,0,type) bucket_end[i] = bucket_st[i] + bucket_cnt[i]-1;
// 終了位置
// LMSをbucket_preに格納
rep(i,0,seed.size()) {
SINT64 no = seed[i];
bucket_pre[bucket_end[Vstr[no]] - cnt1[Vstr[no]]] = no;
cnt1[Vstr[no]]++;
}
// Lをbucket_sortに格納
rep(i,0,Vstr.size()) {
if ((bucket_pre[i] != -1) && (bucket_pre[i] != 0)) {
if (lms_type[bucket_pre[i]-1] == 0) {
// -1がLの場合 SINT64 buf = Vstr[bucket_pre[i]-1]; bucket_pre [bucket_st[buf] +
cnt2[buf]] = bucket_pre[i]-1; bucket_sort[bucket_st[buf] + cnt2[buf]] =
bucket_pre[i]-1; cnt2[buf]++;
}
}
}
// Sをbucket_sortに格納
bucket_sort[0] = Vstr.size()-1;
// 番兵追加 rrep(i,Vstr.size()-1,0) { if ((bucket_sort[i] != -1) &&
(bucket_sort[i] != 0)) { if (lms_type[bucket_sort[i]-1] != 0) { //
-1がS(LMS)の場合 SINT64 buf = Vstr[bucket_sort[i]-1];
bucket_sort[bucket_end[buf] - cnt3[buf]]
= bucket_sort[i]-1; cnt3[buf]++;
}
}
}
}
};
*/
| insert | 98 | 98 | 98 | 103 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bits/stdc++.h> // isupper, islower, isdigit, toupper, tolower
#include <bitset> // bitset
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <deque> // deque
#include <iostream> // cout, endl, cin
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;
int main() {
int N;
string S;
cin >> N >> S;
ll R = 0;
ll G = 0;
ll B = 0;
ll ans = 0;
vector<char> nvec; // Nの各桁の数字を格納するベクター
rep(i, N) {
nvec.push_back(S.at(i));
if (S.at(i) == 'R') {
R++;
}
if (S.at(i) == 'G') {
G++;
}
if (S.at(i) == 'B') {
B++;
}
}
ans = R * G * B;
ll condition2 = 0;
rep(i, N) {
rep2(j, i + 1, N) {
rep2(k, j + 1, N) {
if (j - i == k - j) {
if (S.at(i) != S.at(j) && S.at(j) != S.at(k) && S.at(k) != S.at(i)) {
condition2++;
}
}
}
}
}
cout << ans - condition2 << endl;
return 0;
}
| #include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bits/stdc++.h> // isupper, islower, isdigit, toupper, tolower
#include <bitset> // bitset
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <deque> // deque
#include <iostream> // cout, endl, cin
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <string> // string, to_string, stoi
#include <tuple> // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility> // pair, make_pair
#include <vector> // vector
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;
int main() {
int N;
string S;
cin >> N >> S;
ll R = 0;
ll G = 0;
ll B = 0;
ll ans = 0;
vector<char> nvec; // Nの各桁の数字を格納するベクター
rep(i, N) {
nvec.push_back(S.at(i));
if (S.at(i) == 'R') {
R++;
}
if (S.at(i) == 'G') {
G++;
}
if (S.at(i) == 'B') {
B++;
}
}
ans = R * G * B;
ll condition2 = 0;
rep(i, N) {
rep2(j, i + 1, N) {
ll k = 2 * j - i;
if (k >= N) {
continue;
} else {
if (S.at(i) != S.at(j) && S.at(j) != S.at(k) && S.at(k) != S.at(i)) {
condition2++;
}
}
}
}
cout << ans - condition2 << endl;
return 0;
}
| replace | 51 | 56 | 51 | 57 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1000000000;
// long long
using ll = long long;
// 出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
// begin() end()
#define all(x) (x).begin(), (x).end()
// for
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
// 最大公約数
unsigned gcd(unsigned a, unsigned b) {
if (a < b)
return gcd(b, a);
unsigned r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
// 最小公倍数
unsigned lcm(unsigned a, unsigned b) { return a / gcd(a, b) * b; }
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main() {
int n;
cin >> n;
string s;
cin >> s;
ll ans = 0;
REP(i, n) {
ll cnt = 0;
for (int j = i + 1; j < n; j++) {
if (s[i] != s[j]) {
int d = j - i;
for (int k = j + 1; k < n; k++) {
if (j + d < n)
if (k == j + d)
continue;
if (s[i] != s[k] && s[j] != s[k])
ans++;
}
}
}
}
cout << ans << "\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int INF = 1000000000;
// long long
using ll = long long;
// 出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
// begin() end()
#define all(x) (x).begin(), (x).end()
// for
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
// 最大公約数
unsigned gcd(unsigned a, unsigned b) {
if (a < b)
return gcd(b, a);
unsigned r;
while ((r = a % b)) {
a = b;
b = r;
}
return b;
}
// 最小公倍数
unsigned lcm(unsigned a, unsigned b) { return a / gcd(a, b) * b; }
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main() {
int n;
cin >> n;
string s;
cin >> s;
ll ans = 0;
ll cnt1 = 0, cnt2 = 0, cnt3 = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'R')
cnt1++;
if (s[i] == 'G')
cnt2++;
if (s[i] == 'B')
cnt3++;
}
ans = cnt1 * cnt2 * cnt3;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < n; j++) {
if (j - i < 0 || j + i >= n)
continue;
if (s[j] != s[j - i] && s[j] != s[j + i] && s[j + i] != s[j - i])
ans--;
}
}
cout << ans << "\n";
return 0;
}
| replace | 58 | 71 | 58 | 76 | TLE | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1000000000
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repX(i, n, x) for (int i = x; i < (int)(n); i++)
#define repM(i, n) for (int i = n; i > 0; i--)
int main() {
int N;
cin >> N;
string S;
cin >> S;
vector<vector<int>> RGB(3);
rep(i, N) {
if (S[i] == 'R') {
RGB[0].push_back(i);
}
if (S[i] == 'G') {
RGB[1].push_back(i);
}
if (S[i] == 'B') {
RGB[2].push_back(i);
}
}
int ans = 0;
rep(a, 3) {
rep(i, RGB[a].size()) {
rep(b, 3) {
if (a == b)
continue;
rep(j, RGB[b].size()) {
if (RGB[a][i] >= RGB[b][j])
continue;
rep(c, 3) {
if (a == c || b == c)
continue;
if (RGB[b][i] <= RGB[c][RGB[c].size() - 1])
break;
rep(k, RGB[c].size()) {
if (RGB[b][j] >= RGB[c][k])
continue;
if (RGB[b][j] - RGB[a][i] == RGB[c][k] - RGB[b][j])
continue;
ans++;
}
}
}
}
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1000000000
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repX(i, n, x) for (int i = x; i < (int)(n); i++)
#define repM(i, n) for (int i = n; i > 0; i--)
int main() {
int N;
cin >> N;
string S;
cin >> S;
vector<vector<int>> RGB(3);
rep(i, N) {
if (S[i] == 'R') {
RGB[0].push_back(i);
}
if (S[i] == 'G') {
RGB[1].push_back(i);
}
if (S[i] == 'B') {
RGB[2].push_back(i);
}
}
ll ans = 0;
ans = RGB[0].size() * RGB[1].size() * RGB[2].size();
rep(i, N) {
repX(j, N, i + 1) {
if (S[i] == S[j])
continue;
int k = j * 2 - i;
if (k >= N || S[k] == S[i] || S[k] == S[j])
continue;
ans--;
}
}
cout << ans << endl;
return 0;
} | replace | 26 | 50 | 26 | 36 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define endl '\n'
#define lli long long int
#define rep(i, s, e) for (int i = s; i < e; i++)
int main() {
int N;
cin >> N;
string S;
cin >> S;
vector<int> R, G, B;
rep(i, 0, N) {
switch (S[i]) {
case 'R':
R.push_back(i);
break;
case 'G':
G.push_back(i);
break;
case 'B':
B.push_back(i);
break;
default:
break;
}
}
const int res = R.size() * G.size() * B.size();
unsigned int even = 0;
for (int r : R) {
const int rr = 2 * r;
for (int g : G) {
const int gg = 2 * g;
int rg = r + g;
for (int b : B) {
const int bb = 2 * b;
const int br = b + r;
const int bg = b + g;
// r<g<b
if (gg == br)
even++;
// r<b<g
else if (bb == rg)
even++;
// b<r<g
else if (rr == bg)
even++;
}
}
}
cout << res - even << endl;
} | #include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define endl '\n'
#define lli long long int
#define rep(i, s, e) for (int i = s; i < e; i++)
int main() {
int N;
cin >> N;
string S;
cin >> S;
vector<int> R, G, B;
rep(i, 0, N) {
switch (S[i]) {
case 'R':
R.push_back(i);
break;
case 'G':
G.push_back(i);
break;
case 'B':
B.push_back(i);
break;
default:
break;
}
}
const int res = R.size() * G.size() * B.size();
unsigned int even = 0;
for (int r : R) {
const int rr = 2 * r;
for (int g : G) {
const int gg = 2 * g;
int rg = r + g;
for (int b : B) {
const int bb = 2 * b;
const int br = b + r;
const int bg = b + g;
// r<g<b
if (gg == br || bb == rg || rr == bg)
even++;
}
}
}
cout << res - even << endl;
} | replace | 42 | 49 | 42 | 43 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF = (ll)1e9;
const ll MOD = (ll)1e9 + 7;
const ll MAX = 510000;
vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main() {
ll N, ans = 0;
string S;
cin >> N >> S;
vector<ll> R, G, B;
set<ll> r, g, b;
for (ll i = 0; i < N; i++) {
if (S[i] == 'R') {
R.push_back(i);
r.insert(i);
} else if (S[i] == 'B') {
B.push_back(i);
b.insert(i);
} else if (S[i] == 'G') {
G.push_back(i);
g.insert(i);
}
}
ans = R.size() * B.size() * G.size();
for (ll i = 0; i < R.size(); i++) {
for (ll j = 0; j < B.size(); j++) {
for (ll k = 0; k < G.size(); k++) {
ll d1, d2, d3;
d1 = abs(R[i] - B[j]);
d2 = abs(R[i] - G[k]);
d3 = abs(B[j] - G[k]);
if ((d1 == d2 || d1 == d3) || d2 == d3)
ans--;
}
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define ll long long
#define pq priority_queue
using namespace std;
const ll INF = (ll)1e9;
const ll MOD = (ll)1e9 + 7;
const ll MAX = 510000;
vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
int main() {
ll N, ans = 0;
string S;
cin >> N >> S;
vector<ll> R, G, B;
set<ll> r, g, b;
for (ll i = 0; i < N; i++) {
if (S[i] == 'R') {
R.push_back(i);
r.insert(i);
} else if (S[i] == 'B') {
B.push_back(i);
b.insert(i);
} else if (S[i] == 'G') {
G.push_back(i);
g.insert(i);
}
}
ans = R.size() * B.size() * G.size();
for (ll i = 0; i < R.size(); i++) {
for (ll j = 0; j < B.size(); j++) {
ll d, m;
d = abs(R[i] - B[j]);
if (R[i] > B[j])
m = R[i] - d / 2;
else
m = R[i] + d / 2;
if (g.count(R[i] - d))
ans--;
if (g.count(R[i] + d))
ans--;
if (g.count(B[j] + d))
ans--;
if (g.count(B[j] - d))
ans--;
if ((R[i] + B[j]) % 2 == 0 && g.count(m))
ans--;
}
}
cout << ans << endl;
} | replace | 44 | 52 | 44 | 60 | TLE | |
p02714 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#define mm(a, x) memset(a, x, sizeof(a))
#define sync \
std::ios::sync_with_stdio(false); \
std::cin.tie(0)
#define ll long long
using namespace std;
const int MAXN = 4010;
vector<int> rp, gp, bp;
int vis1[MAXN], vis2[MAXN], vis3[MAXN];
int main(void) {
sync;
int n;
string s;
cin >> n >> s;
for (int i = 0; i < n; ++i)
if (s[i] == 'R') {
rp.push_back(i);
vis1[i] = 1;
} else if (s[i] == 'G') {
gp.push_back(i);
vis2[i] = 1;
} else {
bp.push_back(i);
vis3[i] = 1;
}
ll res = rp.size() * gp.size() * bp.size();
for (auto i : rp)
for (auto j : gp)
if (2 * j - i >= 0 && vis3[2 * j - i])
--res;
for (auto i : gp)
for (auto j : rp)
if (2 * j - i >= 0 && vis3[2 * j - i])
--res;
for (auto i : rp)
for (auto j : bp)
if (2 * j - i >= 0 && vis2[2 * j - i])
--res;
cout << res << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#define mm(a, x) memset(a, x, sizeof(a))
#define sync \
std::ios::sync_with_stdio(false); \
std::cin.tie(0)
#define ll long long
using namespace std;
const int MAXN = 40100;
vector<int> rp, gp, bp;
int vis1[MAXN], vis2[MAXN], vis3[MAXN];
int main(void) {
sync;
int n;
string s;
cin >> n >> s;
for (int i = 0; i < n; ++i)
if (s[i] == 'R') {
rp.push_back(i);
vis1[i] = 1;
} else if (s[i] == 'G') {
gp.push_back(i);
vis2[i] = 1;
} else {
bp.push_back(i);
vis3[i] = 1;
}
ll res = rp.size() * gp.size() * bp.size();
for (auto i : rp)
for (auto j : gp)
if (2 * j - i >= 0 && vis3[2 * j - i])
--res;
for (auto i : gp)
for (auto j : rp)
if (2 * j - i >= 0 && vis3[2 * j - i])
--res;
for (auto i : rp)
for (auto j : bp)
if (2 * j - i >= 0 && vis2[2 * j - i])
--res;
cout << res << endl;
return 0;
} | replace | 12 | 13 | 12 | 13 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M = 1e9 + 7;
const int iinf = 1 << 28;
const long long llinf = 1ll << 60;
const double PI = 3.14159265;
inline int getIdx(char c) {
if (c == 'R')
return 0;
if (c == 'G')
return 1;
return 2;
}
struct S {
vector<int> a;
unordered_map<int, int> m;
};
void work() {
int n;
string s;
cin >> n >> s;
vector<vector<S>> v(n, vector<S>(3));
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if (s[i] != s[j]) {
int idx = getIdx(s[j]);
v[i][idx].a.push_back(j);
v[i][idx].m[j - i]++;
}
}
}
ll ans = 0;
for (int i = 0; i < n; ++i) {
for (int k = 0; k < 3; ++k) {
if (getIdx(s[i]) == k)
continue;
for (int j : v[i][k].a) {
for (int l = 0; l < 3; ++l) {
if (l == getIdx(s[i]) || l == k)
continue;
int d = j - i;
ans += (int)(v[j][l].a.size()) - v[j][l].m[d];
}
}
}
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
// int nt; cin>>nt; while (nt--) work();
work();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M = 1e9 + 7;
const int iinf = 1 << 28;
const long long llinf = 1ll << 60;
const double PI = 3.14159265;
inline int getIdx(char c) {
if (c == 'R')
return 0;
if (c == 'G')
return 1;
return 2;
}
struct S {
vector<int> a;
int m[4001];
};
void work() {
int n;
string s;
cin >> n >> s;
vector<vector<S>> v(n, vector<S>(3));
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if (s[i] != s[j]) {
int idx = getIdx(s[j]);
v[i][idx].a.push_back(j);
v[i][idx].m[j - i]++;
}
}
}
ll ans = 0;
for (int i = 0; i < n; ++i) {
for (int k = 0; k < 3; ++k) {
if (getIdx(s[i]) == k)
continue;
for (int j : v[i][k].a) {
for (int l = 0; l < 3; ++l) {
if (l == getIdx(s[i]) || l == k)
continue;
int d = j - i;
ans += (int)(v[j][l].a.size()) - v[j][l].m[d];
}
}
}
}
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
// int nt; cin>>nt; while (nt--) work();
work();
return 0;
}
| replace | 18 | 19 | 18 | 19 | TLE | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
string s;
cin >> n >> s;
vector<int> r, g, b;
for (int i = 0; i < n; i++) {
if (s.at(i) == 'R')
r.emplace_back(i);
else if (s.at(i) == 'G')
g.emplace_back(i);
else
b.emplace_back(i);
}
ll ans = 0;
for (int i = 0; i < r.size(); i++) {
for (int j = 0; j < g.size(); j++) {
int left = r.at(i), right = g.at(j);
if (left > right)
swap(left, right);
int keep = b.size();
if ((2 * right - left < n) &&
*lower_bound(b.begin(), b.end(), 2 * right - left) ==
2 * right - left &&
lower_bound(b.begin(), b.end(), 2 * right - left) != b.end()) {
keep--;
}
if ((2 * left - right >= 0) &&
*lower_bound(b.begin(), b.end(), 2 * left - right) ==
2 * left - right &&
lower_bound(b.begin(), b.end(), 2 * left - right) != b.end()) {
keep--;
}
if (((left + right) % 2 == 0) &&
*lower_bound(b.begin(), b.end(), (left + right) / 2) ==
(left + right) / 2)
keep--;
ans += keep;
}
}
cout << ans << '\n';
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
string s;
cin >> n >> s;
vector<int> r, g, b;
for (int i = 0; i < n; i++) {
if (s.at(i) == 'R')
r.emplace_back(i);
else if (s.at(i) == 'G')
g.emplace_back(i);
else
b.emplace_back(i);
}
if (r.size() == 0 || g.size() == 0 || b.size() == 0) {
cout << "0\n";
return 0;
}
ll ans = 0;
for (int i = 0; i < r.size(); i++) {
for (int j = 0; j < g.size(); j++) {
int left = r.at(i), right = g.at(j);
if (left > right)
swap(left, right);
int keep = b.size();
if ((2 * right - left < n) &&
*lower_bound(b.begin(), b.end(), 2 * right - left) ==
2 * right - left &&
lower_bound(b.begin(), b.end(), 2 * right - left) != b.end()) {
keep--;
}
if ((2 * left - right >= 0) &&
*lower_bound(b.begin(), b.end(), 2 * left - right) ==
2 * left - right &&
lower_bound(b.begin(), b.end(), 2 * left - right) != b.end()) {
keep--;
}
if (((left + right) % 2 == 0) &&
*lower_bound(b.begin(), b.end(), (left + right) / 2) ==
(left + right) / 2)
keep--;
ans += keep;
}
}
cout << ans << '\n';
} | insert | 21 | 21 | 21 | 26 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <algorithm>
#include <assert.h>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <vector>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
ll gcd(ll a, ll b) {
if (a % b == 0) {
return (b);
} else {
return (gcd(b, a % b));
}
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template <typename T> T seinomi(T a) {
if (a > 0) {
return a;
} else {
return 0;
}
}
// 連想配列[素因数f.first][個数f.second]
template <typename T> map<T, T> soinsuubunkai(T n) {
map<T, T> ret;
for (T i = 2; i * i <= n; i++) {
while (n % i == 0) {
ret[i]++;
n /= i;
}
}
if (n != 1)
ret[n] = 1;
return ret;
}
// 桁数取得
template <typename T> T ketasuu(T num) { return std::to_string(num).length(); }
// 階乗
ll kaizyou(ll k) {
ll sum = 1;
for (ll i = 1; i <= k; ++i) {
sum *= i;
}
return sum;
}
// 階乗を(10^9)+7で割った余り
ll modkaizyou(ll k) {
ll sum = 1;
for (int i = 1; i <= k; ++i) {
sum *= i;
sum = sum % mod;
}
return sum;
}
template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value) {
while (first != last) {
*first++ = value;
++value;
}
}
// 整数乗
ll llpow(ll a, ll n) {
ll rep = a;
for (ll i = 1; i < n; i++) {
rep *= a;
}
return rep;
}
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
template <typename T> T amarinasi(T a, T b) {
if (a % b == 0) {
return a / b;
} else if (a % b > 0) {
return a / b + 1;
} else {
return a / b - 1;
}
}
// 組み合わせ nCr
vector<vector<ll>> nCr_v(5010, vector<ll>(5010, 0));
bool nCr_maekeisan = false;
void nCr_Calculater() {
for (int i = 0; i < nCr_v.size(); i++) {
nCr_v[i][0] = 1;
nCr_v[i][i] = 1;
}
for (int k = 1; k < nCr_v.size(); k++) {
for (int j = 1; j < k; j++) {
nCr_v[k][j] = (nCr_v[k - 1][j - 1] + nCr_v[k - 1][j]);
}
}
}
ll nCr(ll n, ll r) {
if (n > 5010 || n < 0 || r > 5010 || r < 0) {
cout << "Error!! n or r is over 5010 or under 0" << endl;
return 1;
} else {
if (nCr_maekeisan == false) {
nCr_Calculater();
nCr_maekeisan = true;
}
return nCr_v[n][r];
}
}
// 組み合わせnCrを1000000007で割った余り
vector<ll> modnCr_fac(1000010), modnCr_finv(1000010), modnCr_inv(1000010);
bool modnCr_maekeisan = false;
void COMinit() {
modnCr_fac[0] = modnCr_fac[1] = 1;
modnCr_finv[0] = modnCr_finv[1] = 1;
modnCr_inv[1] = 1;
for (int i = 2; i < 1000010; i++) {
modnCr_fac[i] = modnCr_fac[i - 1] * i % mod;
modnCr_inv[i] = mod - modnCr_inv[mod % i] * (mod / i) % mod;
modnCr_finv[i] = modnCr_finv[i - 1] * modnCr_inv[i] % mod;
}
}
ll COM(ll n, ll k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return modnCr_fac[n] * (modnCr_finv[k] * modnCr_finv[n - k] % mod) % mod;
}
ll modnCr(ll n, ll r) {
if (modnCr_maekeisan == false) {
COMinit();
modnCr_maekeisan = true;
}
return COM(n, r);
}
// 順列 nPr
ll nPr(ll n, ll r) {
r = n - r;
ll sum = 1;
ll i;
for (i = n; i >= r + 1; i--)
sum *= i;
return sum;
}
// 重複組み合わせ nHr = (r+n-1)Cr
ll nHr(ll n, ll r) { return modnCr(r + n - 1, r); }
// 弧度法から度数法に変換
double to_deg(double r) { return r * 180.0 / (atan(1.0) * 4.0); }
// 座標から度数法の角度に変換
double kakudo(double dx, double dy) {
return atan2(dx, dy) * 180.0 / (atan(1.0) * 4.0);
}
// 約数列挙配列(1を必ず含むことに注意)
vector<ll> yakusuu(ll n) {
vector<ll> ret;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n)
ret.push_back(n / i);
}
}
sort(begin(ret), end(ret));
return (ret);
}
// 素数判定bool型配列
std::vector<bool> sosuuhantei(ll max) {
vector<bool> ret;
if (max + 1 > ret.size()) { // resizeで要素数が減らないように
ret.resize(max + 1, true); // IsPrimeに必要な要素数を確保
}
ret[0] = false; // 0は素数ではない
ret[1] = false; // 1は素数ではない
for (ll i = 2; i * i <= max; ++i) { // 0からsqrt(max)まで調べる
if (ret[i]) { // iが素数ならば
for (ll j = 2; i * j <= max; ++j) { // (max以下の)iの倍数は
ret[i * j] = false; // 素数ではない
}
}
}
return (ret);
}
// 素数列挙longlong型配列
std::vector<ll> sosuurekkyo(ll max) {
vector<bool> tmp;
vector<ll> ret;
if (max + 1 > tmp.size()) { // resizeで要素数が減らないように
tmp.resize(max + 1, true); // IsPrimeに必要な要素数を確保
}
tmp[0] = false; // 0は素数ではない
tmp[1] = false; // 1は素数ではない
for (ll i = 2; i * i <= max; ++i) { // 0からsqrt(max)まで調べる
if (tmp[i]) { // iが素数ならば
for (ll j = 2; i * j <= max; ++j) { // (max以下の)iの倍数は
tmp[i * j] = false; // 素数ではない
}
}
}
for (ll i = 0; i <= max; i++) {
if (tmp[i]) {
ret.push_back(i);
}
}
return (ret);
}
// 十進数を二進数にしたときの桁数
ll nisinsize(ll n) {
ll rep = 0;
ll tmp = 1;
while (1) {
rep++;
tmp *= 2;
if (tmp > n) {
break;
}
}
return rep;
}
ll modcomb(ll n, ll r) {
ll num = 1;
for (ll i = 1; i <= r; i++) {
num = num * (n - i + 1) / i;
num %= mod;
}
return num;
}
ll comb(ll n, ll r) {
ll num = 1;
for (ll i = 1; i <= r; i++) {
num = num * (n - i + 1) / i;
}
return num;
}
// 小数点以下10桁テンプレート(main関数内の最初に貼付け)
// std::cout << std::fixed << std::setprecision(10);
//----------------------------------------------------------------
int main() {
ll n;
string s;
cin >> n;
cin >> s;
ll ans = 0;
for (ll i = 0; i < n - 2; i++) {
for (ll j = i + 1; j < n - 1; j++) {
for (ll k = j + 1; k < n; k++) {
if (j - i != k - j) {
if (s[i] != s[j] && s[j] != s[k] && s[i] != s[k]) {
ans++;
}
}
}
}
}
cout << ans << endl;
}
| #include <algorithm>
#include <assert.h>
#include <bitset>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <vector>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
ll gcd(ll a, ll b) {
if (a % b == 0) {
return (b);
} else {
return (gcd(b, a % b));
}
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template <typename T> T seinomi(T a) {
if (a > 0) {
return a;
} else {
return 0;
}
}
// 連想配列[素因数f.first][個数f.second]
template <typename T> map<T, T> soinsuubunkai(T n) {
map<T, T> ret;
for (T i = 2; i * i <= n; i++) {
while (n % i == 0) {
ret[i]++;
n /= i;
}
}
if (n != 1)
ret[n] = 1;
return ret;
}
// 桁数取得
template <typename T> T ketasuu(T num) { return std::to_string(num).length(); }
// 階乗
ll kaizyou(ll k) {
ll sum = 1;
for (ll i = 1; i <= k; ++i) {
sum *= i;
}
return sum;
}
// 階乗を(10^9)+7で割った余り
ll modkaizyou(ll k) {
ll sum = 1;
for (int i = 1; i <= k; ++i) {
sum *= i;
sum = sum % mod;
}
return sum;
}
template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value) {
while (first != last) {
*first++ = value;
++value;
}
}
// 整数乗
ll llpow(ll a, ll n) {
ll rep = a;
for (ll i = 1; i < n; i++) {
rep *= a;
}
return rep;
}
long long modpow(long long a, long long n, long long mod) {
long long res = 1;
while (n > 0) {
if (n & 1)
res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
template <typename T> T amarinasi(T a, T b) {
if (a % b == 0) {
return a / b;
} else if (a % b > 0) {
return a / b + 1;
} else {
return a / b - 1;
}
}
// 組み合わせ nCr
vector<vector<ll>> nCr_v(5010, vector<ll>(5010, 0));
bool nCr_maekeisan = false;
void nCr_Calculater() {
for (int i = 0; i < nCr_v.size(); i++) {
nCr_v[i][0] = 1;
nCr_v[i][i] = 1;
}
for (int k = 1; k < nCr_v.size(); k++) {
for (int j = 1; j < k; j++) {
nCr_v[k][j] = (nCr_v[k - 1][j - 1] + nCr_v[k - 1][j]);
}
}
}
ll nCr(ll n, ll r) {
if (n > 5010 || n < 0 || r > 5010 || r < 0) {
cout << "Error!! n or r is over 5010 or under 0" << endl;
return 1;
} else {
if (nCr_maekeisan == false) {
nCr_Calculater();
nCr_maekeisan = true;
}
return nCr_v[n][r];
}
}
// 組み合わせnCrを1000000007で割った余り
vector<ll> modnCr_fac(1000010), modnCr_finv(1000010), modnCr_inv(1000010);
bool modnCr_maekeisan = false;
void COMinit() {
modnCr_fac[0] = modnCr_fac[1] = 1;
modnCr_finv[0] = modnCr_finv[1] = 1;
modnCr_inv[1] = 1;
for (int i = 2; i < 1000010; i++) {
modnCr_fac[i] = modnCr_fac[i - 1] * i % mod;
modnCr_inv[i] = mod - modnCr_inv[mod % i] * (mod / i) % mod;
modnCr_finv[i] = modnCr_finv[i - 1] * modnCr_inv[i] % mod;
}
}
ll COM(ll n, ll k) {
if (n < k)
return 0;
if (n < 0 || k < 0)
return 0;
return modnCr_fac[n] * (modnCr_finv[k] * modnCr_finv[n - k] % mod) % mod;
}
ll modnCr(ll n, ll r) {
if (modnCr_maekeisan == false) {
COMinit();
modnCr_maekeisan = true;
}
return COM(n, r);
}
// 順列 nPr
ll nPr(ll n, ll r) {
r = n - r;
ll sum = 1;
ll i;
for (i = n; i >= r + 1; i--)
sum *= i;
return sum;
}
// 重複組み合わせ nHr = (r+n-1)Cr
ll nHr(ll n, ll r) { return modnCr(r + n - 1, r); }
// 弧度法から度数法に変換
double to_deg(double r) { return r * 180.0 / (atan(1.0) * 4.0); }
// 座標から度数法の角度に変換
double kakudo(double dx, double dy) {
return atan2(dx, dy) * 180.0 / (atan(1.0) * 4.0);
}
// 約数列挙配列(1を必ず含むことに注意)
vector<ll> yakusuu(ll n) {
vector<ll> ret;
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n)
ret.push_back(n / i);
}
}
sort(begin(ret), end(ret));
return (ret);
}
// 素数判定bool型配列
std::vector<bool> sosuuhantei(ll max) {
vector<bool> ret;
if (max + 1 > ret.size()) { // resizeで要素数が減らないように
ret.resize(max + 1, true); // IsPrimeに必要な要素数を確保
}
ret[0] = false; // 0は素数ではない
ret[1] = false; // 1は素数ではない
for (ll i = 2; i * i <= max; ++i) { // 0からsqrt(max)まで調べる
if (ret[i]) { // iが素数ならば
for (ll j = 2; i * j <= max; ++j) { // (max以下の)iの倍数は
ret[i * j] = false; // 素数ではない
}
}
}
return (ret);
}
// 素数列挙longlong型配列
std::vector<ll> sosuurekkyo(ll max) {
vector<bool> tmp;
vector<ll> ret;
if (max + 1 > tmp.size()) { // resizeで要素数が減らないように
tmp.resize(max + 1, true); // IsPrimeに必要な要素数を確保
}
tmp[0] = false; // 0は素数ではない
tmp[1] = false; // 1は素数ではない
for (ll i = 2; i * i <= max; ++i) { // 0からsqrt(max)まで調べる
if (tmp[i]) { // iが素数ならば
for (ll j = 2; i * j <= max; ++j) { // (max以下の)iの倍数は
tmp[i * j] = false; // 素数ではない
}
}
}
for (ll i = 0; i <= max; i++) {
if (tmp[i]) {
ret.push_back(i);
}
}
return (ret);
}
// 十進数を二進数にしたときの桁数
ll nisinsize(ll n) {
ll rep = 0;
ll tmp = 1;
while (1) {
rep++;
tmp *= 2;
if (tmp > n) {
break;
}
}
return rep;
}
ll modcomb(ll n, ll r) {
ll num = 1;
for (ll i = 1; i <= r; i++) {
num = num * (n - i + 1) / i;
num %= mod;
}
return num;
}
ll comb(ll n, ll r) {
ll num = 1;
for (ll i = 1; i <= r; i++) {
num = num * (n - i + 1) / i;
}
return num;
}
// 小数点以下10桁テンプレート(main関数内の最初に貼付け)
// std::cout << std::fixed << std::setprecision(10);
//----------------------------------------------------------------
int main() {
ll n;
string s;
cin >> n;
cin >> s;
ll ans = 0;
map<char, ll> rensou;
for (ll i = 0; i < s.size(); i++) {
rensou[s[i]]++;
}
ll sum = rensou['R'] * rensou['G'] * rensou['B'];
ll hiku = 0;
for (ll i = 0; i < n - 1; i++) {
for (ll j = i + 1; j < n; j++) {
ll k = j * 2 - i;
if (k <= j) {
continue;
}
if (k >= n) {
continue;
}
if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) {
hiku++;
}
}
}
cout << sum - hiku << endl;
}
| replace | 304 | 317 | 304 | 326 | TLE | |
p02714 | C++ | Time Limit Exceeded | #define _GLIBCXX_DEBUG
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;
typedef vector<vector<vector<ll>>> VVV;
typedef vector<vector<vector<vector<ll>>>> VVVV;
#define REP(i, a, b) for (ll i = (a); i < (b); i++)
#define PER(i, a, b) for (ll i = (a); i >= (b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF = 1e18 + 18;
const ll MAX = 100005;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define Each(a, b) for (auto &a : b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#ifdef LOCAL
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) \
cerr << #mp << ":" << endl; \
for (auto i = mp.begin(); i != mp.end(); ++i) { \
cerr << i->first << ":" << i->second << endl; \
}
#define dbgarr(n, m, arr) \
rep(i, n) { \
rep(j, m) { cerr << arr[i][j] << " "; } \
cerr << endl; \
}
#define dbgdp(n, arr) \
rep(i, n) { cerr << arr[i] << " "; } \
cerr << endl;
#define dbgmint(n, arr) \
rep(i, n) { cerr << arr[i].x << " "; } \
cerr << endl;
#define dbgarrmint(n, m, arr) \
rep(i, n) { \
rep(j, m) { cerr << arr[i][j].x << " "; } \
cerr << endl; \
}
#else
#define dbg(...)
#define dbgmap(...)
#define dbgarr(...)
#define dbgdp(...)
#define dbgmint(...)
#define dbgarrmint(...)
#endif
#define out(a) cout << a << endl
#define out2(a, b) cout << a << " " << b << endl
#define vout(v) \
rep(i, v.size()) { cout << v[i] << " "; } \
cout << endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
return s << "(" << p.first << ", " << p.second << ")";
}
template <typename T> istream &operator>>(istream &i, vector<T> &v) {
rep(j, v.size()) i >> v[j];
return i;
}
// vector
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
int len = v.size();
for (int i = 0; i < len; ++i) {
s << v[i];
if (i < len - 1)
s << " ";
}
return s;
}
// 2 dimentional vector
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &vv) {
int len = vv.size();
for (int i = 0; i < len; ++i) {
s << vv[i] << endl;
}
return s;
}
// mint
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
mint &operator+=(const mint a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime MOD
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
struct combination {
vector<mint> fact, ifact;
combination(int n) : fact(n + 1), ifact(n + 1) {
assert(n < MOD);
fact[0] = 1;
for (int i = 1; i <= n; ++i)
fact[i] = fact[i - 1] * i;
ifact[n] = fact[n].inv();
for (int i = n; i >= 1; --i)
ifact[i - 1] = ifact[i] * i;
}
mint operator()(int n, int k) {
if (k < 0 || k > n)
return 0;
return fact[n] * ifact[k] * ifact[n - k];
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << std::setprecision(10);
ll n;
cin >> n;
string s;
cin >> s;
VV g(3);
rep(i, n) {
if (s[i] == 'R')
g[0].pb(i);
if (s[i] == 'G')
g[1].pb(i);
if (s[i] == 'B')
g[2].pb(i);
}
dbg(g);
ll ans = g[0].size() * g[1].size() * g[2].size();
dbg(ans);
ll R = g[0].size();
ll G = g[1].size();
Vec B = g[2];
rep(i, R) {
rep(j, G) {
ll x = g[0][i];
ll y = g[1][j];
if (x > y)
swap(x, y);
ll z1 = 2 * y - x;
ll z2 = 2 * x - y;
if (binary_search(ALL(B), z1))
ans--;
if (binary_search(ALL(B), z2))
ans--;
if ((x + y) % 2 == 0) {
ll z3 = (x + y) / 2;
if (binary_search(ALL(B), z3))
ans--;
}
}
}
cout << ans << endl;
return 0;
}
| #pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<P> VP;
typedef vector<vector<ll>> VV;
typedef vector<vector<int>> VVi;
typedef vector<vector<vector<ll>>> VVV;
typedef vector<vector<vector<vector<ll>>>> VVVV;
#define REP(i, a, b) for (ll i = (a); i < (b); i++)
#define PER(i, a, b) for (ll i = (a); i >= (b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF = 1e18 + 18;
const ll MAX = 100005;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define Each(a, b) for (auto &a : b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#ifdef LOCAL
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) \
cerr << #mp << ":" << endl; \
for (auto i = mp.begin(); i != mp.end(); ++i) { \
cerr << i->first << ":" << i->second << endl; \
}
#define dbgarr(n, m, arr) \
rep(i, n) { \
rep(j, m) { cerr << arr[i][j] << " "; } \
cerr << endl; \
}
#define dbgdp(n, arr) \
rep(i, n) { cerr << arr[i] << " "; } \
cerr << endl;
#define dbgmint(n, arr) \
rep(i, n) { cerr << arr[i].x << " "; } \
cerr << endl;
#define dbgarrmint(n, m, arr) \
rep(i, n) { \
rep(j, m) { cerr << arr[i][j].x << " "; } \
cerr << endl; \
}
#else
#define dbg(...)
#define dbgmap(...)
#define dbgarr(...)
#define dbgdp(...)
#define dbgmint(...)
#define dbgarrmint(...)
#endif
#define out(a) cout << a << endl
#define out2(a, b) cout << a << " " << b << endl
#define vout(v) \
rep(i, v.size()) { cout << v[i] << " "; } \
cout << endl
#define Uniq(v) v.erase(unique(v.begin(), v.end()), v.end())
#define fi first
#define se second
template <class T> bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) {
return s << "(" << p.first << ", " << p.second << ")";
}
template <typename T> istream &operator>>(istream &i, vector<T> &v) {
rep(j, v.size()) i >> v[j];
return i;
}
// vector
template <typename T> ostream &operator<<(ostream &s, const vector<T> &v) {
int len = v.size();
for (int i = 0; i < len; ++i) {
s << v[i];
if (i < len - 1)
s << " ";
}
return s;
}
// 2 dimentional vector
template <typename T>
ostream &operator<<(ostream &s, const vector<vector<T>> &vv) {
int len = vv.size();
for (int i = 0; i < len; ++i) {
s << vv[i] << endl;
}
return s;
}
// mint
struct mint {
ll x; // typedef long long ll;
mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
mint &operator+=(const mint a) {
if ((x += a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator-=(const mint a) {
if ((x += MOD - a.x) >= MOD)
x -= MOD;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= MOD;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(ll t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime MOD
mint inv() const { return pow(MOD - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
struct combination {
vector<mint> fact, ifact;
combination(int n) : fact(n + 1), ifact(n + 1) {
assert(n < MOD);
fact[0] = 1;
for (int i = 1; i <= n; ++i)
fact[i] = fact[i - 1] * i;
ifact[n] = fact[n].inv();
for (int i = n; i >= 1; --i)
ifact[i - 1] = ifact[i] * i;
}
mint operator()(int n, int k) {
if (k < 0 || k > n)
return 0;
return fact[n] * ifact[k] * ifact[n - k];
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << std::setprecision(10);
ll n;
cin >> n;
string s;
cin >> s;
VV g(3);
rep(i, n) {
if (s[i] == 'R')
g[0].pb(i);
if (s[i] == 'G')
g[1].pb(i);
if (s[i] == 'B')
g[2].pb(i);
}
dbg(g);
ll ans = g[0].size() * g[1].size() * g[2].size();
dbg(ans);
ll R = g[0].size();
ll G = g[1].size();
Vec B = g[2];
rep(i, R) {
rep(j, G) {
ll x = g[0][i];
ll y = g[1][j];
if (x > y)
swap(x, y);
ll z1 = 2 * y - x;
ll z2 = 2 * x - y;
if (binary_search(ALL(B), z1))
ans--;
if (binary_search(ALL(B), z2))
ans--;
if ((x + y) % 2 == 0) {
ll z3 = (x + y) / 2;
if (binary_search(ALL(B), z3))
ans--;
}
}
}
cout << ans << endl;
return 0;
}
| delete | 0 | 1 | 0 | 0 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll, ll>
#define FOR(I, A, B) for (ll I = ll(A); I < ll(B); ++I)
#define FORR(I, A, B) for (ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x, t, f) ((x) ? (t) : (f))
#define SORT(x) (sort(x.begin(), x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x, v) \
(lower_bound(x.begin(), x.end(), v) - x.begin()) // xi>=v x is sorted
#define POSU(x, v) \
(upper_bound(x.begin(), x.end(), v) - x.begin()) // xi>v x is sorted
#define NUM(x, v) (POSU(x, v) - POSL(x, v)) // x is sorted
#define REV(x) (reverse(x.begin(), x.end())) // reverse
ll gcd_(ll a, ll b) {
if (a % b == 0)
return b;
return gcd_(b, a % b);
}
ll lcm_(ll a, ll b) {
ll c = gcd_(a, b);
return ((a / c) * (b / c) * c);
}
#define NEXTP(x) next_permutation(x.begin(), x.end())
const ll INF = ll(1e16) + ll(7);
const ll MOD = 1000000007LL;
#define out(a) cout << fixed << setprecision((a))
// tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a) {
ll r = 0;
while (a) {
a /= 10;
r++;
}
return r;
}
ll ketawa(ll a) {
ll r = 0;
while (a) {
r += a % 10;
a /= 10;
}
return r;
}
int main() {
int n;
string s;
cin >> n >> s;
ll ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; j++) {
if (s[i] == s[j])
continue;
for (int k = j + 1; k < n; k++) {
if (j - k != i - j && s[k] != s[i] && s[k] != s[j])
ans++;
}
}
}
cout << ans << endl;
}
| #pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll, ll>
#define FOR(I, A, B) for (ll I = ll(A); I < ll(B); ++I)
#define FORR(I, A, B) for (ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x, t, f) ((x) ? (t) : (f))
#define SORT(x) (sort(x.begin(), x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x, v) \
(lower_bound(x.begin(), x.end(), v) - x.begin()) // xi>=v x is sorted
#define POSU(x, v) \
(upper_bound(x.begin(), x.end(), v) - x.begin()) // xi>v x is sorted
#define NUM(x, v) (POSU(x, v) - POSL(x, v)) // x is sorted
#define REV(x) (reverse(x.begin(), x.end())) // reverse
ll gcd_(ll a, ll b) {
if (a % b == 0)
return b;
return gcd_(b, a % b);
}
ll lcm_(ll a, ll b) {
ll c = gcd_(a, b);
return ((a / c) * (b / c) * c);
}
#define NEXTP(x) next_permutation(x.begin(), x.end())
const ll INF = ll(1e16) + ll(7);
const ll MOD = 1000000007LL;
#define out(a) cout << fixed << setprecision((a))
// tie(a,b,c) = make_tuple(10,9,87);
#define pop_(a) __builtin_popcount((a))
ll keta(ll a) {
ll r = 0;
while (a) {
a /= 10;
r++;
}
return r;
}
ll ketawa(ll a) {
ll r = 0;
while (a) {
r += a % 10;
a /= 10;
}
return r;
}
int main() {
int n;
string s;
cin >> n >> s;
ll ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; j++) {
if (s[i] == s[j])
continue;
for (int k = j + 1; k < n; k++) {
if (j - k != i - j && s[k] != s[i] && s[k] != s[j])
ans++;
}
}
}
cout << ans << endl;
}
| insert | 0 | 0 | 0 | 4 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <typeinfo>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REP2(i, s, n) for (int i = s; i < n; i++)
#define REP_1(i, n) for (int i = 1; i < n + 1; i++)
#define bitSearch(bit, n) for (int bit = 0; bit < (1 << n); bit++)
#define sz(x) int(x.size())
using namespace std;
template <class T> void print(const T &value) {
std::cout << value << std::endl;
}
void yesno(bool a) {
if (a)
cout << "yes" << endl;
else
cout << "no" << endl;
}
void YesNo(bool a) {
if (a)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
void YESNO(bool a) {
if (a)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
typedef long long ll;
typedef unsigned long ul;
typedef long double ld;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const ll INF = 1000001000;
const ll mod = 1000000007; // 10^9+7
ll power(ll x, ll n, ll mod) { // x^nをmodで割った余り
ll res = 1;
if (n > 0) {
res = power(x, n / 2, mod);
if (n % 2 == 0)
res = (res * res) % mod;
else
res = (((res * res) % mod) * x) % mod;
}
return res;
}
// const int dx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
// const int dy[8] = {0, -1, 1, 0, -1, 1, -1, 1};
const int dx[6] = {1, 0, -1, 1, -1, 0};
const int dy[6] = {1, 1, 1, 0, 0, -1};
struct Edge {
int to, cost;
Edge(int to, int cost) : to(to), cost(cost){};
};
using Graph =
vector<vector<int>>; // 隣接リスト:G[i]にはiと隣接する頂点が入るよ。
using GraphW = vector<vector<Edge>>; // 重み付きの隣接リスト
using P = pair<int, int>; // BFSで利用。queueに入れる。
using lP = pair<ll, ll>;
using PP = pair<int, P>; // dijkstraで利用,priority_queueに入れる。
using p_queue = priority_queue<int, vector<int>, greater<int>>; // 小さい順
class UnionFindTree {
public:
UnionFindTree(int size) : memberSize(size) {
par.resize(size * sizeof(ll));
rnk.resize(size * sizeof(ll));
diff_weight.resize(size * sizeof(ll));
REP(i, size) {
par[i] = i;
rnk[i] = 0;
diff_weight[i] = 0;
}
}
int memberSize;
vector<int> par;
vector<int> rnk;
vector<ll> diff_weight;
// n個のnodeで初期化する関数
void init(ll n) {
REP(i, n) {
par[i] = i;
rnk[i] = 1;
}
}
// 木の根を求める。この際,親は根に更新される。
int find(ll x) {
if (par[x] == x) {
return x;
} else {
int r = find(par[x]);
diff_weight[x] += diff_weight[par[x]];
return par[x] = r;
}
}
// xとyが同じ集合に属するか判定
bool same(ll x, ll y) { return find(x) == find(y); }
// xとyの属する集合を融合
void unite(ll x, ll y) {
x = find(x);
y = find(y);
if (x == y) {
return;
}
if (rnk[x] < rnk[y]) {
par[x] = y;
} else {
par[y] = x;
if (rnk[x] == rnk[y]) {
rnk[x]++;
}
}
}
// xの重み
ll weight(ll x) {
find(x);
return diff_weight[x];
}
ll diff(ll x, ll y) { return weight(y) - weight(x); }
// 重みごと更新。weight(y)-weight(x)=wとなるようにする
void merge(int x, int y, int w) {
w += weight(x);
w -= weight(y);
x = find(x);
y = find(y);
if (x == y) {
return;
}
if (rnk[x] < rnk[y]) {
par[x] = y;
diff_weight[x] = -w;
} else {
par[y] = x;
diff_weight[y] = w;
if (rnk[x] == rnk[y]) {
rnk[x]++;
}
}
}
};
priority_queue<P, vector<P>, greater<P>> que;
struct Coordinate {
int x, y;
Coordinate(int y, int x) : y(y), x(x){};
};
ll gcd(ll a, ll b) {
if (a < b) {
ll tmp = a;
a = b;
b = tmp;
}
ll r = a % b;
while (r != 0) {
a = b;
b = r;
r = a % b;
}
return b;
}
// 番号ズレ注意!!
int main() {
int N;
string S;
cin >> N >> S;
vector<int> r, g, b;
REP(i, N) {
if (S[i] == 'R') {
r.push_back(i);
}
if (S[i] == 'G') {
g.push_back(i);
}
if (S[i] == 'B') {
b.push_back(i);
}
}
int ans = 0;
REP(i, r.size()) {
REP(j, g.size()) {
REP(k, b.size()) {
int x = r[i], y = g[j], z = b[k];
if (abs(x - y) != abs(y - z) && abs(y - z) != abs(z - x) &&
abs(z - x) != abs(x - y))
ans++;
}
}
}
print(ans);
} | #include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <typeinfo>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REP2(i, s, n) for (int i = s; i < n; i++)
#define REP_1(i, n) for (int i = 1; i < n + 1; i++)
#define bitSearch(bit, n) for (int bit = 0; bit < (1 << n); bit++)
#define sz(x) int(x.size())
using namespace std;
template <class T> void print(const T &value) {
std::cout << value << std::endl;
}
void yesno(bool a) {
if (a)
cout << "yes" << endl;
else
cout << "no" << endl;
}
void YesNo(bool a) {
if (a)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
void YESNO(bool a) {
if (a)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
typedef long long ll;
typedef unsigned long ul;
typedef long double ld;
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
const ll INF = 1000001000;
const ll mod = 1000000007; // 10^9+7
ll power(ll x, ll n, ll mod) { // x^nをmodで割った余り
ll res = 1;
if (n > 0) {
res = power(x, n / 2, mod);
if (n % 2 == 0)
res = (res * res) % mod;
else
res = (((res * res) % mod) * x) % mod;
}
return res;
}
// const int dx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
// const int dy[8] = {0, -1, 1, 0, -1, 1, -1, 1};
const int dx[6] = {1, 0, -1, 1, -1, 0};
const int dy[6] = {1, 1, 1, 0, 0, -1};
struct Edge {
int to, cost;
Edge(int to, int cost) : to(to), cost(cost){};
};
using Graph =
vector<vector<int>>; // 隣接リスト:G[i]にはiと隣接する頂点が入るよ。
using GraphW = vector<vector<Edge>>; // 重み付きの隣接リスト
using P = pair<int, int>; // BFSで利用。queueに入れる。
using lP = pair<ll, ll>;
using PP = pair<int, P>; // dijkstraで利用,priority_queueに入れる。
using p_queue = priority_queue<int, vector<int>, greater<int>>; // 小さい順
class UnionFindTree {
public:
UnionFindTree(int size) : memberSize(size) {
par.resize(size * sizeof(ll));
rnk.resize(size * sizeof(ll));
diff_weight.resize(size * sizeof(ll));
REP(i, size) {
par[i] = i;
rnk[i] = 0;
diff_weight[i] = 0;
}
}
int memberSize;
vector<int> par;
vector<int> rnk;
vector<ll> diff_weight;
// n個のnodeで初期化する関数
void init(ll n) {
REP(i, n) {
par[i] = i;
rnk[i] = 1;
}
}
// 木の根を求める。この際,親は根に更新される。
int find(ll x) {
if (par[x] == x) {
return x;
} else {
int r = find(par[x]);
diff_weight[x] += diff_weight[par[x]];
return par[x] = r;
}
}
// xとyが同じ集合に属するか判定
bool same(ll x, ll y) { return find(x) == find(y); }
// xとyの属する集合を融合
void unite(ll x, ll y) {
x = find(x);
y = find(y);
if (x == y) {
return;
}
if (rnk[x] < rnk[y]) {
par[x] = y;
} else {
par[y] = x;
if (rnk[x] == rnk[y]) {
rnk[x]++;
}
}
}
// xの重み
ll weight(ll x) {
find(x);
return diff_weight[x];
}
ll diff(ll x, ll y) { return weight(y) - weight(x); }
// 重みごと更新。weight(y)-weight(x)=wとなるようにする
void merge(int x, int y, int w) {
w += weight(x);
w -= weight(y);
x = find(x);
y = find(y);
if (x == y) {
return;
}
if (rnk[x] < rnk[y]) {
par[x] = y;
diff_weight[x] = -w;
} else {
par[y] = x;
diff_weight[y] = w;
if (rnk[x] == rnk[y]) {
rnk[x]++;
}
}
}
};
priority_queue<P, vector<P>, greater<P>> que;
struct Coordinate {
int x, y;
Coordinate(int y, int x) : y(y), x(x){};
};
ll gcd(ll a, ll b) {
if (a < b) {
ll tmp = a;
a = b;
b = tmp;
}
ll r = a % b;
while (r != 0) {
a = b;
b = r;
r = a % b;
}
return b;
}
// 番号ズレ注意!!
int main() {
int N;
string S;
cin >> N >> S;
vector<int> r, g, b;
REP(i, N) {
if (S[i] == 'R') {
r.push_back(i);
}
if (S[i] == 'G') {
g.push_back(i);
}
if (S[i] == 'B') {
b.push_back(i);
}
}
ll ans = r.size() * g.size() * b.size();
for (int i = 0; i < N; i++) {
for (int j = 1; i + 2 * j < N; j++) {
if (S[i] != S[i + j] && S[i + j] != S[i + 2 * j] &&
S[i + 2 * j] != S[i]) {
ans--;
}
}
}
print(ans);
} | replace | 233 | 241 | 233 | 239 | TLE | |
p02714 | C++ | Time Limit Exceeded | #pragma GCC optimize("O3")
#include <algorithm>
#include <chrono>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
typedef long int l;
#define f(i, a, b) for (ll i = (ll)a; i < (ll)b; i += 1)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i -= 1)
#define endl '\n'
#define N 1000000007 // prime modulo value
#define all(x) x.begin(), x.end()
#define FAST \
ios_base::sync_with_stdio(0); \
cin.tie(0), cout.tie(0)
using namespace std;
#define MAX 1000001
l spf[MAX];
void precompute() {
spf[1] = 1;
for (l i = 2; i < MAX; i++)
spf[i] = i;
for (l i = 4; i < MAX; i += 2)
spf[i] = 2;
for (l i = 3; i * i < MAX; i++) {
if (spf[i] == i) {
for (l j = i * i; j < MAX; j += i)
if (spf[j] == j)
spf[j] = i;
}
}
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int main() {
FAST;
ll n;
cin >> n;
string s;
cin >> s;
vector<ll> red;
vector<ll> green;
vector<ll> blue;
f(i, 0, n) {
if (s[i] == 'R')
red.push_back(i);
else if (s[i] == 'B')
blue.push_back(i);
else
green.push_back(i);
}
ll r = red.size(), g = green.size(), b = blue.size();
ll ans = 0;
f(i, 0, r) {
f(j, 0, g) {
f(k, 0, b) {
ll mini = min(red[i], min(green[j], blue[k]));
ll maxi = max(red[i], max(green[j], blue[k]));
ll mid = red[i] + green[j] + blue[k] - mini - maxi;
if ((2 * mid) != mini + maxi)
ans += 1;
}
}
}
cout << ans;
return 0;
} | #pragma GCC optimize("O3")
#pragma GCC target("avx,avx2,fma")
#include <algorithm>
#include <chrono>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
typedef long int l;
#define f(i, a, b) for (ll i = (ll)a; i < (ll)b; i += 1)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i -= 1)
#define endl '\n'
#define N 1000000007 // prime modulo value
#define all(x) x.begin(), x.end()
#define FAST \
ios_base::sync_with_stdio(0); \
cin.tie(0), cout.tie(0)
using namespace std;
#define MAX 1000001
l spf[MAX];
void precompute() {
spf[1] = 1;
for (l i = 2; i < MAX; i++)
spf[i] = i;
for (l i = 4; i < MAX; i += 2)
spf[i] = 2;
for (l i = 3; i * i < MAX; i++) {
if (spf[i] == i) {
for (l j = i * i; j < MAX; j += i)
if (spf[j] == j)
spf[j] = i;
}
}
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int main() {
FAST;
ll n;
cin >> n;
string s;
cin >> s;
vector<ll> red;
vector<ll> green;
vector<ll> blue;
f(i, 0, n) {
if (s[i] == 'R')
red.push_back(i);
else if (s[i] == 'B')
blue.push_back(i);
else
green.push_back(i);
}
ll r = red.size(), g = green.size(), b = blue.size();
ll ans = 0;
f(i, 0, r) {
f(j, 0, g) {
f(k, 0, b) {
ll mini = min(red[i], min(green[j], blue[k]));
ll maxi = max(red[i], max(green[j], blue[k]));
ll mid = red[i] + green[j] + blue[k] - mini - maxi;
if ((2 * mid) != mini + maxi)
ans += 1;
}
}
}
cout << ans;
return 0;
} | insert | 1 | 1 | 1 | 2 | TLE | |
p02714 | C++ | Time Limit Exceeded | /**
* author : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
* created : 2020-04-13 12:11:29
**/
// #pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using int64 = long long;
template <class T>
using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec) {
os << '{';
size_t n = vec.size();
for (size_t i = 0; i < n; ++i) {
os << vec[i];
if (i != n - 1)
os << ',';
}
os << '}';
return os;
}
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
return os << '{' << p.first << " " << p.second << '}';
}
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::map<T, U> &mp) {
os << '{';
for (auto it = mp.begin(); it != mp.end(); ++it) {
os << '{' << it->first << ':' << it->second << '}';
if (it != --mp.end())
os << ',';
}
os << '}';
return os;
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::set<T> &st) {
os << '{';
for (auto it = st.begin(); it != st.end(); ++it) {
os << *it;
if (it != --st.end())
os << ',';
}
os << '}';
return os;
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
size_t n = vec.size();
for (size_t i = 0; i < n; ++i)
is >> vec[i];
return is;
}
#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
void debug_out() { std::cerr << '\n'; }
template <class Head, class... Tail>
void debug_out(Head &&head, Tail &&...tail) {
std::cerr << head;
if (sizeof...(Tail) != 0)
std::cerr << ", ";
debug_out(std::forward<Tail>(tail)...);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
string s;
cin >> s;
int64 ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if (s[i] == s[j])
continue;
for (int k = j + 1; k < n; ++k) {
if (s[j] != s[k] && s[i] != s[k] && j - i != k - j)
++ans;
}
}
}
cout << ans << '\n';
return 0;
} | /**
* author : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
* created : 2020-04-13 12:11:29
**/
#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <complex>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using int64 = long long;
template <class T>
using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec) {
os << '{';
size_t n = vec.size();
for (size_t i = 0; i < n; ++i) {
os << vec[i];
if (i != n - 1)
os << ',';
}
os << '}';
return os;
}
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::pair<T, U> &p) {
return os << '{' << p.first << " " << p.second << '}';
}
template <class T, class U>
std::ostream &operator<<(std::ostream &os, const std::map<T, U> &mp) {
os << '{';
for (auto it = mp.begin(); it != mp.end(); ++it) {
os << '{' << it->first << ':' << it->second << '}';
if (it != --mp.end())
os << ',';
}
os << '}';
return os;
}
template <class T>
std::ostream &operator<<(std::ostream &os, const std::set<T> &st) {
os << '{';
for (auto it = st.begin(); it != st.end(); ++it) {
os << *it;
if (it != --st.end())
os << ',';
}
os << '}';
return os;
}
template <class T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
size_t n = vec.size();
for (size_t i = 0; i < n; ++i)
is >> vec[i];
return is;
}
#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
void debug_out() { std::cerr << '\n'; }
template <class Head, class... Tail>
void debug_out(Head &&head, Tail &&...tail) {
std::cerr << head;
if (sizeof...(Tail) != 0)
std::cerr << ", ";
debug_out(std::forward<Tail>(tail)...);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
string s;
cin >> s;
int64 ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
if (s[i] == s[j])
continue;
for (int k = j + 1; k < n; ++k) {
if (s[j] != s[k] && s[i] != s[k] && j - i != k - j)
++ans;
}
}
}
cout << ans << '\n';
return 0;
} | replace | 5 | 8 | 5 | 8 | TLE | |
p02714 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define ll long long
int n;
char s[2005];
int num[2005];
ll a, b, c, ans;
int main() {
scanf("%d", &n);
scanf("%s", s);
for (int i = 1; i <= n; i++) {
if (s[i - 1] == 'R') {
num[i] = 0;
a++;
} else if (s[i - 1] == 'G') {
num[i] = 1;
b++;
} else if (s[i - 1] == 'B') {
num[i] = 2;
c++;
}
}
int l, r;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i - j < 1 || i + j > n)
break;
if (num[i] != num[i - j] && num[i] != num[i + j] &&
num[i - j] != num[i + j])
ans++;
}
}
printf("%lld", a * b * c - ans);
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
#define ll long long
int n;
char s[4005];
int num[4005];
ll a, b, c, ans;
int main() {
scanf("%d", &n);
scanf("%s", s);
for (int i = 1; i <= n; i++) {
if (s[i - 1] == 'R') {
num[i] = 0;
a++;
} else if (s[i - 1] == 'G') {
num[i] = 1;
b++;
} else if (s[i - 1] == 'B') {
num[i] = 2;
c++;
}
}
int l, r;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i - j < 1 || i + j > n)
break;
if (num[i] != num[i - j] && num[i] != num[i + j] &&
num[i - j] != num[i + j])
ans++;
}
}
printf("%lld", a * b * c - ans);
return 0;
} | replace | 8 | 10 | 8 | 10 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
using namespace std;
using ll = long long;
int main() {
int N;
string S;
cin >> N >> S;
ll ans = 0;
FOR(i, 0, N - 2) FOR(j, i + 1, N - 1) FOR(k, j + 1, N) {
if (j - i != k - j && S[i] != S[j] && S[i] != S[k] && S[j] != S[k])
ans += 1;
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
using namespace std;
using ll = long long;
int main() {
int N;
string S;
cin >> N >> S;
vector<ll> cnt(3);
rep(i, N) {
if (S[i] == 'R')
cnt[0] += 1;
if (S[i] == 'G')
cnt[1] += 1;
if (S[i] == 'B')
cnt[2] += 1;
}
ll ans = cnt[0] * cnt[1] * cnt[2];
rep(j, N) rep(i, j) {
int k = 2 * j - i;
if (k < N) {
if (S[i] != S[j] && S[j] != S[k] && S[k] != S[i])
ans -= 1;
}
}
cout << ans << endl;
return 0;
} | replace | 10 | 14 | 10 | 26 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(), (x).end()
#define INF (1 << 30) - 1
using ll = long long;
using namespace std;
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;
}
int main() {
int n;
cin >> n;
string s;
cin >> s;
int ans = 0;
rep(i, n - 2) {
for (int j = i + 1; j < n - 1; j++) {
if (s[i] != s[j]) {
for (int k = j + 1; k < n; k++) {
if (s[i] != s[k] && s[j] != s[k]) {
if (j - i != k - j) {
ans++;
}
}
}
}
}
}
cout << ans;
cout << "\n";
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(), (x).end()
#define INF (1 << 30) - 1
using ll = long long;
using namespace std;
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;
}
int main() {
int n;
cin >> n;
string s;
cin >> s;
vi txt(n);
rep(i, n) {
if (s[i] == 'R')
txt[i] = 0;
if (s[i] == 'G')
txt[i] = 1;
if (s[i] == 'B')
txt[i] = 2;
}
vi rgb(3);
rep(i, n) rgb[txt[i]]++;
ll ans = 1;
rep(i, 3) ans *= rgb[i];
rep(j, n) {
rep(i, j) {
if (2 * j - i < n && txt[i] != txt[j] && txt[j] != txt[2 * j - i] &&
txt[2 * j - i] != txt[i])
ans--;
}
}
cout << ans;
cout << "\n";
return 0;
}
| replace | 27 | 39 | 27 | 45 | TLE | |
p02714 | C++ | Time Limit Exceeded | #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define repe1(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define eb(k, v) emplace_back(k, v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
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;
}
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) { return (a % b) ? gcd(b, a % b) : b; }
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
string s;
cin >> s;
int ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = i + 1; j < n; ++j) {
for (int k = j + 1; k < n; ++k) {
if (s[i] != s[j] && s[k] != s[i] && s[k] != s[j] && j - i != k - j) {
ans++;
}
}
}
}
ct(ans);
}
| #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define repe1(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define eb(k, v) emplace_back(k, v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
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;
}
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) { return (a % b) ? gcd(b, a % b) : b; }
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
string s;
cin >> s;
ll ans = 0;
map<char, vector<ll>> mp;
for (ll i = 0; i < n; ++i) {
mp[s[i]].pb(i + 1);
}
ll r = mp['R'].size();
ll g = mp['G'].size();
ll b = mp['B'].size();
ans = r * g * b;
for (ll i = 0; i < n; ++i) {
for (ll j = i + 1; j < n; ++j) {
ll k = j + j - i;
if (k < n && s[i] != s[j] && s[j] != s[k] && s[i] != s[k]) {
ans--;
}
}
}
ct(ans);
}
| replace | 39 | 46 | 39 | 53 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1e+9 + 7;
// マクロ
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 10000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
int main() {
int n;
cin >> n;
string s;
cin >> s;
map<char, vector<int>> mp;
rep(i, n) { mp[s[i]].push_back(i); }
string sample = "RGB";
vector<int> r = mp[sample[0]];
vector<int> g = mp[sample[1]];
vector<int> b = mp[sample[2]];
ll ans = 0;
rep(i, r.size()) {
int R = r[i];
rep(j, g.size()) {
int G = g[j];
int mx, mn, md;
md = INF;
int tmpMx = max(R, G);
int tmpMn = min(R, G);
mx = tmpMx + tmpMx - tmpMn;
mn = max(tmpMn - (tmpMx - tmpMn), 0);
if ((tmpMx + tmpMn) % 2 == 0) {
md = (tmpMn + tmpMx) / 2;
}
rep(k, b.size()) {
if (b[k] == mn || b[k] == mx || b[k] == md) {
continue;
}
ans++;
}
}
}
cout << ans << "\n";
return 0;
} | #include <algorithm> //sort,二分探索,など
#include <bitset> //固定長bit集合
#include <cmath> //pow,logなど
#include <complex> //複素数
#include <deque> //両端アクセスのキュー
#include <functional> //sortのgreater
#include <iomanip> //setprecision(浮動小数点の出力の誤差)
#include <iostream> //入出力
#include <map> //map(辞書)
#include <numeric> //iota(整数列の生成),gcdとlcm(c++17)
#include <queue> //キュー
#include <set> //集合
#include <stack> //スタック
#include <string> //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility> //pair
#include <vector> //可変長配列
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1e+9 + 7;
// マクロ
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 10000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
int main() {
int n;
cin >> n;
string s;
cin >> s;
map<char, vector<int>> mp;
rep(i, n) { mp[s[i]].push_back(i); }
string sample = "RGB";
vector<int> r = mp[sample[0]];
vector<int> g = mp[sample[1]];
vector<int> b = mp[sample[2]];
ll ans = 0;
rep(i, r.size()) {
int R = r[i];
rep(j, g.size()) {
int G = g[j];
int mx, mn, md;
md = INF;
int tmpMx = max(R, G);
int tmpMn = min(R, G);
mx = tmpMx + tmpMx - tmpMn;
mn = max(tmpMn - (tmpMx - tmpMn), 0);
if ((tmpMx + tmpMn) % 2 == 0) {
md = (tmpMn + tmpMx) / 2;
}
rep(k, b.size()) {
if (b[k] == mn || b[k] == mx || b[k] == md) {
continue;
}
ans++;
}
}
}
cout << ans << "\n";
return 0;
} | replace | 0 | 1 | 0 | 18 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int(i) = 0; i < (n); i++)
#define REP(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f) ? "Yes" : "No")
#define YORN(f) puts((f) ? "YES" : "NO")
#define sec second
#define fir first
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
typedef vector<int> Vec;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; };
int lcm(int a, int b) { return a / gcd(a, b) * b; };
int mod(int a, int b) { return (a + b - 1) / b; };
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
};
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
};
signed main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int n;
string s;
cin >> n >> s;
Vec r;
Vec g;
Vec b;
rep(i, n) {
if (s[i] == 'R')
r.push_back(i);
if (s[i] == 'G')
g.push_back(i);
if (s[i] == 'B')
b.push_back(i);
}
int ans = 0;
rep(i, r.size()) {
rep(j, g.size()) {
rep(k, b.size()) {
int d1 = abs(r[i] - g[j]);
int d2 = abs(g[j] - b[k]);
int d3 = abs(r[i] - b[k]);
if (d1 != d2 && d2 != d3 && d1 != d3)
ans++;
}
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int(i) = 0; i < (n); i++)
#define REP(i, m, n) for (int(i) = (m); (i) < (n); (i)++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f) ? "Yes" : "No")
#define YORN(f) puts((f) ? "YES" : "NO")
#define sec second
#define fir first
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
typedef vector<int> Vec;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; };
int lcm(int a, int b) { return a / gcd(a, b) * b; };
int mod(int a, int b) { return (a + b - 1) / b; };
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
std::fill((T *)array, (T *)(array + N), val);
}
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
};
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
};
signed main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
int n;
string s;
cin >> n >> s;
Vec r;
Vec g;
Vec b;
rep(i, n) {
if (s[i] == 'R')
r.push_back(i);
if (s[i] == 'G')
g.push_back(i);
if (s[i] == 'B')
b.push_back(i);
}
int ans = 0;
rep(i, r.size()) {
rep(j, g.size()) {
int d = abs(r[i] - g[j]);
int L = min(r[i], g[j]);
int R = max(r[i], g[j]);
ans += b.size();
if (L - d >= 0 && s[L - d] == 'B')
ans--;
if (R + d < n && s[R + d] == 'B')
ans--;
if (d % 2 == 0 && s[L + d / 2] == 'B')
ans--;
}
}
cout << ans << endl;
return 0;
} | replace | 63 | 70 | 63 | 73 | TLE | |
p02714 | C++ | Time Limit Exceeded | // g++ .cpp && ./a.out
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef pair<int, int> p;
typedef long long ll;
const int mod = 1000000007;
const int inf = 1000000007;
int main() {
int n;
string s;
cin >> n >> s;
int cnt = 0;
for (int i = 0; i < n - 2; i++) {
for (int j = i + 1; j < n - 1; j++) {
for (int k = j + 1; k < n; k++) {
if (j - i != k - j && s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) {
cnt++;
}
}
}
}
cout << cnt << endl;
}
| // g++ .cpp && ./a.out
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef pair<int, int> p;
typedef long long ll;
const int mod = 1000000007;
const int inf = 1000000007;
int main() {
int n;
string s;
cin >> n >> s;
ll cnt = 0;
vector<ll> cntR(n);
vector<ll> cntB(n);
vector<ll> cntG(n);
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (s[j] == 'R')
cntR[i]++;
if (s[j] == 'B')
cntB[i]++;
if (s[j] == 'G')
cntG[i]++;
}
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
{
if (s[i] == 'R' && s[j] == 'B') {
cnt += cntG[j];
if (s[2 * (j - i) + i] == 'G' && 2 * (j - i) + i < n)
cnt--;
}
if (s[i] == 'R' && s[j] == 'G') {
cnt += cntB[j];
if (s[2 * (j - i) + i] == 'B' && 2 * (j - i) + i < n)
cnt--;
}
if (s[i] == 'B' && s[j] == 'R') {
cnt += cntG[j];
if (s[2 * (j - i) + i] == 'G' && 2 * (j - i) + i < n)
cnt--;
}
if (s[i] == 'B' && s[j] == 'G') {
cnt += cntR[j];
if (s[2 * (j - i) + i] == 'R' && 2 * (j - i) + i < n)
cnt--;
}
if (s[i] == 'G' && s[j] == 'B') {
cnt += cntR[j];
if (s[2 * (j - i) + i] == 'R' && 2 * (j - i) + i < n)
cnt--;
}
if (s[i] == 'G' && s[j] == 'R') {
cnt += cntB[j];
if (s[2 * (j - i) + i] == 'B' && 2 * (j - i) + i < n)
cnt--;
}
}
}
}
cout << cnt << endl;
}
| replace | 15 | 21 | 15 | 61 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <type_traits>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)
#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
rep(i, (int)v.size()) {
if (i)
os << ",";
os << v[i];
}
os << "}";
return os;
}
template <typename T, size_t S> void printArray(const T (&array)[S]) {
for (auto val : array)
std::cout << val << ", ";
std::cout << "\n";
}
const int mod = 1e9 + 7;
const int inf = 1e9 + 5;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << std::setprecision(10);
int n;
std::cin >> n;
string s;
std::cin >> s;
vi r, g, b;
rep(i, n) {
if (s[i] == 'R')
r.pb(i);
else if (s[i] == 'G')
g.pb(i);
else
b.pb(i);
}
int rsz = r.size(), gsz = g.size(), bsz = b.size();
ll ans = 0;
for (int p1 : r)
for (int p2 : g) {
int pp1 = p1;
if (pp1 > p2)
swap(pp1, p2);
int diff = p2 - pp1;
ans += bsz;
if (binary_search(rng(b), pp1 - diff))
ans--;
if (diff % 2 == 0 && binary_search(rng(b), pp1 + diff / 2))
ans--;
if (binary_search(rng(b), p2 + diff))
ans--;
}
int tmp = 0;
rep(i, rsz) rep(j, gsz) rep(k, bsz) {
vi vec = {r[i], g[j], b[k]};
sort(rng(vec));
int d1 = vec[1] - vec[0], d2 = vec[2] - vec[1];
if (d1 != d2)
tmp++;
}
std::cout << ans << "\n";
}
| #include <bits/stdc++.h>
#include <type_traits>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)
#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "(" << p.first << "," << p.second << ")";
return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
rep(i, (int)v.size()) {
if (i)
os << ",";
os << v[i];
}
os << "}";
return os;
}
template <typename T, size_t S> void printArray(const T (&array)[S]) {
for (auto val : array)
std::cout << val << ", ";
std::cout << "\n";
}
const int mod = 1e9 + 7;
const int inf = 1e9 + 5;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << std::setprecision(10);
int n;
std::cin >> n;
string s;
std::cin >> s;
vi r, g, b;
rep(i, n) {
if (s[i] == 'R')
r.pb(i);
else if (s[i] == 'G')
g.pb(i);
else
b.pb(i);
}
int rsz = r.size(), gsz = g.size(), bsz = b.size();
ll ans = 0;
for (int p1 : r)
for (int p2 : g) {
int pp1 = p1;
if (pp1 > p2)
swap(pp1, p2);
int diff = p2 - pp1;
ans += bsz;
if (binary_search(rng(b), pp1 - diff))
ans--;
if (diff % 2 == 0 && binary_search(rng(b), pp1 + diff / 2))
ans--;
if (binary_search(rng(b), p2 + diff))
ans--;
}
std::cout << ans << "\n";
}
| delete | 89 | 97 | 89 | 89 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include "bits/stdc++.h"
#define hhh cerr << "hhh" << endl
#define see(x) cerr << (#x) << '=' << (x) << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pr;
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (c != '-' && (c < '0' || c > '9'))
c = getchar();
if (c == '-')
f = -1, c = getchar();
while (c >= '0' && c <= '9')
x = x * 10 + c - '0', c = getchar();
return f * x;
}
const int maxn = 3e5 + 7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
inline int id(char c) {
if (c == 'R')
return 0;
if (c == 'G')
return 1;
if (c == 'B')
return 2;
return -1;
}
int cnt[3][maxn];
bool vis[maxn];
char s[maxn];
int main() {
int n = read();
scanf("%s", s + 1);
for (int i = 1; i <= n; ++i)
cnt[id(s[i])][i] = 1;
for (int c = 0; c < 3; ++c) {
for (int i = n - 1; i; --i)
cnt[c][i] += cnt[c][i + 1];
}
ll ans = 0;
for (int i = 1; i <= n - 2; ++i) {
for (int j = i + 1; j <= n - 1; ++j)
if (s[i] != s[j]) {
memset(vis, 0, sizeof(vis));
vis[id(s[i])] = 1;
vis[id(s[j])] = 1;
int c;
for (int i = 0; i < 3; ++i)
if (!vis[i]) {
c = i;
break;
}
ans += cnt[c][j + 1];
if (2 * j - i <= n && id(s[2 * j - i]) == c)
ans--;
}
}
cout << ans << endl;
} | #include "bits/stdc++.h"
#define hhh cerr << "hhh" << endl
#define see(x) cerr << (#x) << '=' << (x) << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pr;
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (c != '-' && (c < '0' || c > '9'))
c = getchar();
if (c == '-')
f = -1, c = getchar();
while (c >= '0' && c <= '9')
x = x * 10 + c - '0', c = getchar();
return f * x;
}
const int maxn = 3e5 + 7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
inline int id(char c) {
if (c == 'R')
return 0;
if (c == 'G')
return 1;
if (c == 'B')
return 2;
return -1;
}
int cnt[3][maxn];
bool vis[3];
char s[maxn];
int main() {
int n = read();
scanf("%s", s + 1);
for (int i = 1; i <= n; ++i)
cnt[id(s[i])][i] = 1;
for (int c = 0; c < 3; ++c) {
for (int i = n - 1; i; --i)
cnt[c][i] += cnt[c][i + 1];
}
ll ans = 0;
for (int i = 1; i <= n - 2; ++i) {
for (int j = i + 1; j <= n - 1; ++j)
if (s[i] != s[j]) {
memset(vis, 0, sizeof(vis));
vis[id(s[i])] = 1;
vis[id(s[j])] = 1;
int c;
for (int i = 0; i < 3; ++i)
if (!vis[i]) {
c = i;
break;
}
ans += cnt[c][j + 1];
if (2 * j - i <= n && id(s[2 * j - i]) == c)
ans--;
}
}
cout << ans << endl;
} | replace | 33 | 34 | 33 | 34 | TLE | |
p02714 | C++ | Runtime Error | #pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (int)(b); i++)
#define FORD(i, a, b) for (int i = a; i > (int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i)&1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;
const int maxN = 1 << 13;
int pref[400][maxN];
char T[maxN];
void solve() {
int n;
scanf("%d %s", &n, T + 1);
FOR(i, 1, n + 1) {
for (char c : {'R', 'G', 'B'})
pref[i][c] = pref[i - 1][c];
pref[i][T[i]]++;
}
long long res = 0;
FOR(i, 1, n + 1) FOR(j, i + 2, n + 1) if (T[i] != T[j]) {
char x = T[i] ^ T[j] ^ 'R' ^ 'G' ^ 'B';
int k = (i + j) / 2;
res += pref[j][x] - pref[i][x];
if ((i - j) % 2 == 0 and T[k] == x)
res--;
}
printf("%lld\n", res);
}
int main() {
int t;
t = 1; // scanf ("%d", &t);
while (t--)
solve();
return 0;
}
| #pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (int)(b); i++)
#define FORD(i, a, b) for (int i = a; i > (int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i)&1)
#define ft first
#define sd second
#define kw(a) ((a) * (a))
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;
const int maxN = 1 << 13;
int pref[maxN][400];
char T[maxN];
void solve() {
int n;
scanf("%d %s", &n, T + 1);
FOR(i, 1, n + 1) {
for (char c : {'R', 'G', 'B'})
pref[i][c] = pref[i - 1][c];
pref[i][T[i]]++;
}
long long res = 0;
FOR(i, 1, n + 1) FOR(j, i + 2, n + 1) if (T[i] != T[j]) {
char x = T[i] ^ T[j] ^ 'R' ^ 'G' ^ 'B';
int k = (i + j) / 2;
res += pref[j][x] - pref[i][x];
if ((i - j) % 2 == 0 and T[k] == x)
res--;
}
printf("%lld\n", res);
}
int main() {
int t;
t = 1; // scanf ("%d", &t);
while (t--)
solve();
return 0;
} | replace | 22 | 23 | 22 | 23 | 0 | |
p02714 | C++ | Runtime Error | /*
Coded and Decoded by : Yash Kapoor
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair
#define pll pair<ll, ll>
#define vl vector<ll>
#define sl set<ll>
#define vll vector<pll>
#define ml map<ll, ll>
#define mll map<pll, ll>
#define all(a) a.begin(), a.end()
#define x first
#define y second
#define sz(x) (ll) x.size()
#define dl '\n'
// #define why (ll)1000000007
#define why (ll)998244353
#define lp(i, a, b) for (ll i = a; i < b; ++i)
#define lpr(i, a, b) for (ll i = a; i >= b; i--)
#define lpd(i, x) for (auto i : x)
#define ios \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
ll inf = 1e18;
ld pi = 3.141592653589;
ll mod = why;
ll fast_power(ll base, ll power, ll mod) {
ll result = 1;
while (power) {
if (power % 2)
result = (result * base) % mod;
base = (base * base) % mod;
power /= 2;
}
return result;
}
ll inverse(ll base, ll mod) { return fast_power(base, mod - 2, mod); }
ll solve() {
ll n;
string s;
cin >> n >> s;
ll dp[4][n + 5];
memset(dp, 0, sizeof(dp));
lp(i, 0, n) {
if (i) {
dp[0][i] += dp[0][i - 1];
dp[1][i] += dp[1][i - 1];
dp[2][i] += dp[2][i - 1];
}
if (s[i] == 'R') {
s[i] = 0;
dp[0][i]++;
}
if (s[i] == 'G') {
s[i] = 1;
dp[1][i]++;
}
if (s[i] == 'B') {
s[i] = 2;
dp[2][i]++;
}
}
ll sum = 0;
lp(i, 0, n) lp(j, i + 1, n) {
if (s[i] == s[j])
continue;
lp(k, 0, 3) {
if (k == s[i] or k == s[j])
continue;
sum += dp[k][n - 1] - dp[k][j];
if (j + (j - i) < n && s[j + (j - i)] == k)
sum--;
}
}
cout << sum << endl;
}
int main() {
ios ll t = 1;
// cin>>t;
while (t--) {
solve();
}
} | /*
Coded and Decoded by : Yash Kapoor
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair
#define pll pair<ll, ll>
#define vl vector<ll>
#define sl set<ll>
#define vll vector<pll>
#define ml map<ll, ll>
#define mll map<pll, ll>
#define all(a) a.begin(), a.end()
#define x first
#define y second
#define sz(x) (ll) x.size()
#define dl '\n'
// #define why (ll)1000000007
#define why (ll)998244353
#define lp(i, a, b) for (ll i = a; i < b; ++i)
#define lpr(i, a, b) for (ll i = a; i >= b; i--)
#define lpd(i, x) for (auto i : x)
#define ios \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
ll inf = 1e18;
ld pi = 3.141592653589;
ll mod = why;
ll fast_power(ll base, ll power, ll mod) {
ll result = 1;
while (power) {
if (power % 2)
result = (result * base) % mod;
base = (base * base) % mod;
power /= 2;
}
return result;
}
ll inverse(ll base, ll mod) { return fast_power(base, mod - 2, mod); }
ll solve() {
ll n;
string s;
cin >> n >> s;
ll dp[4][n + 5];
memset(dp, 0, sizeof(dp));
lp(i, 0, n) {
if (i) {
dp[0][i] += dp[0][i - 1];
dp[1][i] += dp[1][i - 1];
dp[2][i] += dp[2][i - 1];
}
if (s[i] == 'R') {
s[i] = 0;
dp[0][i]++;
}
if (s[i] == 'G') {
s[i] = 1;
dp[1][i]++;
}
if (s[i] == 'B') {
s[i] = 2;
dp[2][i]++;
}
}
ll sum = 0;
lp(i, 0, n) lp(j, i + 1, n) {
if (s[i] == s[j])
continue;
lp(k, 0, 3) {
if (k == s[i] or k == s[j])
continue;
sum += dp[k][n - 1] - dp[k][j];
if (j + (j - i) < n && s[j + (j - i)] == k)
sum--;
}
}
cout << sum << endl;
return 0;
}
int main() {
ios ll t = 1;
// cin>>t;
while (t--) {
solve();
}
} | insert | 91 | 91 | 91 | 92 | 0 | |
p02714 | C++ | Runtime Error | #include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
const int N = 4e3 + 7;
char s[N];
int a[N];
int b[N];
int c[N];
int main() {
memset(a, 0, sizeof a);
memset(b, 0, sizeof b);
memset(c, 0, sizeof c);
int n;
ll ans = 0;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> s[i];
for (int i = n; i >= 1; i--) {
a[i] += a[i + 1] + (s[i] == 'R');
b[i] += b[i + 1] + (s[i] == 'G');
c[i] += c[i + 1] + (s[i] == 'B');
}
// for(int i = 1; i <= n; i++)
// cout << a[i] << " ";
// cout << endl;
// for(int i = 1; i <= n; i++)
// cout << b[i] << " ";
// cout << endl;
// for(int i = 1; i <= n; i++)
// cout << c[i] << " ";
// cout << endl;
for (int i = 1; i <= n; i++) {
if (s[i] == 'R') {
for (int j = i + 1; j <= n; j++) {
if (s[j] == 'G') {
ans += c[j + 1];
if (s[j * 2 - i] == 'B' && j * 2 - i <= n)
ans--;
} else if (s[j] == 'B') {
ans += b[j + 1];
if (s[j * 2 - i] == 'G' && j * 2 - i <= n)
ans--;
}
}
}
if (s[i] == 'G') {
for (int j = i + 1; j <= n; j++) {
if (s[j] == 'R') {
ans += c[j + 1];
if (s[j * 2 - i] == 'B' && j * 2 - i <= n)
ans--;
} else if (s[j] == 'B') {
ans += a[j + 1];
if (s[j * 2 - i] == 'R' && j * 2 - i <= n)
ans--;
}
}
}
if (s[i] == 'B') {
for (int j = i + 1; j <= n; j++) {
if (s[j] == 'R') {
ans += b[j + 1];
if (s[j * 2 - i] == 'G' && j * 2 - i <= n)
ans--;
} else if (s[j] == 'G') {
ans += a[j + 1];
if (s[j * 2 - i] == 'R' && j * 2 - i <= n)
ans--;
}
}
}
}
cout << ans << endl;
return 0;
}
| #include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
const int N = 1e4 + 7;
char s[N];
int a[N];
int b[N];
int c[N];
int main() {
memset(a, 0, sizeof a);
memset(b, 0, sizeof b);
memset(c, 0, sizeof c);
int n;
ll ans = 0;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> s[i];
for (int i = n; i >= 1; i--) {
a[i] += a[i + 1] + (s[i] == 'R');
b[i] += b[i + 1] + (s[i] == 'G');
c[i] += c[i + 1] + (s[i] == 'B');
}
// for(int i = 1; i <= n; i++)
// cout << a[i] << " ";
// cout << endl;
// for(int i = 1; i <= n; i++)
// cout << b[i] << " ";
// cout << endl;
// for(int i = 1; i <= n; i++)
// cout << c[i] << " ";
// cout << endl;
for (int i = 1; i <= n; i++) {
if (s[i] == 'R') {
for (int j = i + 1; j <= n; j++) {
if (s[j] == 'G') {
ans += c[j + 1];
if (s[j * 2 - i] == 'B' && j * 2 - i <= n)
ans--;
} else if (s[j] == 'B') {
ans += b[j + 1];
if (s[j * 2 - i] == 'G' && j * 2 - i <= n)
ans--;
}
}
}
if (s[i] == 'G') {
for (int j = i + 1; j <= n; j++) {
if (s[j] == 'R') {
ans += c[j + 1];
if (s[j * 2 - i] == 'B' && j * 2 - i <= n)
ans--;
} else if (s[j] == 'B') {
ans += a[j + 1];
if (s[j * 2 - i] == 'R' && j * 2 - i <= n)
ans--;
}
}
}
if (s[i] == 'B') {
for (int j = i + 1; j <= n; j++) {
if (s[j] == 'R') {
ans += b[j + 1];
if (s[j * 2 - i] == 'G' && j * 2 - i <= n)
ans--;
} else if (s[j] == 'G') {
ans += a[j + 1];
if (s[j * 2 - i] == 'R' && j * 2 - i <= n)
ans--;
}
}
}
}
cout << ans << endl;
return 0;
}
| replace | 4 | 5 | 4 | 5 | 0 | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define inf 0x3f3f3f3f
#define ll long long
#define pb push_back
#define PII pair<int, int>
#define X first
#define Y second
#define MP make_pair
#define PI acos(-1.0)
#define eps 1e-8
const int maxn = 5e4 + 10;
const int maxm = 1.5e7 + 10;
const int mod = 998244353;
using namespace std;
int n;
int a[maxn];
char s[maxn];
vector<int> st[3];
int main() {
scanf("%d%s", &n, s);
for (int i = 0; i < n; i++) {
if (s[i] == 'R')
a[i] = 0;
else if (s[i] == 'G')
a[i] = 1;
else
a[i] = 2;
st[a[i]].pb(i);
}
ll ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= 2; j++) {
for (int k = 0; k <= 2; k++) {
if (j != k && j != a[i] && k != a[i]) {
vector<int>::iterator it = lower_bound(st[j].begin(), st[j].end(), i);
for (; it != st[j].end(); it++) {
int tmp = 2 * (*it) - i;
ans += st[k].end() - lower_bound(st[k].begin(), st[k].end(), *it);
it = lower_bound(st[k].begin(), st[k].end(), tmp);
if (it != st[k].end() && *it == tmp)
ans--;
}
}
}
}
}
printf("%lld", ans);
// system("pause");
return 0;
} | #include <bits/stdc++.h>
#define mem(a, b) memset(a, b, sizeof(a))
#define inf 0x3f3f3f3f
#define ll long long
#define pb push_back
#define PII pair<int, int>
#define X first
#define Y second
#define MP make_pair
#define PI acos(-1.0)
#define eps 1e-8
const int maxn = 5e4 + 10;
const int maxm = 1.5e7 + 10;
const int mod = 998244353;
using namespace std;
int n;
int a[maxn];
char s[maxn];
vector<int> st[3];
int main() {
scanf("%d%s", &n, s);
for (int i = 0; i < n; i++) {
if (s[i] == 'R')
a[i] = 0;
else if (s[i] == 'G')
a[i] = 1;
else
a[i] = 2;
st[a[i]].pb(i);
}
ll ans = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= 2; j++) {
for (int k = 0; k <= 2; k++) {
if (j != k && j != a[i] && k != a[i]) {
vector<int>::iterator it = lower_bound(st[j].begin(), st[j].end(), i);
for (; it != st[j].end(); it++) {
int tmp = 2 * (*it) - i;
ans += st[k].end() - lower_bound(st[k].begin(), st[k].end(), *it);
vector<int>::iterator itt =
lower_bound(st[k].begin(), st[k].end(), tmp);
if (itt != st[k].end() && *itt == tmp)
ans--;
}
}
}
}
}
printf("%lld", ans);
// system("pause");
return 0;
} | replace | 41 | 43 | 41 | 44 | TLE | |
p02714 | C++ | Time Limit Exceeded | /* #region Head */
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pll = pair<ll, ll>;
template <class T> using vc = vector<T>;
template <class T> using vvc = vc<vc<T>>;
using vll = vc<ll>;
using vvll = vvc<ll>;
using vld = vc<ld>;
using vvld = vvc<ld>;
using vs = vc<string>;
using vvs = vvc<string>;
template <class T, class U> using um = unordered_map<T, U>;
template <class T> using pq = priority_queue<T>;
template <class T> using pqa = priority_queue<T, vc<T>, greater<T>>;
#define REP(i, m, n) for (ll i = (m), i##_len = (ll)(n); i < i##_len; ++(i))
#define REPM(i, m, n) for (ll i = (m), i##_max = (ll)(n); i <= i##_max; ++(i))
#define REPR(i, m, n) for (ll i = (m), i##_min = (ll)(n); i >= i##_min; --(i))
#define REPD(i, m, n, d) \
for (ll i = (m), i##_len = (ll)(n); i < i##_len; i += (d))
#define REPMD(i, m, n, d) \
for (ll i = (m), i##_max = (ll)(n); i <= i##_max; i += (d))
#define REPI(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define ALL(x) begin(x), end(x)
#define SIZE(x) ((ll)(x).size())
#define PERM(c) \
sort(ALL(c)); \
for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))
#define UNIQ(v) v.erase(unique(ALL(v)), v.end());
#define endl '\n'
#define sqrt sqrtl
#define floor floorl
#define log2 log2l
constexpr ll INF = 1'010'000'000'000'000'017LL;
constexpr ll MOD = 1'000'000'007LL; // 1e9 + 7
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.14159265358979323846;
template <typename T>
istream &operator>>(istream &is, vc<T> &vec) { // vector 入力
for (T &x : vec)
is >> x;
return is;
}
template <typename T>
ostream &operator<<(ostream &os, vc<T> &vec) { // vector 出力 (for dump)
os << "{";
REP(i, 0, SIZE(vec)) os << vec[i] << (i == i_len - 1 ? "" : ", ");
os << "}";
return os;
}
template <typename T>
ostream &operator>>(ostream &os, vc<T> &vec) { // vector 出力 (inline)
REP(i, 0, SIZE(vec)) os << vec[i] << (i == i_len - 1 ? "\n" : " ");
return os;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &pair_var) { // pair 入力
is >> pair_var.first >> pair_var.second;
return is;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) { // pair 出力
os << "(" << pair_var.first << ", " << pair_var.second << ")";
return os;
}
// map, um, set 出力
template <class T> ostream &out_iter(ostream &os, T &map_var) {
os << "{";
REPI(itr, map_var) {
os << *itr;
auto itrcp = itr;
if (++itrcp != map_var.end())
os << ", ";
}
os << "}";
return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
return out_iter(os, map_var);
}
template <typename T, typename U>
ostream &operator<<(ostream &os, um<T, U> &map_var) {
return out_iter(os, map_var);
}
template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) {
return out_iter(os, set_var);
}
// dump
#define DUMPOUT cerr
void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&...tail) {
DUMPOUT << head;
if (sizeof...(Tail) > 0)
DUMPOUT << ", ";
dump_func(move(tail)...);
}
// chmax (更新「される」かもしれない値が前)
template <typename T, typename U, typename Comp = less<>>
bool chmax(T &xmax, const U &x, Comp comp = {}) {
if (comp(xmax, x)) {
xmax = x;
return true;
}
return false;
}
// chmin (更新「される」かもしれない値が前)
template <typename T, typename U, typename Comp = less<>>
bool chmin(T &xmin, const U &x, Comp comp = {}) {
if (comp(x, xmin)) {
xmin = x;
return true;
}
return false;
}
// ローカル用
#define DEBUG_
#ifdef DEBUG_
#define DEB
#define dump(...) \
DUMPOUT << " " << string(#__VA_ARGS__) << ": " \
<< "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
<< " ", \
dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
struct AtCoderInitialize {
static constexpr int IOS_PREC = 15;
static constexpr bool AUTOFLUSH = false;
AtCoderInitialize() {
ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
cout << fixed << setprecision(IOS_PREC);
if (AUTOFLUSH)
cout << unitbuf;
}
} ATCODER_INITIALIZE;
string yes = "Yes", no = "No";
// string yes = "YES", no = "NO";
void yn(bool p) { cout << (p ? yes : no) << endl; }
/* #endregion */
// Problem
void solve() {
ll n;
cin >> n;
string s;
cin >> s;
ll ret = 0;
REP(i, 0, n - 2) REP(j, i + 1, n - 1) REP(k, j + 1, n) {
if (j - i == k - j)
continue;
if (s[i] != s[j] && s[j] != s[k] && s[k] != s[i])
ret++;
}
cout << ret << endl;
}
// entry point
int main() {
solve();
return 0;
}
| /* #region Head */
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pll = pair<ll, ll>;
template <class T> using vc = vector<T>;
template <class T> using vvc = vc<vc<T>>;
using vll = vc<ll>;
using vvll = vvc<ll>;
using vld = vc<ld>;
using vvld = vvc<ld>;
using vs = vc<string>;
using vvs = vvc<string>;
template <class T, class U> using um = unordered_map<T, U>;
template <class T> using pq = priority_queue<T>;
template <class T> using pqa = priority_queue<T, vc<T>, greater<T>>;
#define REP(i, m, n) for (ll i = (m), i##_len = (ll)(n); i < i##_len; ++(i))
#define REPM(i, m, n) for (ll i = (m), i##_max = (ll)(n); i <= i##_max; ++(i))
#define REPR(i, m, n) for (ll i = (m), i##_min = (ll)(n); i >= i##_min; --(i))
#define REPD(i, m, n, d) \
for (ll i = (m), i##_len = (ll)(n); i < i##_len; i += (d))
#define REPMD(i, m, n, d) \
for (ll i = (m), i##_max = (ll)(n); i <= i##_max; i += (d))
#define REPI(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define ALL(x) begin(x), end(x)
#define SIZE(x) ((ll)(x).size())
#define PERM(c) \
sort(ALL(c)); \
for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))
#define UNIQ(v) v.erase(unique(ALL(v)), v.end());
#define endl '\n'
#define sqrt sqrtl
#define floor floorl
#define log2 log2l
constexpr ll INF = 1'010'000'000'000'000'017LL;
constexpr ll MOD = 1'000'000'007LL; // 1e9 + 7
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.14159265358979323846;
template <typename T>
istream &operator>>(istream &is, vc<T> &vec) { // vector 入力
for (T &x : vec)
is >> x;
return is;
}
template <typename T>
ostream &operator<<(ostream &os, vc<T> &vec) { // vector 出力 (for dump)
os << "{";
REP(i, 0, SIZE(vec)) os << vec[i] << (i == i_len - 1 ? "" : ", ");
os << "}";
return os;
}
template <typename T>
ostream &operator>>(ostream &os, vc<T> &vec) { // vector 出力 (inline)
REP(i, 0, SIZE(vec)) os << vec[i] << (i == i_len - 1 ? "\n" : " ");
return os;
}
template <typename T, typename U>
istream &operator>>(istream &is, pair<T, U> &pair_var) { // pair 入力
is >> pair_var.first >> pair_var.second;
return is;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) { // pair 出力
os << "(" << pair_var.first << ", " << pair_var.second << ")";
return os;
}
// map, um, set 出力
template <class T> ostream &out_iter(ostream &os, T &map_var) {
os << "{";
REPI(itr, map_var) {
os << *itr;
auto itrcp = itr;
if (++itrcp != map_var.end())
os << ", ";
}
os << "}";
return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
return out_iter(os, map_var);
}
template <typename T, typename U>
ostream &operator<<(ostream &os, um<T, U> &map_var) {
return out_iter(os, map_var);
}
template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) {
return out_iter(os, set_var);
}
// dump
#define DUMPOUT cerr
void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&...tail) {
DUMPOUT << head;
if (sizeof...(Tail) > 0)
DUMPOUT << ", ";
dump_func(move(tail)...);
}
// chmax (更新「される」かもしれない値が前)
template <typename T, typename U, typename Comp = less<>>
bool chmax(T &xmax, const U &x, Comp comp = {}) {
if (comp(xmax, x)) {
xmax = x;
return true;
}
return false;
}
// chmin (更新「される」かもしれない値が前)
template <typename T, typename U, typename Comp = less<>>
bool chmin(T &xmin, const U &x, Comp comp = {}) {
if (comp(x, xmin)) {
xmin = x;
return true;
}
return false;
}
// ローカル用
#define DEBUG_
#ifdef DEBUG_
#define DEB
#define dump(...) \
DUMPOUT << " " << string(#__VA_ARGS__) << ": " \
<< "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
<< " ", \
dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
struct AtCoderInitialize {
static constexpr int IOS_PREC = 15;
static constexpr bool AUTOFLUSH = false;
AtCoderInitialize() {
ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
cout << fixed << setprecision(IOS_PREC);
if (AUTOFLUSH)
cout << unitbuf;
}
} ATCODER_INITIALIZE;
string yes = "Yes", no = "No";
// string yes = "YES", no = "NO";
void yn(bool p) { cout << (p ? yes : no) << endl; }
/* #endregion */
// Problem
void solve() {
ll n;
cin >> n;
string s;
cin >> s;
ll cr = 0, cg = 0, cb = 0;
REP(i, 0, n) {
if (s[i] == 'R')
cr++;
else if (s[i] == 'G')
cg++;
else
cb++;
}
ll ret = cr * cg * cb;
REPM(step, 1, n / 2) {
REP(i, 0, n - 2 * step) {
if (i + 2 * step >= n)
continue;
if (s[i] != s[i + step] && s[i + step] != s[i + 2 * step] &&
s[i + 2 * step] != s[i])
ret--;
}
}
cout << ret << endl;
}
// entry point
int main() {
solve();
return 0;
}
| replace | 169 | 175 | 169 | 189 | TLE | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main(void) {
// Your code here
int N;
string S;
int i;
long long r = 0, g = 0, b = 0;
long long x = 0, y = 0, z = 0;
cin >> N >> S;
for (i = 0; i < N; i++) {
if (S.at(i) == 'R')
r++;
if (S.at(i) == 'G')
g++;
if (S.at(i) == 'B')
b++;
}
long long all = r * g * b;
for (x = 0; x < N - 2; x++) {
for (y = x + 1; y < N - 1; y++) {
z = y * 2 - x;
if (z > N - 1;
S.at(x) == S.at(z) || S.at(y) == S.at(z) || S.at(x) == S.at(y))
continue;
all--;
}
}
cout << all << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main(void) {
// Your code here
int N;
string S;
int i;
long long r = 0, g = 0, b = 0;
long long x = 0, y = 0, z = 0;
cin >> N >> S;
for (i = 0; i < N; i++) {
if (S.at(i) == 'R')
r++;
if (S.at(i) == 'G')
g++;
if (S.at(i) == 'B')
b++;
}
long long all = r * g * b;
for (x = 0; x < N - 2; x++) {
for (y = x + 1; y < N - 1; y++) {
z = y * 2 - x;
if (z > N - 1 || S.at(x) == S.at(z) || S.at(y) == S.at(z) ||
S.at(x) == S.at(y))
continue;
all--;
}
}
cout << all << endl;
}
| replace | 28 | 30 | 28 | 30 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 4) >= this->size() (which is 4)
|
p02714 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <cfenv>
#include <cmath>
#include <deque>
#include <forward_list>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <streambuf>
#include <unordered_map>
#include <unordered_set>
#include <vector>
typedef long long ll;
using namespace std;
int main() {
int N, sum = 0;
char S[4002];
cin >> N;
cin >> S;
ll R = 0;
ll G = 0;
ll B = 0;
for (int i = 0; i < N; i++) {
if (S[i] == 'R') {
R++;
} else if (S[i] == 'G') {
G++;
} else if (S[i] == 'B') {
B++;
}
}
ll cnt = R * G * B;
for (int i = 0; i < N - 2; i++) {
for (int j = i + 1; j < N - 1; j++) {
int k = (j - i) + j;
if (S[i] != S[j] && S[j] != S[k] && S[k] != S[i] && k < N) {
cnt--;
}
}
}
cout << cnt;
return 0;
} | #include <algorithm>
#include <array>
#include <cfenv>
#include <cmath>
#include <deque>
#include <forward_list>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <streambuf>
#include <unordered_map>
#include <unordered_set>
#include <vector>
typedef long long ll;
using namespace std;
int main() {
int N, sum = 0;
char S[4002];
cin >> N;
cin >> S;
ll R = 0;
ll G = 0;
ll B = 0;
for (int i = 0; i < N; i++) {
if (S[i] == 'R') {
R++;
} else if (S[i] == 'G') {
G++;
} else if (S[i] == 'B') {
B++;
}
}
ll cnt = R * G * B;
for (int i = 0; i < N - 2; i++) {
for (int j = i + 1; j < N - 1; j++) {
int k = (j - i) + j;
if (k < N) {
if (S[i] != S[j] && S[j] != S[k] && S[k] != S[i]) {
cnt--;
}
}
}
}
cout << cnt;
return 0;
} | replace | 52 | 54 | 52 | 56 | 0 | |
p02714 | C++ | Runtime Error | /***
***Fresher***
Md Mahfujur Rahman Khan
Dept. of CSE
CSE-28 Batch
JU-48 Batch
Jahangirnagar University
***/
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define V_ vector
#define Q_ queue
#define S_ set
#define ST_ stack
#define M_ map
#define DQ_ deque
/***PAIR***/
#define pii pair<ll, ll>
#define pci pair<char, ll>
#define psi pair<string, ll>
#define pis pair<ll, string>
#define pic pair<ll, char>
/***MAP***/
#define mii map<ll, ll>
#define msi map<string, ll>
#define mis map<ll, string>
#define mib map<ll, bool>
#define msb map<string, bool>
#define mci map<char, ll>
/***VECTOR***/
#define vi vector<ll>
#define vs vector<string>
/***ITERASTORS***/
#define ivi vector<ll>::iterator
#define ivs vector<string>::iterator
#define imii map<ll, ll>::iterator
#define imsi map<string, ll>::iterator
#define imis map<ll, string>::iterator
#define imib map<ll, bool>::iterator
#define imsb map<string, bool>::iterator
#define imci map<char, ll>::iterator
/*** FAST ***/
#define FAST \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
/***FUNCTIONS AND MACROS***/
#define F first
#define S second
#define M_P(x, y) make_pair(x, y)
#define pi 2 * acos(0.0)
#define PB(x) push_back(x)
#define PP(x) push(x)
#define RSZ(n) resize(n)
#define POB pop_back()
#define P_ pop()
#define CL_ clear()
#define LEN_ length()
#define SZ_ size()
#define CNT(x) count(x)
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second
#define B_ begin()
#define E_ end()
#define F_ front()
#define t_ top()
#define IN_ insert
#define ER_ erase
#define GT(x) getline(cin, x)
#define NL_ "\n"
#define SP_ " "
#define R_0 return 0
#define R_ return
#define ul unsigned long long int
#define ll long long int
/***
//prime fact
#define most_prime_loop 1001
#define most_prime_number 500000*2+1
#define prime_MAX_arr 500010
ll PRIME[prime_MAX_arr];
void seive()
{
for(auto &x: PRIME )
x = 1;
for(ll i= 3; i <= most_prime_loop; i+=2)
{
for(ll j = i*i; j <= most_prime_number; j+=2*i)
PRIME[j/2] = 0;
}
}
//
***/
#define fr(i, n) for (ll i = 0; i < n; i++)
#define fe(x, n) for (ll i = x; i <= n; i++)
#define fa(a) for (auto &x : a)
#define SR(x) sqrt(x)
#define IC (ll)
const ll inf = 1000000000;
ll i, T, N, tc = 0, t = 0;
ll arr[100100];
ll n, k;
pii temp[100100];
ll pay;
vector<pii> vl;
pii ch(ll i, ll val, ll us) {
if (temp[i].F != -1) {
// cout <<temp[i].F <<"\n\n";
return temp[i];
}
if (val >= pay) {
// cout << val << " " << us <<"\n";
// vl.PB(M_P(val, us));
return M_P(val, us);
}
if (i == n)
return M_P(LLONG_MAX, LLONG_MAX);
pii temp2 = ch(i + 1, val + arr[i], us + 1);
pii temp1 = ch(i + 1, val, us);
// cout << temp1.F <<SP_ << temp2.F <<NL_;
if (temp1.F < temp2.F) {
temp[i] = temp1;
} else
temp[i] = temp2;
return temp[i];
}
ll ar[17];
bool ch(ll i, ll j) {
if (ar[i] > ar[j])
R_ 0;
while (i < j - 1) {
if (ar[i] > ar[i + 1])
R_ 0;
i++;
}
R_ 1;
}
int main() {
ll g[402], r[402], b[402];
fa(g) x = 0;
fa(r) x = 0;
fa(b) x = 0;
ll n;
cin >> n;
string s;
cin >> s;
ll rr = 0, bb = 0, gg = 0;
// cout <<"fgjg";
for (ul i = s.SZ_; i > 0; i--) {
if (s[i - 1] == 'G') {
gg++;
} else if (s[i - 1] == 'R') {
rr++;
} else
bb++;
g[i - 1] = gg;
r[i - 1] = rr;
b[i - 1] = bb;
}
// for(ll i= 0; i < s.SZ_; i++)
// {
// cout << g[i] <<" " << r[i] <<" " << b[i] <<"\n";
// }
ll sum = 0;
for (ll i = 0; i < n - 2; i++) {
for (ll j = i + 1; j < n - 1; j++) {
if ((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R')) {
sum += b[j + 1];
ll k = j - i + j;
if (k < n && s[k] == 'B')
sum--;
} else if ((s[i] == 'B' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'B')) {
sum += r[j + 1];
ll k = j - i + j;
if (k < n && s[k] == 'R')
sum--;
} else if ((s[i] == 'B' && s[j] == 'R') || (s[i] == 'R' && s[j] == 'B')) {
sum += g[j + 1];
ll k = j - i + j;
if (k < n && s[k] == 'G')
sum--;
}
}
}
cout << sum;
R_0;
}
| /***
***Fresher***
Md Mahfujur Rahman Khan
Dept. of CSE
CSE-28 Batch
JU-48 Batch
Jahangirnagar University
***/
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define V_ vector
#define Q_ queue
#define S_ set
#define ST_ stack
#define M_ map
#define DQ_ deque
/***PAIR***/
#define pii pair<ll, ll>
#define pci pair<char, ll>
#define psi pair<string, ll>
#define pis pair<ll, string>
#define pic pair<ll, char>
/***MAP***/
#define mii map<ll, ll>
#define msi map<string, ll>
#define mis map<ll, string>
#define mib map<ll, bool>
#define msb map<string, bool>
#define mci map<char, ll>
/***VECTOR***/
#define vi vector<ll>
#define vs vector<string>
/***ITERASTORS***/
#define ivi vector<ll>::iterator
#define ivs vector<string>::iterator
#define imii map<ll, ll>::iterator
#define imsi map<string, ll>::iterator
#define imis map<ll, string>::iterator
#define imib map<ll, bool>::iterator
#define imsb map<string, bool>::iterator
#define imci map<char, ll>::iterator
/*** FAST ***/
#define FAST \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
/***FUNCTIONS AND MACROS***/
#define F first
#define S second
#define M_P(x, y) make_pair(x, y)
#define pi 2 * acos(0.0)
#define PB(x) push_back(x)
#define PP(x) push(x)
#define RSZ(n) resize(n)
#define POB pop_back()
#define P_ pop()
#define CL_ clear()
#define LEN_ length()
#define SZ_ size()
#define CNT(x) count(x)
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second
#define B_ begin()
#define E_ end()
#define F_ front()
#define t_ top()
#define IN_ insert
#define ER_ erase
#define GT(x) getline(cin, x)
#define NL_ "\n"
#define SP_ " "
#define R_0 return 0
#define R_ return
#define ul unsigned long long int
#define ll long long int
/***
//prime fact
#define most_prime_loop 1001
#define most_prime_number 500000*2+1
#define prime_MAX_arr 500010
ll PRIME[prime_MAX_arr];
void seive()
{
for(auto &x: PRIME )
x = 1;
for(ll i= 3; i <= most_prime_loop; i+=2)
{
for(ll j = i*i; j <= most_prime_number; j+=2*i)
PRIME[j/2] = 0;
}
}
//
***/
#define fr(i, n) for (ll i = 0; i < n; i++)
#define fe(x, n) for (ll i = x; i <= n; i++)
#define fa(a) for (auto &x : a)
#define SR(x) sqrt(x)
#define IC (ll)
const ll inf = 1000000000;
ll i, T, N, tc = 0, t = 0;
ll arr[100100];
ll n, k;
pii temp[100100];
ll pay;
vector<pii> vl;
pii ch(ll i, ll val, ll us) {
if (temp[i].F != -1) {
// cout <<temp[i].F <<"\n\n";
return temp[i];
}
if (val >= pay) {
// cout << val << " " << us <<"\n";
// vl.PB(M_P(val, us));
return M_P(val, us);
}
if (i == n)
return M_P(LLONG_MAX, LLONG_MAX);
pii temp2 = ch(i + 1, val + arr[i], us + 1);
pii temp1 = ch(i + 1, val, us);
// cout << temp1.F <<SP_ << temp2.F <<NL_;
if (temp1.F < temp2.F) {
temp[i] = temp1;
} else
temp[i] = temp2;
return temp[i];
}
ll ar[17];
bool ch(ll i, ll j) {
if (ar[i] > ar[j])
R_ 0;
while (i < j - 1) {
if (ar[i] > ar[i + 1])
R_ 0;
i++;
}
R_ 1;
}
int main() {
ll g[4002], r[4002], b[4002];
fa(g) x = 0;
fa(r) x = 0;
fa(b) x = 0;
ll n;
cin >> n;
string s;
cin >> s;
ll rr = 0, bb = 0, gg = 0;
// cout <<"fgjg";
for (ul i = s.SZ_; i > 0; i--) {
if (s[i - 1] == 'G') {
gg++;
} else if (s[i - 1] == 'R') {
rr++;
} else
bb++;
g[i - 1] = gg;
r[i - 1] = rr;
b[i - 1] = bb;
}
// for(ll i= 0; i < s.SZ_; i++)
// {
// cout << g[i] <<" " << r[i] <<" " << b[i] <<"\n";
// }
ll sum = 0;
for (ll i = 0; i < n - 2; i++) {
for (ll j = i + 1; j < n - 1; j++) {
if ((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R')) {
sum += b[j + 1];
ll k = j - i + j;
if (k < n && s[k] == 'B')
sum--;
} else if ((s[i] == 'B' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'B')) {
sum += r[j + 1];
ll k = j - i + j;
if (k < n && s[k] == 'R')
sum--;
} else if ((s[i] == 'B' && s[j] == 'R') || (s[i] == 'R' && s[j] == 'B')) {
sum += g[j + 1];
ll k = j - i + j;
if (k < n && s[k] == 'G')
sum--;
}
}
}
cout << sum;
R_0;
}
| replace | 163 | 164 | 163 | 164 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int pan(char a, char b, char c) {
if (a != b && b != c && c != a)
return 1;
return 0;
}
int main() {
int n;
cin >> n;
char a[n];
cin >> a;
long long cnt = 0;
for (int i = 0; i < n - 2; i++) {
for (int j = 1; j + i < n - 1; j++) {
for (int x = 1; x + j + i < n; x++)
if (j != x && pan(a[i], a[i + j], a[i + j + x]))
cnt++;
}
}
cout << cnt;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int pan(char a, char b, char c) {
if (a != b && b != c && c != a)
return 1;
return 0;
}
int main() {
int n;
cin >> n;
char a[n];
cin >> a;
long long cnt = 0;
int x = 0, y = 0, z = 0;
for (int i = 0; i < n; i++) {
if (a[i] == 'R')
x++;
if (a[i] == 'G')
y++;
if (a[i] == 'B')
z++;
}
cnt = (long long)x * y * z;
for (int i = 0; i < n; i++) {
for (int d = 1; i + d + d < n; d++)
if (pan(a[i], a[i + d], a[i + d + d]))
cnt--;
}
cout << cnt;
return 0;
} | replace | 13 | 19 | 13 | 27 | TLE | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
typedef long long ll;
int main() {
ll n;
cin >> n;
string s;
cin >> s;
if (n <= 3) {
cout << 0 << endl;
return 0;
}
vector<ll> r, g, b;
rep(i, 0, n) {
if (s[i] == 'R')
r.push_back(i);
else if (s[i] == 'G')
g.push_back(i);
else if (s[i] == 'B')
b.push_back(i);
}
ll an = 0;
rep(i, 0, n - 2) {
rep(j, i + 1, n - 1) {
if (s[i] == s[j])
continue;
if ((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R')) {
ll tm = b.end() - lower_bound(b.begin(), b.end(), j + 1);
an += tm;
if (j + (j - i) < n) {
auto upp = lower_bound(b.begin(), b.end(), 2 * j - i);
ll tmp = *upp;
if (upp != b.end() && tmp == 2 * j - i)
an--;
}
} else if ((s[i] == 'B' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'B')) {
ll tm = r.end() - lower_bound(r.begin(), r.end(), j + 1);
an += tm;
if (j + (j - i) < n) {
auto upp = lower_bound(r.begin(), r.end(), 2 * j - i);
ll tmp = *upp;
if (upp != b.end() && tmp == 2 * j - i)
an--;
}
} else if ((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R')) {
ll tm = g.end() - lower_bound(g.begin(), g.end(), j + 1);
an += tm;
if (j + (j - i) < n) {
auto upp = lower_bound(g.begin(), g.end(), 2 * j - i);
ll tmp = *upp;
if (upp != b.end() && tmp == 2 * j - i)
an--;
}
}
}
}
cout << an << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
typedef long long ll;
int main() {
ll n;
cin >> n;
string s;
cin >> s;
if (n <= 3) {
cout << 0 << endl;
return 0;
}
vector<ll> r, g, b;
rep(i, 0, n) {
if (s[i] == 'R')
r.push_back(i);
else if (s[i] == 'G')
g.push_back(i);
else if (s[i] == 'B')
b.push_back(i);
}
if (r.size() * b.size() * g.size() == 0) {
cout << 0 << endl;
return 0;
}
ll an = 0;
rep(i, 0, n - 2) {
rep(j, i + 1, n - 1) {
if (s[i] == s[j])
continue;
if ((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R')) {
ll tm = b.end() - lower_bound(b.begin(), b.end(), j + 1);
an += tm;
if (j + (j - i) < n) {
auto upp = lower_bound(b.begin(), b.end(), 2 * j - i);
ll tmp = *upp;
if (upp != b.end() && tmp == 2 * j - i)
an--;
}
} else if ((s[i] == 'B' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'B')) {
ll tm = r.end() - lower_bound(r.begin(), r.end(), j + 1);
an += tm;
if (j + (j - i) < n) {
auto upp = lower_bound(r.begin(), r.end(), 2 * j - i);
ll tmp = *upp;
if (upp != b.end() && tmp == 2 * j - i)
an--;
}
} else if ((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R')) {
ll tm = g.end() - lower_bound(g.begin(), g.end(), j + 1);
an += tm;
if (j + (j - i) < n) {
auto upp = lower_bound(g.begin(), g.end(), 2 * j - i);
ll tmp = *upp;
if (upp != b.end() && tmp == 2 * j - i)
an--;
}
}
}
}
cout << an << endl;
}
| insert | 22 | 22 | 22 | 26 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
int n;
string s;
cin >> n >> s;
vector<int> r, g, b;
REP(i, n) {
if (s[i] == 'R')
r.push_back(i);
else if (s[i] == 'G')
g.push_back(i);
else
b.push_back(i);
}
ll ans = 0;
REP(i, r.size()) {
REP(j, g.size()) {
REP(k, b.size()) {
vector<int> ind = {r[i], g[j], b[k]};
sort(ALL(ind));
if (ind[1] - ind[0] != ind[2] - ind[1])
ans++;
}
}
}
cout << ans << '\n';
return 0;
}
| #include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
int n;
string s;
cin >> n >> s;
vector<int> r, g, b;
REP(i, n) {
if (s[i] == 'R')
r.push_back(i);
else if (s[i] == 'G')
g.push_back(i);
else
b.push_back(i);
}
ll ans = r.size() * g.size() * b.size();
REP(i, n) {
for (int k = i + 2; k < n; k += 2) {
int j = (i + k) / 2;
if (s[i] != s[j] && s[j] != s[k] && s[k] != s[i])
ans--;
}
}
cout << ans << '\n';
return 0;
}
| replace | 21 | 30 | 21 | 27 | TLE | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 4e3 + 5;
int main() {
ll i, j, k, n, sum[maxn][3] = {0}, ans = 0;
char s[maxn];
scanf("%d%s", &n, s + 1);
for (i = n; i >= 1; i--) {
sum[i][0] = sum[i + 1][0];
sum[i][1] = sum[i + 1][1];
sum[i][2] = sum[i + 1][2];
if (s[i] == 'R')
sum[i][0]++;
if (s[i] == 'G')
sum[i][1]++;
if (s[i] == 'B')
sum[i][2]++;
}
for (i = 1; i <= n; i++) {
for (j = i + 1; j <= n; j++) {
if (s[i] == s[j])
continue;
if (s[i] != 'R' && s[j] != 'R') {
ans = ans + sum[j + 1][0];
if (s[j + (j - i)] == 'R')
ans--;
}
if (s[i] != 'G' && s[j] != 'G') {
ans = ans + sum[j + 1][1];
if (s[j + (j - i)] == 'G')
ans--;
}
if (s[i] != 'B' && s[j] != 'B') {
ans = ans + sum[j + 1][2];
if (s[j + (j - i)] == 'B')
ans--;
}
}
}
printf("%lld\n", ans);
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 9;
int main() {
ll i, j, k, n, sum[maxn][3] = {0}, ans = 0;
char s[maxn];
scanf("%d%s", &n, s + 1);
for (i = n; i >= 1; i--) {
sum[i][0] = sum[i + 1][0];
sum[i][1] = sum[i + 1][1];
sum[i][2] = sum[i + 1][2];
if (s[i] == 'R')
sum[i][0]++;
if (s[i] == 'G')
sum[i][1]++;
if (s[i] == 'B')
sum[i][2]++;
}
for (i = 1; i <= n; i++) {
for (j = i + 1; j <= n; j++) {
if (s[i] == s[j])
continue;
if (s[i] != 'R' && s[j] != 'R') {
ans = ans + sum[j + 1][0];
if (s[j + (j - i)] == 'R')
ans--;
}
if (s[i] != 'G' && s[j] != 'G') {
ans = ans + sum[j + 1][1];
if (s[j + (j - i)] == 'G')
ans--;
}
if (s[i] != 'B' && s[j] != 'B') {
ans = ans + sum[j + 1][2];
if (s[j + (j - i)] == 'B')
ans--;
}
}
}
printf("%lld\n", ans);
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <iostream>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
string x, y, z;
long long ans = 0;
for (int i = 0; i < n - 2; i++) {
x = s[i];
for (int j = i + 1; j < n - 1; j++) {
y = s[j];
if (y == x)
continue;
for (int k = j + 1; k < n; k++) {
z = s[k];
if (x == z || y == z)
continue;
if (j - i != k - j)
ans++;
}
}
}
cout << ans << endl;
return 0;
} | #include <iostream>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
string x, y, z;
long long r = 0;
long long g = 0;
long long b = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'R')
r++;
if (s[i] == 'G')
g++;
if (s[i] == 'B')
b++;
}
long long ans = r * g * b;
for (int i = 0; i < n - 1; i++) {
for (int j = 1; i + 2 * j < n; j++) {
if (s[i] != s[i + j] && s[i + j] != s[i + 2 * j] &&
s[i + 2 * j] != s[i]) {
ans--;
}
}
}
cout << ans << endl;
return 0;
} | replace | 11 | 24 | 11 | 29 | TLE | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int R[1001] = {};
int G[1001] = {};
int B[1001] = {};
int Rcnt = 0;
int Gcnt = 0;
int Bcnt = 0;
string s;
cin >> s;
long long int ans = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'R') {
R[i] = 1;
Rcnt++;
} else if (s[i] == 'G') {
G[i] = 1;
Gcnt++;
} else if (s[i] == 'B') {
B[i] = 1;
Bcnt++;
}
}
for (int i = 0; i < s.size(); i++)
for (int j = 0; j < s.size(); j++) {
if (R[i] == 1 && G[j] == 1) {
ans += Bcnt;
int temp = abs(j - i);
int temp_2 = i + j;
if (temp + max(i, j) <= s.size()) {
if (B[temp + max(i, j)] == 1)
ans--;
}
if (min(i, j) - temp >= 0) {
if (B[min(i, j) - temp] == 1)
ans--;
}
if (temp_2 % 2 == 0) {
if (B[temp_2 / 2] == 1)
ans--;
}
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int R[4001] = {};
int G[4001] = {};
int B[4001] = {};
int Rcnt = 0;
int Gcnt = 0;
int Bcnt = 0;
string s;
cin >> s;
long long int ans = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'R') {
R[i] = 1;
Rcnt++;
} else if (s[i] == 'G') {
G[i] = 1;
Gcnt++;
} else if (s[i] == 'B') {
B[i] = 1;
Bcnt++;
}
}
for (int i = 0; i < s.size(); i++)
for (int j = 0; j < s.size(); j++) {
if (R[i] == 1 && G[j] == 1) {
ans += Bcnt;
int temp = abs(j - i);
int temp_2 = i + j;
if (temp + max(i, j) <= s.size()) {
if (B[temp + max(i, j)] == 1)
ans--;
}
if (min(i, j) - temp >= 0) {
if (B[min(i, j) - temp] == 1)
ans--;
}
if (temp_2 % 2 == 0) {
if (B[temp_2 / 2] == 1)
ans--;
}
}
}
cout << ans << endl;
return 0;
} | replace | 6 | 9 | 6 | 9 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vl vector<ll>
int main() {
int N;
string S;
cin >> N >> S;
ll ans = 0;
for (int i = 0; i < N - 2; i++) {
for (int j = i + 1; j < N - 1; j++) {
for (int k = j + 1; k < N; k++) {
if (S[i] != S[j] && S[j] != S[k] && S[k] != S[i] && (j - i) != (k - j))
ans++;
}
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vl vector<ll>
int main() {
int N;
string S;
cin >> N >> S;
ll ans = 0;
ll r = 0;
ll g = 0;
ll b = 0;
for (int i = 0; i < N; ++i) {
if (S[i] == 'R')
r++;
if (S[i] == 'G')
g++;
if (S[i] == 'B')
b++;
}
ans = r * g * b;
for (int d = 1; d * 2 < N; d++) {
for (int i = 0; i + d * 2 < N; i++) {
int j = i + d;
int k = i + 2 * d;
if (S[i] != S[j] && S[j] != S[k] && S[k] != S[i])
ans--;
}
}
cout << ans << endl;
return 0;
}
| replace | 12 | 18 | 12 | 33 | TLE | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define l_ength size
const int inf = (1 << 30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;
const int red = 1, green = 2, blue = 4;
ll sum[10][4010];
int main() {
int n;
cin >> n;
string s;
cin >> s;
vector<int> seq;
for (char c : s) {
if (c == 'R')
seq.push_back(red);
if (c == 'G')
seq.push_back(green);
if (c == 'B')
seq.push_back(blue);
}
for (int i = 0; i < n; ++i) {
for (int color = red; color <= blue; color << 1) {
sum[color][i + 1] = sum[color][i];
}
sum[seq[i]][i + 1] += 1;
}
ll ans = 0;
for (int left = 0; left < n - 2; ++left) {
for (int right = left + 2; right < n; ++right) {
if (seq[left] == seq[right])
continue;
int needed_c = 7 - seq[left] - seq[right];
ans += (sum[needed_c][right] - sum[needed_c][left + 1]);
if ((right - left) % 2 == 0 and seq[(left + right) / 2] == needed_c)
ans -= 1;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
#define l_ength size
const int inf = (1 << 30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;
const int red = 1, green = 2, blue = 4;
ll sum[10][4010];
int main() {
int n;
cin >> n;
string s;
cin >> s;
vector<int> seq;
for (char c : s) {
if (c == 'R')
seq.push_back(red);
if (c == 'G')
seq.push_back(green);
if (c == 'B')
seq.push_back(blue);
}
for (int i = 0; i < n; ++i) {
for (int color = red; color <= blue; color *= 2) {
sum[color][i + 1] = sum[color][i];
}
sum[seq[i]][i + 1] += 1;
}
ll ans = 0;
for (int left = 0; left < n - 2; ++left) {
for (int right = left + 2; right < n; ++right) {
if (seq[left] == seq[right])
continue;
int needed_c = 7 - seq[left] - seq[right];
ans += (sum[needed_c][right] - sum[needed_c][left + 1]);
if ((right - left) % 2 == 0 and seq[(left + right) / 2] == needed_c)
ans -= 1;
}
}
cout << ans << endl;
} | replace | 26 | 27 | 26 | 27 | TLE | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#define LOG(x) 0
#endif
#define pb push_back
#define mod 1000000007
#define endl '\n'
typedef int integer;
#define int long long
using namespace std;
int powmod(int a, int b) {
int res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
const integer NN = 200005;
int ar[NN];
int n, m, k;
int sum[1000][3];
integer main() {
ios_base::sync_with_stdio(false);
int t = 1;
// cin >> t;
while (t--) {
cin >> n;
string s;
cin >> s;
int g = 0;
int b = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'R') {
sum[i][0] = 1;
s[i] = 0;
} else if (s[i] == 'B') {
sum[i][1] = 1;
s[i] = 1;
} else {
sum[i][2] = 1;
s[i] = 2;
}
if (i) {
sum[i][0] += sum[i - 1][0];
sum[i][1] += sum[i - 1][1];
sum[i][2] += sum[i - 1][2];
}
}
int ans = 0;
for (int i = 1; i < n - 1; i++) {
if (s[i] == 2) {
ans += sum[i][0] * (sum[n - 1][1] - sum[i][1]);
ans += sum[i][1] * (sum[n - 1][0] - sum[i][0]);
} else if (s[i] == 1) {
ans += sum[i][0] * (sum[n - 1][2] - sum[i][2]);
ans += sum[i][2] * (sum[n - 1][0] - sum[i][0]);
} else {
ans += sum[i][2] * (sum[n - 1][1] - sum[i][1]);
ans += sum[i][1] * (sum[n - 1][2] - sum[i][2]);
}
}
for (int i = 0; i < n; i++) {
if (s[i] != 0)
continue;
int st = i - 1, en = i + 1;
while (st >= 0 && en < n) {
if (s[st] == 1 && s[en] == 2)
ans--;
else if (s[st] == 2 && s[en] == 1)
ans--;
st--;
en++;
}
}
for (int i = 0; i < n; i++) {
if (s[i] != 1)
continue;
int st = i - 1, en = i + 1;
while (st >= 0 && en < n) {
if (s[st] == 0 && s[en] == 2)
ans--;
else if (s[st] == 2 && s[en] == 0)
ans--;
st--;
en++;
}
}
for (int i = 0; i < n; i++) {
if (s[i] != 2)
continue;
int st = i - 1, en = i + 1;
while (st >= 0 && en < n) {
if (s[st] == 1 && s[en] == 0)
ans--;
else if (s[st] == 0 && s[en] == 1)
ans--;
st--;
en++;
}
}
cout << ans << endl;
}
}
| #include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#define LOG(x) 0
#endif
#define pb push_back
#define mod 1000000007
#define endl '\n'
typedef int integer;
#define int long long
using namespace std;
int powmod(int a, int b) {
int res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
const integer NN = 200005;
int ar[NN];
int n, m, k;
int sum[5000][3];
integer main() {
ios_base::sync_with_stdio(false);
int t = 1;
// cin >> t;
while (t--) {
cin >> n;
string s;
cin >> s;
int g = 0;
int b = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'R') {
sum[i][0] = 1;
s[i] = 0;
} else if (s[i] == 'B') {
sum[i][1] = 1;
s[i] = 1;
} else {
sum[i][2] = 1;
s[i] = 2;
}
if (i) {
sum[i][0] += sum[i - 1][0];
sum[i][1] += sum[i - 1][1];
sum[i][2] += sum[i - 1][2];
}
}
int ans = 0;
for (int i = 1; i < n - 1; i++) {
if (s[i] == 2) {
ans += sum[i][0] * (sum[n - 1][1] - sum[i][1]);
ans += sum[i][1] * (sum[n - 1][0] - sum[i][0]);
} else if (s[i] == 1) {
ans += sum[i][0] * (sum[n - 1][2] - sum[i][2]);
ans += sum[i][2] * (sum[n - 1][0] - sum[i][0]);
} else {
ans += sum[i][2] * (sum[n - 1][1] - sum[i][1]);
ans += sum[i][1] * (sum[n - 1][2] - sum[i][2]);
}
}
for (int i = 0; i < n; i++) {
if (s[i] != 0)
continue;
int st = i - 1, en = i + 1;
while (st >= 0 && en < n) {
if (s[st] == 1 && s[en] == 2)
ans--;
else if (s[st] == 2 && s[en] == 1)
ans--;
st--;
en++;
}
}
for (int i = 0; i < n; i++) {
if (s[i] != 1)
continue;
int st = i - 1, en = i + 1;
while (st >= 0 && en < n) {
if (s[st] == 0 && s[en] == 2)
ans--;
else if (s[st] == 2 && s[en] == 0)
ans--;
st--;
en++;
}
}
for (int i = 0; i < n; i++) {
if (s[i] != 2)
continue;
int st = i - 1, en = i + 1;
while (st >= 0 && en < n) {
if (s[st] == 1 && s[en] == 0)
ans--;
else if (s[st] == 0 && s[en] == 1)
ans--;
st--;
en++;
}
}
cout << ans << endl;
}
}
| replace | 31 | 32 | 31 | 32 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string S;
cin >> S;
int ans = 0;
for (int l = 0; l < N - 2; l++) {
for (int i = l + 1; i < N - 1; i++) {
for (int r = i + 1; r < N; r++) {
if (i - l != r - i) {
if (S[l] != S[i] && S[i] != S[r] && S[r] != S[l])
ans += 1;
}
}
}
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string S;
cin >> S;
map<char, long int> count;
for (int i = 0; i < N; i++)
count[S[i]] += 1;
long int ans = count['R'] * count['G'] * count['B'];
for (int i = 1; i < N - 1; i++) {
for (int r = 1; r <= min(i, N - 1 - i); r++) {
if (S[i - r] != S[i] && S[i + r] != S[i] && S[i - r] != S[i + r])
ans -= 1;
}
}
cout << ans;
return 0;
} | replace | 7 | 16 | 7 | 15 | TLE | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define per(i, a, n) for (ll i = n - 1; i >= a; i--)
#define fill0(n) setfill('0') << right << setw(n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
const long double EPS = 0.0000000001;
int n;
string s;
vector<int> blue(4001), green(4001), red(4001);
int calc(int i, int j) {
int ret;
if (s[i] == 'R' and s[j] == 'G') {
ret = blue[j];
if (s[j + (j - i)] == 'B')
ret--;
} else if (s[i] == 'R' and s[j] == 'B') {
ret = green[j];
if (s[j + (j - i)] == 'G')
ret--;
} else if (s[i] == 'G' and s[j] == 'B') {
ret = red[j];
if (s[j + (j - i)] == 'R')
ret--;
} else if (s[i] == 'G' and s[j] == 'R') {
ret = blue[j];
if (s[j + (j - i)] == 'B')
ret--;
} else if (s[i] == 'B' and s[j] == 'R') {
ret = green[j];
if (s[j + (j - i)] == 'G')
ret--;
} else if (s[i] == 'B' and s[j] == 'G') {
ret = red[j];
if (s[j + (j - i)] == 'R')
ret--;
}
return ret;
}
int main() {
cin >> n;
cin >> s;
ll ans = 0;
blue[n] = 0;
green[n] = 0;
red[n] = 0;
per(i, 1, n) {
if (s[i] == 'R') {
red[i - 1] += red[i] + 1;
blue[i - 1] += blue[i];
green[i - 1] += green[i];
} else if (s[i] == 'G') {
red[i - 1] += red[i];
blue[i - 1] += blue[i];
green[i - 1] += green[i] + 1;
} else {
red[i - 1] += red[i];
blue[i - 1] += blue[i] + 1;
green[i - 1] += green[i];
}
}
// for(int i = 0; i < n+1; i++)cout << red[i] << " ";
// cout << endl;
// for(int i = 0; i < n+1; i++)cout << blue[i] << " ";
// cout << endl;
// for(int i = 0; i < n+1; i++)cout << green[i] << " ";
// cout << endl;
for (int i = 0; i < n - 2; i++) {
for (int j = i + 1; j < n - 1; j++) {
if (s[i] == s[j])
continue;
// cout << i << " " << j << endl;
ans += calc(i, j);
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
#define rep(i, a, n) for (ll i = a; i < n; i++)
#define per(i, a, n) for (ll i = n - 1; i >= a; i--)
#define fill0(n) setfill('0') << right << setw(n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
const long double EPS = 0.0000000001;
int n;
string s;
vector<int> blue(5000), green(5000), red(5000);
int calc(int i, int j) {
int ret;
if (s[i] == 'R' and s[j] == 'G') {
ret = blue[j];
if (s[j + (j - i)] == 'B')
ret--;
} else if (s[i] == 'R' and s[j] == 'B') {
ret = green[j];
if (s[j + (j - i)] == 'G')
ret--;
} else if (s[i] == 'G' and s[j] == 'B') {
ret = red[j];
if (s[j + (j - i)] == 'R')
ret--;
} else if (s[i] == 'G' and s[j] == 'R') {
ret = blue[j];
if (s[j + (j - i)] == 'B')
ret--;
} else if (s[i] == 'B' and s[j] == 'R') {
ret = green[j];
if (s[j + (j - i)] == 'G')
ret--;
} else if (s[i] == 'B' and s[j] == 'G') {
ret = red[j];
if (s[j + (j - i)] == 'R')
ret--;
}
return ret;
}
int main() {
cin >> n;
cin >> s;
ll ans = 0;
blue[n] = 0;
green[n] = 0;
red[n] = 0;
per(i, 1, n) {
if (s[i] == 'R') {
red[i - 1] += red[i] + 1;
blue[i - 1] += blue[i];
green[i - 1] += green[i];
} else if (s[i] == 'G') {
red[i - 1] += red[i];
blue[i - 1] += blue[i];
green[i - 1] += green[i] + 1;
} else {
red[i - 1] += red[i];
blue[i - 1] += blue[i] + 1;
green[i - 1] += green[i];
}
}
// for(int i = 0; i < n+1; i++)cout << red[i] << " ";
// cout << endl;
// for(int i = 0; i < n+1; i++)cout << blue[i] << " ";
// cout << endl;
// for(int i = 0; i < n+1; i++)cout << green[i] << " ";
// cout << endl;
for (int i = 0; i < n - 2; i++) {
for (int j = i + 1; j < n - 1; j++) {
if (s[i] == s[j])
continue;
// cout << i << " " << j << endl;
ans += calc(i, j);
}
}
cout << ans << endl;
} | replace | 19 | 20 | 19 | 20 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
typedef long long ll;
int main() {
ll N;
cin >> N;
string s;
cin >> s;
ll r = 0, g = 0, b = 0;
for (int i = 0; i < N; i++) {
if (s[i] == 'R') {
r++;
} else if (s[i] == 'G') {
g++;
} else {
b++;
}
}
ll ans = r * g * b;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
for (int k = j + 1; k < N; k++) {
if (j - i != k - j) {
continue;
}
else if (s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) {
ans--;
}
}
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
typedef long long ll;
int main() {
ll N;
cin >> N;
string s;
cin >> s;
ll r = 0, g = 0, b = 0;
for (int i = 0; i < N; i++) {
if (s[i] == 'R') {
r++;
} else if (s[i] == 'G') {
g++;
} else {
b++;
}
}
ll ans = r * g * b;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
if (s[i] == s[j]) {
continue;
}
ll k = 2 * j - i;
if (k >= N)
continue;
else if (s[j] != s[k] && s[k] != s[i]) {
ans--;
}
}
}
cout << ans << endl;
}
| replace | 23 | 31 | 23 | 31 | TLE | |
p02714 | C++ | Runtime Error | // Author: Mostafa Mounir Shehab
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265 // PI = acos(-1)
#define EPS (1e-10)
#define endl "\n"
#define SZ(v) (int)(v.size())
typedef long long ll;
typedef long double ld;
// template <class Type>
void Fast() {
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cerr.tie(NULL);
}
inline int D() {
int t;
scanf("%d", &t);
return t;
}
inline ll llD() {
ll t;
scanf("%lld", &t);
return t;
}
ll MOD = 1e9 + 7;
const int N = 4e3 + 5;
char arr[N];
int OO = 1e6;
ll n, m, k, cnt, SU, idx, len, MN, MX, T;
ll l, r, mid;
ll a, b, c, d;
vector<int> vec, v;
string str = "BGR", s;
bool flage;
map<char, vector<int>> mp;
int valid(int i, int j) {
if (arr[i] == arr[j])
return 0;
int len = 0;
do {
if (str[0] == arr[i] && str[1] == arr[j]) {
if (!SZ(mp[str[2]]))
return 0;
if (mp[str[2]].back() <= j)
continue;
len += SZ(mp[str[2]]) -
(lower_bound(mp[str[2]].begin(), mp[str[2]].end(), j) -
mp[str[2]].begin());
len -= (arr[j + j - i] == str[2]);
}
} while (next_permutation(str.begin(), str.end()));
// cerr<<i<<" "<<j<<" "<<len<<endl;
return len;
}
int main() {
scanf("%lld", &n);
scanf("%s", arr);
for (int i = 0; i < n; ++i)
mp[arr[i]].push_back(i);
for (int i = 0; i < n; ++i)
for (int j = i + 1; j < n; ++j)
cnt += valid(i, j);
printf("%lld\n", cnt);
}
| // Author: Mostafa Mounir Shehab
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265 // PI = acos(-1)
#define EPS (1e-10)
#define endl "\n"
#define SZ(v) (int)(v.size())
typedef long long ll;
typedef long double ld;
// template <class Type>
void Fast() {
std::ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cerr.tie(NULL);
}
inline int D() {
int t;
scanf("%d", &t);
return t;
}
inline ll llD() {
ll t;
scanf("%lld", &t);
return t;
}
ll MOD = 1e9 + 7;
const int N = 1e5 + 5;
char arr[N];
int OO = 1e6;
ll n, m, k, cnt, SU, idx, len, MN, MX, T;
ll l, r, mid;
ll a, b, c, d;
vector<int> vec, v;
string str = "BGR", s;
bool flage;
map<char, vector<int>> mp;
int valid(int i, int j) {
if (arr[i] == arr[j])
return 0;
int len = 0;
do {
if (str[0] == arr[i] && str[1] == arr[j]) {
if (!SZ(mp[str[2]]))
return 0;
if (mp[str[2]].back() <= j)
continue;
len += SZ(mp[str[2]]) -
(lower_bound(mp[str[2]].begin(), mp[str[2]].end(), j) -
mp[str[2]].begin());
len -= (arr[j + j - i] == str[2]);
}
} while (next_permutation(str.begin(), str.end()));
// cerr<<i<<" "<<j<<" "<<len<<endl;
return len;
}
int main() {
scanf("%lld", &n);
scanf("%s", arr);
for (int i = 0; i < n; ++i)
mp[arr[i]].push_back(i);
for (int i = 0; i < n; ++i)
for (int j = i + 1; j < n; ++j)
cnt += valid(i, j);
printf("%lld\n", cnt);
}
| replace | 32 | 33 | 32 | 33 | 0 | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll n;
cin >> n;
string s;
cin >> s;
map<char, vector<ll>> ind;
for (ll i = 0; i < n; i++) {
ind[s[i]].push_back(i);
}
ll ans = 0;
for (ll i = 0; i < n; i++) {
for (ll j = i + 1; j < n; j++) {
if (s[i] == s[j])
continue;
set<char> cols = {'R', 'G', 'B'};
cols.erase(s[i]);
cols.erase(s[j]);
char c = *cols.begin();
auto begin = lower_bound(ind[c].begin(), ind[c].end(), j + 1);
auto it = lower_bound(begin, ind[c].end(), 2 * j - i);
if (*it == 2 * j - i)
ans += ind[c].end() - begin - 1;
else
ans += ind[c].end() - begin;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll n;
cin >> n;
string s;
cin >> s;
map<char, vector<ll>> ind;
for (ll i = 0; i < n; i++) {
ind[s[i]].push_back(i);
}
ll ans = 0;
for (ll i = 0; i < n; i++) {
for (ll j = i + 1; j < n; j++) {
if (s[i] == s[j])
continue;
set<char> cols = {'R', 'G', 'B'};
cols.erase(s[i]);
cols.erase(s[j]);
char c = *cols.begin();
auto begin = lower_bound(ind[c].begin(), ind[c].end(), j + 1);
auto exist = binary_search(begin, ind[c].end(), 2 * j - i);
if (exist)
ans += ind[c].end() - begin - 1;
else
ans += ind[c].end() - begin;
}
}
cout << ans << endl;
}
| replace | 27 | 29 | 27 | 29 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <iostream>
#include <unordered_set>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
long long res = 0;
unordered_set<int> r, g, b;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'R')
r.insert(i);
else if (s[i] == 'G')
g.insert(i);
else
b.insert(i);
}
for (auto i : r) {
for (auto j : g) {
for (auto k : b) {
int _max = max(max(i, j), k);
int _min = min(min(i, j), k);
if ((_max + _min) * 3 != (i + j + k) * 2)
res++;
}
}
}
cout << res;
} | #include <iostream>
#include <unordered_set>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
long long res = 0;
unordered_set<int> r, g, b;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'R')
r.insert(i);
else if (s[i] == 'G')
g.insert(i);
else
b.insert(i);
}
for (auto i : r) {
for (auto j : g) {
res += b.size();
if (b.count(2 * i - j))
res--;
if (b.count(2 * j - i))
res--;
if ((i + j) % 2 == 0 && b.count((i + j) / 2))
res--;
}
}
cout << res;
} | replace | 22 | 28 | 22 | 29 | TLE | |
p02714 | C++ | Runtime Error | /*
* Matheus Oliveira
* 09:20:02 12/04/2020
* d.cpp
*/
#include <bits/stdc++.h>
using namespace std;
#define EPS
#define INF
#define MAXN 4040
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define sc(x) scanf("%d", &x);
#define sc2(x, y) scanf("%d %d", &x, &y);
#define sc3(x, y, z) scanf("%d %d %d", &x, &y, &z);
#define debug(x) printf("%s: %d\n", #x, x);
#define debugarr(x, bg, ed) \
printf("%s: ", #x); \
for (int i = bg; i < ed; i++) \
printf("%d%c", x[i], (i == ed - 1) ? '\n' : ' ');
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
char inp[MAXN];
int r[MAXN], g[MAXN], b[MAXN];
char getLast(char f, char s) {
if ('R' != f and 'R' != s)
return 'R';
if ('G' != f and 'G' != s)
return 'G';
return 'B';
}
int main() {
char last;
int n, dist;
scanf("%d", &n);
getchar();
scanf("%s", inp);
ll ans = 0;
for (int i = 0; i < n; i++) {
if (i == 0) {
r[i] = (inp[i] == 'R');
g[i] = (inp[i] == 'G');
b[i] = (inp[i] == 'B');
} else {
r[i] = r[i - 1] + (inp[i] == 'R');
g[i] = g[i - 1] + (inp[i] == 'G');
b[i] = b[i - 1] + (inp[i] == 'B');
}
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (inp[i] != inp[j]) {
last = getLast(inp[i], inp[j]);
dist = j - i;
if (last == 'R')
ans += ((ll)(r[n - 1] - r[j]) - (inp[j + dist] == 'R'));
if (last == 'G')
ans += ((ll)(g[n - 1] - g[j]) - (inp[j + dist] == 'G'));
if (last == 'B')
ans += ((ll)(b[n - 1] - b[j]) - (inp[j + dist] == 'B'));
}
}
}
printf("%lld\n", ans);
return 0;
} | /*
* Matheus Oliveira
* 09:20:02 12/04/2020
* d.cpp
*/
#include <bits/stdc++.h>
using namespace std;
#define EPS
#define INF
#define MAXN 14040
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define sc(x) scanf("%d", &x);
#define sc2(x, y) scanf("%d %d", &x, &y);
#define sc3(x, y, z) scanf("%d %d %d", &x, &y, &z);
#define debug(x) printf("%s: %d\n", #x, x);
#define debugarr(x, bg, ed) \
printf("%s: ", #x); \
for (int i = bg; i < ed; i++) \
printf("%d%c", x[i], (i == ed - 1) ? '\n' : ' ');
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
char inp[MAXN];
int r[MAXN], g[MAXN], b[MAXN];
char getLast(char f, char s) {
if ('R' != f and 'R' != s)
return 'R';
if ('G' != f and 'G' != s)
return 'G';
return 'B';
}
int main() {
char last;
int n, dist;
scanf("%d", &n);
getchar();
scanf("%s", inp);
ll ans = 0;
for (int i = 0; i < n; i++) {
if (i == 0) {
r[i] = (inp[i] == 'R');
g[i] = (inp[i] == 'G');
b[i] = (inp[i] == 'B');
} else {
r[i] = r[i - 1] + (inp[i] == 'R');
g[i] = g[i - 1] + (inp[i] == 'G');
b[i] = b[i - 1] + (inp[i] == 'B');
}
}
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (inp[i] != inp[j]) {
last = getLast(inp[i], inp[j]);
dist = j - i;
if (last == 'R')
ans += ((ll)(r[n - 1] - r[j]) - (inp[j + dist] == 'R'));
if (last == 'G')
ans += ((ll)(g[n - 1] - g[j]) - (inp[j + dist] == 'G'));
if (last == 'B')
ans += ((ll)(b[n - 1] - b[j]) - (inp[j + dist] == 'B'));
}
}
}
printf("%lld\n", ans);
return 0;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p02714 | C++ | Time Limit Exceeded | #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
int main() {
using namespace std;
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, sum;
long long count = 0;
string s;
vector<int> r, g, b;
cin >> n >> s;
for (int i = 0; i <= n; i++) {
switch (s[i]) {
case 'R':
r.push_back(i + 1);
break;
case 'G':
g.push_back(i + 1);
break;
case 'B':
b.push_back(i + 1);
break;
default:
break;
}
}
for (int i = 0; i < (int)r.size(); i++) {
for (int j = 0; j < (int)g.size(); j++) {
for (int k = 0; k < (int)b.size(); k++) {
sum = r[i] + g[j] + b[k];
if (3 * r[i] == sum) {
count--;
continue;
} else if (3 * g[j] == sum) {
count--;
continue;
} else if (3 * b[k] == sum) {
count--;
continue;
}
}
}
}
count += r.size() * g.size() * b.size();
cout << count << endl;
return 0;
}
| #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
int main() {
using namespace std;
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, sum;
long long count = 0;
string s;
vector<int> r, g, b;
cin >> n >> s;
for (int i = 0; i <= n; i++) {
switch (s[i]) {
case 'R':
r.push_back(i + 1);
break;
case 'G':
g.push_back(i + 1);
break;
case 'B':
b.push_back(i + 1);
break;
default:
break;
}
}
for (int i = 0; i < (int)r.size(); i++) {
for (int j = 0; j < (int)g.size(); j++) {
for (int k = 0; k < (int)b.size(); k++) {
sum = r[i] + g[j] + b[k];
if (3 * r[i] == sum || 3 * g[j] == sum || 3 * b[k] == sum) {
count--;
continue;
}
}
}
}
count += r.size() * g.size() * b.size();
cout << count << endl;
return 0;
}
| replace | 31 | 38 | 31 | 32 | TLE | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int64_t pairs(string s, int n) {
int64_t sum = 0;
int64_t r = 0;
int64_t g = 0;
int64_t b = 0;
for (int i = 0; i < n; i++) {
if (s.at(i) == 'R') {
r++;
} else if (s.at(i) == 'G') {
g++;
} else if (s.at(i) == 'B') {
b++;
}
}
int64_t no = 0;
for (int i = 0; i < n - 2; i++) {
for (int d = 1;; d++) {
if (2 * d >= n) {
break;
}
if (s.at(i) != s.at(i + d) && s.at(i + d) != s.at(i + 2 * d) &&
s.at(i + 2 * d) != s.at(i)) {
no++;
}
}
}
sum = r * g * b - no;
return sum;
}
int main() {
int n;
string s;
cin >> n >> s;
cout << pairs(s, n) << endl;
} | #include <bits/stdc++.h>
using namespace std;
int64_t pairs(string s, int n) {
int64_t sum = 0;
int64_t r = 0;
int64_t g = 0;
int64_t b = 0;
for (int i = 0; i < n; i++) {
if (s.at(i) == 'R') {
r++;
} else if (s.at(i) == 'G') {
g++;
} else if (s.at(i) == 'B') {
b++;
}
}
int64_t no = 0;
for (int i = 0; i < n - 2; i++) {
for (int d = 1;; d++) {
if (i + 2 * d >= n) {
break;
}
if (s.at(i) != s.at(i + d) && s.at(i + d) != s.at(i + 2 * d) &&
s.at(i + 2 * d) != s.at(i)) {
no++;
}
}
}
sum = r * g * b - no;
return sum;
}
int main() {
int n;
string s;
cin >> n >> s;
cout << pairs(s, n) << endl;
} | replace | 22 | 23 | 22 | 23 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, n) for (int i = 1; i < (n); i++)
typedef long long ll;
int main() {
int n;
cin >> n;
string s;
cin >> s;
vector<int> r(0), g(0), b(0);
rep(i, n) {
if (s[i] == 'R')
r.push_back(i);
if (s[i] == 'G')
g.push_back(i);
if (s[i] == 'B')
b.push_back(i);
}
ll ans = 0;
for (int i : r) {
for (int j : g) {
ll IJ = abs(i - j);
for (int k : b) {
ll JK = abs(j - k);
ll KI = abs(k - i);
if (IJ == JK || JK == KI || KI == IJ)
continue;
else
ans++;
}
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, n) for (int i = 1; i < (n); i++)
typedef long long ll;
int main() {
int n;
cin >> n;
string s;
cin >> s;
vector<int> r(0), g(0), b(0);
rep(i, n) {
if (s[i] == 'R')
r.push_back(i);
if (s[i] == 'G')
g.push_back(i);
if (s[i] == 'B')
b.push_back(i);
}
ll ans = r.size() * g.size() * b.size();
for (auto i : r) {
for (auto j : g) {
if (i % 2 == j % 2) {
if (s[(i + j) / 2] == 'B')
ans--;
}
if (0 <= 2 * i - j && 2 * i - j < n) {
if (s[2 * i - j] == 'B')
ans--;
}
if (0 <= 2 * j - i && 2 * j - i < n) {
if (s[2 * j - i] == 'B')
ans--;
}
}
}
cout << ans << endl;
} | replace | 20 | 31 | 20 | 34 | TLE | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
/*
R=0
G=1
B=2
*/
int main() {
int n;
string ss;
cin >> n >> ss;
long long ans = 0;
int f[402][3] = {0};
for (int i = ss.length() - 1; i >= 0; i--) {
if (ss[i] == 'R') {
f[i][0] = f[i + 1][0] + 1;
f[i][1] = f[i + 1][1];
f[i][2] = f[i + 1][2];
} else if (ss[i] == 'G') {
f[i][1] = f[i + 1][1] + 1;
f[i][0] = f[i + 1][0];
f[i][2] = f[i + 1][2];
} else {
f[i][2] = f[i + 1][2] + 1;
f[i][0] = f[i + 1][0];
f[i][1] = f[i + 1][1];
}
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (ss[i] == 'R' && ss[j] == 'G') {
ans += f[j][2];
if (ss[2 * j - i] == 'B')
ans = ans - 1;
} else if (ss[i] == 'R' && ss[j] == 'B') {
ans += f[j][1];
if (ss[2 * j - i] == 'G')
ans = ans - 1;
} else if (ss[i] == 'B' && ss[j] == 'G') {
ans += f[j][0];
if (ss[2 * j - i] == 'R')
ans = ans - 1;
} else if (ss[i] == 'B' && ss[j] == 'R') {
ans += f[j][1];
if (ss[2 * j - i] == 'G')
ans = ans - 1;
} else if (ss[i] == 'G' && ss[j] == 'R') {
ans += f[j][2];
if (ss[2 * j - i] == 'B')
ans = ans - 1;
} else if (ss[i] == 'G' && ss[j] == 'B') {
ans += f[j][0];
if (ss[2 * j - i] == 'R')
ans = ans - 1;
}
}
}
cout << ans << endl;
/*
for(int i=0;i<n;i++){
cout<<ss[i]<<" ";
for(int j=0;j<3;j++){
cout<<f[i][j]<<" ";
}
cout<<endl;
}
*/
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
/*
R=0
G=1
B=2
*/
int main() {
int n;
string ss;
cin >> n >> ss;
long long ans = 0;
int f[4002][3] = {0};
for (int i = ss.length() - 1; i >= 0; i--) {
if (ss[i] == 'R') {
f[i][0] = f[i + 1][0] + 1;
f[i][1] = f[i + 1][1];
f[i][2] = f[i + 1][2];
} else if (ss[i] == 'G') {
f[i][1] = f[i + 1][1] + 1;
f[i][0] = f[i + 1][0];
f[i][2] = f[i + 1][2];
} else {
f[i][2] = f[i + 1][2] + 1;
f[i][0] = f[i + 1][0];
f[i][1] = f[i + 1][1];
}
}
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
if (ss[i] == 'R' && ss[j] == 'G') {
ans += f[j][2];
if (ss[2 * j - i] == 'B')
ans = ans - 1;
} else if (ss[i] == 'R' && ss[j] == 'B') {
ans += f[j][1];
if (ss[2 * j - i] == 'G')
ans = ans - 1;
} else if (ss[i] == 'B' && ss[j] == 'G') {
ans += f[j][0];
if (ss[2 * j - i] == 'R')
ans = ans - 1;
} else if (ss[i] == 'B' && ss[j] == 'R') {
ans += f[j][1];
if (ss[2 * j - i] == 'G')
ans = ans - 1;
} else if (ss[i] == 'G' && ss[j] == 'R') {
ans += f[j][2];
if (ss[2 * j - i] == 'B')
ans = ans - 1;
} else if (ss[i] == 'G' && ss[j] == 'B') {
ans += f[j][0];
if (ss[2 * j - i] == 'R')
ans = ans - 1;
}
}
}
cout << ans << endl;
/*
for(int i=0;i<n;i++){
cout<<ss[i]<<" ";
for(int j=0;j<3;j++){
cout<<f[i][j]<<" ";
}
cout<<endl;
}
*/
return 0;
}
| replace | 13 | 14 | 13 | 14 | 0 | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve(long long N, std::string S) {
ll R = 0, G = 0, B = 0;
for (auto ch : S) {
if (ch == 'R') {
R++;
}
if (ch == 'G') {
G++;
}
if (ch == 'B') {
B++;
}
}
ll Rl = 0, Gl = 0, Bl = 0;
ll ans = 0;
for (ll i = 0; i < N; i++) {
auto ch = S[i];
if (ch == 'R') {
ans += Gl * B + Bl * G;
Rl++;
R--;
}
if (ch == 'G') {
ans += Rl * B + Bl * R;
Gl++;
G--;
}
if (ch == 'B') {
ans += Rl * G + Gl * R;
Bl++;
B--;
}
for (ll j = 1; 0 <= i - j && i + j < N; j++) {
if (ch != S[i - j] && ch != S[i + j] && S[i - j] != S[i + j]) {
ans--;
}
}
}
cout << ans << endl;
}
// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips:
// You use the default template now. You can remove this line by using your
// custom template)
// clang-format off
#pragma GCC diagnostic ignored "-Wunused-result"
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long N;
scanf("%lld",&N);
std::string S;
std::cin >> S;
solve(N, S);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve(long long N, std::string S) {
ll R = 0, G = 0, B = 0;
for (auto ch : S) {
if (ch == 'R') {
R++;
}
if (ch == 'G') {
G++;
}
if (ch == 'B') {
B++;
}
}
ll Rl = 0, Gl = 0, Bl = 0;
ll ans = 0;
for (ll i = 0; i < N; i++) {
auto ch = S[i];
if (ch == 'R') {
ans += Gl * B + Bl * G;
Rl++;
R--;
}
if (ch == 'G') {
ans += Rl * B + Bl * R;
Gl++;
G--;
}
if (ch == 'B') {
ans += Rl * G + Gl * R;
Bl++;
B--;
}
for (ll j = 1; 0 <= i - j && i + j < N; j++) {
if (ch != S[i - j] && ch != S[i + j] && S[i - j] != S[i + j]) {
ans--;
}
}
}
cout << ans << endl;
}
// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools (tips:
// You use the default template now. You can remove this line by using your
// custom template)
// clang-format off
#pragma GCC diagnostic ignored "-Wunused-result"
int main(){
long long N;
scanf("%lld",&N);
std::string S;
std::cin >> S;
solve(N, S);
return 0;
}
| delete | 51 | 54 | 51 | 51 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int N;
cin >> N;
string s;
cin >> s;
vector<int> r;
vector<int> g;
vector<int> b;
for (int i = 0; i < N; i++) {
if (s[i] == 'R')
r.push_back(i);
if (s[i] == 'G')
g.push_back(i);
if (s[i] == 'B')
b.push_back(i);
}
if (r.size() < 1 || g.size() < 1 || b.size() < 1) {
cout << 0 << endl;
return 0;
}
int count = 0;
for (int i = 0; i < r.size(); i++) {
for (int j = 0; j < g.size(); j++) {
for (int k = 0; k < b.size(); k++) {
int maxnum = max(max(r[i], g[j]), b[k]);
int minnum = min(min(r[i], g[j]), b[k]);
int middle = r[i] + g[j] + b[k] - maxnum - minnum;
if (maxnum - middle != middle - minnum)
count++;
}
}
}
cout << count << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int N;
cin >> N;
string s;
cin >> s;
vector<int> r;
vector<int> g;
vector<int> b;
for (int i = 0; i < N; i++) {
if (s[i] == 'R')
r.push_back(i);
if (s[i] == 'G')
g.push_back(i);
if (s[i] == 'B')
b.push_back(i);
}
if (r.size() < 1 || g.size() < 1 || b.size() < 1) {
cout << 0 << endl;
return 0;
}
long long count = r.size() * g.size() * b.size();
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
int k = 2 * j - i;
if (k >= N)
continue;
if (s[i] != s[j] && s[j] != s[k] && s[i] != s[k])
count--;
}
}
cout << count << endl;
} | replace | 26 | 36 | 26 | 34 | TLE | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007
bool c[4002];
int main() {
ll n;
cin >> n;
string s;
cin >> s;
ll R = 0, B = 0, G = 0;
vector<ll> a, b;
for (ll i = 0; i < n; i++) {
if (s[i] == 'B') {
c[i] = true;
} else if (s[i] == 'R') {
a.push_back(i);
} else {
b.push_back(i);
}
}
ll ans = a.size() * b.size() * (n - a.size() - b.size());
// cout <<ans;
for (ll i = 0; i < b.size(); i++) {
ll now = b[i];
// cout << now<<endl;
for (ll j = 0; j < a.size(); j++) {
ll next = a[j];
// cout << next;
ll dex = abs(now - next);
if (c[next + dex] && next + dex < n) {
ans--;
}
if (c[next - dex] && next - dex >= 0) {
ans--;
}
if (c[now + dex] && now + dex < n) {
ans--;
}
if (c[now - dex] && now - dex >= 0) {
ans--;
}
if (dex % 2 == 0) {
if (c[(now + next) / 2]) {
ans--;
}
}
}
// cout <<ans;
}
cout << ans;
// your code goes here
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007
bool c[20002];
int main() {
ll n;
cin >> n;
string s;
cin >> s;
ll R = 0, B = 0, G = 0;
vector<ll> a, b;
for (ll i = 0; i < n; i++) {
if (s[i] == 'B') {
c[i] = true;
} else if (s[i] == 'R') {
a.push_back(i);
} else {
b.push_back(i);
}
}
ll ans = a.size() * b.size() * (n - a.size() - b.size());
// cout <<ans;
for (ll i = 0; i < b.size(); i++) {
ll now = b[i];
// cout << now<<endl;
for (ll j = 0; j < a.size(); j++) {
ll next = a[j];
// cout << next;
ll dex = abs(now - next);
if (c[next + dex] && next + dex < n) {
ans--;
}
if (c[next - dex] && next - dex >= 0) {
ans--;
}
if (c[now + dex] && now + dex < n) {
ans--;
}
if (c[now - dex] && now - dex >= 0) {
ans--;
}
if (dex % 2 == 0) {
if (c[(now + next) / 2]) {
ans--;
}
}
}
// cout <<ans;
}
cout << ans;
// your code goes here
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define SPEED \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
signed main() {
SPEED;
int n, i, j, k;
cin >> n;
string s;
cin >> s;
int ans = 0;
for (j = 1; j < n - 1; ++j) {
char ch[1000] = {'0'};
int cr = 0, cb = 0, cg = 0;
for (i = 0; i < j; ++i) {
if (s[j] != s[i]) {
if (s[i] == 'R')
cr++;
else if (s[i] == 'B')
cb++;
else
cg++;
ch[j - i] = s[i];
}
}
for (k = j + 1; k < n; ++k) {
if (s[j] != s[k]) {
if (s[k] == 'B') {
if (ch[k - j] != 'R' && ch[k - j] != 'G')
ans += cr + cg;
else
ans += cr + cg - 1;
} else if (s[k] == 'R') {
if (ch[k - j] != 'B' && ch[k - j] != 'G')
ans += cb + cg;
else
ans += cb + cg - 1;
} else if (s[k] == 'G') {
if (ch[k - j] != 'B' && ch[k - j] != 'R')
ans += cr + cb;
else
ans += cr + cb - 1;
}
}
}
}
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define pb push_back
#define SPEED \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
signed main() {
SPEED;
int n, i, j, k;
cin >> n;
string s;
cin >> s;
int ans = 0;
for (j = 1; j < n - 1; ++j) {
char ch[4000] = {'0'};
int cr = 0, cb = 0, cg = 0;
for (i = 0; i < j; ++i) {
if (s[j] != s[i]) {
if (s[i] == 'R')
cr++;
else if (s[i] == 'B')
cb++;
else
cg++;
ch[j - i] = s[i];
}
}
for (k = j + 1; k < n; ++k) {
if (s[j] != s[k]) {
if (s[k] == 'B') {
if (ch[k - j] != 'R' && ch[k - j] != 'G')
ans += cr + cg;
else
ans += cr + cg - 1;
} else if (s[k] == 'R') {
if (ch[k - j] != 'B' && ch[k - j] != 'G')
ans += cb + cg;
else
ans += cb + cg - 1;
} else if (s[k] == 'G') {
if (ch[k - j] != 'B' && ch[k - j] != 'R')
ans += cr + cb;
else
ans += cr + cb - 1;
}
}
}
}
cout << ans;
} | replace | 17 | 18 | 17 | 18 | 0 | |
p02714 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
ll n;
string s;
cin >> n >> s;
vvll m(3);
rep(i, n) {
if (s[i] == 'R') {
m[0].push_back(i);
} else if (s[i] == 'G') {
m[1].push_back(i);
} else {
m[2].push_back(i);
}
}
ll ans = m[0].size() * m[1].size() * m[2].size();
FORm(r, m[0]) {
FORm(g, m[1]) {
ll v = *r - *g;
ll cand1 = *r + v;
ll cand2 = *g - v;
ll cand_max = max(cand1, cand2);
bool is_even = (v % 2 == 0);
ll cand3 = (*r + *g) / 2;
FORm(b, m[2]) {
if (*b > cand_max) {
break;
}
if (*b == cand1) {
ans--;
} else if (*b == cand2) {
ans--;
} else if (is_even && *b == cand3) {
ans--;
}
}
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)
signed main() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
ll n;
string s;
cin >> n >> s;
vvll m(3);
rep(i, n) {
if (s[i] == 'R') {
m[0].push_back(i);
} else if (s[i] == 'G') {
m[1].push_back(i);
} else {
m[2].push_back(i);
}
}
ll ans = m[0].size() * m[1].size() * m[2].size();
FORm(r, m[0]) {
FORm(g, m[1]) {
ll v = *r - *g;
if (binary_search(all(m[2]), *r + v)) {
ans--;
}
if (binary_search(all(m[2]), *g - v)) {
ans--;
}
if (v % 2 == 0) {
if (binary_search(all(m[2]), (*r + *g) / 2)) {
ans--;
}
}
}
}
cout << ans << endl;
return 0;
}
| replace | 47 | 61 | 47 | 56 | TLE | |
p02714 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0);
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ((n) ? "Yes" : "No") << '\n';
#define CFYN(n) cout << ((n) ? "YES" : "NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
int main(void) {
IOS int n;
cin >> n;
string s;
cin >> s;
vector<int> r, g, b;
REP(i, n) {
if (s[i] == 'R')
r.push_back(i);
else if (s[i] == 'G')
g.push_back(i);
else
b.push_back(i);
}
ll ans = 0;
if (g.size() == 0) {
OUT(0)
return 0;
}
for (auto i : r) {
for (auto j : g) {
// if (i > j) swap(i,j);
int d = j - i;
int bs = b.size();
auto it1 = lower_bound(ALL(b), i - d);
if (*it1 == i - d)
bs--;
auto it2 = lower_bound(ALL(b), j + d);
if (*it2 == j + d)
bs--;
if (d % 2 == 0) {
auto it3 = lower_bound(ALL(b), i + d / 2);
if (*it3 == i + d / 2)
bs--;
}
ans += bs;
}
}
cout << ans << '\n';
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0);
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ((n) ? "Yes" : "No") << '\n';
#define CFYN(n) cout << ((n) ? "YES" : "NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
int main(void) {
IOS int n;
cin >> n;
string s;
cin >> s;
vector<int> r, g, b;
REP(i, n) {
if (s[i] == 'R')
r.push_back(i);
else if (s[i] == 'G')
g.push_back(i);
else
b.push_back(i);
}
ll ans = 0;
if (b.size() == 0) {
OUT(0)
return 0;
}
for (auto i : r) {
for (auto j : g) {
// if (i > j) swap(i,j);
int d = j - i;
int bs = b.size();
auto it1 = lower_bound(ALL(b), i - d);
if (*it1 == i - d)
bs--;
auto it2 = lower_bound(ALL(b), j + d);
if (*it2 == j + d)
bs--;
if (d % 2 == 0) {
auto it3 = lower_bound(ALL(b), i + d / 2);
if (*it3 == i + d / 2)
bs--;
}
ans += bs;
}
}
cout << ans << '\n';
return 0;
}
| replace | 33 | 34 | 33 | 34 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.