結果

問題 No.1041 直線大学
ユーザー motmot
提出日時 2020-05-01 21:36:46
言語 C++11
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,937 bytes
コンパイル時間 766 ms
コンパイル使用メモリ 83,456 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-24 23:08:50
合計ジャッジ時間 1,917 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16 WA * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:65:36: warning: ‘tmpans’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   65 |                     if(xx==0)tmpans++;
      |                              ~~~~~~^~

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
const int inf=1e9+7;
const ll mod=1e9+7;

int gcd(int x, int y){
    int v0 = x, v1 = y, v2 = x % y;
    while(v2!=0){
        v0 = v1;
        v1 = v2;
        v2 = v0 % v1;
    }
    return v1;
}

int main() {
    int N;
    cin>>N;
    vector<int> X(N), Y(N);
    for(int i=0;i<N;++i){
        cin>>X[i]>>Y[i];
    }
    int x, y, xx, yy;
    int tmp;
    int tmpans;
    int ans = 0;
    for(int i=0;i<N;++i){
        for(int j=0;j<i;++j){
            x = X[i] - X[j];
            y = Y[i] - Y[j];
            if((x!=0) & (y!=0)){
                tmp = gcd(x, y);
                x /= tmp;
                y /= tmp;
                tmpans = 2;
                for(int k=0;k<N;++k){
                    if((k==i) | (k==j)) continue;
                    xx = X[i] - X[k];
                    yy = Y[i] - Y[k];
                    if((xx==0) | (yy==0)) continue;
                    tmp = gcd(xx, yy);
                    xx /= tmp;
                    yy /= tmp;
                    if((x==xx) & (y==yy)) tmpans++;
                }
                if(ans < tmpans) ans = tmpans;
            }
            else if(x==0){
                for(int k=0;k<N;++k){
                    if((k==i) | (k==j)) continue;
                    xx = X[i] - X[k];
                    if(xx==0)tmpans++;
                }
                if(ans < tmpans) ans = tmpans;
            }
            else {
                for(int k=0;k<N;++k){
                    if((k==i) | (k==j)) continue;
                    yy = Y[i] - Y[k];
                    if(yy==0) tmpans++;
                }
                if(ans < tmpans) ans = tmpans;
            }
        }
    }
    cout<<ans<<endl;
}

0