Submission #1315798


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
typedef pair<int, int> pii;
typedef long long ll;
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, M;

signed main() {
    scanf("%lld%lld", &N, &M);
    // ma[i] := i 番目の区間までの右端の最大値
    vector<pii> es(M);
    vector<int> ma(M);
    rep(i,0,M) {
        int a, b; scanf("%lld%lld", &a, &b);
        es[i] = pii(a, b);
    }
    sort(es.begin(), es.end());
    ma[0] = es[0].second;
    rep(i,1,M) {
        // printf("es[%lld] = (%lld, %lld)\n", i, es[i].first, es[i].second);
        ma[i] = max(ma[i-1], es[i].second);
    }

    int cur = 1, cnt = 0;
    while(1) {
        // 条件を満たす区間の 1 つ先を upper_bound で取得
        int k = upper_bound(es.begin(), es.end(), pii(cur, INF)) - es.begin() - 1;
        if(k < 0 || ma[k] < cur) {
            printf("Impossible\n");
            return 0;
        }

        // 次の cur を決める
        cnt++;
        cur = ma[k] + 1;
        if(cur == N+1) {
            printf("%lld\n", cnt);
            return 0;
        }
        else if(cur > N) assert(false);
    }
    return 0;
}

Submission Info

Submission Time
Task D - 権力
User tsutaj
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1571 Byte
Status AC
Exec Time 1 ms
Memory 256 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:18:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld%lld", &N, &M);
                              ^
./Main.cpp:23:44: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         int a, b; scanf("%lld%lld", &a, &b);
                                            ^

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 53
Set Name Test Cases
All 00_sample_1, 00_sample_2, 00_teuchi_1, 00_teuchi_2, 00_teuchi_3, 00_teuchi_4, 10_max1_06, 10_max1_07, 10_max1_08, 10_max1_09, 10_max1_10, 10_max1_11, 10_max1_12, 10_max2_13, 10_max2_14, 10_max2_15, 10_max2_16, 10_max2_17, 10_max2_18, 10_max2_19, 10_max2_20, 10_max2_21, 10_max2_22, 10_min_00, 10_min_01, 10_min_02, 10_min_03, 10_min_04, 10_min_05, 10_rand_27, 10_rand_28, 10_rand_29, 10_rand_30, 10_rand_31, 10_rand_32, 10_rand_33, 10_rand_34, 10_rand_35, 10_rand_36, 10_rand_37, 10_rand_38, 10_rand_39, 10_rand_40, 10_rand_41, 10_rand_42, 10_rand_43, 10_rand_44, 10_rand_45, 10_rand_46, 10_unif_23, 10_unif_24, 10_unif_25, 10_unif_26
Case Name Status Exec Time Memory
00_sample_1 AC 1 ms 256 KB
00_sample_2 AC 1 ms 256 KB
00_teuchi_1 AC 1 ms 256 KB
00_teuchi_2 AC 1 ms 256 KB
00_teuchi_3 AC 1 ms 256 KB
00_teuchi_4 AC 1 ms 256 KB
10_max1_06 AC 1 ms 256 KB
10_max1_07 AC 1 ms 256 KB
10_max1_08 AC 1 ms 256 KB
10_max1_09 AC 1 ms 256 KB
10_max1_10 AC 1 ms 256 KB
10_max1_11 AC 1 ms 256 KB
10_max1_12 AC 1 ms 256 KB
10_max2_13 AC 1 ms 256 KB
10_max2_14 AC 1 ms 256 KB
10_max2_15 AC 1 ms 256 KB
10_max2_16 AC 1 ms 256 KB
10_max2_17 AC 1 ms 256 KB
10_max2_18 AC 1 ms 256 KB
10_max2_19 AC 1 ms 256 KB
10_max2_20 AC 1 ms 256 KB
10_max2_21 AC 1 ms 256 KB
10_max2_22 AC 1 ms 256 KB
10_min_00 AC 1 ms 256 KB
10_min_01 AC 1 ms 256 KB
10_min_02 AC 1 ms 256 KB
10_min_03 AC 1 ms 256 KB
10_min_04 AC 1 ms 256 KB
10_min_05 AC 1 ms 256 KB
10_rand_27 AC 1 ms 256 KB
10_rand_28 AC 1 ms 256 KB
10_rand_29 AC 1 ms 256 KB
10_rand_30 AC 1 ms 256 KB
10_rand_31 AC 1 ms 256 KB
10_rand_32 AC 1 ms 256 KB
10_rand_33 AC 1 ms 256 KB
10_rand_34 AC 1 ms 256 KB
10_rand_35 AC 1 ms 256 KB
10_rand_36 AC 1 ms 256 KB
10_rand_37 AC 1 ms 256 KB
10_rand_38 AC 1 ms 256 KB
10_rand_39 AC 1 ms 256 KB
10_rand_40 AC 1 ms 256 KB
10_rand_41 AC 1 ms 256 KB
10_rand_42 AC 1 ms 256 KB
10_rand_43 AC 1 ms 256 KB
10_rand_44 AC 1 ms 256 KB
10_rand_45 AC 1 ms 256 KB
10_rand_46 AC 1 ms 256 KB
10_unif_23 AC 1 ms 256 KB
10_unif_24 AC 1 ms 256 KB
10_unif_25 AC 1 ms 256 KB
10_unif_26 AC 1 ms 256 KB