Submission #8070415


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
#define what_is(x) cerr << #x << " is " << x << endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
const int N = 2e3+5;
const int INF = 1e9;
const int MOD = 1e9+7;

int n;
int l[N];

int main()
{
	IOS
	// freopen("input.txt", "r", stdin);
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> l[i];
	}
	sort(l, l+n);
	int ans = 0;
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			int L = upper_bound(l, l+n, l[j]-l[i]) - l;
			int R = lower_bound(l, l+n, l[j]+l[i]) - l - 1;
			if (L<=R){
				ans += R-L+1;
				if (i>=L && j<=R) ans -= 2;
				else if (i>=L || j<=R) ans -= 1; 
			}
		}
	}
	cout << ans/3 << endl;

	return 0;
}

Submission Info

Submission Time
Task D - Triangles
User hd7
Language C++14 (GCC 5.4.1)
Score 0
Code Size 824 Byte
Status WA
Exec Time 128 ms
Memory 256 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
AC × 3
AC × 14
WA × 1
Set Name Test Cases
Sample sample00, sample01, sample02
All handmade03, handmade04, handmade05, random06, random07, random08, random09, random10, random11, random12, random13, random14, sample00, sample01, sample02
Case Name Status Exec Time Memory
handmade03 AC 1 ms 256 KB
handmade04 WA 60 ms 256 KB
handmade05 AC 1 ms 256 KB
random06 AC 127 ms 256 KB
random07 AC 126 ms 256 KB
random08 AC 124 ms 256 KB
random09 AC 127 ms 256 KB
random10 AC 126 ms 256 KB
random11 AC 128 ms 256 KB
random12 AC 126 ms 256 KB
random13 AC 127 ms 256 KB
random14 AC 128 ms 256 KB
sample00 AC 1 ms 256 KB
sample01 AC 1 ms 256 KB
sample02 AC 1 ms 256 KB