結果

問題 No.2197 Same Dish
ユーザー lddlinan
提出日時 2023-03-14 15:38:57
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,170 bytes
コンパイル時間 684 ms
コンパイル使用メモリ 89,284 KB
最終ジャッジ日時 2025-02-11 11:09:00
ジャッジサーバーID
(参考情報)
judge1 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 7 WA * 13
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:30:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   30 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:31:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   31 |     for (i=0; i<n; i++) scanf("%d %d", &rs[i].s, &rs[i].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 s, e; } RNode;
RNode rs[100004];
bool mycmp(const RNode& a, const RNode& b) { return a.s<b.s; }
int sx[100004];
#define MOD 998244353
int main() {
    int n, i, k, ck, s, e, j, nj, d, cc;
    LL b, r, bb, v, t;
    scanf("%d %d", &n, &k);
    for (i=0; i<n; i++) scanf("%d %d", &rs[i].s, &rs[i].e);
    r=1; for (i=1; i<=n; i++) { r*=k; r%=MOD; }
    sort(rs, rs+n, mycmp);
    bb=1;
    for (i=n-1; i>=0; i--) {
        s=rs[i].s; e=rs[i].e-1;
        j=i; d=n-i; while(d) {
            while(1) {
                nj=j+d; if (nj>=n) break;
                if (rs[nj].s>e) break;
                j=nj;
            }
            d>>=1;
        }
        cc=j-i;
        if (cc>=k) { bb=0; break; }
        bb*=(k-cc); bb%=MOD;
    }
    r-=bb; if (r<0) r%=MOD;
    printf("%lld\n", r);
    return 0;
}
0