AtCoder Grand Contest 018

Submission #5901453

Source codeソースコード

#include <bits/stdc++.h>
using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

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

int main()
{
    ll N, K;
    cin >> N >> K;

    vector<ll> A(N);

    rep(i, N) cin >> A[i];

    ll gcd_m = INF;
    ll max_n = A[0];
    repd(i, 1, N) {
        max_n = max(max_n, A[i]);
        gcd_m = min(gcd_m, gcd(A[i - 1], A[i]));
    }

    bool flag = false;

    if (K > max_n) {
        cout << "IMPOSSIBLE" << endl;
    }
    else {
        rep(i, N) {
            if (A[i] % gcd_m == K % gcd_m) {
                flag = true;
                break;
            }
        }
        if (flag) {
            cout << "POSSIBLE" << endl;
        }
        else {
            cout << "IMPOSSIBLE" << endl;
        }
    }

    return 0;
}

Submission

Task問題 A - Getting Difference
User nameユーザ名 p_yellow
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 300
Source lengthソースコード長 1155 Byte
File nameファイル名
Exec time実行時間 65 ms
Memory usageメモリ使用量 1024 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - sample_01.txt,sample_02.txt,sample_03.txt,sample_04.txt
All 300 / 300 sample_01.txt,sample_02.txt,sample_03.txt,sample_04.txt,sample_01.txt,sample_02.txt,sample_03.txt,sample_04.txt,subtask_1_01.txt,subtask_1_02.txt,subtask_1_03.txt,subtask_1_04.txt,subtask_1_05.txt,subtask_1_06.txt,subtask_1_07.txt,subtask_1_08.txt,subtask_1_09.txt,subtask_1_10.txt,subtask_1_11.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt AC 1 ms 256 KB
sample_04.txt AC 1 ms 256 KB
subtask_1_01.txt AC 1 ms 256 KB
subtask_1_02.txt AC 1 ms 256 KB
subtask_1_03.txt AC 65 ms 1024 KB
subtask_1_04.txt AC 41 ms 1024 KB
subtask_1_05.txt AC 22 ms 640 KB
subtask_1_06.txt AC 9 ms 384 KB
subtask_1_07.txt AC 35 ms 768 KB
subtask_1_08.txt AC 46 ms 896 KB
subtask_1_09.txt AC 22 ms 512 KB
subtask_1_10.txt AC 39 ms 768 KB
subtask_1_11.txt AC 43 ms 896 KB