AtCoder Grand Contest 018

Submission #5896587

Source codeソースコード

    #include <bits/stdc++.h>
    using namespace std;
    
    long n, k ;
    vector<long> v;
    
    
    long gcd(long a, long b) {
        if(b == 0)
            return a;
        else
            return gcd(b, a % b);
    }

    
    bool check(){
        long t;
        t = gcd(v[0],v[1]);
        for(int i = 1 ; i < v.size() - 1; i++){
            t = gcd(t , v[i+1]);
        }
        if(t == 1){
            return true;
        }
        if(k % t == 0){
            k = k / t;
            for(int i = 0 ; i < v.size() ; i++ ){
                v[i] = v[i] / t;
            }
            return check();
        }
        return false;
    }
        
    int main(){
        cin >> n >> k;
        long a;
        bool flg;
        flg = false;
        for(int i = 0; i < n ; i++ ){
            cin >> a;
            v.push_back(a);
            if(k == a){
                cout << "POSSIBLE" << endl;
                return 0;
            }else if(k < a){
                 flg = true;
            }
        }
        if(flg){
        }else{
            cout << "IMPOSSIBLE" << endl;
            return 0;
        }
        if(check()){
            cout << "POSSIBLE" << endl;
        }else{
            cout << "IMPOSSIBLE" << endl;
        }
        
        return 0;
    }

Submission

Task問題 A - Getting Difference
User nameユーザ名 okuni
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 300
Source lengthソースコード長 1348 Byte
File nameファイル名
Exec time実行時間 55 ms
Memory usageメモリ使用量 1400 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 55 ms 1400 KB
subtask_1_04.txt AC 1 ms 256 KB
subtask_1_05.txt AC 29 ms 892 KB
subtask_1_06.txt AC 9 ms 512 KB
subtask_1_07.txt AC 33 ms 892 KB
subtask_1_08.txt AC 47 ms 1400 KB
subtask_1_09.txt AC 24 ms 892 KB
subtask_1_10.txt AC 39 ms 1400 KB
subtask_1_11.txt AC 43 ms 1400 KB