Submission #201578

#TimeUsernameProblemLanguageResultExecution timeMemory
201578ArKCaBob (COCI14_bob)C++17
0 / 120
1079 ms8568 KiB
#include<bits/stdc++.h> #define f1 first #define s2 second #define pb push_back #define pob pop_back #define int ll #define ll long long #define PII pair<int,int> #define N 1003 using namespace std; int n,m,ans; int st[4*N],dizi[N],sagtosol[N]; int matris[N][N]; void build(int v, int tl,int tr){ if(tl==tr){ st[v]=tl; } else{ int tm=(tl+tr)/2; build( v*2, tl, tm ); build( v*2+1, tm+1, tr ); if(dizi[st[v*2]]<dizi[st[v*2+1]]){ st[v]=st[v*2]; } else{ st[v]=st[v*2+1]; } } } int query( int v, int tl, int tr, int l, int r ){ if(l>r){ return 0; } if(l==tl && r==tr){ return st[v]; } int tm=(tl+tr)/2; int allah,belani,versin; allah=query( v*2, tl, tm,l,min(tm,r) ); belani=query( v*2+1, tm+1, tr,max(l,tm+1),r ); if(dizi[allah]<dizi[belani]){ versin=allah; } else{ versin=belani; } return versin; } void calc(int ss,int se,int last,int kat){ if(ss>se) return; if(se==ss){ ans+=dizi[se]; ans-=last; return; } int mn=query(1,1,m,ss,se); if(mn==0)return; for(int i=1;i<=m;i++){ ans+=dizi[mn]*min(se-i+1,sagtosol[i]); ans-=last*min(se-i+1,sagtosol[i]); } calc(ss,mn-1,dizi[mn],kat); calc(mn+1,se,dizi[mn],kat); } int32_t main(){ // freopen("a.gir","r",stdin); // freopen("a.cik","w",stdout); scanf("%lld %lld",&n,&m); dizi[0]=INT_MAX; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ scanf("%lld",&matris[i][j]); } } for(int i=1;i<=m;i++){ dizi[i]=1; } sagtosol[m]=1; for(int i=m-1;i>0;i--){ if(matris[1][i]==matris[1][i+1]){ sagtosol[i]=sagtosol[i+1]+1; } else{ sagtosol[i]=1; } } build(1,1,m); calc(1,m,0,1); for(int j=2;j<=n;j++){ for(int i=1;i<=m;i++){ if(matris[j-1][i]==matris[j][i]) dizi[i]++; else dizi[i]=1; } sagtosol[m]=1; for(int i=m-1;i>0;i--){ if(matris[j][i]==matris[j][i+1]){ sagtosol[i]=sagtosol[i+1]+1; } else{ sagtosol[i]=1; } } /*for(int i=1;i<=m;i++){ printf("%lld ",dizi[i] ); } printf("\n");*/ build(1,1,m); calc(1,m,0,1); // printf("%lld\n",ans ); } printf("%lld\n",ans ); }

Compilation message (stderr)

bob.cpp: In function 'int32_t main()':
bob.cpp:76:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld",&n,&m);
  ~~~~~^~~~~~~~~~~~~~~~~~~
bob.cpp:80:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%lld",&matris[i][j]);
    ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...