답안 #1054514

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1054514 2024-08-12T10:24:28 Z kiryl_krutsko Safety (NOI18_safety) C++14
4 / 100
2000 ms 262144 KB
#include <iostream>
#include <vector>
#include <climits>

using namespace std;

void out(vector<vector<int> >* results) {
    cout << endl;
    for (int i = 0; i < results->size(); i++) {
        for (int j = 0; j < results->at(i).size(); j++) {
            cout << results->at(i)[j] << " ";
        }
        cout << endl;
    }
}


int main()
{
    int n, H;
    int maxh = 0;
    cin >> n >> H;
    vector<int> input;
    int in;
    for (int i = 0; i < n; i++) {
        cin >> in;
        if (in > maxh) maxh = in;
        input.push_back(in);
    }
    vector<vector<int> > results(2, vector<int> (maxh + 1));
    int cur = input[0];
    for (int i = 0; i < maxh + 1; i++) {
        results[0][i] = abs(i - cur);
    }
    for (int i = 1; i < n - 1; i++) {
        cur = input[i];
        for (int j = 0; j < maxh + 1; j++) {
            int best_last = INT_MAX;
            for (int h = H; h >= -H; h--) {
                if (j + h >= 0 && j + h < maxh + 1){
                    if(results[0][j + h] < best_last)
                        best_last = results[0][j + h];
                }
            }
            results[1][j] = abs(j - cur) + best_last;
            //out(&results);
        }
        results.erase(results.begin());
        results.push_back(vector<int>(maxh + 1));
    }
    cur = input[n - 1];
    int best_result = INT_MAX;
    for (int j = 0; j < maxh + 1; j++) {
        int best_last = INT_MAX;
        for (int h = H; h >= -H; h--) {
            if (j + h >= 0 && j + h < maxh + 1) {
                if (results[0][j + h] < best_last) {
                    best_last = results[0][j + h]; 
                }
            }
        }
        if (abs(j - cur) + best_last < best_result) best_result = abs(j - cur) + best_last;
    }
    /*
    int best_result = INT_MAX;
    for (int i = 0; i < maxh + 1; i++) {
        if (results[0][i] < best_result) best_result = results[0][i];
    }*/
    cout << best_result << endl;
}

Compilation message

safety.cpp: In function 'void out(std::vector<std::vector<int> >*)':
safety.cpp:10:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for (int i = 0; i < results->size(); i++) {
      |                     ~~^~~~~~~~~~~~~~~~~
safety.cpp:11:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |         for (int j = 0; j < results->at(i).size(); j++) {
      |                         ~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Execution timed out 2091 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 51 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 74 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Execution timed out 2091 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Execution timed out 2091 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Execution timed out 2091 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Execution timed out 2091 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Execution timed out 2091 ms 348 KB Time limit exceeded
5 Halted 0 ms 0 KB -