結果

問題 No.2197 Same Dish
ユーザー lddlinan
提出日時 2023-03-14 16:00:10
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,116 bytes
コンパイル時間 798 ms
コンパイル使用メモリ 87,424 KB
最終ジャッジ日時 2025-02-11 11:09:13
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:33:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   33 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:36:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   36 |         scanf("%d %d", &s, &e);
      |         ~~~~~^~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <algorithm>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <string>
using namespace std;

bool rcmp(int a, int b) { return a>b; }
typedef long long LL;



typedef struct { int i, k; } RNode;
RNode rs[200004];
bool mycmp(const RNode& a, const RNode& b) {
    if (a.i!=b.i) return a.i<b.i;
    return a.k<b.k;
}
#define MOD 998244353

int main() {
    int n, i, k, ck, s, e, j, nj, d, cc, c;
    LL b, r, bb, v, t;
    scanf("%d %d", &n, &k);
    c=0;
    for (i=0; i<n; i++) {
        scanf("%d %d", &s, &e);
        rs[c].i=s; rs[c].k=1; c++;
        rs[c].i=e; rs[c].k=-1; c++;
    }
    r=1; for (i=1; i<=n; i++) { r*=k; r%=MOD; }
    sort(rs, rs+c, mycmp);
    bb=1;
    cc=0;
    for (i=0; i<c; i++) {
        j=rs[i].k; if (j<0) cc--; else {
            if (cc>=k) { bb=0; break; }
            bb*=(k-cc); bb%=MOD;
            cc++;
        }
    }
    r-=bb; if (r<0) r+=MOD;
    printf("%lld\n", r);
    return 0;
}
0