Submission #926544

# Submission time Handle Problem Language Result Execution time Memory
926544 2024-02-13T08:52:49 Z Toast Snail (NOI18_snail) C++14
100 / 100
3 ms 860 KB
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <cmath>
using namespace std;

int main() {
    double H,N,diff;
    long maxim=0;
    long currentheight=0;
    long currentphase=0;
    long temp = -1;
    bool flag = true;
    string P;
    cin >> H >> N;
    cin.ignore();
    getline(cin, P);
    stringstream ss(P);
    vector<long>v;
    vector<long>max;
    while (getline(ss,P,' ')) {
        v.push_back(stoul(P));
    }
    long currentday = -1;
    for (int i=0;i<2;i++) {
        currentday++;
        for (int i=0;i<N;i++) {
            if (currentheight+v[i]<0) {
                currentheight = 0;
            }
            else {
                currentheight +=v[i];
                if (currentheight>maxim) {
                    maxim=currentheight;
                }
            }
            if (currentheight>=H) {
                flag=false;
                currentphase=i;
                cout << currentday << " " << currentphase;
                break;
            }
        }
        max.push_back(maxim);
        if (!flag) {
            break;
        }
        if (temp==currentheight) {
            cout << -1 << " " << -1; 
            flag = false;
            break;
        }
        diff = currentheight-temp;
        temp = currentheight;
    }
    currentday=ceil((H-max[0])/(max[1]-max[0]));
    temp = currentheight+(currentday-2)*diff;
    while (flag) {
        for (int i=0;i<N;i++) {
            if (v[i]+temp>=H) {
                cout << currentday << " " << i;
                flag = false;
                break;
              }
             else {
                 temp+=v[i];
             }
        }
    } 
}

Compilation message

snail.cpp: In function 'int main()':
snail.cpp:58:40: warning: 'diff' may be used uninitialized in this function [-Wmaybe-uninitialized]
   58 |     temp = currentheight+(currentday-2)*diff;
      |                          ~~~~~~~~~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 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 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 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 1 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 3 ms 860 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 2 ms 604 KB Output is correct
6 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 3 ms 860 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 2 ms 604 KB Output is correct
26 Correct 2 ms 604 KB Output is correct
27 Correct 3 ms 856 KB Output is correct
28 Correct 2 ms 856 KB Output is correct
29 Correct 2 ms 856 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 1 ms 524 KB Output is correct
32 Correct 1 ms 604 KB Output is correct