답안 #317127

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
317127 2020-10-29T03:51:34 Z casperwang DEL13 (info1cup18_del13) C++14
0 / 100
500 ms 74244 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;
    bool p = 0;
    for (int i = 1; i <= n; i++) {
      if (arr[i] > 0) cnt++;
      if (!arr[i] && cnt == (n-k)/2 - ans.size()) {
        while (ans.size() * 2 < n-k)
          ans.pb(i);
      }
      if (arr[i] > 0) p = 0;
    }
    if (ans.size() == (n-k)/2) {
      cout << ans.size() << "\n";
      for (int i = 0; i < ans.size(); i++) 
        cout << ans[i] << " \n"[i==ans.size()-1];
    } else if (ans.size() == (n-k)/2-1) {
      cout << -1 << "\n";
    } else {
      int pos = 0;
      p = 0;
      for (int i = 1; i <= n; i++) {
        if (arr[i] > 0) {
          pos = i;
          if (p) {
            arr[i] = -1;
            break;
          }
        }
        if (!arr[i] && pos) {
          ans.pb(i);
          arr[pos] = -1;
          p = 1;
        }
      }
      cnt = 0;
      p = 0;
      for (int i = 1; i <= n; i++) {
        if (arr[i] > 0) cnt++, p = 0;
        if (!arr[i] && cnt == (n-k)/2 - ans.size()) {
          while (ans.size() * 2 < n-k)
            ans.pb(i);
      }
      cout << ans.size() << "\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:56:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |       if (!arr[i] && cnt == (n-k)/2 - ans.size()) {
      |                      ~~~~^~~~~~~~~~~~~~~~~~~~~~~
del13.cpp:57:31: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   57 |         while (ans.size() * 2 < n-k)
      |                ~~~~~~~~~~~~~~~^~~~~
del13.cpp:62:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   62 |     if (ans.size() == (n-k)/2) {
      |         ~~~~~~~~~~~^~~~~~~~~~
del13.cpp:64:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |       for (int i = 0; i < ans.size(); i++)
      |                       ~~^~~~~~~~~~~~
del13.cpp:65:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |         cout << ans[i] << " \n"[i==ans.size()-1];
      |                                 ~^~~~~~~~~~~~~~
del13.cpp:66:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   66 |     } else if (ans.size() == (n-k)/2-1) {
      |                ~~~~~~~~~~~^~~~~~~~~~~~
del13.cpp:89:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |         if (!arr[i] && cnt == (n-k)/2 - ans.size()) {
      |                        ~~~~^~~~~~~~~~~~~~~~~~~~~~~
del13.cpp:90:33: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   90 |           while (ans.size() * 2 < n-k)
      |                  ~~~~~~~~~~~~~~~^~~~~
del13.cpp:94:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |       for (int i = 0; i < ans.size(); i++)
      |                       ~~^~~~~~~~~~~~
del13.cpp:95:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |         cout << ans[i] << " \n"[i==ans.size()-1];
      |                                 ~^~~~~~~~~~~~~~
del13.cpp:13:10: warning: unused variable 'tf' [-Wunused-variable]
   13 |     bool tf = 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 9 ms 512 KB Output isn't correct
4 Incorrect 9 ms 512 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 768 KB Output isn't correct
2 Incorrect 5 ms 832 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 9 ms 512 KB Output isn't correct
4 Incorrect 9 ms 512 KB Output isn't correct
5 Incorrect 3 ms 512 KB Output isn't correct
6 Incorrect 3 ms 384 KB Output isn't correct
7 Incorrect 3 ms 384 KB Integer 78 violates the range [1, 75]
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Incorrect 9 ms 512 KB Output isn't correct
4 Incorrect 9 ms 512 KB Output isn't correct
5 Incorrect 3 ms 512 KB Output isn't correct
6 Incorrect 3 ms 384 KB Output isn't correct
7 Incorrect 3 ms 384 KB Integer 78 violates the range [1, 75]
8 Execution timed out 688 ms 40572 KB Time limit exceeded
9 Incorrect 10 ms 888 KB Output isn't correct
10 Execution timed out 1059 ms 72312 KB Time limit exceeded
11 Execution timed out 1048 ms 74244 KB Time limit exceeded