結果
| 問題 |
No.440 2次元チワワ問題
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-10-29 16:32:12 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,572 bytes |
| コンパイル時間 | 1,266 ms |
| コンパイル使用メモリ | 115,688 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-24 18:02:07 |
| 合計ジャッジ時間 | 7,123 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 12 RE * 14 |
ソースコード
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;
class CWW
{
private:
int n;
vector<vector<int> > front, back;
public:
CWW(const string& s)
{
static const string cww = "cww";
n = s.size();
front.assign(n+1, vector<int>(4, 0));
back.assign(n+1, vector<int>(4, 0));
front[0][0] = 1;
back[0][0] = 1;
for(int i=0; i<n; ++i){
front[i+1] = front[i];
back[i+1] = back[i];
for(int j=0; j<3; ++j){
if(s[i] == cww[j])
front[i+1][j+1] += front[i][j];
if(s[n-1-i] == cww[2-j])
back[i+1][j+1] += back[i][j];
}
}
}
int get(int a, int b)
{
int ans = front[n][3];
for(int i=1; i<=3; ++i){
ans -= front[a-1][i] * back[n+1-a][3-i];
ans -= back[n-b][i] * front[b][3-i];
}
for(int i=1; i<=2; ++i){
ans += front[a-1][i] * back[n-b][3-i];
}
ans += front[a-1][1] * (back[n+1-a][1] - back[n-b][1]) * back[n-b][1];
return ans;
}
};
int main()
{
int h, w;
cin >> h >> w;
vector<string> s(h);
for(int i=0; i<h; ++i)
cin >> s[i];
int q;
cin >> q;
vector<int> y1(q), x1(q), y2(q), x2(q);
for(int i=0; i<q; ++i)
cin >> y1[i] >> x1[i] >> y2[i] >> x2[i];
vector<long long> ans(q, 0);
for(int r=0; r<4; ++r){
for(int y=1; y<=h; ++y){
CWW cww(s[y-1]);
for(int i=0; i<q; ++i){
if(y1[i] <= y && y <= y2[i])
ans[i] += cww.get(x1[i], x2[i]);
}
}
vector<string> t(w, string(h, ' '));
for(int y=0; y<h; ++y){
for(int x=0; x<w; ++x){
t[x][h-1-y] = s[y][x];
}
}
s.swap(t);
for(int i=0; i<q; ++i){
swap(y1[i], x1[i]);
swap(y2[i], x2[i]);
x1[i] = w + 1 - x1[i];
x2[i] = w + 1 - x2[i];
swap(x1[i], x2[i]);
}
swap(h, w);
}
for(int i=0; i<q; ++i)
cout << ans[i] << endl;
return 0;
}