結果

問題 No.30 たこやき工場
ユーザー ktgktg
提出日時 2016-06-16 01:19:54
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,156 bytes
コンパイル時間 1,088 ms
コンパイル使用メモリ 91,448 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-17 22:49:25
合計ジャッジ時間 1,328 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 WA -
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 WA -
testcase_16 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#include <bits/stdc++.h>
#include <assert.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <iterator>
#include <unistd.h>

using namespace std;

typedef signed long long ll;

#define pp(...) (void)printf(__VA_ARGS__)
#define For(x,to) for(x=0;x<(to);x++)
#define ForAuto(x,arr) for(auto& x:arr)
#define ForBeginEnd(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define All(a) (a.begin()),(a.end())
#define Zeros(a) memset(a,0,sizeof(a))
#define Minus(a) memset(a,0xff,sizeof(a))

#define PI 3.14159265
#define EPS (1e-10)
#define EPS_eq(a,b) (abs((a)-(b)) < EPS)

#pragma GCC diagnostic ignored "-Wconversion"

//#define int long long
#define INF 1000*1000

int dxy[] = {0, 1, 0, -1, 0};

typedef pair<int, int> P;

void pp_int(int x){ printf("%d\n", x); };

int i,j,k;

ll M = 100000009;

//ios::sync_with_stdio(false);

//-------------------------------------------------

// i番の製品を作るのに必要なj番の個数
int dp[105][105];
int p[105], q[105], r[105];
int n,m;

set<int> buy;
vector<pair<int, int> > pqr[105];

void rec(int dst){
    if(dp[dst][0]>=0){
        return;
    }
    memset(dp[dst], 0, sizeof(dp[dst]));
    if(buy.count(dst)){
        dp[dst][dst] = 1;
        return;
    }
    for(int i=0;i<pqr[dst].size();i++){
        pair<int, int> pointer = pqr[dst][i];
        int src = pointer.first;
        int num = pointer.second;
        rec(src);
        for(int j = 1; j <= n - 1; j++){
            dp[dst][j] += num * dp[src][j];
        }
    }
    return;
}

signed main() {
    cin>>n>>m;
    for(int i=0;i<105;i++)
        memset(dp[i], -1, sizeof(dp[i]));

    for(int i=1;i<=n-1;i++){
        buy.insert(i);
    }
    for(int i=0;i<m;i++){
        cin>>p[i]>>q[i]>>r[i];
        pqr[r[i]].push_back({p[i], q[i]});
        buy.erase(r[i]);
    }
    rec(n);
    for(int i=1;i<=n-1;i++){
        if(buy.count(i)){
            cout<<dp[n][i]<<endl;
        } else {
            cout<<0<<endl;
        }
    }
    return 0;
}
0