結果

問題 No.461 三角形はいくつ?
ユーザー FF256grhyFF256grhy
提出日時 2016-12-12 02:28:49
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,009 bytes
コンパイル時間 545 ms
コンパイル使用メモリ 52,432 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-07 01:09:51
合計ジャッジ時間 6,056 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 3 ms
6,944 KB
testcase_34 AC 3 ms
6,940 KB
testcase_35 AC 4 ms
6,940 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:47:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   47 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~
main.cpp:48:26: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   48 |         inc(i, n) { scanf("%d%d%d", &p[i], &a[i], &b[i]); }
      |                     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <cstdio>
#include <cmath>

#include <vector>
#include <utility>
#include <algorithm>

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define inc( i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec( i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

template<typename T> void swap(T & x, T & y) { T t = x; x = y; y = t; return; }
template<typename T> T abs(T x) { return (0 <= x ? x : -x); }
template<typename T> T max(T a, T b) { return (b <= a ? a : b); }
template<typename T> T min(T a, T b) { return (a <= b ? a : b); }
template<typename T> bool setmin(T & a, T b) { if(a <= b) { return false; } else { a = b; return true; } }
template<typename T> bool setmax(T & a, T b) { if(b <= a) { return false; } else { a = b; return true; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n, p[4000], a[4000], b[4000];
LL ans;

typedef std::pair<int, int> PII;
std::vector<PII> vec[3];

bool comp(PII x, PII y) {
	return (x.first * y.second < y.first * x.second);
}

double val(PII x) { return static_cast<double>(x.first) / x.second; }

int main() {
	scanf("%d", &n);
	inc(i, n) { scanf("%d%d%d", &p[i], &a[i], &b[i]); }
	
	inc(i, n) { vec[ p[i] ].push_back(std::make_pair(a[i], a[i] + b[i])); }
	inc(i, 3) { vec[   i  ].push_back(std::make_pair(1, 1)); }
	
	inc(i, 3) { std::sort(vec[i].begin(), vec[i].end(), &comp); }
	
	/*
	inc(i, 3) {
		for(auto && e: vec[i]) { printf("%2d/%2d = %.2f\n", e.first, e.second, static_cast<double>(e.first) / e.second); }
		printf("\n");
	}
	*/
	
	for(auto && e1: vec[1]) {
	for(auto && e2: vec[2]) {
		// printf("e1: <%2d,%4d>, e2: <%2d,%4d>,  ", e1.first, e1.second, e2.first, e2.second);
		
		PII x, y, z;
		x = std::make_pair(e1.second - e1.first, e1.second);
		y = std::make_pair(e2.second - e2.first, e2.second);
		z = std::make_pair((e1.second - e1.first) * e2.second + (e2.second - e2.first) * e1.second, e1.second * e2.second);
		if(comp(std::make_pair(1, 1), z)) { continue; }
		if(comp(y, x)) { swap(x, y); }
		
		auto lby = std::lower_bound(vec[0].begin(), vec[0].end(), y, &comp);
		auto lbz = std::lower_bound(vec[0].begin(), vec[0].end(), z, &comp);
		int v = vec[0].end() - lby, w = (lbz != vec[0].end() && ! comp(*lbz, z) && ! comp(z, *lbz));
		ans += v - w;
		
		/*
		// printf("x: <%2d,%2d>, y: <%2d,%2d>, z: <%2d,%2d>,   ", x.first, x.second, y.first, y.second, z.first, z.second );
		printf("x: [%.2f], y: [%.2f], z: [%.2f],  ", val(x), val(y), val(z) );
		printf("ans += %d -  %d    [%]\n", v, w);
		*/
	}
	}
	
	printf("%lld\n", ans);
	
	return 0;
}
0