답안 #1004343

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1004343 2024-06-21T08:00:59 Z fuad27 Trobojnica (COCI19_trobojnica) C++17
60 / 110
2000 ms 3308 KB
#include <bits/stdc++.h>
using namespace std;
int main () {
  cin.tie(0)->sync_with_stdio(0);
  int n;
  cin >> n;
  vector<array<int,3>> v(n);
  string s;
  cin >> s;
  for(int i = 0;i<n;i++) {
    v[i][2] = (s[i]-'0');
    v[i][0] = i;
    v[i][1] = (i+1)%n;
  }
  vector<array<int,3>> res;
  while(1) {
    bool check=false;
    if(v.size() == 3)break;
    n=v.size();
    for(int i = 0;i<n;i++) {
      if(v[i][2] != v[(i+1)%n][2] and (1^2^3^v[i][2]^v[(i+1)%n][2]) != v[(i+2)%n][2]) {
        check=1;
        int L = v[i][0], R = v[(i+1)%n][1];
        int val = (1^2^3^v[i][2]^v[(i+1)%n][2]);
        res.push_back({L, R, val});
        if(i!=n-1) {
          v.erase(v.begin()+i+1);
          v.erase(v.begin()+i);
          v.insert(v.begin()+i, {L, R, val});
          break;
        }
        else {
          v.erase(v.begin()+i);
          v.erase(v.begin());
          v.insert(v.begin(), {L, R, val});
          break;
        }
      }
    }
    if(check == false) {
    for(int i = 0;i<n;i++) {
      if(v[i][2] != v[(i+1)%n][2]) {
        check=1;
        int L = v[i][0], R = v[(i+1)%n][1];
        int val = (1^2^3^v[i][2]^v[(i+1)%n][2]);
        res.push_back({L, R, val});
        if(i!=n-1) {
          v.erase(v.begin()+i+1);
          v.erase(v.begin()+i);
          v.insert(v.begin()+i, {L, R, val});
          break;
        }
        else {
          v.erase(v.begin()+i);
          v.erase(v.begin());
          v.insert(v.begin(), {L, R, val});
          break;
        }
      }
    }

    }
    if(!check) {
      cout << "NE\n";
      return 0;
    }
  }
  int x=0;
  for(auto i:v) {
    x^=i[2];
  }
  if(x!=0) {
    cout <<"NE\n";
    return 0;
  }
  cout << "DA\n";
  for(auto i:res)cout << i[0]+1 << " " << i[1]+1 << " " << i[2] <<  "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 452 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 452 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Execution timed out 2050 ms 3308 KB Time limit exceeded
22 Halted 0 ms 0 KB -