Submission #852049

#TimeUsernameProblemLanguageResultExecution timeMemory
852049MilosMilutinovicStrah (COCI18_strah)C++14
110 / 110
72 ms24292 KiB
#include <bits/stdc++.h> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define pb push_back #define eb emplace_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) typedef vector<int> VI; typedef basic_string<int> B; typedef long long ll; typedef pair<int,int> PII; typedef double db; mt19937 mrand(random_device{}()); const ll mod=1000000007; int rnd(int x) { return mrand() % x;} ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} // head const int N=2020; int n,m,R[N][N]; char s[N][N]; ll F(ll x) { return x*(x+1)/2; } int main() { scanf("%d%d",&n,&m); rep(i,0,n) { scanf("%s",s+i); } rep(i,0,n) { int p=0; rep(j,0,m) { if (s[i][j]=='#') p=j+1; else R[i][j]=p; } } ll ans=0; rep(j,0,m) { vector<array<int,3>> stk; ll coeff=0,dec=0; rep(i,0,n) { if (s[i][j]=='#') { coeff=0; dec=0; stk.clear(); continue; } int len=j-R[i][j]+1,to=i; while (SZ(stk)&&stk.back()[2]>=len) { coeff-=(stk.back()[1]-stk.back()[0]+1)*1ll*F(stk.back()[2]); dec-=(F(stk.back()[1])-F(stk.back()[0]-1))*1ll*F(stk.back()[2]); to=stk.back()[0]; stk.pop_back(); } coeff+=(i-to+1)*1ll*F(len); dec+=(F(i)-F(to-1))*1ll*F(len); ans+=(i+1)*coeff-dec; stk.pb({to,i,len}); } } printf("%lld",ans); }

Compilation message (stderr)

strah.cpp: In function 'int main()':
strah.cpp:35:11: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'char (*)[2020]' [-Wformat=]
   35 |   scanf("%s",s+i);
      |          ~^  ~~~
      |           |   |
      |           |   char (*)[2020]
      |           char*
strah.cpp:33:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |  scanf("%d%d",&n,&m);
      |  ~~~~~^~~~~~~~~~~~~~
strah.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |   scanf("%s",s+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...
#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...