結果

問題 No.849 yuki国の分割統治
ユーザー tarattata1tarattata1
提出日時 2019-07-06 14:52:51
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,782 bytes
コンパイル時間 730 ms
コンパイル使用メモリ 79,824 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-16 08:32:58
合計ジャッジ時間 2,872 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 40 ms
5,376 KB
testcase_08 AC 49 ms
6,528 KB
testcase_09 AC 47 ms
6,016 KB
testcase_10 AC 45 ms
5,376 KB
testcase_11 AC 44 ms
5,632 KB
testcase_12 AC 42 ms
5,376 KB
testcase_13 AC 50 ms
6,144 KB
testcase_14 AC 48 ms
5,504 KB
testcase_15 AC 48 ms
6,272 KB
testcase_16 AC 70 ms
8,448 KB
testcase_17 AC 38 ms
5,376 KB
testcase_18 AC 69 ms
8,704 KB
testcase_19 AC 47 ms
5,376 KB
testcase_20 AC 60 ms
7,296 KB
testcase_21 AC 31 ms
5,376 KB
testcase_22 WA -
testcase_23 AC 57 ms
7,424 KB
testcase_24 AC 42 ms
5,376 KB
testcase_25 AC 81 ms
9,728 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main(int, char**)’:
main.cpp:32:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   32 |     scanf("%d%d%d%d%d", &a, &b, &c, &d, &n);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:37:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   37 |         scanf("%lld%lld", &x[i], &y[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

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

int main(int argc, char* argv[])
{
    int a,b,c,d,n;
    scanf("%d%d%d%d%d", &a, &b, &c, &d, &n);

    vector<ll> x(n),y(n);
    int i;
    for(i=0; i<n; i++) {
        scanf("%lld%lld", &x[i], &y[i]);
    }

    ll d1=a, a1=d, b1=-b, c1=-c;
    ll det=(ll)a*d-(ll)b*c;

    if(det!=0) {
        map<pair<ll,ll>, int> z;
        det = abs(det);
        for(i=0; i<n; i++) {
            ll tmp0 = a1*x[i]+c1*y[i];
            ll tmp1 = b1*x[i]+d1*y[i];
            tmp0 = (tmp0%det + det)%det;
            tmp1 = (tmp1%det + det)%det;
            z[make_pair(tmp0,tmp1)]++;
        }
        printf("%d\n", (int)z.size());
    }
    else {
        map<pair<ll,ll>, int> z;
        int flag=0;
        if(a*b<0) flag=1;
        a = (a*c!=0? gcd(abs(a),abs(c)): 0);
        b = (b*d!=0? gcd(abs(b),abs(d)): 0);
        if(flag) b=-b;
        for(i=0; i<n; i++) {
            if(a!=0) {
                ll p = x[i] / a;
                x[i] -= p * a;
                y[i] -= p * b;
            }
            else {
                ll p = y[i] / b;
                x[i] -= p * a;
                y[i] -= p * b;
            }
            z[make_pair(x[i],y[i])]++;
        }
        printf("%d\n", (int)z.size());
    }

    return 0;
}
0