57252023-09-10 01:50:45TomaSajtSzínes szobák (50 pont)cpp17Accepted 50/5032ms24740 KiB
// "inspired by" solution by SleepyOverlord on njudge
#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(0), cin.sync_with_stdio(0);

  int n, k, m;
  cin >> n >> k >> m;

  vector<int> pos_color(n + 2);
  for (int i = 1; i <= n; i++) cin >> pos_color[i];

  vector<array<int, 2>> instrs(m);
  for (auto& [c, x] : instrs) cin >> c >> x;
  reverse(instrs.begin(), instrs.end());

  // calculates in reverse what was the position of the people
  // who reached their respective side last
  int left_pos = 0, right_pos = n + 1;
  for (auto& [c, x] : instrs) {
    if (x == -1 && c == pos_color[left_pos + 1]) left_pos++;
    if (x == +1 && c == pos_color[left_pos]) left_pos--;

    if (x == +1 && c == pos_color[right_pos - 1]) right_pos--;
    if (x == -1 && c == pos_color[right_pos]) right_pos++;
  }

  cout << left_pos + (n + 1 - right_pos);
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1828 KiB
2Accepted0/032ms5528 KiB
3Accepted1/13ms3520 KiB
4Accepted1/13ms3756 KiB
5Accepted1/13ms3740 KiB
6Accepted1/13ms4008 KiB
7Accepted1/13ms4244 KiB
8Accepted1/13ms4464 KiB
9Accepted1/13ms4448 KiB
10Accepted1/13ms4720 KiB
11Accepted1/13ms4696 KiB
12Accepted1/13ms4720 KiB
13Accepted1/14ms5200 KiB
14Accepted1/14ms5324 KiB
15Accepted1/14ms5596 KiB
16Accepted1/14ms5792 KiB
17Accepted1/14ms5900 KiB
18Accepted1/14ms5988 KiB
19Accepted1/119ms7816 KiB
20Accepted1/132ms10000 KiB
21Accepted1/125ms10536 KiB
22Accepted1/127ms11928 KiB
23Accepted1/130ms13388 KiB
24Accepted1/132ms14940 KiB
25Accepted1/132ms16124 KiB
26Accepted1/132ms17520 KiB
27Accepted3/330ms18704 KiB
28Accepted3/330ms19620 KiB
29Accepted3/330ms20788 KiB
30Accepted3/330ms21868 KiB
31Accepted3/330ms22868 KiB
32Accepted3/330ms23864 KiB
33Accepted4/417ms22800 KiB
34Accepted4/427ms24740 KiB