結果

問題 No.1041 直線大学
ユーザー phspls
提出日時 2020-05-03 02:08:51
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,717 bytes
コンパイル時間 1,703 ms
コンパイル使用メモリ 184,616 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-16 08:00:08
合計ジャッジ時間 2,784 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 37
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define llong long long

int gcd(int a, int b) {
    if(b == 0) return a;
    if(a % b == 0) return b;
    return gcd(b, a%b);
}

void putVal(int x, int y, int a1, int a2, map<tuple<int, int, int>, set<int>> &result) {
    tuple<int, int, int> key = make_tuple(a1, x, y);
    if(result.find(key) == result.end()) {
        result[key] = set<int>();
    }
    result[key].insert(a2);
}

int main() {
    int n;
    cin >> n;
    vector<pair<int , int>> coords;
    rep(i, n) {
        int x, y;
        cin >> x >> y;
        coords.push_back(make_pair(x, y));
    }

    //x, y, coord
    map<tuple<int, int, int>, set<int>> result;
    rep(i, n) {
        pair<int, int> a1 = coords[i];
        int a1f = a1.first;
        int a1s = a1.second;
        rep(j, n) {
            if(i == j) continue;
            pair<int, int> a2 = coords[j];
            int a2f = a2.first;
            int a2s = a2.second;
            if(a1f < a2f) {
                int x = a2f - a1f;
                int y = a2s - a1s;
                int gcdval = gcd(max(abs(x), abs(y)), min(abs(x), abs(y)));
                putVal(x / gcdval, y / gcdval, i, j, result);
            } else if(a1f == a2f) {
                putVal(0, 0, i, j, result);
            } else {
                int x = a1f - a2f;
                int y = a1s - a2s;
                int gcdval = gcd(max(abs(x), abs(y)), min(abs(x), abs(y)));
                putVal(x / gcdval, y / gcdval, i, j, result);
            }
        }
    }
    int maxval = 0;
    for(auto a: result) {
        maxval = max(maxval, (int)a.second.size() + 1);
    }
    cout << maxval << "\n";
}
0