Submission #930821

# Submission time Handle Problem Language Result Execution time Memory
930821 2024-02-20T13:17:24 Z ksujay2 Building 4 (JOI20_building4) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FOR(i, b) for(int i = 0; i < (b); i++)
#define ROF(i, b) for(int i = (b) - 1; i >= 0; i--)
#define ROF(i, a, b) for(int i = (b) - 1; i >= (a); i--)
using pi = pair<int, int>;
int main() {
  ios::sync_with_stdio(false), cin.tie(nullptr);
  int N; cin >> N;
  vector<int> A(2 * N), B(2 * N);
  FOR(i, 2 * N) cin >> A[i];
  FOR(i, 2 * N) cin >> B[i];
  vector<array<int, 2>> dp(2 * N, {{-1, -1}});
  dp[0][0] = -2;
  dp[0][1] = -2;
  FOR(i, 1, 2 * N) {
    if(dp[i - 1][0] != -1) {
      if(A[i - 1] <= A[i]) {
        dp[i][0] = 0;
      }
      if(A[i - 1] <= B[i]) {
        dp[i][1] = 0;
      }
    }
    if(dp[i - 1][1] != -1) {
      if(B[i - 1] <= A[i]) {
        dp[i][0] = 1;
      }
      if(B[i - 1] <= B[i]) {
        dp[i][1] = 1;
      }
    }
  }
  if(dp.back()[0] != -1) {
    vector<int> choice(2 * N);
    choice[2 * N - 1] = 0;
    ROF(i, 2 * N, 1) {
      choice[i - 1] = dp[i][choice[i]]; 
    }
    FOR(i, 2 * N) {
      if(choice[i] == 0) cout << 'A';
      else cout << 'B';
    }
  } else if(dp.back()[1] != -1) {
    vector<int> choice(2 * N);
    choice[2 * N - 1] = 1;
    ROF(i, 2 * N, 1) {
      choice[i - 1] = dp[i][choice[i]]; 
    }
    FOR(i, 2 * N) {
      if(choice[i] == 0) cout << 'A';
      else cout << 'B';
    }
  } else {
    cout << -1 << endl;
  }
}

Compilation message

building4.cpp:4: warning: "FOR" redefined
    4 | #define FOR(i, b) for(int i = 0; i < (b); i++)
      | 
building4.cpp:3: note: this is the location of the previous definition
    3 | #define FOR(i, a, b) for(int i = (a); i < (b); i++)
      | 
building4.cpp:6: warning: "ROF" redefined
    6 | #define ROF(i, a, b) for(int i = (b) - 1; i >= (a); i--)
      | 
building4.cpp:5: note: this is the location of the previous definition
    5 | #define ROF(i, b) for(int i = (b) - 1; i >= 0; i--)
      | 
building4.cpp:17:18: error: macro "FOR" passed 3 arguments, but takes just 2
   17 |   FOR(i, 1, 2 * N) {
      |                  ^
building4.cpp:4: note: macro "FOR" defined here
    4 | #define FOR(i, b) for(int i = 0; i < (b); i++)
      | 
building4.cpp: In function 'int main()':
building4.cpp:17:3: error: 'FOR' was not declared in this scope
   17 |   FOR(i, 1, 2 * N) {
      |   ^~~