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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02887 | Python | Runtime Error | #!/usr/bin/env python3
import sys
import re
def solve(N: int, S: str):
result = 0
for s in set(S):
regex = re.compile(f"{s}+")
# print(regex.findall(S))
result += len(regex.findall(S))
print(result)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
S = next(tokens) # type: str
solve(N, S)
if __name__ == "__main__":
main()
| #!/usr/bin/env python3
import sys
import re
def solve(N: int, S: str):
result = 0
for s in set(S):
regex = re.compile(s + "+")
# print(regex.findall(S))
result += len(regex.findall(S))
print(result)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
S = next(tokens) # type: str
solve(N, S)
if __name__ == "__main__":
main()
| replace | 8 | 9 | 8 | 9 | 0 | |
p02887 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
// #define int long long
using namespace std;
inline int gi() {
char tmp = getchar();
int flag = 1;
while (tmp < '0' || tmp > '9') {
if (tmp == '-') {
flag = -1;
tmp = getchar();
break;
}
tmp = getchar();
}
int ans = 0;
while (tmp <= '9' and tmp >= '0') {
ans = ans * 10 + tmp - '0';
tmp = getchar();
}
return ans * flag;
}
inline void write(int x) {
static int stk[100], top = 0;
if (x == 0) {
putchar('0');
putchar(' ');
return;
}
if (x < 0) {
x = -x;
putchar('-');
}
while (x) {
stk[++top] = x % 10;
x /= 10;
}
while (top) {
putchar(stk[top--] + '0');
}
putchar(' ');
}
#define line() putchar('\n');
#define Mem(Arr, V) memset(Arr, V, sizeof Arr);
#define Mcpy(Arr, qwq) memcpy(Arr, qwq, sizeof qwq);
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max4(max3(a, b, c), d);
#define in(a) a = gi()
#define in2(a, b) in(a), in(b)
#define in3(a, b, c) in2(a, b), in(c)
#define in4(a, b, c, d) in3(a, b, c), in(d)
#define write2(a, b) write(a), write(b)
#define write3(a, b, c) write2(a, b), write(c)
#define write4(a, b, c, d) write3(a, b, c), write(d)
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
const int inf = 2147483647; // 如果是 long long 记得改!
const int N = 1000001;
char S[N];
signed main() {
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif
int n = gi();
char pre = 0;
int ans = 0;
for (int i = 1; i <= n; ++i) {
char tmp;
scanf(" %c", &tmp);
if (i == 1) {
pre = tmp;
++ans;
} else if (pre == tmp) {
continue;
} else if (pre != tmp) {
pre = tmp;
++ans;
}
}
write(ans);
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
// #define int long long
using namespace std;
inline int gi() {
char tmp = getchar();
int flag = 1;
while (tmp < '0' || tmp > '9') {
if (tmp == '-') {
flag = -1;
tmp = getchar();
break;
}
tmp = getchar();
}
int ans = 0;
while (tmp <= '9' and tmp >= '0') {
ans = ans * 10 + tmp - '0';
tmp = getchar();
}
return ans * flag;
}
inline void write(int x) {
static int stk[100], top = 0;
if (x == 0) {
putchar('0');
putchar(' ');
return;
}
if (x < 0) {
x = -x;
putchar('-');
}
while (x) {
stk[++top] = x % 10;
x /= 10;
}
while (top) {
putchar(stk[top--] + '0');
}
putchar(' ');
}
#define line() putchar('\n');
#define Mem(Arr, V) memset(Arr, V, sizeof Arr);
#define Mcpy(Arr, qwq) memcpy(Arr, qwq, sizeof qwq);
#define max3(a, b, c) max(max(a, b), c)
#define max4(a, b, c, d) max4(max3(a, b, c), d);
#define in(a) a = gi()
#define in2(a, b) in(a), in(b)
#define in3(a, b, c) in2(a, b), in(c)
#define in4(a, b, c, d) in3(a, b, c), in(d)
#define write2(a, b) write(a), write(b)
#define write3(a, b, c) write2(a, b), write(c)
#define write4(a, b, c, d) write3(a, b, c), write(d)
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
const int inf = 2147483647; // 如果是 long long 记得改!
const int N = 1000001;
char S[N];
signed main() {
int n = gi();
char pre = 0;
int ans = 0;
for (int i = 1; i <= n; ++i) {
char tmp;
scanf(" %c", &tmp);
if (i == 1) {
pre = tmp;
++ans;
} else if (pre == tmp) {
continue;
} else if (pre != tmp) {
pre = tmp;
++ans;
}
}
write(ans);
return 0;
} | delete | 66 | 69 | 66 | 66 | TLE | |
p02887 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, c = 0;
cin >> n;
char s[10001];
for (int i = 0; i < n; i++) {
cin >> s[i];
}
for (int j = 0; j < n; j++) {
if (s[j] != s[j + 1])
c++;
}
cout << c << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, c = 0;
cin >> n;
string s;
cin >> s;
for (int j = 0; j < n; j++) {
if (s[j] != s[j + 1])
c++;
}
cout << c << endl;
}
| replace | 5 | 9 | 5 | 7 | 0 | |
p02887 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string S;
cin >> N >> S;
int count = 0;
for (int i = 0; i < N - 1; i++) {
if (S.at(i) != S.at(i + i)) {
count++;
}
}
cout << count + 1 << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string S;
cin >> N >> S;
int count = 0;
for (int i = 0; i + 1 < S.size(); i++) {
if (S.at(i) != S.at(i + 1)) {
count++;
}
}
cout << count + 1 << endl;
} | replace | 9 | 11 | 9 | 11 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 10) >= this->size() (which is 10)
|
p02887 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
int n;
string s;
cin >> n >> s;
vector<char> a(n);
int i = 0;
while (1) {
if (s.at(i) == s.at(i + 1)) {
if (i == s.size() - 2) {
s.erase(s.begin() + (i + 1));
break;
} else
s.erase(s.begin() + (i + 1));
} else if (i == s.size() - 2)
break;
else
i++;
}
cout << s.size() << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
int n;
string s;
cin >> n >> s;
vector<char> a(n);
int i = 0;
while (1) {
if (s.size() == 1)
break;
else if (s.at(i) == s.at(i + 1)) {
if (i == s.size() - 2) {
s.erase(s.begin() + (i + 1));
break;
} else
s.erase(s.begin() + (i + 1));
} else if (i == s.size() - 2)
break;
else
i++;
}
cout << s.size() << endl;
return 0;
} | replace | 11 | 12 | 11 | 14 | 0 | |
p02887 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
char S[N];
cin >> S;
int ans = 1;
for (int i = 0; i < N; i++) {
for (int j = 1; i + j < N; j++) {
if (S[i] != S[i + j]) {
ans++;
i += j - 1;
break;
}
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
char S[N];
cin >> S;
int ans = 1;
for (int i = 0; i < N - 1; i++) {
if (S[i] != S[i + 1])
ans++;
}
cout << ans << endl;
return 0;
} | replace | 9 | 17 | 9 | 12 | TLE | |
p02887 | C++ | Runtime Error | #define _CRT_SECURE_NO_WARNINGS
#include <algorithm> //C++
#include <iostream> //C++
#include <math.h>
#include <queue> //C++
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string> //C++
#include <vector> //C++
using namespace std; // C++
#define rep(i, a, n) for (i = (a); i < (n); i++)
int main() {
int n, i;
cin >> n;
char s[100];
rep(i, 0, n) cin >> s[i];
int Ans = 1;
rep(i, 0, n - 1) {
if (s[i] == s[i + 1]) {
continue;
} else
Ans++;
}
cout << Ans;
} | #define _CRT_SECURE_NO_WARNINGS
#include <algorithm> //C++
#include <iostream> //C++
#include <math.h>
#include <queue> //C++
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string> //C++
#include <vector> //C++
using namespace std; // C++
#define rep(i, a, n) for (i = (a); i < (n); i++)
int main() {
int n, i;
cin >> n;
char s[100000];
rep(i, 0, n) cin >> s[i];
int Ans = 1;
rep(i, 0, n - 1) {
if (s[i] == s[i + 1]) {
continue;
} else
Ans++;
}
cout << Ans;
} | replace | 17 | 18 | 17 | 18 | 0 | |
p02887 | C++ | Time Limit Exceeded | #include <stdio.h>
char a[1000000];
int main() {
int n, i;
scanf("%d", &n);
scanf("%s", &a);
int sum = 0;
for (i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] == a[j]) {
a[j] = 0;
} else {
if (a[i] != 0)
sum++;
break;
}
}
}
printf("%d", sum + 1);
} | #include <stdio.h>
char a[1000000];
int main() {
int n, i;
scanf("%d", &n);
scanf("%s", &a);
int sum = 0;
for (i = 0; i < n - 1; i++) {
if (a[i] != a[i + 1])
sum++;
}
printf("%d", sum + 1);
} | replace | 7 | 17 | 7 | 10 | TLE | |
p02887 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string S;
cin >> N >> S;
int count = 1;
for (int i = 0; i < N; i++) {
if (S.at(i) != S.at(i + 1))
count++;
}
cout << count << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
string S;
cin >> N >> S;
int count = 1;
for (int i = 0; i < N - 1; i++) {
if (S.at(i) != S.at(i + 1))
count++;
}
cout << count << endl;
}
| replace | 9 | 10 | 9 | 10 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 10) >= this->size() (which is 10)
|
p02887 | Python | Time Limit Exceeded | n = int(input())
s = input()
conti = True
while conti:
conti = False
for count, char in enumerate(s):
if (count - 1) >= 0 and s[count] == s[count - 1]:
s = s[:count] + s[count + 1 :]
conti = True
break
print(len(s))
| n = int(input())
s = input()
conti = True
while conti:
try:
conti = False
for count, char in enumerate(s):
if (count - 1) >= 0 and s[count] == s[count - 1]:
s = s[:count] + s[count + 1 :]
conti = True
except IndexError:
pass
print(len(s))
| replace | 5 | 11 | 5 | 13 | TLE | |
p02887 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int a, result = 0;
string slime;
cin >> a;
for (int i = 0; i < a; i++) {
if (i == 0 || slime[i] != slime[i - 1])
result++;
}
cout << result << endl;
return 0;
} | #include <iostream>
using namespace std;
int main() {
int a, result = 0;
string slime;
cin >> a;
cin >> slime;
for (int i = 0; i < a; i++) {
if (i == 0 || slime[i] != slime[i - 1])
result++;
}
cout << result << endl;
return 0;
} | insert | 6 | 6 | 6 | 7 | 0 | |
p02887 | C++ | Runtime Error | #include <iostream>
using namespace std;
char s[10005];
int main() {
int n;
int slimes = 1;
cin >> n;
cin >> s;
for (int i = 1; i < n; i++) {
if (s[i] != s[i - 1])
slimes++;
}
cout << slimes << endl;
return 0;
} | #include <iostream>
using namespace std;
char s[100005];
int main() {
int n;
int slimes = 1;
cin >> n;
cin >> s;
for (int i = 1; i < n; i++) {
if (s[i] != s[i - 1])
slimes++;
}
cout << slimes << endl;
return 0;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p02887 | C++ | Runtime Error | #include <algorithm>
#include <bits/stdc++.h>
#include <stdlib.h>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pi 3.14159265359
#define nl printf("\n")
#define gcd(a, b) __gcd(a, b)
#define yes \
cout << "Yes" \
<< "\n"
#define no \
cout << "No" \
<< "\n"
#define pf printf
#define sf scanf
#define FIO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
const int N = 2e5 + 5;
typedef long long int ll;
int main() {
FIO;
int i, j, k, temp, n, f = 0, ans = 1;
cin >> n;
string str;
rep(i, n) {
cin >> str[i];
if (i > 0 && (str[i] != str[i - 1]))
ans++;
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <bits/stdc++.h>
#include <stdlib.h>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pi 3.14159265359
#define nl printf("\n")
#define gcd(a, b) __gcd(a, b)
#define yes \
cout << "Yes" \
<< "\n"
#define no \
cout << "No" \
<< "\n"
#define pf printf
#define sf scanf
#define FIO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
const int N = 2e5 + 5;
typedef long long int ll;
int main() {
FIO;
int i, j, k, temp, n, f = 0, ans = 1;
cin >> n;
string str;
cin >> str;
for (i = 1; i < str.size(); i++) {
if (str[i] != str[i - 1])
ans++;
}
cout << ans << endl;
return 0;
}
| replace | 30 | 33 | 30 | 33 | 0 | |
p02887 | C++ | Runtime Error | /*
@author: sharrad99
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define mp make_pair
#define ff first
#define ss second
#define mll map<ll, ll>
#define pll pair<ll, ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mod 1000000007
int main() {
#ifndef ONLINE_JUDGE
freopen("C:\\Users\\sharr\\Documents\\Input.txt", "r", stdin);
freopen("C:\\Users\\sharr\\Documents\\Output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n;
cin >> n;
string s;
cin >> s;
string res = "";
res.pb(s[0]);
for (ll i = 0; i < n; i++) {
if (res.back() != s[i]) {
res.pb(s[i]);
}
}
cout << res.size();
} | /*
@author: sharrad99
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define mp make_pair
#define ff first
#define ss second
#define mll map<ll, ll>
#define pll pair<ll, ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mod 1000000007
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
ll n;
cin >> n;
string s;
cin >> s;
string res = "";
res.pb(s[0]);
for (ll i = 0; i < n; i++) {
if (res.back() != s[i]) {
res.pb(s[i]);
}
}
cout << res.size();
} | delete | 18 | 22 | 18 | 18 | -11 | |
p02887 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
string s;
for (int i = 0; i < N; i++) {
cin >> s[i];
}
int sum = 1;
for (int i = 1; i < N; i++) {
if (s[i] != s[i - 1]) {
sum++;
}
}
cout << sum << endl;
} | #include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
string s;
cin >> s;
int sum = 1;
for (int i = 1; i < N; i++) {
if (s[i] != s[i - 1]) {
sum++;
}
}
cout << sum << endl;
} | replace | 6 | 9 | 6 | 7 | 0 | |
p02887 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#define rep(i, x) for (int i = 0; i < x; i++)
#include <string>
using namespace std;
int main() {
long long N;
cin >> N;
string S;
rep(i, N) { cin >> S[i]; }
long long count = N;
for (long long i = 0; i < (N - 1); i++) {
if (S[i] == S[i + 1]) {
count--;
}
}
cout << count;
} | #include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
#define rep(i, x) for (int i = 0; i < x; i++)
#include <string>
using namespace std;
int main() {
long long N;
cin >> N;
string S;
cin >> S;
long long count = N;
for (long long i = 0; i < (N - 1); i++) {
if (S[i] == S[i + 1]) {
count--;
}
}
cout << count;
} | replace | 13 | 14 | 13 | 14 | 0 | |
p02887 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int n, cou = 1;
char str[10001];
cin >> n >> str;
for (int i = 0; i < n - 1; ++i)
if (str[i] != str[i + 1])
cou++;
cout << cou << endl;
return 0;
} | #include <iostream>
using namespace std;
int main() {
int n, cou = 1;
char str[100001];
cin >> n >> str;
for (int i = 0; i < n - 1; ++i)
if (str[i] != str[i + 1])
cou++;
cout << cou << endl;
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02887 | C++ | Runtime Error | #include <stdio.h>
int main(void) {
int N = 0, i = 0, j = 0, sum = 0;
char S[10 ^ 5];
scanf("%d", &N);
scanf("%s", S);
sum = N;
for (i = 0; i < N - 1; i++) {
// for (j = i + 1; j < N ; j++)
//{
if (S[i] == S[i + 1]) {
sum -= 1;
}
//}
}
printf("%d", sum);
return 0;
} | #include <stdio.h>
int main(void) {
int N = 0, i = 0, j = 0, sum = 0;
char S[100000];
scanf("%d", &N);
scanf("%s", S);
sum = N;
for (i = 0; i < N - 1; i++) {
// for (j = i + 1; j < N ; j++)
//{
if (S[i] == S[i + 1]) {
sum -= 1;
}
//}
}
printf("%d", sum);
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02887 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
int n;
string str;
cin >> n >> str;
int ans = 1;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (str[i] == str[j]) {
continue;
} else {
ans++;
i = j - 1;
break;
}
}
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
int n;
string str;
cin >> n >> str;
int ans = 1;
char c = str.at(0);
for (int i = 1; i < n; i++) {
if (c == str.at(i)) {
continue;
} else {
ans++;
c = str.at(i);
}
}
cout << ans << endl;
return 0;
}
| replace | 18 | 27 | 18 | 25 | TLE | |
p02887 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int main() {
int N;
string S;
cin >> N >> S;
int ans = 1;
for (int i = 0; i < N; i++) {
char tmp = S[i];
for (int j = i + 1; j < N; j++) {
if (S[j] != tmp) {
ans++;
i = j - 1;
break;
}
}
}
cout << ans << endl;
return 0;
} | #include <iostream>
using namespace std;
int main() {
int N;
string S;
cin >> N >> S;
int ans = 1;
for (int i = 0; i < N; i++) {
char tmp = S[i];
for (int j = i + 1; j < N; j++) {
if (S[j] != tmp) {
ans++;
i = j - 1;
break;
}
if (j == N - 1)
i = j + 1;
}
}
cout << ans << endl;
return 0;
} | insert | 15 | 15 | 15 | 17 | TLE | |
p02887 | C++ | Runtime Error | #include <stdio.h>
int main(void) {
char S[10000];
int N;
int k = 1;
scanf("%d", &N);
scanf("%s", S);
for (int i = 0; i < N - 1; i++) {
if (S[i] != S[i + 1]) {
k++;
}
}
printf("%d\n", k);
} | #include <stdio.h>
int main(void) {
char S[100000];
int N;
int k = 1;
scanf("%d", &N);
scanf("%s", S);
for (int i = 0; i < N - 1; i++) {
if (S[i] != S[i + 1]) {
k++;
}
}
printf("%d\n", k);
} | replace | 2 | 3 | 2 | 3 | 0 | |
p02887 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, c = 0;
cin >> n;
string s;
cin >> s;
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
if (s[i] != s[j]) {
c++;
i = j - 1;
break;
}
}
}
cout << c + 1 << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, c = 0;
cin >> n;
string s;
cin >> s;
char key = s[0];
for (int i = 1; i < n; i++) {
// for(int j=i;j<n;j++)
// {
// if(s[i]!=s[j])
// {
// c++;
// i=j-1;
// break;
// }
// }
if (key != s[i]) {
c++;
key = s[i];
}
}
cout << c + 1 << endl;
return 0;
}
| replace | 11 | 18 | 11 | 25 | TLE | |
p02887 | C++ | Time Limit Exceeded | #include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
bool flag = 1;
int i = 0;
while (flag) {
while (s[i] == s[i + 1]) {
s.erase(i, 1);
if (s.size() == i + 1) {
flag = 0;
break;
}
}
i++;
if (s.size() == i + 1)
break;
}
cout << s.size() << endl;
} | #include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
int n;
string s;
cin >> n >> s;
bool flag = 1;
int i = 0;
if (n == 1) {
cout << 1 << endl;
return 0;
}
while (flag) {
while (s[i] == s[i + 1]) {
s.erase(i, 1);
if (s.size() == i + 1) {
flag = 0;
break;
}
}
i++;
if (s.size() == i + 1)
break;
}
cout << s.size() << endl;
} | insert | 10 | 10 | 10 | 14 | TLE | |
p02887 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string S;
cin >> S;
int ans = 1;
for (int i = 1; i < S.size() - 1; i++) {
if (S.at(i) == S.at(i + 1) && S.at(i - 1) != S.at(i)) {
ans++;
} else if (S.at(i) != S.at(i + 1) && S.at(i - 1) != S.at(i)) {
ans++;
}
}
if (S.at(N - 1) != S.at(N - 2)) {
ans++;
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string S;
cin >> S;
int ans = 1;
if (N == 1) {
cout << ans << endl;
return 0;
}
for (int i = 1; i < S.size() - 1; i++) {
if (S.at(i) == S.at(i + 1) && S.at(i - 1) != S.at(i)) {
ans++;
} else if (S.at(i) != S.at(i + 1) && S.at(i - 1) != S.at(i)) {
ans++;
}
}
if (S.at(N - 1) != S.at(N - 2)) {
ans++;
}
cout << ans << endl;
} | insert | 10 | 10 | 10 | 15 | 0 | |
p02887 | C++ | Runtime Error | #include <stdio.h>
int main() {
int i, N;
char S[10 ^ 5]; // おいしさ
int sum = 1; // おいしさのサム値
// 数を取得
scanf("%d", &N);
// 文字列を取得
scanf("%s", S);
for (i = 1; i < N; i++) {
if (S[i] == S[i - 1]) {
// printf("一緒:%d,%c\n", i,S[i]);
} else {
sum++;
// printf("違う:%d,%c\n", i,S[i]);
}
}
printf("%d", sum);
} | #include <stdio.h>
int main() {
long int i, N;
char S[10 * 10 * 10 * 10 * 10]; // おいしさ
long int sum = 1; // おいしさのサム値
// 数を取得
scanf("%d", &N);
// 文字列を取得
scanf("%s", S);
for (i = 1; i < N; i++) {
if (S[i] == S[i - 1]) {
// printf("一緒:%d,%c\n", i,S[i]);
} else {
sum++;
// printf("違う:%d,%c\n", i,S[i]);
}
}
printf("%d", sum);
} | replace | 2 | 5 | 2 | 5 | 0 | |
p02887 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int N, count = 1;
char s[10000];
cin >> N >> s[0];
for (int i = 1; i < N; i++) {
cin >> s[i];
if (s[i] != s[i - 1])
count += 1;
}
cout << count << endl;
}
| #include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int N, count = 1;
char s[100000];
cin >> N >> s[0];
for (int i = 1; i < N; i++) {
cin >> s[i];
if (s[i] != s[i - 1])
count += 1;
}
cout << count << endl;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p02887 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string S;
cin >> S;
int a = S.size();
for (int i = 0; i < S.size(); i++) {
if (S.at(i) == S.at(i + 1)) {
a--;
}
}
cout << a << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
string S;
cin >> S;
int a = S.size();
for (int i = 0; i < S.size() - 1; i++) {
if (S.at(i) == S.at(i + 1)) {
a--;
}
}
cout << a << endl;
} | replace | 9 | 10 | 9 | 10 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 10) >= this->size() (which is 10)
|
p02887 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
int ans = 0;
for (int i = 0; i < n; i++) {
if (s.at(i) != s.at(i + 1)) {
ans++;
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
int ans = 1;
for (int i = 0; i < n - 1; i++) {
if (s.at(i) != s.at(i + 1)) {
ans++;
}
}
cout << ans << endl;
}
| replace | 8 | 10 | 8 | 10 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): basic_string::at: __n (which is 10) >= this->size() (which is 10)
|
p02887 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
char s[10001];
int n, c = 0;
cin >> n;
cin >> s;
for (int i = 0; i < strlen(s); i++) {
if (s[i] != s[i + 1])
c++;
}
cout << c;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
char s[100001];
int n, c = 0;
cin >> n;
cin >> s;
for (int i = 0; i < strlen(s); i++) {
if (s[i] != s[i + 1])
c++;
}
cout << c;
return 0;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p02887 | C++ | Runtime Error | #include <iostream>
using namespace std;
int main() {
int n;
char s[10001] = {};
cin >> n;
int tag = 0;
int ans = 0;
cin >> s;
for (int i = 0; i < n; i++) {
if (s[i] == s[i + 1]) {
continue;
}
ans++;
}
cout << ans;
return 0;
}
| #include <iostream>
using namespace std;
int main() {
int n;
char s[100001] = {};
cin >> n;
int tag = 0;
int ans = 0;
cin >> s;
for (int i = 0; i < n; i++) {
if (s[i] == s[i + 1]) {
continue;
}
ans++;
}
cout << ans;
return 0;
}
| replace | 5 | 6 | 5 | 6 | 0 | |
p02887 | C++ | Runtime Error | #include <stdio.h>
#include <string.h>
int main(void) {
int N;
char S[10001];
scanf("%d", &N);
scanf("%s", S);
int i;
int ans = N;
for (i = 0; i < N; i++) {
if (S[i] == S[i + 1]) {
ans = ans - 1;
}
}
printf("%d", ans);
return 0;
} | #include <stdio.h>
#include <string.h>
int main(void) {
int N;
char S[100001];
scanf("%d", &N);
scanf("%s", S);
int i;
int ans = N;
for (i = 0; i < N; i++) {
if (S[i] == S[i + 1]) {
ans = ans - 1;
}
}
printf("%d", ans);
return 0;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02887 | C++ | Runtime Error | #include <stdio.h>
int main() {
int n, i;
char s[10000];
while (~scanf("%d", &n)) {
int acm = 1;
scanf("%s", s);
for (i = 0; i < n - 1; i++)
if (s[i] != s[i + 1])
acm++;
printf("%d\n", acm);
}
return 0;
}
| #include <stdio.h>
int main() {
int n, i;
char s[120000];
while (~scanf("%d", &n)) {
int acm = 1;
scanf("%s", s);
for (i = 0; i < n - 1; i++)
if (s[i] != s[i + 1])
acm++;
printf("%d\n", acm);
}
return 0;
}
| replace | 3 | 4 | 3 | 4 | 0 | |
p02887 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
scanf("%d", &N);
string S;
cin >> S;
int ans = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
if (S.at(i) == S.at(j)) {
continue;
} else {
ans++;
i = j;
}
}
}
printf("%d", ans + 1);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
scanf("%d", &N);
string S;
cin >> S;
int ans = 0;
for (int i = 0; i < N - 1; i++) {
if (S.at(i) == S.at(i + 1)) {
continue;
} else {
ans++;
}
}
printf("%d", ans + 1);
return 0;
}
| replace | 10 | 18 | 10 | 15 | TLE | |
p02887 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
ifstream fin("fisier.in");
ofstream fout("fisier.out");
char s[1005];
char actual;
int main() {
int n, i, j, answer = 1;
cin >> n;
cin >> s;
actual = s[0];
for (i = 1; i < n; i++)
if (s[i] != actual) {
actual = s[i];
answer++;
}
cout << answer;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
ifstream fin("fisier.in");
ofstream fout("fisier.out");
char s[100005];
char actual;
int main() {
int n, i, j, answer = 1;
cin >> n;
cin >> s;
actual = s[0];
for (i = 1; i < n; i++)
if (s[i] != actual) {
actual = s[i];
answer++;
}
cout << answer;
return 0;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p02887 | C++ | Runtime Error | // Author:: MUKUL KUMAR RAI
// Institution:: Jalpaiguri Government Engineering College
// If you are not doing well now just stick to it and learn new things one day
// you will be... Compete with yourself
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
///*template{{{
#define sz(x) (ll) x.size()
#define all(x) (x.begin(), x.end())
#define trav(a, x) for (auto &a : x)
#define fr(i, a, b) for (ll i = a; i <= b; i++)
#define fr1(i, a) for (ll i = 0; i < a; i++)
#define frr(i, a, b) for (ll i = b; i >= a; i--)
#define frr1(i, a) for (ll i = a - 1; i >= 0; i--)
#define sorta(a, n) sort(a, a + n)
#define sortd(a, n) sort(a, a + n, greater<ll>())
#define sortva(a) sort(a.begin(), a.end())
#define sortvd(a) sort(a.begin(), a.end(), greater<ll>())
#define tc(t) while (t--)
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
using vi = vector<ll>;
using vvi = vector<vi>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vld = vector<ld>;
using pii = pair<ll, ll>;
using psi = pair<string, ll>;
using pci = pair<char, ll>;
using vpii = vector<pii>;
//}}}template*/
ll mod = 1e9 + 7;
ll const maxn = 1e6 + 5;
ll const inf = 1e18;
bool ss(const pair<ll, ll> &a, const pair<ll, ll> &b) {
return a.first * b.second + a.second < b.first * a.second + b.second;
}
ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }
ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
ll powm(ll x, ll n, ll M) {
ll result = 1;
while (n > 0) {
if (n % 2 == 1)
result = (result * x) % M;
x = (x * x) % M;
n = n / 2;
}
return result;
}
ll modinverse(ll a, ll m) { return powm(a, m - 2, m); }
bool prime(ll x) {
if (x <= 1)
return false;
for (int i = 2; i <= sqrt(x); i++)
if (x % i == 0)
return false;
return true;
}
ll divisor(ll x) {
ll cnt = 0;
for (int i = 1; i <= sqrt(x); i++) {
if (x % i == 0) {
if (i != x / i)
cnt += 2;
else
cnt += 1;
}
}
return cnt;
}
vector<ll> sieve(ll n) {
bool prim[n + 1];
memset(prim, true, sizeof(prim));
for (ll p = 2; p * p <= n; p++) {
if (prim[p] == true) {
for (int i = p * p; i <= n; i += p)
prim[i] = false;
}
}
vector<ll> v;
for (int i = 2; i <= n; i++)
if (prim[i])
v.push_back(i);
return v;
}
bool check(string s) {
ll l = 0, r = sz(s) - 1;
while (l <= r) {
if (s[l] != s[r])
return false;
l++;
r--;
}
return true;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fio;
ll n;
cin >> n;
string s;
cin >> s;
ll ans = 0;
ll cnt = 0;
ll k = 0;
fr1(i, sz(s) - 1) {
if (s[i] != s[i + 1]) {
cnt = 0;
ans++;
if (i == n - 2)
k = 1;
} else
cnt++;
}
if (k)
ans++;
if (cnt)
ans++;
if (n == 1)
ans++;
cout << ans;
return 0;
} | // Author:: MUKUL KUMAR RAI
// Institution:: Jalpaiguri Government Engineering College
// If you are not doing well now just stick to it and learn new things one day
// you will be... Compete with yourself
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
///*template{{{
#define sz(x) (ll) x.size()
#define all(x) (x.begin(), x.end())
#define trav(a, x) for (auto &a : x)
#define fr(i, a, b) for (ll i = a; i <= b; i++)
#define fr1(i, a) for (ll i = 0; i < a; i++)
#define frr(i, a, b) for (ll i = b; i >= a; i--)
#define frr1(i, a) for (ll i = a - 1; i >= 0; i--)
#define sorta(a, n) sort(a, a + n)
#define sortd(a, n) sort(a, a + n, greater<ll>())
#define sortva(a) sort(a.begin(), a.end())
#define sortvd(a) sort(a.begin(), a.end(), greater<ll>())
#define tc(t) while (t--)
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
using vi = vector<ll>;
using vvi = vector<vi>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vld = vector<ld>;
using pii = pair<ll, ll>;
using psi = pair<string, ll>;
using pci = pair<char, ll>;
using vpii = vector<pii>;
//}}}template*/
ll mod = 1e9 + 7;
ll const maxn = 1e6 + 5;
ll const inf = 1e18;
bool ss(const pair<ll, ll> &a, const pair<ll, ll> &b) {
return a.first * b.second + a.second < b.first * a.second + b.second;
}
ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }
ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
ll powm(ll x, ll n, ll M) {
ll result = 1;
while (n > 0) {
if (n % 2 == 1)
result = (result * x) % M;
x = (x * x) % M;
n = n / 2;
}
return result;
}
ll modinverse(ll a, ll m) { return powm(a, m - 2, m); }
bool prime(ll x) {
if (x <= 1)
return false;
for (int i = 2; i <= sqrt(x); i++)
if (x % i == 0)
return false;
return true;
}
ll divisor(ll x) {
ll cnt = 0;
for (int i = 1; i <= sqrt(x); i++) {
if (x % i == 0) {
if (i != x / i)
cnt += 2;
else
cnt += 1;
}
}
return cnt;
}
vector<ll> sieve(ll n) {
bool prim[n + 1];
memset(prim, true, sizeof(prim));
for (ll p = 2; p * p <= n; p++) {
if (prim[p] == true) {
for (int i = p * p; i <= n; i += p)
prim[i] = false;
}
}
vector<ll> v;
for (int i = 2; i <= n; i++)
if (prim[i])
v.push_back(i);
return v;
}
bool check(string s) {
ll l = 0, r = sz(s) - 1;
while (l <= r) {
if (s[l] != s[r])
return false;
l++;
r--;
}
return true;
}
int main() {
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// #endif
fio;
ll n;
cin >> n;
string s;
cin >> s;
ll ans = 0;
ll cnt = 0;
ll k = 0;
fr1(i, sz(s) - 1) {
if (s[i] != s[i + 1]) {
cnt = 0;
ans++;
if (i == n - 2)
k = 1;
} else
cnt++;
}
if (k)
ans++;
if (cnt)
ans++;
if (n == 1)
ans++;
cout << ans;
return 0;
} | replace | 104 | 108 | 104 | 108 | 0 | |
p02887 | C++ | Runtime Error | // 此程序使用了qt专属名称,请勿模仿。侵权必究!!!
// 我真是太菜了……
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1010, P = 1 << 30;
int n, ans = 0;
char a[N];
inline int read() {
int sum = 0, flag = 1;
char c;
for (; c < '0' || c > '9'; c = getchar())
if (c == '-')
flag = -1;
for (; c >= '0' && c <= '9'; c = getchar())
sum = (sum << 1) + (sum << 3) + c - '0';
return sum * flag;
}
int main() {
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
n = read();
scanf("%s", a + 1);
for (int i = 1; i <= n; ++i) {
if (a[i] != a[i - 1]) {
++ans;
}
}
printf("%d\n", ans);
return 0;
} | // 此程序使用了qt专属名称,请勿模仿。侵权必究!!!
// 我真是太菜了……
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 100100, P = 1 << 30;
int n, ans = 0;
char a[N];
inline int read() {
int sum = 0, flag = 1;
char c;
for (; c < '0' || c > '9'; c = getchar())
if (c == '-')
flag = -1;
for (; c >= '0' && c <= '9'; c = getchar())
sum = (sum << 1) + (sum << 3) + c - '0';
return sum * flag;
}
int main() {
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
n = read();
scanf("%s", a + 1);
for (int i = 1; i <= n; ++i) {
if (a[i] != a[i - 1]) {
++ans;
}
}
printf("%d\n", ans);
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02887 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi = acos(-1.0);
const ll mod = pow(10, 9) + 7;
const ll INF = pow(2, 31) - 1;
using str = string;
typedef pair<int, int> P;
typedef vector<int> vi;
ll gcd(ll a, ll b) {
ll v0 = a, v1 = b, v2 = a % b;
while (v2 != 0) {
v0 = v1;
v1 = v2;
v2 = v0 % v1;
}
return v1;
}
ll lcm(ll a, ll b) { return (a * b / gcd(a, b)); }
int main() {
int n;
cin >> n;
str S;
cin >> S;
S.erase(unique(S.begin(), S.end()));
cout << S.size() << endl;
return 0;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi = acos(-1.0);
const ll mod = pow(10, 9) + 7;
const ll INF = pow(2, 31) - 1;
using str = string;
typedef pair<int, int> P;
typedef vector<int> vi;
ll gcd(ll a, ll b) {
ll v0 = a, v1 = b, v2 = a % b;
while (v2 != 0) {
v0 = v1;
v1 = v2;
v2 = v0 % v1;
}
return v1;
}
ll lcm(ll a, ll b) { return (a * b / gcd(a, b)); }
int main() {
int n;
cin >> n;
str S;
cin >> S;
S.erase(unique(S.begin(), S.end()), S.end());
cout << S.size() << endl;
return 0;
} | replace | 29 | 30 | 29 | 30 | 0 | |
p02887 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#define int long long
using namespace std;
inline void read(int &x) {
x = 0;
int f = 1;
char c = getchar();
while (c > '9' || c < '0') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
x *= f;
}
char s[10020];
int n, cnt;
signed main() {
scanf("%lld", &n);
scanf("%s", s + 1);
for (int i = 1; i <= n; i++)
if (s[i] != s[i - 1])
cnt++;
cout << cnt;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stack>
#include <stdio.h>
#include <string.h>
#define int long long
using namespace std;
inline void read(int &x) {
x = 0;
int f = 1;
char c = getchar();
while (c > '9' || c < '0') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
x *= f;
}
char s[100020];
int n, cnt;
signed main() {
scanf("%lld", &n);
scanf("%s", s + 1);
for (int i = 1; i <= n; i++)
if (s[i] != s[i - 1])
cnt++;
cout << cnt;
} | replace | 22 | 23 | 22 | 23 | 0 | |
p02888 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
// Repetitions
#define FOR(i, a, n) for (ll i = ((ll)a); i < ((ll)n); ++i)
#define FORR(i, s, g) for (ll i = ((ll)s - 1); i >= ((ll)g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)
// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0, sizeof(a))
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
// For Debug
#define DMP(x) cerr << #x << " = " << (x) << endl
#define DBG(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl
// Aliases
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef string str;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
// I/O Asynchronizing
struct aaa {
aaa() {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
};
} aaaaaaa;
inline bool can_create_triangle(const int a, const int b, const int c) {
return a < b + c && b < c + a && c < a + b;
}
#define MAX_L 1000
int cnt[MAX_L + 1] = {0};
inline ll combi3(const int n) { return ((ll)n) * (n - 1) * (n - 2) / 6; }
inline ll combi2(const int n) { return ((ll)n) * (n - 1) / 2; }
int main() {
int n;
cin >> n;
vi l;
set<int> st;
REP(i, n) {
int a;
cin >> a;
if (st.count(a) == 0)
l.push_back(a);
cnt[a]++;
st.insert(a);
}
SORTALL(l);
ll ans = 0;
REP(i, l.size()) {
FOR(j, i + 1, l.size()) {
for (int k = j + 1; l[k] < l[i] + l[j] && k < l.size(); k++) {
ans += ((ll)cnt[l[k]]) * cnt[l[i]] * cnt[l[j]];
}
}
}
// DBG(ans);
REP(i, n) {
if (cnt[l[i]] >= 2) {
for (int j = 0; l[j] < 2 * l[i] && j < l.size(); j++) {
if (i == j)
continue;
// DBG(l[i]);
// DBG(l[j]);
ans += combi2(cnt[l[i]]) * cnt[l[j]];
// DBG(ans);
}
}
}
// DBG(ans);
REP(i, l.size()) {
if (cnt[l[i]] >= 3)
ans += combi3(cnt[l[i]]);
}
cout << ans << "\n";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
// Repetitions
#define FOR(i, a, n) for (ll i = ((ll)a); i < ((ll)n); ++i)
#define FORR(i, s, g) for (ll i = ((ll)s - 1); i >= ((ll)g); --i)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) FORR(i, n, 0)
// Container Utils
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define SORTALL(v) sort(ALL(v))
#define SZ(a) int((a).size())
#define CLR(a) memset((a), 0, sizeof(a))
#define EACH(i, c) \
for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
// For Debug
#define DMP(x) cerr << #x << " = " << (x) << endl
#define DBG(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
<< " " << __FILE__ << endl
// Aliases
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef string str;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
// I/O Asynchronizing
struct aaa {
aaa() {
cin.tie(0);
ios::sync_with_stdio(0);
cout << fixed << setprecision(20);
};
} aaaaaaa;
inline bool can_create_triangle(const int a, const int b, const int c) {
return a < b + c && b < c + a && c < a + b;
}
#define MAX_L 1000
int cnt[MAX_L + 1] = {0};
inline ll combi3(const int n) { return ((ll)n) * (n - 1) * (n - 2) / 6; }
inline ll combi2(const int n) { return ((ll)n) * (n - 1) / 2; }
int main() {
int n;
cin >> n;
vi l;
set<int> st;
REP(i, n) {
int a;
cin >> a;
if (st.count(a) == 0)
l.push_back(a);
cnt[a]++;
st.insert(a);
}
SORTALL(l);
ll ans = 0;
REP(i, l.size()) {
FOR(j, i + 1, l.size()) {
for (int k = j + 1; l[k] < l[i] + l[j] && k < l.size(); k++) {
ans += ((ll)cnt[l[k]]) * cnt[l[i]] * cnt[l[j]];
}
}
}
// DBG(ans);
REP(i, l.size()) {
if (cnt[l[i]] >= 2) {
for (int j = 0; l[j] < 2 * l[i] && j < l.size(); j++) {
if (i == j)
continue;
// DBG(l[i]);
// DBG(l[j]);
ans += combi2(cnt[l[i]]) * cnt[l[j]];
// DBG(ans);
}
}
}
// DBG(ans);
REP(i, l.size()) {
if (cnt[l[i]] >= 3)
ans += combi3(cnt[l[i]]);
}
cout << ans << "\n";
return 0;
}
| replace | 84 | 85 | 84 | 85 | 0 | |
p02888 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n, i, j, k, flag, count = 0;
cin >> n;
long long int l[n];
for (i = 0; i < n; i++) {
cin >> l[i];
}
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
for (k = j + 1; k < n; k++) {
if ((l[i] + l[j] > l[k]) && (l[i] + l[k] > l[j]) &&
(l[k] + l[j] > l[i]))
count++;
}
}
}
cout << count;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n, i, j, k, flag, count = 0;
cin >> n;
long long int l[n];
for (i = 0; i < n; i++) {
cin >> l[i];
}
sort(l, l + n);
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
for (k = j + 1; k < n; k++) {
if ((l[i] + l[j] > l[k]) && (l[i] + l[k] > l[j]) &&
(l[k] + l[j] > l[i]))
count++;
}
}
}
cout << count;
return 0;
}
| insert | 13 | 13 | 13 | 14 | TLE | |
p02888 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> l(n);
for (int i = 0; i < n; i++) {
cin >> l.at(i);
}
sort(l.begin(), l.end());
vector<pair<int, int>> combi;
for (int i = 0; i < n - 2; i++) {
int iL = l.at(i);
for (int j = i + 1; j < n - 1; j++) {
int jL = l.at(j);
combi.push_back(make_pair(j, iL + jL));
//
}
}
int cnt = 0;
for (int k = 0; k < n; k++) {
int kL = l.at(k);
for (int i = 0; i < combi.size(); i++) {
if (k <= combi.at(i).first) {
continue; // kがj以下なら被るのでサヨナラ
} else if (kL >= combi.at(i).second) {
continue; // kLが二辺の和以上なら条件xなのでサヨナラ
} else {
cnt++;
}
}
}
cout << cnt << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> l(n);
for (int i = 0; i < n; i++) {
cin >> l.at(i);
}
sort(l.begin(), l.end());
vector<pair<int, int>> combi;
for (int i = 0; i < n - 2; i++) {
int iL = l.at(i);
for (int j = i + 1; j < n - 1; j++) {
int jL = l.at(j);
combi.push_back(make_pair(j, iL + jL));
//
}
}
int cnt = 0;
for (int i = 0; i < combi.size(); i++) {
for (int k = combi.at(i).first + 1; k < n; k++) {
int kL = l.at(k);
if (kL < combi.at(i).second) {
cnt++;
}
}
}
cout << cnt << endl;
}
| replace | 23 | 31 | 23 | 27 | TLE | |
p02888 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[]) {
int n;
cin >> n;
vector<int> l(n);
rep(i, n) cin >> l[i];
sort(ALL(l));
int ans = 0;
rep(i, n) rep(j, i + 1, n) {
int low = (upper_bound(ALL(l), l[j] - l[i]) - l.begin());
for (int k = low; l[k] < l[i] + l[j]; k++) {
if (i < k && k < j) {
ans++;
}
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[]) {
int n;
cin >> n;
vector<int> l(n);
rep(i, n) cin >> l[i];
sort(ALL(l));
int ans = 0;
rep(i, n) rep(j, i + 1, n) {
int low = (upper_bound(ALL(l), l[j] - l[i]) - l.begin());
for (int k = max(low, (int)i + 1); l[k] < l[i] + l[j] && k < j; k++) {
if (i < k && k < j) {
ans++;
}
}
}
cout << ans << endl;
return 0;
}
| replace | 28 | 29 | 28 | 29 | TLE | |
p02888 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
void answer1() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int N;
cin >> N;
vector<int> l(N);
for (auto &l_i : l) {
cin >> l_i;
}
int count = 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 (l[i] < l[j] + l[k] && l[j] < l[k] + l[i] && l[k] < l[i] + l[j]) {
count++;
}
}
}
}
cout << count << endl;
}
int main() { answer1(); }
| #include <bits/stdc++.h>
using namespace std;
void answer1() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int N;
cin >> N;
vector<int> l(N);
for (auto &l_i : l) {
cin >> l_i;
}
int count = 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 (l[i] < l[j] + l[k] && l[j] < l[k] + l[i] && l[k] < l[i] + l[j]) {
count++;
}
}
}
}
cout << count << endl;
}
void answer2() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int N;
cin >> N;
vector<int> l(N);
for (auto &l_i : l) {
cin >> l_i;
}
sort(l.begin(), l.end());
int count = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
//
int target = l[i] + l[j];
// target以上値を探す
auto itr = lower_bound(l.begin() + j + 1, l.end(), target);
count += itr - (l.begin() + j + 1);
}
}
cout << count << endl;
}
int main() {
// answer1(); // 実行時間制限超過
answer2();
}
| replace | 26 | 27 | 26 | 55 | TLE | |
p02888 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int main() {
int n, num, i;
cin >> n;
num = 0;
vector<int> L;
for (i = 0; i < n; i++) {
cin >> L[i];
}
sort(L.begin(), L.end());
rep(b, n) rep(a, b) {
int ab = L[a] + L[b];
int r = lower_bound(L.begin(), L.end(), ab) - L.begin();
int l = b + 1;
num += max(0, r - l);
}
cout << num << endl;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int main() {
int n, num, i;
cin >> n;
num = 0;
vector<int> L(n);
for (i = 0; i < n; i++) {
cin >> L[i];
}
sort(L.begin(), L.end());
rep(b, n) rep(a, b) {
int ab = L[a] + L[b];
int r = lower_bound(L.begin(), L.end(), ab) - L.begin();
int l = b + 1;
num += max(0, r - l);
}
cout << num << endl;
}
| replace | 8 | 9 | 8 | 9 | -11 | |
p02888 | C++ | Time Limit Exceeded | #define _GLIBCXX_DEBUG
#include <algorithm>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod = 1e+9 + 7;
int main() {
ll N;
cin >> N;
vector<ll> l(N);
rep(i, N) cin >> l[i];
sort(l.begin(), l.end());
ll ans = 0;
for (int i = 0; i < N - 2; i++) {
for (int j = i + 1; j < N - 1; j++) {
int a = lower_bound(l.begin(), l.end(), l[i] + l[j]) - l.begin();
ans += a - (j + 1);
}
}
cout << ans << endl;
}
| // #define _GLIBCXX_DEBUG
#include <algorithm>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod = 1e+9 + 7;
int main() {
ll N;
cin >> N;
vector<ll> l(N);
rep(i, N) cin >> l[i];
sort(l.begin(), l.end());
ll ans = 0;
for (int i = 0; i < N - 2; i++) {
for (int j = i + 1; j < N - 1; j++) {
int a = lower_bound(l.begin(), l.end(), l[i] + l[j]) - l.begin();
ans += a - (j + 1);
}
}
cout << ans << endl;
}
| replace | 0 | 1 | 0 | 1 | TLE | |
p02888 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int vect[1006];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> vect[i];
}
sort(vect + 1, vect + n + 1);
int ans = 0;
for (int i = 1; i <= n - 2; i++) {
for (int j = i + 1; j <= n - 1; j++) {
int st = j + 1;
int dr = n;
int sol = -1;
while (st <= dr) {
int mij = (st + dr) / 2;
if (vect[mij] < vect[i] + vect[j]) {
sol = mij;
st = mij + 1;
} else {
dr = mij - 1;
}
}
if (sol != -1) {
ans = ans + sol - j;
}
}
}
cout << ans;
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int vect[2006];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> vect[i];
}
sort(vect + 1, vect + n + 1);
int ans = 0;
for (int i = 1; i <= n - 2; i++) {
for (int j = i + 1; j <= n - 1; j++) {
int st = j + 1;
int dr = n;
int sol = -1;
while (st <= dr) {
int mij = (st + dr) / 2;
if (vect[mij] < vect[i] + vect[j]) {
sol = mij;
st = mij + 1;
} else {
dr = mij - 1;
}
}
if (sol != -1) {
ans = ans + sol - j;
}
}
}
cout << ans;
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02888 | C++ | Runtime Error | #include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int l[1005];
for (int i = 0; i < n; ++i)
scanf("%d", &l[i]);
sort(l, l + n, greater<int>());
long long ans = 0;
for (int i = 0; i < n - 2; ++i) {
int left = i + 1;
int right = n - 1;
while (left < right) {
if (l[left] + l[right] > l[i]) {
ans += right - left;
++left;
} else
--right;
}
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int l[2005];
for (int i = 0; i < n; ++i)
scanf("%d", &l[i]);
sort(l, l + n, greater<int>());
long long ans = 0;
for (int i = 0; i < n - 2; ++i) {
int left = i + 1;
int right = n - 1;
while (left < right) {
if (l[left] + l[right] > l[i]) {
ans += right - left;
++left;
} else
--right;
}
}
cout << ans << endl;
return 0;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p02888 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef map<int, int> mii;
#define fastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define endl "\n"
#define MOD 1000000007
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
int main() {
int n;
cin >> n;
vi l(n);
for (int i = 0; i < n; i++)
cin >> l[i];
ll 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 (l[i] < l[j] + l[k] && l[j] < l[i] + l[k] && l[k] < l[i] + l[j])
++ans;
}
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef map<int, int> mii;
#define fastIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define endl "\n"
#define MOD 1000000007
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
int main() {
int n;
cin >> n;
vi l(n);
for (int i = 0; i < n; i++)
cin >> l[i];
ll ans = 0;
sort(l.begin(), l.end());
for (int i = 0; i < n - 2; i++) {
for (int j = i + 1; j < n - 1; j++) {
auto it = lower_bound(l.begin() + j, l.end(), l[i] + l[j]);
int k = it - l.begin();
if (k == n)
--k;
if (k < n && l[k] >= l[i] + l[j])
--k;
// cout << i << " " << j << " " << k << endl;
ans += (k - j);
}
}
cout << ans << endl;
return 0;
} | replace | 26 | 32 | 26 | 37 | TLE | |
p02888 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n, l[1002];
cin >> n;
for (int i = 0; i < n; i++)
cin >> l[i];
sort(l, l + n);
int ans = 0;
for (int i = n - 1; i > 1; i--) {
for (int j = i - 1; j > 0; j--) {
int mmin = l[i] - l[j];
for (int k = j - 1; k >= 0; k--) {
if (l[k] <= mmin)
break;
else
ans++;
}
}
}
cout << ans << endl;
} | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n, l[2002];
cin >> n;
for (int i = 0; i < n; i++)
cin >> l[i];
sort(l, l + n);
int ans = 0;
for (int i = n - 1; i > 1; i--) {
for (int j = i - 1; j > 0; j--) {
int mmin = l[i] - l[j];
for (int k = j - 1; k >= 0; k--) {
if (l[k] <= mmin)
break;
else
ans++;
}
}
}
cout << ans << endl;
} | replace | 4 | 5 | 4 | 5 | 0 | |
p02888 | C++ | Runtime Error | #include <bits/stdc++.h>
#define PI acos(-1)
#define all(a) a.begin(), a.end()
#define full(a, n) a, a + n
#define ma(type, size) (type *)malloc(sizeof(type) * size)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define f0(i, n) for (i = 0; i < (n); i++)
#define f1(i, n) for (i = 1; i < (n); i++)
#define f1n(i, n) for (i = 1; i <= (n); i++)
#define fab(i, a, b) for (i = (a); i <= (b); i++)
#define fr(i, b, a) for (i = (b); i >= (a); i--)
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
//*/
typedef long long int ll;
typedef long int lo;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tll;
//* utility function
inline bool compare(ll i, ll j) { return i > j; }
//*/
//* function prototypes
template <typename T> T gcd(T a, T b);
template <typename T> T modpow(T number, T power, T mod_value);
//*/
// int row, column;
// int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
// int dy[8] = {0, -1, -1, -1, 0, 1, 1, 1};
// int dx[4] = {1, 0, -1, 0};
// int dy[4] = {0, -1, 0, 1};
// ll p2[63] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192,
// 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304,
// 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912,
// 1073741824, 2147483648, 4294967296, 8589934592, 17179869184, 34359738368,
// 68719476736, 137438953472, 274877906944, 549755813888, 1099511627776,
// 2199023255552, 4398046511104, 8796093022208, 17592186044416, 35184372088832,
// 70368744177664, 140737488355328, 281474976710656, 562949953421312,
// 1125899906842624, 2251799813685248, 4503599627370496, 9007199254740992,
// 18014398509481984, 36028797018963968, 72057594037927936, 144115188075855872,
// 288230376151711744, 576460752303423488, 1152921504606846976,
// 2305843009213693952, 4611686018427387904};
#ifdef DEBUG
#endif // DEBUG
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ll number_of_test_case = 1, test_case;
// cin >> number_of_test_case;
for (test_case = 1; test_case <= number_of_test_case; test_case++) {
ll i, j, k, n, ans = 0, ans2 = 0;
cin >> n;
ll arr[n];
f0(i, n) cin >> arr[i];
sort(arr, arr + n, compare);
ll tri[3];
f0(i, n) {
fab(j, i + 1, n - 1) {
if (arr[j] + arr[j] < arr[i])
break;
ll a = j, b = n - 1;
k = 0;
// cout << "binery search ";
for (ll l = (b - a + 1) / 2; l >= 1; l /= 2) {
// cout << l << " ";
while (1) {
tri[0] = arr[i];
tri[1] = arr[j];
tri[2] = arr[l + k + a];
sort(tri, tri + 3);
if (tri[0] + tri[1] > tri[2]) {
k += l;
} else
break;
}
}
// cout << "\nk = " << k << " ";
ans += k; /*
fab(k, j+1, n-1)
{
tri[0] = arr[i];
tri[1] = arr[j];
tri[2] = arr[k];
sort(tri, tri+3);
if (tri[0] + tri[1] > tri[2])
ans2++;
else
break;
}
cout << k-1 << endl;*/
}
}
cout << ans << endl;
// cout << ans2 << endl;
// cout << "Test #" << test_case << ": ";
// cout << "Case " << test_case << ": ";
}
return 0;
}
template <typename T> T gcd(T a, T b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
template <typename T> T modpow(T number, T power, T mod_value) {
if (power == 0)
return 1 % mod_value;
ll u = modpow(number, power / 2, mod_value);
u = (u * u) % mod_value;
if (power % 2 == 1)
u = (u * number) % mod_value;
return u;
}
| #include <bits/stdc++.h>
#define PI acos(-1)
#define all(a) a.begin(), a.end()
#define full(a, n) a, a + n
#define ma(type, size) (type *)malloc(sizeof(type) * size)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define f0(i, n) for (i = 0; i < (n); i++)
#define f1(i, n) for (i = 1; i < (n); i++)
#define f1n(i, n) for (i = 1; i <= (n); i++)
#define fab(i, a, b) for (i = (a); i <= (b); i++)
#define fr(i, b, a) for (i = (b); i >= (a); i--)
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
//*/
typedef long long int ll;
typedef long int lo;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tll;
//* utility function
inline bool compare(ll i, ll j) { return i > j; }
//*/
//* function prototypes
template <typename T> T gcd(T a, T b);
template <typename T> T modpow(T number, T power, T mod_value);
//*/
// int row, column;
// int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
// int dy[8] = {0, -1, -1, -1, 0, 1, 1, 1};
// int dx[4] = {1, 0, -1, 0};
// int dy[4] = {0, -1, 0, 1};
// ll p2[63] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192,
// 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304,
// 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912,
// 1073741824, 2147483648, 4294967296, 8589934592, 17179869184, 34359738368,
// 68719476736, 137438953472, 274877906944, 549755813888, 1099511627776,
// 2199023255552, 4398046511104, 8796093022208, 17592186044416, 35184372088832,
// 70368744177664, 140737488355328, 281474976710656, 562949953421312,
// 1125899906842624, 2251799813685248, 4503599627370496, 9007199254740992,
// 18014398509481984, 36028797018963968, 72057594037927936, 144115188075855872,
// 288230376151711744, 576460752303423488, 1152921504606846976,
// 2305843009213693952, 4611686018427387904};
#ifdef DEBUG
#endif // DEBUG
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ll number_of_test_case = 1, test_case;
// cin >> number_of_test_case;
for (test_case = 1; test_case <= number_of_test_case; test_case++) {
ll i, j, k, n, ans = 0, ans2 = 0;
cin >> n;
ll arr[n];
f0(i, n) cin >> arr[i];
sort(arr, arr + n, compare);
ll tri[3];
f0(i, n) {
fab(j, i + 1, n - 1) {
if (arr[j] + arr[j] < arr[i])
break;
ll a = j, b = n - 1;
k = 0;
// cout << "binery search ";
for (ll l = (b - a + 1) / 2; l >= 1; l /= 2) {
// cout << l << " ";
while (1) {
if (l + k + a >= n)
break;
tri[0] = arr[i];
tri[1] = arr[j];
tri[2] = arr[l + k + a];
sort(tri, tri + 3);
if (tri[0] + tri[1] > tri[2]) {
k += l;
} else
break;
}
}
// cout << "\nk = " << k << " ";
ans += k; /*
fab(k, j+1, n-1)
{
tri[0] = arr[i];
tri[1] = arr[j];
tri[2] = arr[k];
sort(tri, tri+3);
if (tri[0] + tri[1] > tri[2])
ans2++;
else
break;
}
cout << k-1 << endl;*/
}
}
cout << ans << endl;
// cout << ans2 << endl;
// cout << "Test #" << test_case << ": ";
// cout << "Case " << test_case << ": ";
}
return 0;
}
template <typename T> T gcd(T a, T b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
template <typename T> T modpow(T number, T power, T mod_value) {
if (power == 0)
return 1 % mod_value;
ll u = modpow(number, power / 2, mod_value);
u = (u * u) % mod_value;
if (power % 2 == 1)
u = (u * number) % mod_value;
return u;
}
| insert | 87 | 87 | 87 | 90 | 0 | |
p02888 | C++ | Time Limit Exceeded | #include "bits/stdc++.h"
#define rep(i, a) for (ll i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define FORV(a, A) for (auto &a : A)
using namespace std;
using ll = long long;
void Main() {
int n;
cin >> n;
vector<int> l(n);
rep(i, n) cin >> l[i];
sort(l.begin(), l.end());
int ans = 0;
rep(i, n - 2) REP(j, i + 1, n - 1) {
int a = l[i] + l[j];
int k = j + 1;
while (a > l[k] && k < n)
ans++;
}
cout << ans << endl;
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << std::fixed << std::setprecision(15);
Main();
return 0;
}
| #include "bits/stdc++.h"
#define rep(i, a) for (ll i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define FORV(a, A) for (auto &a : A)
using namespace std;
using ll = long long;
void Main() {
int n;
cin >> n;
vector<int> l(n);
rep(i, n) cin >> l[i];
sort(l.begin(), l.end());
int ans = 0;
rep(i, n - 2) REP(j, i + 1, n - 1) {
int a = l[i] + l[j];
auto position = lower_bound(l.begin() + j, l.end(), a);
ans += distance(l.begin(), position) - j - 1;
}
cout << ans << endl;
}
int main() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << std::fixed << std::setprecision(15);
Main();
return 0;
}
| replace | 19 | 22 | 19 | 21 | TLE | |
p02888 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v.at(i);
}
sort(v.begin(), v.end());
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 ((v.at(i) < v.at(j) + v.at(k)) && (v.at(j) < v.at(i) + v.at(k)) &&
(v.at(k) < v.at(i) + v.at(j))) {
ans++;
}
}
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v.at(i);
}
sort(v.begin(), v.end());
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int itr = lower_bound(v.begin(), v.end(), v.at(i) + v.at(j)) - v.begin();
ans += max(itr - (j + 1), 0);
}
}
cout << ans << endl;
} | replace | 14 | 20 | 14 | 16 | TLE | |
p02888 | C++ | Time Limit Exceeded | #include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < n; i++)
template <class T>
using reversed_priority_queue = priority_queue<T, vector<T>, greater<T>>;
int main() {
int N;
cin >> N;
int L[2010];
REP(i, N) cin >> L[i];
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 (L[i] < L[j] + L[k]) {
if (L[j] < L[i] + L[k]) {
if (L[k] < L[i] + L[j]) {
ans++;
}
}
}
}
}
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
#define REP(i, n) for (int i = 0; i < n; i++)
template <class T>
using reversed_priority_queue = priority_queue<T, vector<T>, greater<T>>;
int main() {
int N;
cin >> N;
int L[2010];
REP(i, N) cin >> L[i];
sort(L, L + N);
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 (L[i] < L[j] + L[k]) {
if (L[j] < L[i] + L[k]) {
if (L[k] < L[i] + L[j]) {
ans++;
}
}
}
}
}
}
cout << ans << endl;
return 0;
}
| insert | 32 | 32 | 32 | 34 | TLE | |
p02888 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, cnt = 0;
cin >> n;
vector<int> v;
for (int i = 0; i < n; i++) {
cin >> a;
v.push_back(a);
}
sort(v.begin(), v.end(), greater<int>());
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
for (int k = j + 1; k < n; k++) {
if (v[i] < v[j] + v[k] && v[j] < v[k] + v[i] && v[k] < v[i] + v[j])
cnt++;
else
break;
}
}
}
cout << cnt << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, cnt = 0;
cin >> n;
vector<int> v;
for (int i = 0; i < n; i++) {
cin >> a;
v.push_back(a);
}
sort(v.begin(), v.end(), greater<int>());
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
for (int k = j + 1; k < n; k++) {
if (v[i] < v[j] + v[k] && v[j] < v[k] + v[i] && v[k] < v[i] + v[j])
cnt++;
else
continue;
}
}
}
cout << cnt << endl;
return 0;
}
| replace | 19 | 20 | 19 | 20 | TLE | |
p02888 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int ans;
ans = 0;
vector<int> L;
for (int i = 0; i < N; i++) {
cin >> L[i];
}
sort(L.begin(), L.end());
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 (L[k] < (L[i] + L[j])) {
ans = ans + 1;
} else {
break;
}
}
}
}
cout << ans;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int ans;
ans = 0;
vector<int> L(N);
for (int i = 0; i < N; i++) {
cin >> L[i];
}
sort(L.begin(), L.end());
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 (L[k] < (L[i] + L[j])) {
ans = ans + 1;
} else {
break;
}
}
}
}
cout << ans;
return 0;
} | replace | 7 | 8 | 7 | 8 | -11 | |
p02888 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> vc(n);
for (int i = 0; i < n; i++) {
cin >> vc.at(i);
}
sort(vc.begin(), vc.end());
int ans = 0;
int a, b, c;
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++) {
a = vc.at(i);
b = vc.at(j);
c = vc.at(k);
if (a + b <= c)
break;
else if (a < (b + c) && b < (a + c) && c < (b + c)) {
ans++;
}
}
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> vc(n);
for (int i = 0; i < n; i++) {
cin >> vc.at(i);
}
sort(vc.begin(), vc.end());
int ans = 0;
int a, b, c;
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++) {
a = vc.at(i);
b = vc.at(j);
c = vc.at(k);
if (a + b <= c)
break;
else if (c < (b + c)) {
ans++;
}
}
}
}
cout << ans << endl;
} | replace | 22 | 23 | 22 | 23 | TLE | |
p02888 | C++ | Time Limit Exceeded | #include "bits/stdc++.h"
using namespace std;
int main(void) {
int input, ans = 0, flag;
cin >> input;
vector<int> side(input);
for (int i = 0; i < input; i++) {
cin >> side.at(i);
}
sort(side.begin(), side.end());
reverse(side.begin(), side.end());
vector<int> num;
for (int i = 0; i < input; i++) {
flag = 0;
for (int j = i + 1; j < input; j++) {
for (int k = j + 1; k < input; k++) {
if (side.at(i) < side.at(j) + side.at(k) &&
side.at(j) < side.at(k) + side.at(i) &&
side.at(k) < side.at(i) + side.at(j)) {
ans++;
num.push_back(i);
} else {
break;
flag++;
}
}
if (flag != 0) {
break;
}
}
}
cout << ans << endl;
} | #include "bits/stdc++.h"
using namespace std;
int main(void) {
int input, ans = 0, flag;
cin >> input;
vector<int> side(input);
for (int i = 0; i < input; i++) {
cin >> side.at(i);
}
sort(side.begin(), side.end());
reverse(side.begin(), side.end());
vector<int> num;
for (int i = 0; i < input; i++) {
flag = 0;
for (int j = i + 1; j < input; j++) {
for (int k = j + 1; k < input; k++) {
if (side.at(i) < side.at(j) + side.at(k) &&
side.at(j) < side.at(k) + side.at(i) &&
side.at(k) < side.at(i) + side.at(j)) {
ans++;
} else {
break;
flag++;
}
}
if (flag != 0) {
break;
}
}
}
cout << ans << endl;
} | delete | 24 | 25 | 24 | 24 | TLE | |
p02888 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls(s) (s & (-s))
#define ll long long
const int N = 3000300;
#define rep(i, begin, end) \
for (__typeof(end) i = (begin) - ((begin) > (end)); \
i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const int mod = 1e9 + 7;
ll n, ans;
ll arr[1005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
rep(i, 1, n + 1) cin >> arr[i];
sort(arr, arr + n + 1);
for (int i = 1; i <= n - 2; i++) {
for (int j = i + 1; j <= n - 1; j++) {
ll sum = arr[i] + arr[j];
ll x = lower_bound(arr, arr + n, sum) - arr;
while (arr[x] >= sum)
x--;
if (x > j)
ans += (x - j);
// cout<<i<<" "<<j<<" "<<x<<endl;
}
}
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls(s) (s & (-s))
#define ll long long
const int N = 3000300;
#define rep(i, begin, end) \
for (__typeof(end) i = (begin) - ((begin) > (end)); \
i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const int mod = 1e9 + 7;
ll n, ans;
ll arr[2005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
rep(i, 1, n + 1) cin >> arr[i];
sort(arr, arr + n + 1);
for (int i = 1; i <= n - 2; i++) {
for (int j = i + 1; j <= n - 1; j++) {
ll sum = arr[i] + arr[j];
ll x = lower_bound(arr, arr + n, sum) - arr;
while (arr[x] >= sum)
x--;
if (x > j)
ans += (x - j);
// cout<<i<<" "<<j<<" "<<x<<endl;
}
}
cout << ans;
} | replace | 13 | 14 | 13 | 14 | 0 | |
p02888 | C++ | Time Limit Exceeded | #include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int a[10000] = {0};
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
long long num = 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 (a[k] < (a[i] + a[j]) && a[i] < (a[j] + a[k]) &&
a[j] < (a[k] + a[i]))
num++;
}
}
}
printf("%lld\n", num);
} | #include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int a[10000] = {0};
for (int i = 0; i < n; i++)
scanf("%d", &a[i]);
sort(a, a + n);
long long num = 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 (a[k] < (a[i] + a[j]) && a[i] < (a[j] + a[k]) &&
a[j] < (a[k] + a[i]))
num++;
}
}
}
printf("%lld\n", num);
} | insert | 10 | 10 | 10 | 11 | TLE | |
p02888 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int a[20005];
int main() {
int num = 0;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
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 (a[i] + a[j] > a[k] && a[i] + a[k] > a[j] && a[j] + a[k] > a[i]) {
if (a[k] - a[j] >= a[i]) {
break;
}
num++;
}
}
}
}
cout << num << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int a[20005];
int main() {
int num = 0;
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
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 (a[i] + a[j] > a[k] && a[i] + a[k] > a[j]) {
num++;
}
}
}
}
cout << num << endl;
return 0;
} | replace | 14 | 18 | 14 | 15 | TLE | |
p02888 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int l[1010];
static int memo[1010][2020] = {};
for (int i = 0; i < n; i++)
cin >> l[i];
for (int i = 0; i < n; i++)
memo[i][l[i]]++;
for (int i = 0; i < n; i++) {
for (int j = 0; j + 1 < 2020; j++)
memo[i][j + 1] += memo[i][j];
}
for (int j = 0; j < 2020; j++) {
for (int i = 0; i + 1 < n; i++)
memo[i + 1][j] += memo[i][j];
}
int res = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int index_lmax = l[i] + l[j] - 1;
int index_lmin = max(0, max(l[i] - l[j], l[j] - l[i]));
int count = memo[n - 1][index_lmax] - memo[n - 1][index_lmin] -
memo[j][index_lmax] + memo[j][index_lmin];
if (count > 0)
res += count;
}
}
cout << res << endl;
return 0;
} | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int l[2020];
static int memo[2020][2020] = {};
for (int i = 0; i < n; i++)
cin >> l[i];
for (int i = 0; i < n; i++)
memo[i][l[i]]++;
for (int i = 0; i < n; i++) {
for (int j = 0; j + 1 < 2020; j++)
memo[i][j + 1] += memo[i][j];
}
for (int j = 0; j < 2020; j++) {
for (int i = 0; i + 1 < n; i++)
memo[i + 1][j] += memo[i][j];
}
int res = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int index_lmax = l[i] + l[j] - 1;
int index_lmin = max(0, max(l[i] - l[j], l[j] - l[i]));
int count = memo[n - 1][index_lmax] - memo[n - 1][index_lmin] -
memo[j][index_lmax] + memo[j][index_lmin];
if (count > 0)
res += count;
}
}
cout << res << endl;
return 0;
} | replace | 7 | 9 | 7 | 9 | 0 | |
p02888 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
int main() {
int n;
cin >> n;
vector<int> L(n, 0);
rep(i, n) { cin >> L[i]; }
int ans = 0;
for (int a = 0; a < n - 2; a++) {
for (int b = a + 1; b < n - 1; b++) {
for (int c = b + 1; c < n; c++) {
if ((L[a] < L[b] + L[c]) && (L[b] < L[c] + L[a]) &&
(L[c] < L[a] + L[b])) {
ans++;
}
}
}
}
cout << ans << endl;
return 0;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
int main() {
int n;
cin >> n;
vector<int> L(n, 0);
rep(i, n) { cin >> L[i]; }
sort(L.begin(), L.end());
int ans = 0;
for (int a = 0; a < n - 2; a++) {
for (int b = a + 1; b < n - 1; b++) {
for (int c = b + 1; c < n; c++) {
if ((L[a] < L[b] + L[c]) && (L[b] < L[c] + L[a]) &&
(L[c] < L[a] + L[b])) {
ans++;
}
}
}
}
cout << ans << endl;
return 0;
}
| replace | 16 | 17 | 16 | 17 | TLE | |
p02888 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = (1e9) + 7;
void fastIO() {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
int main() {
fastIO();
int n;
cin >> n;
vector<int> sticks(n);
for (int i = 0; i < n; i++) {
cin >> sticks[i];
}
sort(sticks.begin(), sticks.end());
int tot = 0;
for (int A = 0; A < n; A++) {
for (int B = A; B < n; B++) {
for (int C = B; C < n; C++) {
int a = sticks[A], b = sticks[B], c = sticks[C];
if (a >= b + c) {
cout << tot << endl;
return 0;
}
if ((a < b + c) && (b < a + c) && (c < b + a) &&
(a != b && a != c && b != c)) {
tot++;
}
}
}
}
cout << tot << endl;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = (1e9) + 7;
void fastIO() {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
int main() {
fastIO();
int n;
cin >> n;
vector<int> sticks(n);
for (int i = 0; i < n; i++) {
cin >> sticks[i];
}
sort(sticks.begin(), sticks.end());
int tot = 0;
for (int A = 0; A < n; A++) {
for (int B = A + 1; B < n; B++) {
int a = sticks[A], b = sticks[B];
int x = lower_bound(sticks.begin(), sticks.end(), a + b) - sticks.begin();
tot += x - B;
tot--;
}
}
cout << tot << endl;
}
| replace | 20 | 32 | 20 | 25 | TLE | |
p02888 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
size_t n;
cin >> n;
vector<size_t> l(n, 0);
for (size_t i = 0; i < n; ++i)
cin >> l[i];
size_t d = 0;
for (size_t i = 0; i < l.size(); ++i) {
auto a = l[i];
for (size_t j = i + 1; j < l.size(); ++j) {
auto b = l[j];
for (size_t k = j + 1; k < l.size(); ++k) {
auto c = l[k];
if (a < b + c && b < a + c && c < a + b)
++d;
}
}
}
cout << d << endl;
return 0;
}
| #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
size_t n;
cin >> n;
vector<size_t> l(n, 0);
for (size_t i = 0; i < n; ++i)
cin >> l[i];
sort(begin(l), end(l), greater<size_t>());
size_t d = 0;
for (size_t i = 0; i < l.size(); ++i) {
auto a = l[i];
for (size_t j = i + 1; j < l.size(); ++j) {
auto b = l[j];
for (size_t k = j + 1; k < l.size(); ++k) {
auto c = l[k];
if (a < b + c && b < a + c && c < a + b)
++d;
}
}
}
cout << d << endl;
return 0;
}
| insert | 19 | 19 | 19 | 20 | TLE | |
p02888 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t n, a = 0;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++)
cin >> v.at(i);
sort(v.begin(), v.end());
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 (v.at(i) + v.at(j) > v.at(k) && v.at(i) + v.at(k) > v.at(j) &&
v.at(k) + v.at(j) > v.at(i))
a++;
else
break;
}
}
}
cout << a << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int64_t n, a = 0;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++)
cin >> v.at(i);
sort(v.begin(), v.end());
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 (v.at(i) + v.at(j) > v.at(k))
a++;
else
break;
}
}
}
cout << a << endl;
}
| replace | 13 | 15 | 13 | 14 | TLE | |
p02888 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define LOCAL 1
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define fore(i, a, b) for (int i = (a), _b = (b); i < (_b); ++i)
#define fort(i, a, b) for (int i = (a), _b = (b); i <= (_b); ++i)
#define ford(i, a, b) for (int i = (a), _b = (b); i >= (_b); --i)
#define bug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &arg1) {
cerr << name << ": " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &arg1, Args &...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " /";
__f(comma + 1, args...);
}
template <class T> bool mini(T &a, T b) { return a > b ? (a = b, 1) : 0; }
template <class T> bool maxi(T &a, T b) { return a < b ? (a = b, 1) : 0; }
typedef long long LL;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
const int INF = 1e9 + 7;
int main() {
#if LOCAL
freopen("CP.inp", "r", stdin);
// freopen("CP.out", "w", stdout);
#endif // LOCAL
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vi a(n);
fore(i, 0, n) cin >> a[i];
sort(a.begin(), a.end());
LL ans = 0;
fore(i, 0, n) fore(j, i + 1, n) {
ans += upper_bound(a.begin() + j + 1, a.end(), a[i] + a[j] - 1) -
lower_bound(a.begin() + j + 1, a.end(), a[j] - a[i] + 1);
}
cout << ans << '\n';
return 0;
}
| #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define LOCAL 0
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define fore(i, a, b) for (int i = (a), _b = (b); i < (_b); ++i)
#define fort(i, a, b) for (int i = (a), _b = (b); i <= (_b); ++i)
#define ford(i, a, b) for (int i = (a), _b = (b); i >= (_b); --i)
#define bug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &arg1) {
cerr << name << ": " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &arg1, Args &...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " /";
__f(comma + 1, args...);
}
template <class T> bool mini(T &a, T b) { return a > b ? (a = b, 1) : 0; }
template <class T> bool maxi(T &a, T b) { return a < b ? (a = b, 1) : 0; }
typedef long long LL;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
const int INF = 1e9 + 7;
int main() {
#if LOCAL
freopen("CP.inp", "r", stdin);
// freopen("CP.out", "w", stdout);
#endif // LOCAL
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vi a(n);
fore(i, 0, n) cin >> a[i];
sort(a.begin(), a.end());
LL ans = 0;
fore(i, 0, n) fore(j, i + 1, n) {
ans += upper_bound(a.begin() + j + 1, a.end(), a[i] + a[j] - 1) -
lower_bound(a.begin() + j + 1, a.end(), a[j] - a[i] + 1);
}
cout << ans << '\n';
return 0;
}
| replace | 20 | 21 | 20 | 21 | TLE | |
p02888 | C++ | Runtime Error | #include <algorithm>
#include <bits/stdc++.h>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> piiii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef queue<char> qc;
typedef queue<string> qs;
typedef vector<char> vc;
typedef vector<string> vs;
typedef map<char, int> mpci;
typedef map<int, int> mpii;
typedef map<string, int> mpsi;
typedef set<int> sei;
typedef set<char> sec;
typedef set<string> ses;
typedef stack<ll> si;
typedef stack<char> sc;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<pll> vpll;
typedef vector<pdd> vdd;
typedef unsigned int uint;
typedef long double ld;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vii> vvii;
/*=====================================================================*/
#define pb push_back
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define sz(a) (int)(a.size())
#define len(a) (int)(a.length())
#define all(s) (s).begin(), (s).end()
#define fi first
#define se second
#define be begin
#define en end
#define m_p make_pair
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define forn(i, p, n) for (int i = p; i <= n; i++)
#define ford(i, p, n) for (int i = n; i >= p; i--)
#define foreach(i, c) \
for (__typeof(c.begin()) i = (c.begin()); i != (c).end(); ++i)
#define zero(a) memset(a, 0, sizeof(a))
#define number(a, num) memeset(a, num, sizeof(a))
/*=====================================================================*/
inline void read(int &x) {
short negative = 1;
x = 0;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
negative = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
x *= negative;
}
inline void write(long long x) {
static long long sta[35];
long long top = 0;
do {
sta[top++] = x % 10, x /= 10;
} while (x);
while (top)
putchar(sta[--top] + 48);
puts("");
}
void finish(string s) {
cout << s << endl;
exit(0);
}
/*======================================================================*/
bool prime(int n) {
if (n == 0 || n == 1)
return false;
for (int i = 2; i * i <= n; i++)
if (n % i == 0)
return false;
return true;
}
const ll power(int n, int k) {
ll t = 1;
rep(i, k) t *= n;
return t;
}
const string turn2(int n) {
string s = "";
while (n != 0) {
s += (char)(n % 2 + '0');
n /= 2;
}
reverse(s.begin(), s.end());
return s;
}
string turn(int n, int k) {
string s = "";
while (n) {
s += (char)(n % k + '0');
n /= k;
}
reverse(s.begin(), s.end());
return s;
}
const string turn16(int n) {
string s = "";
while (n != 0) {
if (n % 16 > 9)
s += (char)('A' + n % 16 - 10);
else
s += (char)('0' + n % 16);
n /= 16;
}
reverse(s.begin(), s.end());
return s;
}
const ll quickpower(int n, int k) {
if (k == 1)
return n;
if (k % 2 == 1)
return n * quickpower(n, k / 2) * quickpower(n, k / 2);
else
return quickpower(n, k / 2) * (quickpower(n, k / 2));
}
/*
void merge(int a[],int left,int mid,int right)
{
int n1=mid-left;
int n2=right-mid;
for(int i=0;i<n1;i++)
{
l[i]=a[i+left];
}
for(int i=0;i<n2;i++)
{
r[i]=a[mid+i];
}
r[n2]=l[n1]=INF;
int i=0;
int j=0;
for(int k=left;k<right;k++)
{
if(l[i]<=r[j])
{
a[k]=l[i++];
}
else
{
a[k]=r[j++];
}
}
}
void mergesort(int a[],int left,int right)
{
if(left+1<right)
{
int mid=(left+right)/2;
mergesort(a,left,mid);
mergesort(a,mid,right);
merge(a,left,mid,right);
}
}
int binsearch(int x,int v[],int n)
{
int low=0,high=n-1;
int mid;
while(low<=high)
{
mid=(low+high)/2;
if(x<v[mid])
high=mid-1;
else
if(x>v[mid])
low=mid+1;
else
return mid+1;
}
return -1;
}
int partition(int a[],int left,int right)
{
int p=a[left];
int i=left;
int j=right+1;
for(;;)
{
while(a[++i]<p)
if(i>=right)
break;
while(a[j--]>p)
if(j<=left)
break;
if(i>=j)
break;
else
swap(a[i],a[j]);
}
if(j>=left)
return j;
swap(a[left],a[j]);
return j;
}
void quicksort(int a[],int left,int right)
{
int q;
while(right>left)
{
q=partition(a,left,right);
if(n-q+1==k)
{
cout<<a[q];
exit(0);
}
quicksort(a,left,q-1);
quicksort(a,q+1,right);
}
}
void dfs(int n)
{
if(use[n])
return;
use[n]=true;
cout<<n<<endl;
for(int i=0;i<v[n].size();i++)
dfs(v[n][i]);
}*/
/*======================================================================*/
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
const int month[2][12] = {{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
int a[1010];
/*======================================================================*/
int main() {
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/
/*====================================================================*/
int n;
cin >> n;
rep(i, n) { cin >> a[i]; }
ll ans = 0;
sort(a, a + n);
reverse(a, a + n);
rep(fir, n - 2) {
for (int sec = fir + 1; sec < n - 1; sec++) {
if (a[sec] + a[sec + 1] <= a[fir])
break;
int thi = sec + 1;
while (thi < n && a[sec] + a[thi] > a[fir])
thi++;
ans += (thi - sec - 1);
}
}
cout << ans << endl;
return 0;
}
| #include <algorithm>
#include <bits/stdc++.h>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> piiii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef queue<char> qc;
typedef queue<string> qs;
typedef vector<char> vc;
typedef vector<string> vs;
typedef map<char, int> mpci;
typedef map<int, int> mpii;
typedef map<string, int> mpsi;
typedef set<int> sei;
typedef set<char> sec;
typedef set<string> ses;
typedef stack<ll> si;
typedef stack<char> sc;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<pll> vpll;
typedef vector<pdd> vdd;
typedef unsigned int uint;
typedef long double ld;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vii> vvii;
/*=====================================================================*/
#define pb push_back
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define sz(a) (int)(a.size())
#define len(a) (int)(a.length())
#define all(s) (s).begin(), (s).end()
#define fi first
#define se second
#define be begin
#define en end
#define m_p make_pair
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define forn(i, p, n) for (int i = p; i <= n; i++)
#define ford(i, p, n) for (int i = n; i >= p; i--)
#define foreach(i, c) \
for (__typeof(c.begin()) i = (c.begin()); i != (c).end(); ++i)
#define zero(a) memset(a, 0, sizeof(a))
#define number(a, num) memeset(a, num, sizeof(a))
/*=====================================================================*/
inline void read(int &x) {
short negative = 1;
x = 0;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
negative = -1;
c = getchar();
}
while (c >= '0' && c <= '9')
x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
x *= negative;
}
inline void write(long long x) {
static long long sta[35];
long long top = 0;
do {
sta[top++] = x % 10, x /= 10;
} while (x);
while (top)
putchar(sta[--top] + 48);
puts("");
}
void finish(string s) {
cout << s << endl;
exit(0);
}
/*======================================================================*/
bool prime(int n) {
if (n == 0 || n == 1)
return false;
for (int i = 2; i * i <= n; i++)
if (n % i == 0)
return false;
return true;
}
const ll power(int n, int k) {
ll t = 1;
rep(i, k) t *= n;
return t;
}
const string turn2(int n) {
string s = "";
while (n != 0) {
s += (char)(n % 2 + '0');
n /= 2;
}
reverse(s.begin(), s.end());
return s;
}
string turn(int n, int k) {
string s = "";
while (n) {
s += (char)(n % k + '0');
n /= k;
}
reverse(s.begin(), s.end());
return s;
}
const string turn16(int n) {
string s = "";
while (n != 0) {
if (n % 16 > 9)
s += (char)('A' + n % 16 - 10);
else
s += (char)('0' + n % 16);
n /= 16;
}
reverse(s.begin(), s.end());
return s;
}
const ll quickpower(int n, int k) {
if (k == 1)
return n;
if (k % 2 == 1)
return n * quickpower(n, k / 2) * quickpower(n, k / 2);
else
return quickpower(n, k / 2) * (quickpower(n, k / 2));
}
/*
void merge(int a[],int left,int mid,int right)
{
int n1=mid-left;
int n2=right-mid;
for(int i=0;i<n1;i++)
{
l[i]=a[i+left];
}
for(int i=0;i<n2;i++)
{
r[i]=a[mid+i];
}
r[n2]=l[n1]=INF;
int i=0;
int j=0;
for(int k=left;k<right;k++)
{
if(l[i]<=r[j])
{
a[k]=l[i++];
}
else
{
a[k]=r[j++];
}
}
}
void mergesort(int a[],int left,int right)
{
if(left+1<right)
{
int mid=(left+right)/2;
mergesort(a,left,mid);
mergesort(a,mid,right);
merge(a,left,mid,right);
}
}
int binsearch(int x,int v[],int n)
{
int low=0,high=n-1;
int mid;
while(low<=high)
{
mid=(low+high)/2;
if(x<v[mid])
high=mid-1;
else
if(x>v[mid])
low=mid+1;
else
return mid+1;
}
return -1;
}
int partition(int a[],int left,int right)
{
int p=a[left];
int i=left;
int j=right+1;
for(;;)
{
while(a[++i]<p)
if(i>=right)
break;
while(a[j--]>p)
if(j<=left)
break;
if(i>=j)
break;
else
swap(a[i],a[j]);
}
if(j>=left)
return j;
swap(a[left],a[j]);
return j;
}
void quicksort(int a[],int left,int right)
{
int q;
while(right>left)
{
q=partition(a,left,right);
if(n-q+1==k)
{
cout<<a[q];
exit(0);
}
quicksort(a,left,q-1);
quicksort(a,q+1,right);
}
}
void dfs(int n)
{
if(use[n])
return;
use[n]=true;
cout<<n<<endl;
for(int i=0;i<v[n].size();i++)
dfs(v[n][i]);
}*/
/*======================================================================*/
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
const int month[2][12] = {{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
int a[2020];
/*======================================================================*/
int main() {
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/
/*====================================================================*/
int n;
cin >> n;
rep(i, n) { cin >> a[i]; }
ll ans = 0;
sort(a, a + n);
reverse(a, a + n);
rep(fir, n - 2) {
for (int sec = fir + 1; sec < n - 1; sec++) {
if (a[sec] + a[sec + 1] <= a[fir])
break;
int thi = sec + 1;
while (thi < n && a[sec] + a[thi] > a[fir])
thi++;
ans += (thi - sec - 1);
}
}
cout << ans << endl;
return 0;
}
| replace | 259 | 260 | 259 | 260 | 0 | |
p02888 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> L(N, 0);
for (int i = 0; i < N; i++) {
cin >> L.at(i);
}
int cnt = 0;
sort(L.begin(), L.end());
/*
if(N==3){
if((L.at(0) + L.at(1) > L.at(2)) && (L.at(0) < L.at(1) + L.at(2)) &&
(L.at(0) + L.at(2) > L.at(0))){ cnt++;
}
cout << cnt << endl;
return 0;
}
*/
for (int i = 0; i < N; i++) {
for (int j = i; j < N; j++) {
for (int k = j; k < N; k++) {
if (i != j && j != k && i != k) {
if ((L.at(i) + L.at(j)) - L.at(k) > 0) {
cnt++;
} else {
break;
}
}
}
}
}
cout << cnt << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> L(N, 0);
for (int i = 0; i < N; i++) {
cin >> L.at(i);
}
int cnt = 0;
sort(L.begin(), L.end());
/*
if(N==3){
if((L.at(0) + L.at(1) > L.at(2)) && (L.at(0) < L.at(1) + L.at(2)) &&
(L.at(0) + L.at(2) > L.at(0))){ cnt++;
}
cout << cnt << endl;
return 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 ((L.at(i) + L.at(j)) - L.at(k) > 0) {
cnt++;
} else {
break;
}
}
}
}
cout << cnt << endl;
}
| replace | 25 | 33 | 25 | 31 | TLE | |
p02888 | C++ | Time Limit Exceeded | #define _GLIBCXX_DEBUG
#include "bits/stdc++.h"
using namespace std;
//------------------------------- Libraries --------------------------------//
//------------------------------- Type Names -------------------------------//
using i64 = int_fast64_t;
using seika = string;
// akari : 1D, yukari : 2D, maki : 3D vector
template <class kizuna> using akari = vector<kizuna>;
template <class yuzuki> using yukari = akari<akari<yuzuki>>;
template <class tsurumaki> using maki = akari<yukari<tsurumaki>>;
// akane : ascending order, aoi : decending order
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha> using aoi = priority_queue<kotonoha>;
//------------------------------- Dubug Functions ---------------------------//
inline void print() { cout << endl; }
template <typename First, typename... Rest>
void print(const First &first, const Rest &...rest) {
cout << first << ' ';
print(rest...);
}
//------------------------------- Solver ------------------------------------//
void solve() {
int n;
cin >> n;
akari<int> ls(n);
for (int i = 0; i < n; i++) {
cin >> ls[i];
}
sort(ls.begin(), ls.end());
long ans = 0;
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++) {
ans += distance(ls.begin(),
lower_bound(ls.begin(), ls.end(), ls[i] + ls[j])) -
j - 1;
}
cout << ans << endl;
}
int main() {
solve();
return 0;
}
| // #define _GLIBCXX_DEBUG
#include "bits/stdc++.h"
using namespace std;
//------------------------------- Libraries --------------------------------//
//------------------------------- Type Names -------------------------------//
using i64 = int_fast64_t;
using seika = string;
// akari : 1D, yukari : 2D, maki : 3D vector
template <class kizuna> using akari = vector<kizuna>;
template <class yuzuki> using yukari = akari<akari<yuzuki>>;
template <class tsurumaki> using maki = akari<yukari<tsurumaki>>;
// akane : ascending order, aoi : decending order
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha> using aoi = priority_queue<kotonoha>;
//------------------------------- Dubug Functions ---------------------------//
inline void print() { cout << endl; }
template <typename First, typename... Rest>
void print(const First &first, const Rest &...rest) {
cout << first << ' ';
print(rest...);
}
//------------------------------- Solver ------------------------------------//
void solve() {
int n;
cin >> n;
akari<int> ls(n);
for (int i = 0; i < n; i++) {
cin >> ls[i];
}
sort(ls.begin(), ls.end());
long ans = 0;
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++) {
ans += distance(ls.begin(),
lower_bound(ls.begin(), ls.end(), ls[i] + ls[j])) -
j - 1;
}
cout << ans << endl;
}
int main() {
solve();
return 0;
}
| replace | 0 | 1 | 0 | 1 | TLE | |
p02888 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int l[1005];
for (int i = 0; i < n; ++i) {
cin >> l[i];
}
sort(l, l + n);
int res = 0;
for (int i = 0; i < n - 1; ++i) {
for (int j = i + 1; j < n; ++j) {
int tmp = l[i] + l[j];
int *pos = lower_bound(l, l + n, tmp);
res += max(0, (int)(pos - (l + j) - 1));
}
}
cout << res << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int l[2005];
for (int i = 0; i < n; ++i) {
cin >> l[i];
}
sort(l, l + n);
int res = 0;
for (int i = 0; i < n - 1; ++i) {
for (int j = i + 1; j < n; ++j) {
int tmp = l[i] + l[j];
int *pos = lower_bound(l, l + n, tmp);
res += max(0, (int)(pos - (l + j) - 1));
}
}
cout << res << endl;
return 0;
}
| replace | 7 | 8 | 7 | 8 | 0 | |
p02888 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
cin >> n;
vector<int> l(n);
for (int i = 0; i < n; i++) {
cin >> l[i];
}
sort(l.begin(), l.end());
int count = 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 (l[i] < l[j] + l[k] && l[j] < l[k] + l[i] && l[k] < l[i] + l[j]) {
count++;
} else if (l[k] >= l[i] + l[j]) {
break;
}
}
}
}
cout << count << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main(void) {
int n;
cin >> n;
vector<int> l(n);
for (int i = 0; i < n; i++) {
cin >> l[i];
}
sort(l.begin(), l.end());
int count = 0;
for (int i = 0; i < n - 2; i++) {
for (int j = i + 1; j < n - 1; j++) {
if (l[n - 1] < l[i] + l[j]) {
count += n - j - 1;
} else {
for (int k = j + 1; k < n; k++) {
if (l[i] < l[j] + l[k] && l[j] < l[k] + l[i] && l[k] < l[i] + l[j]) {
count++;
} else if (l[k] >= l[i] + l[j]) {
break;
}
}
}
}
}
cout << count << endl;
} | replace | 17 | 22 | 17 | 26 | TLE | |
p02888 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> L(N);
for (int i = 0; i < N; i++) {
cin >> L.at(i);
}
sort(L.begin(), L.end());
int count = 0;
for (int i = 0; i < N; i++) {
int a = L.at(i);
for (int j = 0; j < N; j++) {
if (i >= j) {
continue;
}
int b = L.at(j);
for (int k = 0; k < N; k++) {
if (j >= k) {
continue;
}
int c = L.at(k);
if (abs(b - c) >= a) {
break;
} else {
count++;
}
}
}
}
cout << count << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> L(N);
for (int i = 0; i < N; i++) {
cin >> L.at(i);
}
sort(L.begin(), L.end());
int count = 0;
for (int i = 0; i < N; i++) {
int a = L.at(i);
for (int j = 1; i + j < N; j++) {
int b = L.at(i + j);
for (int k = 1; i + j + k < N; k++) {
int c = L.at(i + j + k);
if (abs(b - c) >= a) {
break;
} else {
count++;
}
}
}
}
cout << count << endl;
return 0;
}
| replace | 18 | 28 | 18 | 22 | TLE | |
p02888 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(), (v).end()
#define REP(i, p, n) for (int i = p; i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int, int> P;
using ll = long long;
using VI = vector<int>;
int main() {
int n;
cin >> n;
vector<int> a(n);
int x, y, z; // a,b,c
int ans = 0;
for (auto &i : a)
cin >> i;
for (int i = 0; i <= n - 3; i++) {
for (int j = i + 1; j <= n - 2; j++) {
for (int k = j + 1; k <= n - 1; k++) {
if (a[i] < a[j] + a[k] && a[j] < a[i] + a[k] && a[k] < a[i] + a[j])
ans++;
}
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(), (v).end()
#define REP(i, p, n) for (int i = p; i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int, int> P;
using ll = long long;
using VI = vector<int>;
int main() {
int n;
cin >> n;
vector<int> a(n);
int x, y, z; // a,b,c
int ans = 0;
for (auto &i : a)
cin >> i;
sort(a.begin(), a.end());
for (int i = 0; i <= n - 3; i++) {
for (int j = i + 1; j <= n - 2; j++) {
for (int k = j + 1; k <= n - 1; k++) {
if (a[i] < a[j] + a[k] && a[j] < a[i] + a[k] && a[k] < a[i] + a[j])
ans++;
}
}
}
cout << ans << endl;
}
| insert | 21 | 21 | 21 | 22 | TLE | |
p02888 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long inf = 100000000000000;
typedef pair<int, int> P;
int main() { // 全探索できるか
int n;
cin >> n;
int a[1100], i;
for (i = 0; i < n; i++) {
cin >> a[i];
}
stable_sort(a, a + n);
int j, k;
int ans = 0;
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
for (k = j + 1; k < n; k++) {
if (a[i] < a[j] + a[k] && a[j] < a[i] + a[k] && a[k] < a[i] + a[j])
ans++;
else
break;
}
}
}
cout << ans;
return (0);
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
long long inf = 100000000000000;
typedef pair<int, int> P;
int main() { // 全探索できるか
int n;
cin >> n;
int a[2100], i;
for (i = 0; i < n; i++) {
cin >> a[i];
}
stable_sort(a, a + n);
int j, k;
int ans = 0;
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
for (k = j + 1; k < n; k++) {
if (a[i] < a[j] + a[k] && a[j] < a[i] + a[k] && a[k] < a[i] + a[j])
ans++;
else
break;
}
}
}
cout << ans;
return (0);
} | replace | 8 | 9 | 8 | 9 | 0 | |
p02888 | Python | Runtime Error | import bisect
N = int(input())
L = [int(i) for i in input().split()]
SL = sorted(L)
ans = 0
for i in range(N - 2):
for j in range(i + 1, N - 1):
right = bisect.bisect_left(SL, SL[i] + SL[j])
left = j + 1
ans += max(right - left)
print(ans)
| import bisect
N = int(input())
L = [int(i) for i in input().split()]
SL = sorted(L)
ans = 0
for i in range(N - 2):
for j in range(i + 1, N - 1):
right = bisect.bisect_left(SL, SL[i] + SL[j])
left = j + 1
ans += right - left
print(ans)
| replace | 11 | 12 | 11 | 12 | TypeError: 'int' object is not iterable | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02888/Python/s179459045.py", line 11, in <module>
ans += max(right - left)
TypeError: 'int' object is not iterable
|
p02888 | Python | Time Limit Exceeded | import bisect
N = int(input())
L = list(map(int, input().split()))
assert len(L) == N
L.sort()
n = 0
# Choose two edges
for i in range(N):
for j in range(i + 1, N):
a = L[i] + L[j]
k = bisect.bisect_left(L, a, lo=j + 1)
# assert all(v < a for v in L[:k]) and all(v >= a for v in L[k:])
# the number of candidates of the third edge
n += k - (j + 1)
print(n)
| import bisect
N = int(input())
L = list(map(int, input().split()))
assert len(L) == N
L.sort()
n = 0
# Choose two edges
for i in range(N):
for j in range(i + 1, N):
a = L[i] + L[j]
k = bisect.bisect_left(L, a, lo=j + 1)
# assert all(v < a for v in L[:k]) and all(v >= a for v in L[k:])
# the number of candidates of the third edge
n += k - (j + 1)
print(n)
| delete | 9 | 10 | 9 | 9 | TLE | |
p02888 | Python | Time Limit Exceeded | import bisect
n = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(n - 2):
a = L[i]
for j in range(i + 1, n - 1):
b = L[j]
k = bisect.bisect_left(L[j + 1 :], a + b)
ans += k
print(ans)
| import bisect
n = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(n - 2):
a = L[i]
for j in range(i + 1, n - 1):
b = L[j]
k = bisect.bisect_left(L, a + b)
ans += k - j - 1
print(ans)
| replace | 10 | 12 | 10 | 12 | TLE | |
p02888 | Python | Time Limit Exceeded | import bisect
N = int(input())
L = sorted(map(int, input().split(" ")))
ans = 0
for i in range(len(L)):
for j in range(i + 1, len(L)):
a = L[i]
b = L[j]
ans += bisect.bisect_right(L[j + 1 :], a + b - 1)
print(ans)
| import bisect
N = int(input())
L = sorted(map(int, input().split(" ")))
ans = 0
for i in range(len(L)):
for j in range(i + 1, len(L)):
a = L[i]
b = L[j]
ans += max(0, bisect.bisect_right(L, a + b - 1) - (j + 1))
print(ans)
| replace | 10 | 11 | 10 | 11 | TLE | |
p02888 | Python | Time Limit Exceeded | #!/usr/bin/env python3
N = int(input())
L = sorted([int(s) for s in input().split()])
MAX_SEARCH = max(L) + 1
def check_search(middle, idx_short2, l_lng, l_lows):
return l_lows[middle] + l_lows[idx_short2] > l_lng
l_lows = L[:2]
triangles = 0
for l_lng in L[2:]:
for idx, l_low in enumerate(l_lows):
left = 0
right = len(l_lows) - 1 - idx
end = right
while left < right:
middle = (left + right) // 2
if check_search(middle, len(l_lows) - 1 - idx, l_lng, l_lows):
right = middle
else:
left = middle + 1
triangles += end - right
l_lows.append(l_lng)
print(triangles)
| #!/usr/bin/env python3
N = int(input())
L = sorted([int(s) for s in input().split()])
def check_search(middle, idx_short2, l_lng, l_lows):
return l_lows[middle] + l_lows[idx_short2] > l_lng
l_lows = L[:2]
triangles = 0
for l_lng in L[2:]:
for idx, l_low in enumerate(l_lows):
left = 0
right = len(l_lows) - 1 - idx
end = right
while left < right:
middle = (left + right) // 2
if check_search(middle, len(l_lows) - 1 - idx, l_lng, l_lows):
right = middle
else:
left = middle + 1
triangles += end - right
l_lows.append(l_lng)
print(triangles)
| delete | 3 | 5 | 3 | 3 | TLE | |
p02888 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int(i) = 0; i < (n); i++)
int main() {
int n, ans = 0;
cin >> n;
vector<int> l(n, 0);
REP(i, n) cin >> l.at(i);
sort(l.begin(), l.end());
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++) {
bool f = 1;
if (l.at(i) >= l.at(j) + l.at(k))
f = 0;
if (l.at(j) >= l.at(k) + l.at(i))
f = 0;
if (l.at(k) >= l.at(i) + l.at(j))
f = 0;
if (f)
ans++;
else
break;
}
}
}
cout << ans;
} | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int(i) = 0; i < (n); i++)
int main() {
int n, ans = 0;
cin >> n;
vector<int> l(n, 0);
REP(i, n) cin >> l.at(i);
sort(l.begin(), l.end());
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 (l.at(k) < l.at(i) + l.at(j))
ans++;
else
break;
}
}
}
cout << ans;
} | replace | 14 | 22 | 14 | 15 | TLE | |
p02888 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
#define endl '\n'
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
ll binary_search2(ll min, ll max, ll i, ll j, vll l) {
if (min + 1 == max) { // 解近傍の処理
if (l[max] < l[i] + l[j])
return max;
else
return min;
}
ll med = (min + max) / 2;
if (l[med] < l[i] + l[j])
return binary_search2(med, max, i, j, l);
else
return binary_search2(min, med, i, j, l);
}
int main() {
ll n;
cin >> n;
vll l(n);
for (ll i = 0; i < n; i++)
cin >> l[i];
sort(all(l));
ll ans = 0;
for (ll i = 0; i < n - 2; i++) {
for (ll j = i + 1; j < n - 1; j++) {
ll x;
if (l[j + 1] >= l[i] + l[j])
continue;
else if (l[n - 1] < l[i] + l[j])
x = n - 1;
else
x = binary_search2(j + 1, n - 1, i, j, l);
ans += x - (j + 1) + 1;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
#define endl '\n'
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
ll binary_search2(ll min, ll max, ll i, ll j, vll &l) {
if (min + 1 == max) { // 解近傍の処理
if (l[max] < l[i] + l[j])
return max;
else
return min;
}
ll med = (min + max) / 2;
if (l[med] < l[i] + l[j])
return binary_search2(med, max, i, j, l);
else
return binary_search2(min, med, i, j, l);
}
int main() {
ll n;
cin >> n;
vll l(n);
for (ll i = 0; i < n; i++)
cin >> l[i];
sort(all(l));
ll ans = 0;
for (ll i = 0; i < n - 2; i++) {
for (ll j = i + 1; j < n - 1; j++) {
ll x;
if (l[j + 1] >= l[i] + l[j])
continue;
else if (l[n - 1] < l[i] + l[j])
x = n - 1;
else
x = binary_search2(j + 1, n - 1, i, j, l);
ans += x - (j + 1) + 1;
}
}
cout << ans << endl;
} | replace | 14 | 15 | 14 | 15 | TLE | |
p02888 | C++ | Runtime Error | // Author:: MUKUL KUMAR RAI
// Institution:: Jalpaiguri Government Engineering College
// If you are not doing well now just stick to it and learn new things one day
// you will be... Compete with yourself
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
///*template{{{
#define sz(x) (ll) x.size()
#define all(x) (x.begin(), x.end())
#define trav(a, x) for (auto &a : x)
#define fr(i, a, b) for (ll i = a; i <= b; i++)
#define fr1(i, a) for (ll i = 0; i < a; i++)
#define frr(i, a, b) for (ll i = b; i >= a; i--)
#define frr1(i, a) for (ll i = a - 1; i >= 0; i--)
#define sorta(a, n) sort(a, a + n)
#define sortd(a, n) sort(a, a + n, greater<ll>())
#define sortva(a) sort(a.begin(), a.end())
#define sortvd(a) sort(a.begin(), a.end(), greater<ll>())
#define tc(t) while (t--)
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
using vi = vector<ll>;
using vvi = vector<vi>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vld = vector<ld>;
using pii = pair<ll, ll>;
using psi = pair<string, ll>;
using pci = pair<char, ll>;
using vpii = vector<pii>;
//}}}template*/
ll mod = 1e9 + 7;
ll const maxn = 1e6 + 5;
ll const inf = 1e18;
bool ss(const pair<ll, ll> &a, const pair<ll, ll> &b) {
return a.first * b.second + a.second < b.first * a.second + b.second;
}
ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }
ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
ll powm(ll x, ll n, ll M) {
ll result = 1;
while (n > 0) {
if (n % 2 == 1)
result = (result * x) % M;
x = (x * x) % M;
n = n / 2;
}
return result;
}
ll modinverse(ll a, ll m) { return powm(a, m - 2, m); }
bool prime(ll x) {
if (x <= 1)
return false;
for (int i = 2; i <= sqrt(x); i++)
if (x % i == 0)
return false;
return true;
}
ll divisor(ll x) {
ll cnt = 0;
for (int i = 1; i <= sqrt(x); i++) {
if (x % i == 0) {
if (i != x / i)
cnt += 2;
else
cnt += 1;
}
}
return cnt;
}
vector<ll> sieve(ll n) {
bool prim[n + 1];
memset(prim, true, sizeof(prim));
for (ll p = 2; p * p <= n; p++) {
if (prim[p] == true) {
for (int i = p * p; i <= n; i += p)
prim[i] = false;
}
}
vector<ll> v;
for (int i = 2; i <= n; i++)
if (prim[i])
v.push_back(i);
return v;
}
bool check(string s) {
ll l = 0, r = sz(s) - 1;
while (l <= r) {
if (s[l] != s[r])
return false;
l++;
r--;
}
return true;
}
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fio;
ll n;
cin >> n;
ll A[n];
fr1(i, n) cin >> A[i];
sort(A, A + n);
ll ans = 0;
frr1(i, n) {
ll l = 0, r = i - 1;
while (l < r) {
if (A[l] + A[r] > A[i]) {
ans += (r - l);
r--;
} else
l++;
}
}
cout << ans;
return 0;
} | // Author:: MUKUL KUMAR RAI
// Institution:: Jalpaiguri Government Engineering College
// If you are not doing well now just stick to it and learn new things one day
// you will be... Compete with yourself
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
///*template{{{
#define sz(x) (ll) x.size()
#define all(x) (x.begin(), x.end())
#define trav(a, x) for (auto &a : x)
#define fr(i, a, b) for (ll i = a; i <= b; i++)
#define fr1(i, a) for (ll i = 0; i < a; i++)
#define frr(i, a, b) for (ll i = b; i >= a; i--)
#define frr1(i, a) for (ll i = a - 1; i >= 0; i--)
#define sorta(a, n) sort(a, a + n)
#define sortd(a, n) sort(a, a + n, greater<ll>())
#define sortva(a) sort(a.begin(), a.end())
#define sortvd(a) sort(a.begin(), a.end(), greater<ll>())
#define tc(t) while (t--)
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
using vi = vector<ll>;
using vvi = vector<vi>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vld = vector<ld>;
using pii = pair<ll, ll>;
using psi = pair<string, ll>;
using pci = pair<char, ll>;
using vpii = vector<pii>;
//}}}template*/
ll mod = 1e9 + 7;
ll const maxn = 1e6 + 5;
ll const inf = 1e18;
bool ss(const pair<ll, ll> &a, const pair<ll, ll> &b) {
return a.first * b.second + a.second < b.first * a.second + b.second;
}
ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }
ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
ll powm(ll x, ll n, ll M) {
ll result = 1;
while (n > 0) {
if (n % 2 == 1)
result = (result * x) % M;
x = (x * x) % M;
n = n / 2;
}
return result;
}
ll modinverse(ll a, ll m) { return powm(a, m - 2, m); }
bool prime(ll x) {
if (x <= 1)
return false;
for (int i = 2; i <= sqrt(x); i++)
if (x % i == 0)
return false;
return true;
}
ll divisor(ll x) {
ll cnt = 0;
for (int i = 1; i <= sqrt(x); i++) {
if (x % i == 0) {
if (i != x / i)
cnt += 2;
else
cnt += 1;
}
}
return cnt;
}
vector<ll> sieve(ll n) {
bool prim[n + 1];
memset(prim, true, sizeof(prim));
for (ll p = 2; p * p <= n; p++) {
if (prim[p] == true) {
for (int i = p * p; i <= n; i += p)
prim[i] = false;
}
}
vector<ll> v;
for (int i = 2; i <= n; i++)
if (prim[i])
v.push_back(i);
return v;
}
bool check(string s) {
ll l = 0, r = sz(s) - 1;
while (l <= r) {
if (s[l] != s[r])
return false;
l++;
r--;
}
return true;
}
int main() {
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// #endif
fio;
ll n;
cin >> n;
ll A[n];
fr1(i, n) cin >> A[i];
sort(A, A + n);
ll ans = 0;
frr1(i, n) {
ll l = 0, r = i - 1;
while (l < r) {
if (A[l] + A[r] > A[i]) {
ans += (r - l);
r--;
} else
l++;
}
}
cout << ans;
return 0;
} | replace | 104 | 108 | 104 | 108 | 0 | |
p02888 | C++ | Runtime Error | // Ruthless Coding
#include <bits/stdc++.h>
#define uni(x) (x).resize(unique(ALL(x)) - (x).begin())
#define fprint(v) \
for (auto x : v) \
cout << x << ' '
#define ALL(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846
#define MP(x, y) make_pair(x, y)
#define SZ(x) int((x).size())
#define PB(x) push_back(x)
#define ld long double
#define ll long long
#define S second
#define F first
#define nl '\n'
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V> void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T> void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x)
cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
__print(t);
if (sizeof...(v))
cerr << ", ";
_print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) \
cerr << "[" << #x << "] = ["; \
_print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;
const int N = 2e5 + 5;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
freopen("handmade04.txt", "r", stdin);
int n;
cin >> n;
vector<int> v(n);
unordered_map<int, int> mp;
for (auto &x : v) {
cin >> x;
}
sort(ALL(v));
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int x = v[i] + v[j];
int pos = lower_bound(ALL(v), x) - v.begin();
// debug(i, j, pos);
if (pos > j)
ans += pos - j - 1;
}
}
cout << ans;
return 0;
}
/*
*** Most Impo.. -> check base case always
1. Overflow Check (*, +)
2. Index check (0 - based or 1 - based)
3. Check for n = 1, 2, 3, 4....
4. Corner Cases
*/ | // Ruthless Coding
#include <bits/stdc++.h>
#define uni(x) (x).resize(unique(ALL(x)) - (x).begin())
#define fprint(v) \
for (auto x : v) \
cout << x << ' '
#define ALL(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846
#define MP(x, y) make_pair(x, y)
#define SZ(x) int((x).size())
#define PB(x) push_back(x)
#define ld long double
#define ll long long
#define S second
#define F first
#define nl '\n'
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V> void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T> void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x)
cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
__print(t);
if (sizeof...(v))
cerr << ", ";
_print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...) \
cerr << "[" << #x << "] = ["; \
_print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;
const int N = 2e5 + 5;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> v(n);
unordered_map<int, int> mp;
for (auto &x : v) {
cin >> x;
}
sort(ALL(v));
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int x = v[i] + v[j];
int pos = lower_bound(ALL(v), x) - v.begin();
// debug(i, j, pos);
if (pos > j)
ans += pos - j - 1;
}
}
cout << ans;
return 0;
}
/*
*** Most Impo.. -> check base case always
1. Overflow Check (*, +)
2. Index check (0 - based or 1 - based)
3. Check for n = 1, 2, 3, 4....
4. Corner Cases
*/ | delete | 68 | 69 | 68 | 68 | -6 | terminate called after throwing an instance of 'std::length_error'
what(): cannot create std::vector larger than max_size()
|
p02888 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1000 + 5;
int arr[maxn];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; ++i)
cin >> arr[i];
ll res = 0;
sort(arr, arr + n);
for (int i = 0; i < n; ++i)
for (int j = i + 1; j + 1 < n; ++j) {
auto ptr = lower_bound(arr + j + 1, arr + n, arr[i] + arr[j]);
res += ptr - (arr + j + 1);
}
cout << res << '\n';
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2000 + 5;
int arr[maxn];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; ++i)
cin >> arr[i];
ll res = 0;
sort(arr, arr + n);
for (int i = 0; i < n; ++i)
for (int j = i + 1; j + 1 < n; ++j) {
auto ptr = lower_bound(arr + j + 1, arr + n, arr[i] + arr[j]);
res += ptr - (arr + j + 1);
}
cout << res << '\n';
return 0;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02888 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
using namespace std;
long long a[1010], n, ans;
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
for (int i = 0; i < n - 2; i++)
for (int o = i + 1; o < n - 1; o++)
for (int j = o + 1; j < n; j++)
if (a[i] + a[o] > a[j] && a[o] - a[i] < a[j])
ans++;
cout << ans << endl;
} | #include <algorithm>
#include <iostream>
using namespace std;
long long a[2010], n, ans;
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
for (int i = 0; i < n - 2; i++)
for (int o = i + 1; o < n - 1; o++)
for (int j = o + 1; j < n; j++)
if (a[i] + a[o] > a[j] && a[o] - a[i] < a[j])
ans++;
cout << ans << endl;
} | replace | 3 | 4 | 3 | 4 | 0 | |
p02888 | C++ | Runtime Error | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define dup(x, y) (((x) + (y)-1) / (y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
// std::cout<<std::fixed<<std::setprecision(10);
int main() {
ll N;
cin >> N;
vector<int> L(N);
rep(i, N) cin >> L[i];
sort(L.begin(), L.end());
vector<ll> dp; // dp[i]: L[i+2] までの棒を使用する.
// dp[i+1] = (i+1番目を必ず使用) + dp[i];
if (L[0] + L[1] > L[2])
dp.push_back(1);
else
dp.push_back(0);
for (int i = 1; i < N - 2; i++) {
int cnt = 0;
for (int j = i - 1 + 2; j > 0; j--) {
for (int k = j - 1; k >= 0; k--) {
if (L[j] + L[k] > L[i + 2])
cnt++;
// cout << "cnt " << cnt << ' ' << L[i+2] << ' '<< L[j] << ' '<< L[k] <<
// endl;
}
}
dp[i] = dp[i - 1] + cnt;
// cout << "dp[i]: " << dp[i] << endl;
}
cout << dp[N - 3] << endl;
return 0;
} | #include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (ll i = 0; i < n; i++)
#define dup(x, y) (((x) + (y)-1) / (y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
// std::cout<<std::fixed<<std::setprecision(10);
int main() {
ll N;
cin >> N;
vector<int> L(N);
rep(i, N) cin >> L[i];
sort(L.begin(), L.end());
vector<ll> dp; // dp[i]: L[i+2] までの棒を使用する.
// dp[i+1] = (i+1番目を必ず使用) + dp[i];
if (L[0] + L[1] > L[2])
dp.push_back(1);
else
dp.push_back(0);
for (int i = 1; i < N - 2; i++) {
int cnt = 0;
for (int j = i - 1 + 2; j > 0; j--) {
for (int k = j - 1; k >= 0; k--) {
if (L[j] + L[k] > L[i + 2])
cnt++;
// cout << "cnt " << cnt << ' ' << L[i+2] << ' '<< L[j] << ' '<< L[k] <<
// endl;
}
}
dp.push_back(dp[i - 1] + cnt);
// cout << "dp[i]: " << dp[i] << endl;
}
cout << dp[N - 3] << endl;
return 0;
} | replace | 44 | 45 | 44 | 45 | 0 | |
p02888 | C++ | Time Limit Exceeded | #include "bits/stdc++.h"
using namespace std;
#define show(x) cerr << #x << " = " << x << endl;
#define input_from_file freopen("input.txt", "r", stdin)
#define output_to_file freopen("output.txt", "w", stdout)
#define fastio ios_base::sync_with_stdio(0)
#define endl '\n'
const int N = 2e3 + 1;
int arr[N];
int main() {
#ifdef LOCAL
input_from_file;
output_to_file;
#endif
fastio;
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> arr[i];
sort(arr + 1, arr + n + 1);
int ans = 0, x;
for (int i = 1; i < n; ++i) {
for (int j = i + 1; j <= n; ++j) {
x = lower_bound(arr + 1, arr + n + 1, arr[i] + arr[j]) - arr;
cerr << i << " " << j << " " << arr[i] + arr[j] << " " << x << endl;
if (x - 1 > j)
ans += x - j - 1;
}
}
cout << ans;
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
#define show(x) cerr << #x << " = " << x << endl;
#define input_from_file freopen("input.txt", "r", stdin)
#define output_to_file freopen("output.txt", "w", stdout)
#define fastio ios_base::sync_with_stdio(0)
#define endl '\n'
const int N = 2e3 + 1;
int arr[N];
int main() {
#ifdef LOCAL
input_from_file;
output_to_file;
#endif
fastio;
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> arr[i];
sort(arr + 1, arr + n + 1);
int ans = 0, x;
for (int i = 1; i < n; ++i) {
for (int j = i + 1; j <= n; ++j) {
x = lower_bound(arr + 1, arr + n + 1, arr[i] + arr[j]) - arr;
if (x - 1 > j)
ans += x - j - 1;
}
}
cout << ans;
return 0;
}
| delete | 29 | 30 | 29 | 29 | TLE | |
p02888 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int n;
cin >> n;
vector<int> l(n);
rep(i, n) cin >> l[i];
int result = 0;
for (int i = 0; i < n - 2; ++i) {
int a = l[i];
for (int j = i + 1; j < n - 1; ++j) {
int b = l[j];
for (int k = j + 1; k < n; k++) {
int c = l[k];
if ((a < b + c) && (b < c + a) && (c < a + b)) {
result++;
}
}
}
}
cout << result << endl;
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int n;
cin >> n;
vector<int> l(n);
rep(i, n) cin >> l[i];
sort(l.begin(), l.end());
int result = 0;
for (int i = 0; i < n - 2; ++i) {
int a = l[i];
for (int j = i + 1; j < n - 1; ++j) {
int b = l[j];
for (int k = j + 1; k < n; k++) {
int c = l[k];
if ((a < b + c) && (b < c + a) && (c < a + b)) {
result++;
}
}
}
}
cout << result << endl;
return 0;
}
| replace | 14 | 15 | 14 | 15 | TLE | |
p02888 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int n, tmp, ans = 0;
std::vector<int> data;
void solve() {
sort(data.begin(), data.end());
for (int i = n - 1; i >= 2; i--) {
for (int j = i - 1; j >= 1; j--) {
for (int k = j - 1; k >= 0; k--) {
if (data.at(i) < data.at(j) + data.at(k)) {
ans++;
} else {
break;
}
}
}
}
cout << ans << endl;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> tmp;
data.push_back(tmp);
}
solve();
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int n, tmp, ans = 0;
std::vector<int> data;
void solve() {
sort(data.begin(), data.end());
reverse(data.begin(), data.end());
for (int i = 0; i < n - 2; i++) {
for (int j = i + 1; j < n - 1; j++) {
if (data.at(i) > data.at(j) * 2) {
break;
}
for (int k = j + 1; k < n; k++) {
if (data.at(i) < data.at(j) + data.at(k)) {
ans++;
} else {
break;
}
}
}
}
cout << ans << endl;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> tmp;
data.push_back(tmp);
}
solve();
return 0;
}
| replace | 7 | 10 | 7 | 14 | TLE | |
p02888 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
int compare_int(const void *a, const void *b) { return *(int *)a - *(int *)b; }
int main() {
int N;
cin >> N;
int l[N];
int i;
for (i = 0; i < N; i++)
cin >> l[i];
std::qsort(l, N, 4, compare_int);
int j, k, m;
int sum;
int count = 0;
for (j = N - 1; j > 1; j--) {
for (k = j - 1; k > 0; k--) {
if (l[j] > 2 * l[k])
break;
for (m = k - 1; m > -1; m--) {
sum = l[k] + l[m];
if (l[j] < sum && sum / 2 <= l[j]) {
count++;
}
}
}
}
cout << count << endl;
return 0;
}
| #include <iostream>
using namespace std;
int compare_int(const void *a, const void *b) { return *(int *)a - *(int *)b; }
int main() {
int N;
cin >> N;
int l[N];
int i;
for (i = 0; i < N; i++)
cin >> l[i];
std::qsort(l, N, 4, compare_int);
int j, k, m;
int sum;
int count = 0;
for (j = N - 1; j > 1; j--) {
for (k = j - 1; k > 0; k--) {
if (l[j] > 2 * l[k])
break;
for (m = k - 1; m > -1; m--) {
sum = l[k] + l[m];
if (l[j] < sum && sum <= 2 * l[j]) {
count++;
}
}
}
}
cout << count << endl;
return 0;
}
| replace | 28 | 29 | 28 | 29 | TLE | |
p02888 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
int L[1002];
long long ans = 0;
cin >> N;
for (int i = 0; i < N; i++)
cin >> L[i];
sort(L, L + N);
// for(int i=0;i<N;i++) cout << L[i] << " ";
// cout << endl;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
auto k = lower_bound(L + j + 1, L + N, L[i] + L[j]);
long long temp = (k - L) - (j + 1);
ans += temp;
// cout << L[i] << " " << L[j] << " " << temp << endl;
// cout << max(0LL, temp) << endl;
}
}
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
int L[10002];
long long ans = 0;
cin >> N;
for (int i = 0; i < N; i++)
cin >> L[i];
sort(L, L + N);
// for(int i=0;i<N;i++) cout << L[i] << " ";
// cout << endl;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
auto k = lower_bound(L + j + 1, L + N, L[i] + L[j]);
long long temp = (k - L) - (j + 1);
ans += temp;
// cout << L[i] << " " << L[j] << " " << temp << endl;
// cout << max(0LL, temp) << endl;
}
}
cout << ans << endl;
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02888 | C++ | Time Limit Exceeded | #include <iostream>
using namespace std;
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i, n) for ((i) = 0; (i) < (n); (i)++)
#define per(i, n) for ((i) = (n)-1; (i) >= 0; (i)--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define zt(a, b) (max((a), (b)) - min((a), (b)))
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll nPr(int n, int r) {
ll i, result = 1;
rep(i, r) { result *= (ll)(n - i); }
return result;
}
ll nCr(int n, int r) {
ll i, result = 1;
if (n < r)
return 0;
rep(i, min(r, n - r)) {
result *= (ll)(n - i);
result /= (ll)(i + 1);
}
return result;
}
#define nHr(n, r) nCr((int)((n) + (r) + 1), (int)(r))
#define sankaku(x) (((x) * ((x) + 1)) / 2)
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}, dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int upint(cv *a, cv *b) {
return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0;
}
int downint(cv *a, cv *b) {
return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0;
}
int upchar(cv *left, cv *right) { return strcmp((char *)left, (char *)right); }
int downchar(cv *left, cv *right) {
return strcmp((char *)right, (char *)left);
}
void tmpInit(int *c, ll m) {
ll i;
rep(i, m) c[i] = i;
}
ll modpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1) {
res *= a;
if (mod >= 1)
res %= mod;
}
a *= a;
if (mod >= 1)
a %= mod;
n >>= 1;
}
return res;
}
void initialize() {}
int a[LIMIT2] = {0};
ll findData(ll i) {
// findDataが単調減少のときはbinaryの不等号を反転させる
if (i == -1)
return -1;
return (ll)a[i];
}
ll binaryCeil(ll max, ll min, ll target) {
// targetの数値以上の最小
ll mid;
ll count = 0;
while (max > min && count < 1000) {
mid = (max + min) / 2;
if (findData(mid) >= target)
max = mid;
else
min = mid + 1;
count++;
}
return max;
}
int main(void) {
initialize();
ll n, m, i, j, k, result = 0;
char s[LIMIT1];
cin >> n;
rep(i, n) { cin >> a[i]; }
qsort(a, n, sizeof(int), upint);
for (i = n - 1; i >= 2; i--) {
for (j = i - 1; j >= 1; j--) {
k = binaryCeil((ll)j, -1, (ll)(a[i] - a[j] + 1));
// cout << k << endl;
result += j - k;
}
}
cout << result << endl;
return 0;
} | #include <iostream>
using namespace std;
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i, n) for ((i) = 0; (i) < (n); (i)++)
#define per(i, n) for ((i) = (n)-1; (i) >= 0; (i)--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define zt(a, b) (max((a), (b)) - min((a), (b)))
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll nPr(int n, int r) {
ll i, result = 1;
rep(i, r) { result *= (ll)(n - i); }
return result;
}
ll nCr(int n, int r) {
ll i, result = 1;
if (n < r)
return 0;
rep(i, min(r, n - r)) {
result *= (ll)(n - i);
result /= (ll)(i + 1);
}
return result;
}
#define nHr(n, r) nCr((int)((n) + (r) + 1), (int)(r))
#define sankaku(x) (((x) * ((x) + 1)) / 2)
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1}, dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int upint(cv *a, cv *b) {
return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0;
}
int downint(cv *a, cv *b) {
return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0;
}
int upchar(cv *left, cv *right) { return strcmp((char *)left, (char *)right); }
int downchar(cv *left, cv *right) {
return strcmp((char *)right, (char *)left);
}
void tmpInit(int *c, ll m) {
ll i;
rep(i, m) c[i] = i;
}
ll modpow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1) {
res *= a;
if (mod >= 1)
res %= mod;
}
a *= a;
if (mod >= 1)
a %= mod;
n >>= 1;
}
return res;
}
void initialize() {}
int a[LIMIT2] = {0};
ll findData(ll i) {
// findDataが単調減少のときはbinaryの不等号を反転させる
if (i == -1)
return -1;
return (ll)a[i];
}
ll binaryCeil(ll max, ll min, ll target) {
// targetの数値以上の最小
ll mid;
ll count = 0;
while (max > min && count < 100) {
mid = (max + min) / 2;
if (findData(mid) >= target)
max = mid;
else
min = mid + 1;
count++;
}
return max;
}
int main(void) {
initialize();
ll n, m, i, j, k, result = 0;
char s[LIMIT1];
cin >> n;
rep(i, n) { cin >> a[i]; }
qsort(a, n, sizeof(int), upint);
for (i = n - 1; i >= 2; i--) {
for (j = i - 1; j >= 1; j--) {
k = binaryCeil((ll)j, -1, (ll)(a[i] - a[j] + 1));
// cout << k << endl;
result += j - k;
}
}
cout << result << endl;
return 0;
} | replace | 80 | 81 | 80 | 81 | TLE | |
p02888 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> L(N);
for (int i = 0; i < N; i++)
cin >> L.at(i);
sort(L.begin(), L.end());
int ans = 0;
for (int i = 0; i < N - 2; i++) {
for (int j = i + 1; i < N - 1; j++) {
int c = L.at(i) + L.at(j);
auto itr = lower_bound(L.begin() + j + 1, L.end(), c);
int k = distance(L.begin() + j + 1, itr);
ans += k;
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> L(N);
for (int i = 0; i < N; i++)
cin >> L.at(i);
sort(L.begin(), L.end());
int ans = 0;
for (int i = 0; i < N - 2; i++) {
for (int j = i + 1; j < N - 1; j++) {
int c = L.at(i) + L.at(j);
auto itr = lower_bound(L.begin() + j + 1, L.end(), c);
int k = distance(L.begin() + j + 1, itr);
ans += k;
}
}
cout << ans << endl;
return 0;
}
| replace | 11 | 12 | 11 | 12 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 4) >= this->size() (which is 4)
|
p02888 | C++ | Time Limit Exceeded | #ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x) \
sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \
c i) {
sim > struct rge {
c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i;
ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0);
using ll = long long;
const ll INF = 1e10 + 10;
int main() {
fastio ll n;
cin >> n;
vector<ll> v(n);
for (ll i = 0; i < n; i++) {
cin >> v[i];
}
ll cnt = 0;
for (ll i = 0; i < n; i++) {
for (ll j = i + 1; j < n; j++) {
for (ll c = j + 1; c < n; c++) {
if (v[i] < v[j] + v[c] && v[j] < v[c] + v[i] && v[c] < v[i] + v[j])
cnt++;
}
}
}
cout << cnt << endl;
return 0;
} | #ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x) \
sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \
c i) {
sim > struct rge {
c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i;
ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(0);
using ll = long long;
const ll INF = 1e10 + 10;
int main() {
fastio ll n;
cin >> n;
vector<ll> v(n);
for (ll i = 0; i < n; i++) {
cin >> v[i];
}
sort(v.begin(), v.end());
ll cnt = 0;
for (ll i = 0; i < n; i++) {
for (ll j = i + 1; j < n; j++) {
for (ll c = j + 1; c < n; c++) {
if (v[i] < v[j] + v[c] && v[j] < v[c] + v[i] && v[c] < v[i] + v[j])
cnt++;
}
}
}
cout << cnt << endl;
return 0;
}
| insert | 53 | 53 | 53 | 54 | TLE | |
p02888 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int solve(const vector<int> &L, int i, int j) {
const auto ab = L[i] + L[j];
const auto len = L.size();
int left = 0, right = len - 1;
int count = 0;
for (;;) {
const auto index = (left + right + 1) / 2;
// printf("count=%d, left=%d, right=%d, index = %d\n", count, left, right,
// index);
if (L[index] < ab) {
left = index;
} else {
right = index;
}
if (index == (left + right + 1) / 2) {
break;
}
}
// printf("left=%d, right=%d\n", left, right);
int ans = 0;
for (int k = j + 1; k <= left; ++k) {
if (k == i || k == j) {
continue;
}
if (L[i] >= L[j] + L[k]) {
continue;
}
if (L[j] >= L[i] + L[k]) {
continue;
}
if (L[k] >= L[i] + L[j]) {
continue;
}
// printf("a=%d, b=%d, c=%d\n", L[i], L[j], L[k]);
++ans;
}
return ans;
}
int main() {
int N;
cin >> N;
vector<int> L;
L.resize(N);
for (int i = 0; i < N; ++i) {
cin >> L[i];
}
sort(L.begin(), L.end());
// for (int i = 0; i < N; ++i) {
// cout << L[i] << endl;
// }
int ans = 0;
for (int i = 0; i < N; ++i) {
for (int j = i + 1; j < N; ++j) {
const auto a = L[i];
const auto b = L[j];
const auto ab = a + b;
ans += solve(L, i, j);
// printf("a=%d, b=%d, ab=%d, ans=%d\n", a, b, ab, ans);
}
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int solve(const vector<int> &L, int i, int j) {
const auto ab = L[i] + L[j];
const auto len = L.size();
int left = 0, right = len - 1;
int count = 0;
for (;;) {
const auto index = (left + right + 1) / 2;
// printf("count=%d, left=%d, right=%d, index = %d\n", count, left, right,
// index);
if (L[index] < ab) {
left = index;
} else {
right = index;
}
if (index == (left + right + 1) / 2) {
break;
}
}
// printf("left=%d, right=%d\n", left, right);
return left - j;
}
int main() {
int N;
cin >> N;
vector<int> L;
L.resize(N);
for (int i = 0; i < N; ++i) {
cin >> L[i];
}
sort(L.begin(), L.end());
// for (int i = 0; i < N; ++i) {
// cout << L[i] << endl;
// }
int ans = 0;
for (int i = 0; i < N; ++i) {
for (int j = i + 1; j < N; ++j) {
const auto a = L[i];
const auto b = L[j];
const auto ab = a + b;
ans += solve(L, i, j);
// printf("a=%d, b=%d, ab=%d, ans=%d\n", a, b, ab, ans);
}
}
cout << ans << endl;
return 0;
}
| replace | 25 | 44 | 25 | 26 | TLE | |
p02888 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
#define M_DEBUG if (0)
/******************************************************************************
typedef
******************************************************************************/
typedef unsigned long long int ullint;
typedef long long int llint;
/*! 与えられた3つの非負整数 a, b, c を辺の長さとする三角形が存在するか */
bool isTriangle(ullint a, ullint b, ullint c) {
return ((a < b + c) && (b < a + c) && (c < a + b));
}
/*!
nCk の全組み合わせに対して処理 f を行う関数 foreach_comb と、
再帰的に組み合わせを探索する内部関数 recursive_comb
*/
void recursive_comb(ullint *indexes, llint s, ullint rest,
function<void(ullint *)> f) {
M_DEBUG cout << "s: " << s << " rest: " << rest << endl;
if (rest == 0) {
f(indexes);
} else {
if (s < 0)
return;
recursive_comb(indexes, s - 1, rest, f);
indexes[rest - 1] = s;
recursive_comb(indexes, s - 1, rest - 1, f);
}
}
// nCkの組み合わせに対して処理を実行する
void foreach_comb(ullint n, llint k, function<void(ullint *)> f) {
// int indexes[k];
ullint *indexes = new ullint[k];
recursive_comb(indexes, n - 1, k, f);
delete indexes;
}
/******************************************************************************
Main
******************************************************************************/
int main() {
ullint n = 0;
cin >> n;
assert(n >= 3 && n <= 2000);
vector<ullint> l_list;
for (ullint i = 0; i < n; i++) {
ullint l_i = 0;
cin >> l_i;
assert(l_i >= 1 && l_i <= 1000);
l_list.push_back(l_i);
}
ullint answer = 0; // foreach_comb() で加算するためしかたなく
foreach_comb(n, 3, [&answer, &l_list](ullint *indexes) {
M_DEBUG cout << "isTriangle(" << l_list[indexes[0]] << ','
<< l_list[indexes[1]] << ',' << l_list[indexes[2]] << ") = "
<< isTriangle(l_list[indexes[0]], l_list[indexes[1]],
l_list[indexes[2]])
<< endl;
if (isTriangle(l_list[indexes[0]], l_list[indexes[1]],
l_list[indexes[2]])) {
answer++;
}
});
cout << answer << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define M_DEBUG if (0)
/******************************************************************************
typedef
******************************************************************************/
typedef unsigned long long int ullint;
typedef long long int llint;
/*! 与えられた3つの非負整数 a, b, c を辺の長さとする三角形が存在するか */
bool isTriangle(ullint a, ullint b, ullint c) {
return ((a < b + c) && (b < a + c) && (c < a + b));
}
/*!
nCk の全組み合わせに対して処理 f を行う関数 foreach_comb と、
再帰的に組み合わせを探索する内部関数 recursive_comb
*/
void recursive_comb(ullint *indexes, llint s, ullint rest,
function<void(ullint *)> f) {
M_DEBUG cout << "s: " << s << " rest: " << rest << endl;
if (rest == 0) {
f(indexes);
} else {
if (s < 0)
return;
recursive_comb(indexes, s - 1, rest, f);
indexes[rest - 1] = s;
recursive_comb(indexes, s - 1, rest - 1, f);
}
}
// nCkの組み合わせに対して処理を実行する
void foreach_comb(ullint n, llint k, function<void(ullint *)> f) {
// int indexes[k];
ullint *indexes = new ullint[k];
recursive_comb(indexes, n - 1, k, f);
delete indexes;
}
/******************************************************************************
Main
******************************************************************************/
int main() {
ullint n = 0;
cin >> n;
assert(n >= 3 && n <= 2000);
vector<ullint> l_list;
for (ullint i = 0; i < n; i++) {
ullint l_i = 0;
cin >> l_i;
assert(l_i >= 1 && l_i <= 1000);
l_list.push_back(l_i);
}
ullint answer = 0;
// これでは計算量がO(N^3)になるのでNG
// foreach_comb(n, 3, [&answer, &l_list](ullint *indexes) {
// M_DEBUG cout << "isTriangle(" << l_list[indexes[0]] << ',' <<
// l_list[indexes[1]] << ',' << l_list[indexes[2]] << ") = " <<
// isTriangle(l_list[indexes[0]], l_list[indexes[1]], l_list[indexes[2]]) <<
// endl; if (isTriangle(l_list[indexes[0]], l_list[indexes[1]],
// l_list[indexes[2]])) { answer++;
// }
// });
sort(l_list.begin(), l_list.end()); // 昇順
M_DEBUG {
for (auto a : l_list) {
cout << a << " ";
}
cout << endl;
}
foreach_comb(n, 2, [n, &l_list, &answer](ullint *indexes) {
auto itr = lower_bound(
l_list.begin(), l_list.end(),
l_list[indexes[0]] +
l_list[indexes[1]]); // a + b > c で第3の辺の探索数を削る
ullint ng = distance(itr, l_list.end());
M_DEBUG cout << l_list[indexes[0]] << ',' << l_list[indexes[1]];
// b + c > a(1), a + c > b(2) をチェックする
// ...が、次のような愚直なチェックは不要。
// while (itr != l_list.begin()) {
// if (*itr <= l_list[indexes[1]]) break; // 既にチェックした組み合わせ
// M_DEBUG cout << "isTriangle(" << l_list[indexes[0]] << ',' <<
// l_list[indexes[1]] << ',' << *itr << ") = " <<
// isTriangle(l_list[indexes[0]], l_list[indexes[1]], *itr) << endl; if
// (isTriangle(l_list[indexes[0]], l_list[indexes[1]], *itr)) { answer++;
// }
// itr--;
// }
// なぜなら a < b なので a < b + c が成り立つから(1)はチェックしなくてよい。
// あとは c > b - a であれば条件(2)を満たす。なので、lower_bound( , , b - a)
// から c までの要素はすべて(2)を満たす。 しかし b
// より前の要素を数えてしまうと、既に a と b
// の組み合わせで調べているので二重カウントしてしまう。 よって b
// の次から数えればよく、その個数は N - (n - index of c) - (indexes[1] +1)
answer += n - indexes[1] - 1 - ng;
M_DEBUG {
itr--;
cout << ',' << *itr << endl;
}
});
cout << answer << endl;
return 0;
}
| replace | 59 | 69 | 59 | 108 | TLE | |
p02888 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int my_lower(vector<int> vec, int key, int nimin, int nimax) {
int nimid = nimin + (nimax - nimin) / 2;
if (vec.at(nimid) > key) {
if (vec.at(nimid - 1) < key) {
return nimid;
}
return my_lower(vec, key, nimin, nimid - 1);
}
if (vec.at(nimid) < key) {
if (vec.at(nimid + 1) > key) {
return nimid + 1;
}
return my_lower(vec, key, nimid + 1, nimax);
}
if (vec.at(nimid) == key) {
for (int i = nimid; i >= nimin; i--) {
if (vec.at(nimid) == vec.at(i)) {
continue;
}
return i + 1;
}
}
}
int main() {
int N;
int ans = 0;
cin >> N;
vector<int> bou(N);
for (int i = 0; i < N; i++) {
cin >> bou.at(i);
}
sort(bou.begin(), bou.end());
// a<=b<=cとすると、三角不等式はc<a+bと同値。
// そこで、bouの中で添字が小さい順に見ていき、最初にa+b以上となる場所を二分探索で探す。
for (int i = 0; i < N - 2; i++) {
int bi = bou.at(i);
for (int j = i + 1; j < N - 1; j++) {
int di;
if (bi + bou.at(j) > bou.at(N - 1)) {
di = N - 1 - j;
} else {
di = my_lower(bou, bi + bou.at(j), 0, N - 1) - 1 - j;
}
ans += max(di, 0);
}
}
cout << ans << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int my_lower(vector<int> &vec, int key, int nimin, int nimax) {
int nimid = nimin + (nimax - nimin) / 2;
if (vec.at(nimid) > key) {
if (vec.at(nimid - 1) < key) {
return nimid;
}
return my_lower(vec, key, nimin, nimid - 1);
}
if (vec.at(nimid) < key) {
if (vec.at(nimid + 1) > key) {
return nimid + 1;
}
return my_lower(vec, key, nimid + 1, nimax);
}
if (vec.at(nimid) == key) {
for (int i = nimid; i >= nimin; i--) {
if (vec.at(nimid) == vec.at(i)) {
continue;
}
return i + 1;
}
}
}
int main() {
int N;
int ans = 0;
cin >> N;
vector<int> bou(N);
for (int i = 0; i < N; i++) {
cin >> bou.at(i);
}
sort(bou.begin(), bou.end());
// a<=b<=cとすると、三角不等式はc<a+bと同値。
// そこで、bouの中で添字が小さい順に見ていき、最初にa+b以上となる場所を二分探索で探す。
for (int i = 0; i < N - 2; i++) {
int bi = bou.at(i);
for (int j = i + 1; j < N - 1; j++) {
int di;
if (bi + bou.at(j) > bou.at(N - 1)) {
di = N - 1 - j;
} else {
di = my_lower(bou, bi + bou.at(j), 0, N - 1) - 1 - j;
}
ans += max(di, 0);
}
}
cout << ans << endl;
}
| replace | 3 | 4 | 3 | 4 | TLE | |
p02888 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
// 登録しよう!→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a, ll b) {
return b ? gcd(b, a % b) : a;
} // a,bの最大公約数(gcd)を求める
ll lcm(ll a, ll b) {
return abs(a * b) / gcd(a, b);
} // a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n) {
vector<ll> ret;
for (int i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i != 1 && i * i != n)
ret.push_back(n / i);
}
}
ret.push_back(n);
return ret;
}
// ↑nの約数を求める
vector<bool> IsPrime;
void sieve(size_t max) {
if (max + 1 > IsPrime.size())
IsPrime.resize(max + 1, true);
IsPrime[0] = false;
IsPrime[1] = false;
for (size_t i = 2; i * i <= max; ++i)
if (IsPrime[i])
for (size_t j = 2; i * j <= max; ++j)
IsPrime[i * j] = false;
}
// ↑エラトステネスの篩で素数を求める
#define roundup(divisor, dividend) \
(divisor + (dividend - 1)) / dividend // 切り上げ割り算
#define all(x) (x).begin(), (x).end() // xの初めから終わりまでのポインタ
#define size_t ll // size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater // sortを降順にする
#define pri_queue priority_queue // 優先度付きキュー
#define syo(x) fixed << setprecision(x) // iostreamで小数をx桁表示
void solve(long long N, std::vector<long long> L) {
sort(all(L));
int ans = 0;
for (int i = 0; i < N - 1; i++) {
for (int l = i + 1; l < N; l++) {
sort(all(L));
auto it = lower_bound(all(L), L[i] + L[l]);
ans += (int)(it - L.begin() - 1) - l;
}
}
cout << ans << endl;
}
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
long long N;
scanf("%lld", &N);
std::vector<long long> L(N);
for (int i = 0; i < N; i++) {
scanf("%lld", &L[i]);
}
solve(N, std::move(L));
}
| #include <bits/stdc++.h>
// 登録しよう!→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a, ll b) {
return b ? gcd(b, a % b) : a;
} // a,bの最大公約数(gcd)を求める
ll lcm(ll a, ll b) {
return abs(a * b) / gcd(a, b);
} // a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n) {
vector<ll> ret;
for (int i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i != 1 && i * i != n)
ret.push_back(n / i);
}
}
ret.push_back(n);
return ret;
}
// ↑nの約数を求める
vector<bool> IsPrime;
void sieve(size_t max) {
if (max + 1 > IsPrime.size())
IsPrime.resize(max + 1, true);
IsPrime[0] = false;
IsPrime[1] = false;
for (size_t i = 2; i * i <= max; ++i)
if (IsPrime[i])
for (size_t j = 2; i * j <= max; ++j)
IsPrime[i * j] = false;
}
// ↑エラトステネスの篩で素数を求める
#define roundup(divisor, dividend) \
(divisor + (dividend - 1)) / dividend // 切り上げ割り算
#define all(x) (x).begin(), (x).end() // xの初めから終わりまでのポインタ
#define size_t ll // size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater // sortを降順にする
#define pri_queue priority_queue // 優先度付きキュー
#define syo(x) fixed << setprecision(x) // iostreamで小数をx桁表示
void solve(long long N, std::vector<long long> L) {
sort(all(L));
int ans = 0;
for (int i = 0; i < N - 1; i++) {
for (int l = i + 1; l < N; l++) {
auto it = lower_bound(all(L), L[i] + L[l]);
ans += (int)(it - L.begin() - 1) - l;
}
}
cout << ans << endl;
}
// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
long long N;
scanf("%lld", &N);
std::vector<long long> L(N);
for (int i = 0; i < N; i++) {
scanf("%lld", &L[i]);
}
solve(N, std::move(L));
}
| delete | 49 | 50 | 49 | 49 | TLE | |
p02888 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr long double EPS = 1e-15;
const long double PI = acos(-1);
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9 + 7;
constexpr ll MOD1 = 998244353;
typedef pair<ll, ll> P;
// #define all(v) (v).begin(), (v).end()
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) rep(i, 0, n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
// #define mp make_pair
void solve() {
int n;
int a[1010];
cin >> n;
REP(i, n) cin >> a[i];
sort(a, a + n);
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 (a[i] + a[j] > a[k]) {
ans++;
} else {
break;
}
}
}
}
cout << ans << endl;
}
int main(int argc, char *argv[]) {
// /* Regular */
// int case_num = 1;
// if (argc > 1 && stoi(argv[1])) cin >> case_num;
// REP(case_no, case_num) {
// cerr << endl << "case " << case_no + 1 << endl;
// solve();
// }
/* AOJ */
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr long double EPS = 1e-15;
const long double PI = acos(-1);
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9 + 7;
constexpr ll MOD1 = 998244353;
typedef pair<ll, ll> P;
// #define all(v) (v).begin(), (v).end()
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) rep(i, 0, n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
// #define mp make_pair
void solve() {
int n;
int a[2010];
cin >> n;
REP(i, n) cin >> a[i];
sort(a, a + n);
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 (a[i] + a[j] > a[k]) {
ans++;
} else {
break;
}
}
}
}
cout << ans << endl;
}
int main(int argc, char *argv[]) {
// /* Regular */
// int case_num = 1;
// if (argc > 1 && stoi(argv[1])) cin >> case_num;
// REP(case_no, case_num) {
// cerr << endl << "case " << case_no + 1 << endl;
// solve();
// }
/* AOJ */
solve();
return 0;
} | replace | 22 | 23 | 22 | 23 | 0 | |
p02888 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int l[1000];
for (int i = 0; i < n; ++i)
cin >> l[i];
sort(l, l + n);
int cnt = 0;
for (int i = 0; i < n - 2; ++i)
for (int j = i + 1; j < n - 1; ++j)
for (int k = n - 1; k > j; --k)
if (l[i] + l[j] > l[k]) {
cnt += k - j;
break;
}
cout << cnt;
}
| #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int l[2000];
for (int i = 0; i < n; ++i)
cin >> l[i];
sort(l, l + n);
int cnt = 0;
for (int i = 0; i < n - 2; ++i)
for (int j = i + 1; j < n - 1; ++j)
for (int k = n - 1; k > j; --k)
if (l[i] + l[j] > l[k]) {
cnt += k - j;
break;
}
cout << cnt;
}
| replace | 8 | 9 | 8 | 9 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.