提出 #20957890


ソースコード 拡げる

#include<bits/stdc++.h>
using namespace std;
int mod = 998244353;
int add(int a, int b){
    int ans = a + b;
    while(ans >= mod){
        ans -= mod;
    }
    return ans;
}
void add_self(int & a, int b){
    a = add(a,b);
}
int sub(int a, int b){
    int ans = a - b;
    while(ans < 0){
        ans += mod;
    }
    return ans;
}
void sub_self(int & a, int b){
    a = sub(a,b);
}
int mul(int a, int b){
    int ans = ((int64_t)a * b) % mod;
    return ans;
}
int binexpo(int b, int e){
    int ans = 1;
    while(e){
        if(e & 1){
            ans = mul(ans,b);
        }
        b = mul(b,b);
        e >>= 1;
    }
    return ans;
}
int pw[5003][5003];
int dp[5005][3];
constexpr inline void init(){
    for(int i = 1; i < 5001; ++i){
        for(int j = 0; j < 5001; ++j){
            if(j == 0){
                pw[i][j] = 1;
            }
            
            else{
                pw[i][j] = mul(pw[i][j-1],i);
            }
        }
    }
}
int main(){
    init();
    int n,m;
    cin >> n >> m;
    int ans = 0;
    for(int len = 1; len <= n; ++len){
        int outside_range_0 = pw[m][max(0,n-len-2)];
        int outside_range_1 = pw[m][max(0,n-len-1)];
        for(int k = 1; k <= m; ++k){
            int inside_range = sub(pw[m-k+1][len], pw[m-k][len]);
            int outside_range = 1;
            //for those not connected to the edge
            int km1 = k-1;
            int km1s = mul(km1,km1);
            add_self(dp[len][0],mul(km1s,inside_range));
            //connected to one end
            add_self(dp[len][1],mul(km1,inside_range));
            //connected to both ends
            if(len == n){
                add_self(dp[len][2],inside_range);
            }
        }
        dp[len][0] = mul(dp[len][0],outside_range_0);
        dp[len][1] = mul(dp[len][1],outside_range_1);
    }
    //return 0;
    for(int i = 0; i < n; ++i){
        for(int j = i; j < n; ++j){
           if(i == 0 && j == n-1){
                add_self(ans,dp[j-i+1][2]);
           }
           else if(i == 0 || j == n-1){
                add_self(ans,dp[j-i+1][1]);
           }
           else{
                add_self(ans,dp[j-i+1][0]);
           }
        }
    }
    cout << ans << "\n";
    return 0;
}

提出情報

提出日時
問題 C - Sequence Scores
ユーザ mpily
言語 C++ (GCC 9.2.1)
得点 600
コード長 2333 Byte
結果 AC
実行時間 1776 ms
メモリ 101348 KiB

コンパイルエラー

./Main.cpp: In function ‘int main()’:
./Main.cpp:64:17: warning: unused variable ‘outside_range’ [-Wunused-variable]
   64 |             int outside_range = 1;
      |                 ^~~~~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果
AC × 3
AC × 22
セット名 テストケース
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, s1.txt, s2.txt, s3.txt
ケース名 結果 実行時間 メモリ
01.txt AC 431 ms 101196 KiB
02.txt AC 430 ms 101188 KiB
03.txt AC 521 ms 101024 KiB
04.txt AC 651 ms 101208 KiB
05.txt AC 439 ms 101212 KiB
06.txt AC 667 ms 101232 KiB
07.txt AC 841 ms 101120 KiB
08.txt AC 925 ms 101312 KiB
09.txt AC 539 ms 101232 KiB
10.txt AC 744 ms 101128 KiB
11.txt AC 908 ms 101220 KiB
12.txt AC 1184 ms 101280 KiB
13.txt AC 715 ms 101148 KiB
14.txt AC 1000 ms 101148 KiB
15.txt AC 1087 ms 101072 KiB
16.txt AC 1367 ms 101288 KiB
17.txt AC 427 ms 101252 KiB
18.txt AC 1773 ms 101348 KiB
19.txt AC 1776 ms 101248 KiB
s1.txt AC 428 ms 101088 KiB
s2.txt AC 433 ms 101228 KiB
s3.txt AC 424 ms 101188 KiB