結果

問題 No.849 yuki国の分割統治
ユーザー tarattata1tarattata1
提出日時 2019-07-06 14:57:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 2,012 bytes
コンパイル時間 808 ms
コンパイル使用メモリ 80,212 KB
実行使用メモリ 9,728 KB
最終ジャッジ日時 2024-04-16 08:32:52
合計ジャッジ時間 3,076 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 40 ms
6,944 KB
testcase_08 AC 50 ms
6,944 KB
testcase_09 AC 48 ms
6,940 KB
testcase_10 AC 46 ms
6,940 KB
testcase_11 AC 44 ms
6,944 KB
testcase_12 AC 41 ms
6,944 KB
testcase_13 AC 51 ms
6,944 KB
testcase_14 AC 48 ms
6,940 KB
testcase_15 AC 48 ms
6,940 KB
testcase_16 AC 71 ms
8,448 KB
testcase_17 AC 38 ms
6,944 KB
testcase_18 AC 71 ms
8,704 KB
testcase_19 AC 48 ms
6,940 KB
testcase_20 AC 61 ms
7,296 KB
testcase_21 AC 31 ms
6,944 KB
testcase_22 AC 63 ms
7,936 KB
testcase_23 AC 58 ms
7,424 KB
testcase_24 AC 43 ms
6,940 KB
testcase_25 AC 78 ms
9,728 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main(int, char**)’:
main.cpp:33:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   33 |     scanf("%lld%lld%lld%lld%d", &a, &b, &c, &d, &n);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:38:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   38 |         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[])
{
    ll a,b,c,d;
    int n;
    scanf("%lld%lld%lld%lld%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=a*d-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) {
                if(x[i]<0) {
                    x[i]=-x[i];
                    y[i]=-y[i];
                }
                ll p = x[i] / a;
                x[i] -= p * a;
                y[i] -= p * b;
            }
            else {
                if(y[i]<0) {
                    x[i]=-x[i];
                    y[i]=-y[i];
                }
                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