제출 #1366367

#제출 시각아이디문제언어결과실행 시간메모리
1366367afterzeroSnail (NOI18_snail)C++20
컴파일 에러
0 ms0 KiB
#include<bits/stdc++.h> 
using namespace std ; 

int main(){ 
    long long h , n ; 
    cin >> h >> n ; 
    vector<long long>a(n); 
    vector<long long> pref(n); 
    long long sum = 0 ; 
    
    for(int i = 0 ; i < n ; i++){ 
        cin >> a[i]; 
        sum += a[i]; 
    } 
    
    if( sum<= 0){ 
        cout << -1 << " " << -1 << endl; 
        return 0 ; 
    } 
    
    pref[0] = a[0]; 
        pref[i] = pref[i-1] + a[i]; 
    } 
    
    if(sum >= h){ 
        cout << 0 << " " ; 
        for(int i = 0 ; i < n ; i++){ 
            if(pref[i] >= sum){ 
                cout << i - 1 ; 
            } 
        } 
    } else { 
        if(h % sum == 0){ 
            cout << (h / sum) - 1 << " " << 0 ; 
        } else { 
            long long x = (h / sum); 
            cout << x << " "; 
            long long l = h - (long long)(sum * x) ; 
            for(int i = 0 ; i < n ; i++){ 
                if(pref[i] >= l){ 
                    cout << i - 1 ; 
                } 
            } 
        } 
    } 
}

컴파일 시 표준 에러 (stderr) 메시지

snail.cpp: In function 'int main()':
snail.cpp:22:14: error: 'i' was not declared in this scope
   22 |         pref[i] = pref[i-1] + a[i];
      |              ^
snail.cpp: At global scope:
snail.cpp:25:5: error: expected unqualified-id before 'if'
   25 |     if(sum >= h){
      |     ^~
snail.cpp:32:7: error: expected unqualified-id before 'else'
   32 |     } else {
      |       ^~~~
snail.cpp:46:1: error: expected declaration before '}' token
   46 | }
      | ^