Submission #1062477

# Submission time Handle Problem Language Result Execution time Memory
1062477 2024-08-17T07:44:06 Z zh_h Snail (NOI18_snail) C++17
0 / 100
1 ms 604 KB
#include <bits/stdc++.h>
#define lint long long
#define pb push_back
#define mp make_pair
using namespace std;
lint MOD = 1e9 + 7;
int INF = 1e9;



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    lint h, p;
    cin >> h >> p;
    vector<lint> v;
    lint sum = 0;
    for(int i = 0; i < p; i ++){
        lint temp;
        cin >> temp;
        v.pb(temp);
        sum += temp;
    }

    if(sum < 0){cout << -1 << " " << -1;}
    else if(sum == 0){
        lint h1 = 0;
        int is_valid = -1;
        for(int i = 0; i < p; i ++){
            if(h1 >= h){is_valid = i; break;}
            h1+=v[i];
            if(h1 < 0){h1 = 0;}
        }
        if(is_valid != -1){cout << 0 << " " << is_valid;}
        else cout << -1 << " " << -1;
    }
    else{
        lint m = 0;
        lint temp = 0;
        for(int i = 0; i < p; i ++){
            temp += v[i];
            m = max(m, temp);
        }

        int days = (h-m+sum-1)/sum;
        int thatday = days*sum;
        int valid;
        if(thatday >= h){
            thatday-=sum;
            days--;
        }
        
        for(int i = 0; i < p; i ++){
            thatday += v[i];
            if(thatday >= h){valid = i; break;}
        }
        cout << days << " " << valid;
        
    }

    return 0;
}

Compilation message

snail.cpp: In function 'int main()':
snail.cpp:58:32: warning: 'valid' may be used uninitialized in this function [-Wmaybe-uninitialized]
   58 |         cout << days << " " << valid;
      |                                ^~~~~
# 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 348 KB Output is correct
4 Incorrect 0 ms 420 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 456 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 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 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Incorrect 1 ms 604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 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 348 KB Output is correct
4 Incorrect 0 ms 420 KB Output isn't correct
5 Halted 0 ms 0 KB -