Submission #293865

# Submission time Handle Problem Language Result Execution time Memory
293865 2020-09-08T13:15:11 Z BThero Monochrome Points (JOI20_monochrome) C++17
0 / 100
1 ms 256 KB
// chrono::system_clock::now().time_since_epoch().count()
#include<bits/stdc++.h>

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << " = " << x << endl;

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 300 + 5;
const int INF = (int)1e9;

char s[2 * MAXN];
int n, ans;
vector<char> vec;

void rec(int p, int cur = 0) {
  if (p == 2 * n) {
    if (vec.empty()) {
      ans = max(ans, cur);
    }
    
    return;
  }
    
  if (p < n) {
    vec.pb(s[p]);
    rec(p + 1, cur);
    vec.pop_back();
  }
  else {
    vector<char>::iterator it;
    
    if (s[p] == 'W') {
      it = find(all(vec), 'B');
    }
    else {
      it = find(all(vec), 'W');
    }
    
    assert(it != vec.end());
        
    if (it != vec.end()) {
      vector<char> mem = vec;
      int ncur = cur + vec.end() - it - 1;
      vec.erase(it);
      rec(p + 1, ncur);
      vec = mem;
    }    
  }
}

void solve() {
  scanf("%d", &n);
  scanf("%s", s);
  rec(0);
  printf("%d\n", ans);
}

int main() {
  int tt = 1;
  
  while (tt--) {
    solve();
  }

  return 0;
}

Compilation message

monochrome.cpp: In function 'void solve()':
monochrome.cpp:61:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   61 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
monochrome.cpp:62:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   62 |   scanf("%s", s);
      |   ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Incorrect 0 ms 256 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Incorrect 0 ms 256 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Incorrect 0 ms 256 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Incorrect 0 ms 256 KB Output isn't correct
6 Halted 0 ms 0 KB -