結果

問題 No.118 門松列(2)
ユーザー m1025o1184tm1025o1184t
提出日時 2019-12-02 03:05:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 924 bytes
コンパイル時間 1,683 ms
コンパイル使用メモリ 170,388 KB
実行使用メモリ 14,008 KB
最終ジャッジ日時 2024-05-01 22:19:10
合計ジャッジ時間 8,607 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'void comb()':
main.cpp:14:57: warning: iteration 498 invokes undefined behavior [-Waggressive-loop-optimizations]
   14 |             C[i + 1][j + 1] = C[i][j] % mod + C[i][j + 1] % mod;
      |                                               ~~~~~~~~~~^
main.cpp:12:22: note: within this loop
   12 |         for(int j=1;j<=499;++j){
      |                     ~^~~~~

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;

const int mod = 1000000007;

int C[500][500];

void comb(){
    C[1][1] = 1;
    for(int i= 1;i<=499;++i){
        for(int j=1;j<=499;++j){
            C[i + 1][j] = C[i][j] % mod+ C[i][j - 1] % mod;
            C[i + 1][j + 1] = C[i][j] % mod + C[i][j + 1] % mod;
        }
    }
}

int main(){
    int n;
    cin >> n;
    vector<int> A(n);
    rep(i,n) cin >> A[i];
    comb();
    vector<int> res = A;
    auto result = unique(res.begin(),res.end());
    res.erase(result,res.end());
    if(res.size() == A.size()){
        int ans = C[n][3] % mod;
        cout << ans << endl;
        return 0;
    }
    int sol = 1;
    for(int i=0;i<res.size();++i){
        int k = count(A.begin(),A.end(),res[i]);
        sol *= k;
        sol %= mod;
    }
    int ans2 = C[res.size()][3] * sol % mod;
    cout << ans2 << endl;
    return 0;
}
0