답안 #317149

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
317149 2020-10-29T04:15:51 Z casperwang DEL13 (info1cup18_del13) C++14
0 / 100
11 ms 1408 KB
#include <bits/stdc++.h>
#define pb push_back
using namespace std;

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    vector <int> arr(n+1);
    bool tf = 1;
    for (int i = 1; i <= n; i++)
      arr[i] = i;
    for (int i = 0; i < k; i++) {
      int a;
      cin >> a;
      arr[a] = 0;
    }
    if ((n - k) % 2) {
      cout << -1 << "\n";
      continue;
    }
    int l = 1, r = 0;
    vector <int> ans;
    for (int i = 1; i <= n; i++) {
      if (!arr[i]) {
        if (!arr[r]) {
          l = i+1;
          continue;
        }
        int c = r-l+1;
        if (c % 2) {
          for (int j = 0; j < c/2; j++)
            ans.pb((l+r)/2);
          for (int j = l; j < (l+r)/2; j++)
            arr[j] = -1;
          for (int j = (l+r)/2+1; j <= r; j++)
            arr[j] = -1;
        } else {
          for (int j = 1; j < c/2; j++)
            ans.pb((l+r)/2);
          for (int j = l; j < (l+r)/2; j++)
            arr[j] = -1;
          for (int j = (l+r)/2+1; j < r; j++)
            arr[j] = -1;
        }
        l = r = i+1;
      } else r = i;
    }
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
      if (!arr[i]) {
        if (cnt < 0) {
          tf = 0;
          break;
        } else if (cnt > 0) {
          for (int j = 0; j < cnt; j++)
            ans.pb(i);
          cnt = -cnt;
        }
      } else if (arr[i] > 0) {
        cnt++;
      }
    }
    if (cnt) tf = 0;
    if (!tf) {
      cout << -1 << "\n";
      continue;
    }
    cout << ans.size() << "\n";
    if (!ans.size()) cout << "\n";
    for (int i = 0; i < ans.size(); i++)
      cout << ans[i] << " \n"[i==ans.size()-1];
  }
}

Compilation message

del13.cpp: In function 'int main()':
del13.cpp:74:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |     for (int i = 0; i < ans.size(); i++)
      |                     ~~^~~~~~~~~~~~
del13.cpp:75:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |       cout << ans[i] << " \n"[i==ans.size()-1];
      |                               ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Incorrect 1 ms 384 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Incorrect 4 ms 384 KB Output isn't correct
4 Incorrect 5 ms 384 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 512 KB Output isn't correct
2 Incorrect 2 ms 704 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Incorrect 4 ms 384 KB Output isn't correct
4 Incorrect 5 ms 384 KB Output isn't correct
5 Incorrect 1 ms 384 KB Output isn't correct
6 Incorrect 1 ms 384 KB Output isn't correct
7 Incorrect 1 ms 512 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Incorrect 4 ms 384 KB Output isn't correct
4 Incorrect 5 ms 384 KB Output isn't correct
5 Incorrect 1 ms 384 KB Output isn't correct
6 Incorrect 1 ms 384 KB Output isn't correct
7 Incorrect 1 ms 512 KB Output isn't correct
8 Incorrect 6 ms 768 KB Output isn't correct
9 Incorrect 6 ms 896 KB Output isn't correct
10 Incorrect 6 ms 768 KB Output isn't correct
11 Incorrect 11 ms 1408 KB Output isn't correct