結果

問題 No.1390 Get together
ユーザー soldray
提出日時 2021-02-17 19:54:35
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 689 bytes
コンパイル時間 2,956 ms
コンパイル使用メモリ 130,660 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-14 05:28:20
合計ジャッジ時間 4,635 ms
ジャッジサーバーID
(参考情報)
judge1 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

// Get together

#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int N, M;

  cin >> N >> M;

  vector<int> box;
  vector<pair<int, int> > color;

  for (int i = 0; i < N; i++) {
    int b, c;

    cin >> b >> c;

    b--; c--;

    box.push_back(b);
    color.push_back(make_pair(c, i));
  }

  sort(color.begin(), color.end());

  int ans = 0;

  for (int i = 1; i < N; i++) {
    int index = color[i].second;
    int bef = color[i - 1].second;

    if (color[i].first == color[i - 1].first
        && box[index] != box[bef]) {
      ans++;
      box[index] = box[bef];
    }
  }

  cout << ans << endl;

  return 0;
}
0