結果

問題 No.30 たこやき工場
コンテスト
ユーザー mamekin
提出日時 2015-01-12 14:53:36
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 1,432 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,114 ms
コンパイル使用メモリ 123,052 KB
実行使用メモリ 11,296 KB
最終ジャッジ日時 2026-03-06 10:48:35
合計ジャッジ時間 8,194 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16 TLE * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'std::vector<long long int> solve(int, const std::vector<std::vector<Edge> >&)':
main.cpp:44:18: warning: ignoring return value of 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = std::vector<long long int>; _Alloc = std::allocator<std::vector<long long int> >; reference = std::vector<long long int>&; size_type = long unsigned int]', declared with attribute 'nodiscard' [-Wunused-result]
   44 |         memo[curr];
      |                  ^
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/vector:68,
                 from main.cpp:9:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/stl_vector.h:1261:7: note: declared here
 1261 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~

ソースコード

diff #
raw source code

#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

class Edge
{
public:
    int to, cost;
    Edge(int to0, int cost0){
        to = to0;
        cost = cost0;
    }
};

vector<vector<long long> > memo;

vector<long long> solve(int curr, const vector<vector<Edge> >& edges)
{
    int n = edges.size();
    vector<long long> ret(n, 0);
    if(edges[curr].size() == 0){
        ret[curr] = 1;
        return ret;
    }
    if(!memo[curr].empty())
        memo[curr];

    for(unsigned i=0; i<edges[curr].size(); ++i){
        vector<long long> v = solve(edges[curr][i].to, edges);
        for(int j=0; j<n; ++j)
            ret[j] += v[j] * edges[curr][i].cost;
    }
    return memo[curr] = ret;
}

int main()
{
    int n, m;
    cin >> n >> m;

    vector<vector<Edge> > edges(n);
    for(int i=0; i<m; ++i){
        int p, q, r;
        cin >> p >> q >> r;
        -- p;
        -- r;
        edges[r].push_back(Edge(p, q));
    }

    memo.assign(n, vector<long long>());
    vector<long long> ret = solve(n-1, edges);
    for(int i=0; i<n-1; ++i)
        cout << ret[i] << endl;

    return 0;
}
0