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
Exec Time 128 ms
Memory 256 KB

Test Cases

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