Submission #1072093

# Submission time Handle Problem Language Result Execution time Memory
1072093 2024-08-23T14:16:02 Z ttamx Ancient Machine (JOI21_ancient_machine) C++17
100 / 100
200 ms 8856 KB
#include "Anna.h"
#include <bits/stdc++.h>

using namespace std;

void Anna(int n,vector<char> s){
  const int B=349;
  const int F=500;
  using BS = bitset<B>;
  vector<array<BS,2>> dp(F+1);
  auto add=[&](const BS &a,const BS &b){
    BS res;
    bool carry=0;
    for(int i=0;i<B;i++){
      res[i]=a[i]^b[i]^carry;
      carry=(a[i]&b[i])|((a[i]^b[i])&carry);
    }
    return res;
  };
  dp[1][0]=1;
  dp[1][1]=1;
  for(int i=2;i<=F;i++){
    dp[i][0]=add(dp[i-1][0],dp[i-1][1]);
    dp[i][1]=dp[i-1][0];
  }
  int st=-1;
  for(int i=0;i<n;i++){
    if(s[i]=='X'){
      st=i;
      break;
    }
  }
  if(st==-1){
    Send(0);
    return;
  }
  for(int i=0;i<17;i++){
    Send(st>>i&1);
  }
  int sz=((n-1)/F+1)*F;
  vector<int> seq(sz);
  for(int i=st+1;i<n;i++){
    if(s[i]=='Z'&&(i==n-1||s[i+1]!='Z')){
      seq[i]=1;
    }
  }
  for(int i=0;i<sz;i+=F){
    BS res;
    for(int j=0;j<F;j++){
      if(seq[i+j]){
        res=add(res,dp[F-j][0]);
      }
    }
    for(int j=0;j<B;j++){
      Send(res[j]);
    }
  }
}
#include "Bruno.h"
#include <bits/stdc++.h>

using namespace std;

void Bruno(int n,int m,vector<int> seq){
  if(m==1){
    for(int i=0;i<n;i++){
      Remove(i);
    }
    return;
  }
  const int B=349;
  const int F=500;
  using BS = bitset<B>;
  vector<array<BS,2>> dp(F+1);
  auto add=[&](const BS &a,const BS &b){
    BS res;
    bool carry=0;
    for(int i=0;i<B;i++){
      res[i]=a[i]^b[i]^carry;
      carry=(a[i]&b[i])|((a[i]^b[i])&carry);
    }
    return res;
  };
  auto sub=[&](const BS &a,const BS &b){
    BS res;
    int borrow=0;
    for(int i=0;i<B;i++){
      int x=int(a[i])-b[i];
      x-=borrow;
      if(x<0){
        x+=2;
        borrow=1;
      }else{
        borrow=0;
      }
      res[i]=x;
    }
    return res;
  };
  auto lesseq=[&](const BS &a,const BS &b){
    for(int i=B-1;i>=0;i--){
      if(a[i]<b[i])return true;
      if(a[i]>b[i])return false;
    }
    return true;
  };
  dp[1][0]=1;
  dp[1][1]=1;
  for(int i=2;i<=F;i++){
    dp[i][0]=add(dp[i-1][0],dp[i-1][1]);
    dp[i][1]=dp[i-1][0];
  }
  int p=0;
  for(int i=0;i<17;i++){
    p|=seq[i]<<i;
  }
  vector<int> a;
  for(int i=17;i<m;i+=B){
    BS res;
    for(int j=0;j<B;j++){
      res[j]=seq[i+j];
    }
    for(int j=0;j<F;j++){
      if(lesseq(dp[F-j][0],res)){
        res=sub(res,dp[F-j][0]);
        a.emplace_back(1);
      }else{
        a.emplace_back(0);
      }
    }
  }
  for(int i=0;i<p;i++){
    Remove(i);
  }
  stack<int> s;
  for(int i=p+1;i<n;i++){
    if(a[i]){
      while(!s.empty()){
        Remove(s.top());
        s.pop();
      }
      Remove(i);
    }else{
      s.emplace(i);
    }
  }
  while(!s.empty()){
    Remove(s.top());
    s.pop();
  }
  Remove(p);
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 780 KB Output is correct
2 Correct 2 ms 800 KB Output is correct
3 Correct 2 ms 784 KB Output is correct
4 Correct 2 ms 784 KB Output is correct
5 Correct 2 ms 788 KB Output is correct
6 Correct 2 ms 784 KB Output is correct
7 Correct 2 ms 796 KB Output is correct
8 Correct 2 ms 924 KB Output is correct
9 Correct 2 ms 792 KB Output is correct
10 Correct 1 ms 796 KB Output is correct
11 Correct 2 ms 784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 105 ms 8304 KB Output is correct
2 Correct 106 ms 8332 KB Output is correct
3 Correct 114 ms 8240 KB Output is correct
4 Correct 98 ms 8360 KB Output is correct
5 Correct 113 ms 8488 KB Output is correct
6 Correct 111 ms 8688 KB Output is correct
7 Correct 114 ms 8628 KB Output is correct
8 Correct 106 ms 8440 KB Output is correct
9 Correct 108 ms 8372 KB Output is correct
10 Correct 105 ms 8400 KB Output is correct
11 Correct 113 ms 8644 KB Output is correct
12 Correct 97 ms 8464 KB Output is correct
13 Correct 52 ms 8856 KB Output is correct
14 Correct 200 ms 8508 KB Output is correct
15 Correct 137 ms 8424 KB Output is correct
16 Correct 120 ms 8548 KB Output is correct
17 Correct 52 ms 8548 KB Output is correct
18 Correct 34 ms 7012 KB Output is correct
19 Correct 34 ms 7048 KB Output is correct
20 Correct 137 ms 8552 KB Output is correct
21 Correct 102 ms 8436 KB Output is correct
22 Correct 53 ms 8452 KB Output is correct
23 Correct 102 ms 8508 KB Output is correct
24 Correct 110 ms 8432 KB Output is correct
25 Correct 36 ms 7228 KB Output is correct
26 Correct 51 ms 8616 KB Output is correct
27 Correct 74 ms 8508 KB Output is correct
28 Correct 53 ms 8436 KB Output is correct
29 Correct 34 ms 7152 KB Output is correct
30 Correct 82 ms 8528 KB Output is correct
31 Correct 43 ms 7108 KB Output is correct
32 Correct 90 ms 8532 KB Output is correct
33 Correct 93 ms 8488 KB Output is correct