답안 #631852

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
631852 2022-08-19T01:48:14 Z iee Strah (COCI18_strah) C++17
110 / 110
137 ms 66984 KB
// iee
#include <bits/stdc++.h>
#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using db = double;
using ld = long double;
#define py puts("YES")
#define pn puts("NO")
#define pf puts("-1")
#define hh puts("")
#define fi first
#define se second
#define mkp make_pair
#define re =RD()
#define rd RD()
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define ep emplace
#define ci const int
#define vi vector<int>
#define fn for(int i=1;i<=n;++i)
#define rep(stO,a,b) for(int stO=(a);stO<=(b);stO++)
#define Rep(stO,a,b) for(int stO=(a);stO<(b);stO++)
#define per(Orz,a,b) for(int Orz=(a);Orz>=(b);Orz--)
#define ina int n,a[N];
#define rna n=RD();fn a[i]=RD();
using namespace std;
void big(int &x,int y){if(y>x)x=y;}void sml(int &x,int y){if(y<x)x=y;}
int qpow(int a, int b, int p) { int res = 1 % p; while (b) { if (b % 2) res = 1ll * res * a % p; a = 1ll * a * a % p; b /= 2; } return res; }
int RD() { int x = 0, f = 1, ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + (ch - '0'); ch = getchar(); } return x * f; }
//ci p = 998244353 1000000007; int fac[N], inv[N], ifac[N]; int binom(int x, int y, int MOD = p) { if (x < y) return 0; return 1ll * fac[x] * ifac[y] % p * ifac[x - y] % p; } void init(int LIM = N - 1, int MOD = p) { fac[0] = ifac[0] = inv[1] = 1; rep(i, 1, LIM) fac[i] = 1ll * fac[i - 1] * i % MOD; rep(i, 2, LIM) inv[i] = 1ll * (MOD - MOD / i) * inv[MOD % i] % MOD; rep(i, 1, LIM) ifac[i] = 1ll * ifac[i - 1] * inv[i] % MOD; }
void work(int);

signed main() { int CASINPUT = 1;
  string op = R"(
                 )";if (op.size() == 19) cin >> CASINPUT; rep(CUR, 1, CASINPUT) work(CUR); }
int n, m, ans;
ci N = 2005;
int a[N][N], h[N][N];
char s[N];
int f(int x) { return x * (x + 1) / 2; }
int f(int l, int r) { return f(r) - f(l - 1); }
void solve(vi &v) {
 int s1 = 0, s2 = 0;
 stack<pii> s;
 Rep(i, 0, n) {
  pii x(v[i], 1);
  int rest = i;
  while (!s.empty() && s.top().fi >= x.fi) {
   s1 -= f(s.top().fi) * s.top().se;
   s2 -= f(s.top().fi) * f(rest - s.top().se + 1, rest);
   rest -= s.top().se;
   x.se += s.top().se;
   s.pop();
  }
  s.ep(x);
  s1 += x.se * f(x.fi);
  s2 += f(rest + 1, i + 1) * f(x.fi);
  ans += (i + 2) * s1 - s2;
 }
}
void work(int CASE) {
 n re, m re;
 Rep(i, 0, n) {
  scanf("%s", s);
  Rep(j, 0, m) {
   if (s[j] == '.') a[i][j] = 1;
   else a[i][j] = 0;
   h[i][j] = a[i][j];
  }
 }
 Rep(i, 0, n) Rep(j, 1, m)
  if (a[i][j]) h[i][j] += h[i][j - 1];
 Rep(i, 0, m) {
  vi v;
  Rep(j, 0, n) v.pb(h[j][i]);
  solve(v);
 }
 cout << ans;
}

Compilation message

strah.cpp: In function 'void work(long long int)':
strah.cpp:69:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |   scanf("%s", s);
      |   ~~~~~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4180 KB Output is correct
2 Correct 4 ms 4180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4196 KB Output is correct
2 Correct 5 ms 4180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4180 KB Output is correct
2 Correct 6 ms 4180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 24380 KB Output is correct
2 Correct 82 ms 50068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 44448 KB Output is correct
2 Correct 127 ms 64700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 47 ms 28492 KB Output is correct
2 Correct 108 ms 53372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 19260 KB Output is correct
2 Correct 100 ms 62168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 126 ms 66984 KB Output is correct
2 Correct 137 ms 66948 KB Output is correct