CSES - BAPC 2015 - Results
Submission details
Task:Physical Music
Sender:Antti Röyskö
Submission time:2017-10-17 19:58:42 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.14 sdetails

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:28:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0; i<ans.size(); ++i) cout << ans[i] << "\n";
                              ^

Code

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int T;

bool is[101010];
vector<int> ans;
int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);
  cin >> T;
  for (int i=0; i<T; ++i){
    int N;
    cin >> N;
    for (int j=0; j<=N; ++j) is[j]=0;
    
    ans.clear();
    int gg=1;
    for (int i=1; i<=N; ++i){
      int st;
      cin >> st;
      is[st]=1;
      if (st>gg) ans.push_back(st);
      while (is[gg]) ++gg;
    }
    sort(ans.begin(), ans.end());
    cout << ans.size() << "\n";
    for (int i=0; i<ans.size(); ++i) cout << ans[i] << "\n";
  }
}

Test details

Test 1

Verdict: ACCEPTED

input
20
3
1
2
3
...

correct output
0
2
3
4
3
...

user output
0
2
3
4
3
...