답안 #600619

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
600619 2022-07-21T06:24:54 Z 조영욱(#8469) 빌딩 장식 3 (JOI15_building3) C++14
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;

int n;
int arr[1000000];

int main() {
    scanf("%d",&n);
    int mnp=0;
    int mxp=n-1;
    for(int i=1;i<n;i++) {
        scanf("%d",&arr[i]);
    }
    int pos=0;
    bool flag=true;
    int val;
    for(int i=1;i<n;i++) {
        if (arr[i]>arr[pos]) {
            if (arr[i]>arr[pos]+2||!flag) {
                printf("0");
                return 0;
            }
            if (arr[i]==arr[pos]+2) {
                flag=false;
                mnp=pos;
                mxp=i-1;
                val=arr[pos]+1;
            }
            pos=i;
        }
    }
    if (!flag) {
        int ret=0;
        for(int i=mnp;i<=mxp;i++) {
            if (arr[i+1]!=val) {
                ret++;
            }
        }
        printf("%d",ret);
        return 0;
    }
    int mx=0;
    long long ret=0;
    for(int i=1;i<n;i++) {
        mx=max(mx,arr[i]);
        ret+=mx+(i==n-1?1:0);
    }
    printf("%lld",ret);
}

Compilation message

building3.cpp: In function 'int main()':
building3.cpp:8:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
building3.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         scanf("%d",&arr[i]);
      |         ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Incorrect 1 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -