Submission #676953

# Submission time Handle Problem Language Result Execution time Memory
676953 2023-01-01T18:03:49 Z MohammadAghil Painting Walls (APIO20_paint) C++17
0 / 100
4 ms 7304 KB
      #include <bits/stdc++.h>
#include "paint.h"
//   #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
 using namespace std;
  typedef long long ll;
   typedef pair<int, int> pp;
     #define per(i,r,l) for(int i = (r); i >= (l); i--)
       #define rep(i,l,r) for(int i = (l); i < (r); i++)
          #define all(x) begin(x), end(x)
             #define sz(x) (int)(x).size()
                 #define pb push_back
                     #define ss second
                          #define ff first
                                  void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
void IOS(){
     cin.tie(0) -> sync_with_stdio(0);
     #ifndef ONLINE_JUDGE
          #define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
     #else
          #define er(args ...) 0
     #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 3e5 + 5, lg = 22, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll,md);return k*k%md*(b&1ll?a:1)%md;}

int vl[maxn], m;
vector<int> lik[maxn];

int add(int x, int y){
     x += y;
     if(x >= y) x -= m;
     return x;
}
int rem(int x, int y){
     x -= y;
     if(x < 0) x += m;
     return x;
}

int minimumInstructions(int n, int m, int k, vector<int> c, vector<int> a, vector<vector<int>> b){
     ::m = m;
     rep(i,0,m){
          rep(j,0,a[i]){
               lik[b[i][j]].pb(i);
          }
     }
     int bs = 0, cntm = 0;

     auto upd = [&](int p, int k){
          cntm -= vl[p] == m;
          vl[p] += k;
          cntm += vl[p] == m;
     };

     rep(i,0,m){
          for(int x: lik[c[i]]){
               upd(rem(x, i), 1);
          }
     }

     int lst = -1, mx = -1, ans = 0;
     rep(i,0,n-m+1){
          if(cntm) mx = i + m - 1;
          if(i > lst){
               lst = mx;
               ans++;
               if(i > lst){
                    return -1;
               }
          }
          if(i == n - m) break;
          for(int x: lik[c[i]]){
               upd(add(bs, x), -1);
          }
          for(int x: lik[c[i + m]]){
               upd(add(bs, x), 1);
          }
          rem(bs, -1);
     }
     if(lst - n + 1) {
          if(mx == n-1) ans++;
          else {
               return -1;
          }
     }
     return ans;
}

// int main(){ IOS();
//      int n, k; cin >> n >> m >> k;
//      rep(i,0,n){
//           cin >> c[i];
//      }
//      rep(i,0,m){
//           int a; cin >> a;
//           rep(j,0,a){
//                int cl; cin >> cl;
//                lik[cl].pb(i);
//           }
//      }
//      int bs = 0, cntm = 0;

//      auto upd = [&](int p, int k){
//           cntm -= vl[p] == m;
//           vl[p] += k;
//           cntm += vl[p] == m;
//      };

//      rep(i,0,m){
//           for(int x: lik[c[i]]){
//                upd(rem(x, i), 1);
//           }
//      }

//      int lst = -1, mx = -1, ans = 0;
//      rep(i,0,n-m+1){
//           if(cntm) mx = i + m - 1;
//           if(i > lst){
//                lst = mx;
//                ans++;
//                if(i > lst){
//                     cout << -1 << '\n';
//                     return 0;
//                }
//           }
//           if(i == n - m) break;
//           for(int x: lik[c[i]]){
//                upd(add(bs, x), -1);
//           }
//           for(int x: lik[c[i + m]]){
//                upd(add(bs, x), 1);
//           }
//           rem(bs, -1);
//      }
//      if(lst - n + 1) {
//           if(mx == n-1) ans++;
//           else {
//                cout << -1 << '\n';
//                return 0;
//           }
//      }
//      cout << ans << '\n';
//      return 0-0;
// }
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7304 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Incorrect 4 ms 7252 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7304 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Incorrect 4 ms 7252 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7304 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Incorrect 4 ms 7252 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7304 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Incorrect 4 ms 7252 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 7304 KB Output is correct
2 Correct 4 ms 7252 KB Output is correct
3 Incorrect 4 ms 7252 KB Output isn't correct
4 Halted 0 ms 0 KB -