QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#218279 | #5598. Profitable Trip | Viktor | WA | 1ms | 4112kb | C++14 | 1.7kb | 2023-10-17 22:31:08 | 2023-10-17 22:31:09 |
Judging History
answer
#include <iostream>
#include <vector>
using namespace std;
vector<vector<int>> points[10000]; //graph
int visited_scores[10000]; //Scores of visited points
vector<int> way_scores; //Summarize scores of all routes
int n,m,w; //InputVariables
void reset_visited();
void best_effort(int actual_position, int score);
int main() {
reset_visited();
//Input
cin >> n >> m >> w;
int from, to, cost;
for (int i = 0; i < m; i++) {
cin >> from >> to >> cost;
points[from].push_back({to, cost});
}
best_effort(1,0);
int max_coins = -200;
int size = way_scores.size(); //sequential search
for (int i = 0; i < size; i++) {
if (way_scores[i] > max_coins) { max_coins = way_scores[i]; }
}
cout << max_coins << endl;
return 0;
}
void best_effort(int actual_position, int score) {
if (actual_position == n && (points[actual_position].empty() || visited_scores[actual_position] == score) || (visited_scores[actual_position] > -200 && visited_scores[actual_position] < 0 && score < 0)) { way_scores.push_back(score); reset_visited(); }
else {
visited_scores[actual_position] = score;
int new_score;
int size = points[actual_position].size();
for (int i = 0; i < size; i++) {
new_score = score + points[actual_position][i][1] > w ? w : score + points[actual_position][i][1];
best_effort(points[actual_position][i][0], new_score);
}
}
}
void reset_visited() { for (int i = 0; i < 10000; i++) { visited_scores[i] = -200; } } //make the visited scores unvisited
//I guess I need to consider also where did I come from, so I can better determine when to visit cycles and when do not!
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3812kb
input:
2 1 10 1 2 0
output:
0
result:
ok single line: '0'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3872kb
input:
4 4 9 1 2 5 1 3 -2 2 4 1 3 4 10
output:
8
result:
ok single line: '8'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
4 4 7 1 2 5 1 3 -2 2 4 1 3 4 10
output:
7
result:
ok single line: '7'
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 4112kb
input:
3 3 5 1 3 -10 3 2 2 2 3 -1
output:
-9
result:
wrong answer 1st lines differ - expected: '4', found: '-9'