답안 #411882

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
411882 2021-05-26T07:48:59 Z 조영욱(#7630) Pastiri (COI20_pastiri) C++17
0 / 100
150 ms 540 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> v;
int dp[500000];

int main(void) {
    int n,k;
    scanf("%d %d",&n,&k);
    for(int i=1;i<n;i++) {
        int a,b;
        scanf("%d %d",&a,&b);
    }
    for(int i=0;i<k;i++) {
        int x;
        scanf("%d",&x);
        v.push_back(x);
    }
    sort(v.begin(),v.end());
    dp[0]=1;
    dp[1]=2;
    if (v.size()>1&&(v[1]-v[0])%2==0) {
        dp[1]=1;
    }
    for(int i=2;i<v.size();i++) {
        dp[i]=dp[i-1]+1;
        if ((v[i]-v[i-1])%2==0) {
            dp[i]=max(dp[i],dp[i-2]+1);
        }
    }
    int now=v.size()-1;
    printf("%d\n",dp[now]);
    vector<int> ret;
    while (1) {
        if (now==0) {
            ret.push_back(v[now]);
            break;
        }
        if (now==1) {
            if ((v[1]-v[0])%2==0) {
                ret.push_back((v[0]+v[1])/2);
                break;
            }
        }
        if (dp[now]==dp[now-1]+1) {
            ret.push_back(v[now]);
            now--;
        }
        else if (dp[now]==dp[now-2]+1) {
            ret.push_back((v[now-1]+v[now])/2);
            now-=2;
        }
    }
    reverse(ret.begin(),ret.end());
    for(int i=0;i<ret.size();i++) {
        printf("%d ",ret[i]);
    }
}

Compilation message

pastiri.cpp: In function 'int main()':
pastiri.cpp:25:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for(int i=2;i<v.size();i++) {
      |                 ~^~~~~~~~~
pastiri.cpp:55:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for(int i=0;i<ret.size();i++) {
      |                 ~^~~~~~~~~~~
pastiri.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%d %d",&n,&k);
      |     ~~~~~^~~~~~~~~~~~~~~
pastiri.cpp:12:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |         scanf("%d %d",&a,&b);
      |         ~~~~~^~~~~~~~~~~~~~~
pastiri.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         scanf("%d",&x);
      |         ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 113 ms 204 KB Output is correct
2 Incorrect 117 ms 292 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 150 ms 540 KB Sheep 54 not protected
2 Halted 0 ms 0 KB -