QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#218259#5598. Profitable TripViktorWA 1ms3804kbC++141.5kb2023-10-17 21:51:562023-10-17 21:51:56

Judging History

你现在查看的是最新测评结果

  • [2023-10-17 21:51:56]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3804kb
  • [2023-10-17 21:51:56]
  • 提交

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 = 0;

    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)) { 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

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3668kb

input:

2 1 10
1 2 0

output:

0

result:

ok single line: '0'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3736kb

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: 1ms
memory: 3804kb

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: 0
Accepted
time: 1ms
memory: 3668kb

input:

3 3 5
1 3 -10
3 2 2
2 3 -1

output:

4

result:

ok single line: '4'

Test #5:

score: 0
Accepted
time: 1ms
memory: 3668kb

input:

2 1 10
1 2 1

output:

1

result:

ok single line: '1'

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 3616kb

input:

2 1 10
1 2 -1

output:

0

result:

wrong answer 1st lines differ - expected: '-1', found: '0'