公式

B - Call the ID Number 解説 by en_translator


Write a program that memorizes whether each of the \(N\) people were called out, while simulating the actions of person \(1\), person \(2\), \(\ldots\), and person \(N\) in this order, and your program will be accepted.

A sample code in C++ language follows.

#include <iostream>
using namespace std;

int n;
int a[200001];
bool b[200001];

int main(void)
{
  cin >> n;
  for(int i = 1; i <= n; i++) cin >> a[i];
  for(int i = 1; i <= n; i++) if(!b[i]) b[a[i]] = true;
  
  int k = 0;
  for(int i = 1; i <= n; i++) if(!b[i]) k++;
  cout << k << endl;
  for(int i = 1; i <= n; i++) if(!b[i]) cout << i << " ";
  cout << endl;
  
  return 0;
}

投稿日時:
最終更新: