Submission #209799

#TimeUsernameProblemLanguageResultExecution timeMemory
209799NucleistLamps (JOI19_lamps)C++14
4 / 100
156 ms158928 KiB
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
string kal,kal1;
ll n;
ll dp[1000001][8];
ll on[1000001],off[1000001],tog[1000001],noth[1000001];
ll on1[1000001],off1[1000001],tog1[1000001],noth1[1000001];
bool check(ll x)
{
    if(x>=0 && x<n)return true;
    return false;
}
ll solve(ll index,ll state)
{
    ll ans=INF;
    if(index>=n)return 0; 
    if(dp[index][state]!=-1)return dp[index][state];
    if(check(on[index]))
    {
        ans=min(ans,1+solve(on[index]+1,1));
    }
    if(check(noth[index]))
    {
        ans=min(ans,solve(noth[index]+1,1));
    }
    if(check(off[index]))
    {
        ans=min(ans,1+solve(off[index]+1,1));
    }
    if(check(tog[index]))
    {
        ans=min(ans,1+solve(tog[index]+1,1));
    }
    if(state==1)
    {
    if(check(on1[index]))
    {
        ans=min(ans,2+solve(on1[index]+1,2));
    }
    if(check(noth1[index]))
    {
        ans=min(ans,1+solve(noth1[index]+1,2));
    }
    if(check(off1[index]))
    {
        ans=min(ans,2+solve(off1[index]+1,2));
    }
    if(check(tog1[index]))
    {
        ans=min(ans,2+solve(tog1[index]+1,2));
    }
    }
    if(state==2)
    {
      if(check(on1[index]))
    {
        ans=min(ans,1+solve(on1[index]+1,2));
    }
    if(check(noth1[index]))
    {
        ans=min(ans,solve(noth1[index]+1,2));
    }
    if(check(off1[index]))
    {
        ans=min(ans,1+solve(off1[index]+1,2));
    }
    if(check(tog1[index]))
    {
        ans=min(ans,1+solve(tog1[index]+1,2));
    }  
    }
    /*if(kal[index]==0)
    {
        if(kal1[index]==kal[index])
        {
            
        }
        else
        {
            
        }
    }
    else
    {
        if(kal1[index]==kal[index])
        {
        }
        else
        {
        }
    }*/
    return dp[index][state]=ans;
}
ll preprocess(ll arr[])
{
  ll fin=-1;
  ll deb=-1;
  bool ka=false;
  for (ll i = 0; i < n; ++i)
  {
    if(arr[i]==0)
      {
        if(deb!=-1 && fin!=-1)
        {
            for (ll j = deb; j <= fin; ++j)
        {
            arr[j]=fin;
        }
        }
        deb=fin=-1;
        ka=false;
        arr[i]=-1;
      }
      else if(!ka)
      {
        ka=true;
        deb=fin=i;
      }
      else
      {
        fin++;
      }
  }
  if(deb!=-1)
  {
    for (ll j = deb; j <= fin; ++j)
        {
            arr[j]=fin;
        }
  }
}
int main()
{
  flash;
  cin>>n;
  cin>>kal>>kal1;
  memset(dp,-1,sizeof dp);
  for (ll i = 0; i < kal.size(); ++i)
  {
    if(kal[i]=='0')
    {
        if(kal1[i]==kal[i])
        {
            off[i]=1;
            noth[i]=1;
            tog1[i]=1;
            on1[i]=1;
        }
        else
        {
            on[i]=1;
            tog[i]=1;
            off1[i]=1;
            noth1[i]=1;
        }
    }
    else
    {
        if(kal1[i]==kal[i])
        {
            on[i]=1;
            noth[i]=1;
            tog1[i]=1;
            off1[i]=1;
        }
        else
        {
           off[i]=1;
           tog[i]=1;
           on1[i]=1;
           noth1[i]=1;
        }
    }
  }
  preprocess(off);
  preprocess(on);
  preprocess(tog);
  preprocess(noth);
  preprocess(off1);
  preprocess(on1);
  preprocess(tog1);
  preprocess(noth1);
  cout<<solve(0,1);
  return 0;
}
//code the AC sol !
// BS/queue/map

Compilation message (stderr)

lamp.cpp:4:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("O3")
 
lamp.cpp:5:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("unroll-loops")
 
lamp.cpp: In function 'long long int preprocess(long long int*)':
lamp.cpp:152:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
lamp.cpp: In function 'int main()':
lamp.cpp:159:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (ll i = 0; i < kal.size(); ++i)
                  ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...