結果

問題 No.2355 Unhappy Back Dance
ユーザー Heart_BlueHeart_Blue
提出日時 2023-06-16 22:50:11
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,107 ms / 6,000 ms
コード長 1,724 bytes
コンパイル時間 1,623 ms
コンパイル使用メモリ 140,264 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-24 15:46:20
合計ジャッジ時間 16,226 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e3 + 10;
int flag[N];
pair<LL, LL> vp[N];
map<pair<LL, LL>, vector<int>> mc;
pair<LL, LL> check(pair<LL, LL>& p1, pair<LL, LL>& p2)
{
	LL a = p2.first - p1.first;
	LL b = p2.second - p1.second;
	LL g = gcd(abs(a), abs(b));
	a /= g;
	b /= g;
	if (a < 0) a = -a, b = -b;
	if (a == 0) b = abs(b);
	return { a,b };
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%lld%lld", &vp[i].first, &vp[i].second);
	for (int i = 1; i <= n; i++)
	{
		mc.clear();
		for (int j = 1; j <= n; j++)
		{
			if (i == j) continue;
			mc[check(vp[i], vp[j])].push_back(j);
		}
		for (auto& [x, v] : mc)
		{
			if (v.size() == 1) continue;
			if (v.size() > 2)
			{
				for (auto& y : v)
					flag[y] = 1;
				continue;
			}
			vector<pair<pair<LL, LL>, int>> key;
			for (int j = 0; j < v.size(); j++)
			{
				key.emplace_back(vp[v[j]], v[j]);
			}
			key.emplace_back(vp[i], i);
			sort(key.begin(), key.end());
			flag[key.front().second] = 1;
			flag[key.back().second] = 1;

		}
	}
	printf("%d\n", count(flag, flag + n + 1, 1));
	return 0;
}
0