結果

問題 No.1623 三角形の制作
ユーザー bal4ubal4u
提出日時 2021-08-10 19:35:33
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1,087 ms / 2,000 ms
コード長 1,614 bytes
コンパイル時間 1,175 ms
コンパイル使用メモリ 31,488 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-24 04:50:13
合計ジャッジ時間 14,469 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 4 ms
4,372 KB
testcase_02 AC 1,002 ms
4,372 KB
testcase_03 AC 992 ms
4,372 KB
testcase_04 AC 992 ms
4,372 KB
testcase_05 AC 1,087 ms
4,372 KB
testcase_06 AC 830 ms
4,372 KB
testcase_07 AC 997 ms
4,372 KB
testcase_08 AC 839 ms
4,372 KB
testcase_09 AC 983 ms
4,372 KB
testcase_10 AC 1,057 ms
4,372 KB
testcase_11 AC 1,019 ms
4,372 KB
testcase_12 AC 6 ms
4,372 KB
testcase_13 AC 7 ms
4,372 KB
testcase_14 AC 7 ms
4,372 KB
testcase_15 AC 17 ms
4,372 KB
testcase_16 AC 16 ms
4,372 KB
testcase_17 AC 17 ms
4,372 KB
testcase_18 AC 19 ms
4,372 KB
testcase_19 AC 8 ms
4,372 KB
testcase_20 AC 1 ms
4,372 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function 'in':
main.c:7:14: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration]
    7 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:11:28: note: in expansion of macro 'gc'
   11 |         int n = 0; int c = gc();
      |                            ^~
main.c: In function 'out':
main.c:8:15: warning: implicit declaration of function 'putchar_unlocked' [-Wimplicit-function-declaration]
    8 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:18:17: note: in expansion of macro 'pc'
   18 |         if (!n) pc('0');
      |                 ^~
main.c: In function 'main':
main.c:62:9: warning: implicit declaration of function 'qsort' [-Wimplicit-function-declaration]
   62 |         qsort(a, N, sizeof(int), cmp);
      |         ^~~~~

ソースコード

diff #

// yuki 1623 三角形の制作
// 2021.8.10

#include <stdio.h>

typedef long long ll;
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)

int in() {   // 非負整数の入力
	int n = 0; int c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}
void out(ll n) { // 非負整数の表示(出力)
	int i; char b[30];

	if (!n) pc('0');
	else {
		//		if (n < 0) pc('-'), n = -n;
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
	pc('\n');
}

const int max = 3000;
int N;
int a[200005], g[3005], b[3005];
ll ans;

int cmp(const void *a, const void *b) {
	return *(int *)a - *(int *)b;
}

// a[i]>=x という条件を満たす最小のi
int lower_bound(int x) {
	int m, l = 0, r = N;
	while (l+1 < r) {
		m = (l+r) >> 1;
		if (a[m] < x) l = m; else r = m;
	}
	return a[l] < x? r: l;
}

// a[i]>x という条件を満たす最小のi
int upper_bound(int l, int x) {
	int m, r = N;
	while (l+1 < r) {
		m = (l+r) >> 1;
		if (a[m] <= x) l = m; else r = m;
	}
	return a[l] <= x? r: l;
}

#define MAX(a,b) ((a)>=(b)?(a):(b))

int main() {
	int i, j, k, gmi, bmi, gma, bma;
	N = in();
	for (i = 0; i < N; ++i) a[i] = in();
	qsort(a, N, sizeof(int), cmp);
	for (i = 0; i < N; ++i) g[in()]++;
	gmi = 1; while (!g[gmi]) gmi++;
	gma = max; while (!g[gma]) gma--;
	for (i = 0; i < N; ++i) b[in()]++;
	bmi = 1; while (!b[bmi]) bmi++;
	bma = max; while (!b[bma]) bma--;
	for (i = gmi; i <= gma; ++i) {
		for (j = bmi; j <= bma; ++j) {
			k = lower_bound(MAX(i, j));
			k = upper_bound(k, i+j-1)-k;
			ans += (ll)g[i]*b[j]*k;
		}
	}
	out(ans);
	return 0;
}
0