QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#532999#1995. Sprinklers 2: Return of the AlfalfaRainPPR100 ✓46ms51184kbC++201.3kb2024-08-25 15:35:452024-08-25 15:35:45

Judging History

This is the latest submission verdict.

  • [2024-08-25 15:35:45]
  • Judged
  • Verdict: 100
  • Time: 46ms
  • Memory: 51184kb
  • [2024-08-25 15:35:45]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

#define endl "\n"

// -----------------------------------------------------------------------------

constexpr int MOD = 1e9 + 7;

int qpow(int a, int b, int p) {
	int r = 1;
	for (; b; b >>= 1) {
		if (b & 1)
			r = 1ll * r * a % p;
		a = 1ll * a * a % p;
	}
	return r;
}

const int inv = qpow(2, MOD - 2, MOD);

#define add(x, y) ((x) = ((x) + (y)) % MOD)

constexpr int N = 2010;

int n, A[N][N];

int F[N][N][2];

void Main() {
	cin >> n;
	int cnt = 0;
	for (int i = 1; i <= n; ++i) {
		string str;
		cin >> str;
		for (int j = 1; j <= n; ++j) {
			int c = str[j - 1] == '.';
			cnt += (A[i][j] = c);
		}
	}
	F[0][0][0] = F[0][0][1] = qpow(2, cnt, MOD);
	for (int i = 0; i <= n; ++i)
		for (int j = 0; j <= n; ++j) {
			if (i) {
				add(F[i][j][1], F[i - 1][j][1]);
				if (A[i][j])
					add(F[i][j][1], 1ll * F[i - 1][j][0] * inv % MOD);
			}
			if (j) {
				add(F[i][j][0], F[i][j - 1][0]);
				if (A[i][j])
					add(F[i][j][0], 1ll * F[i][j - 1][1] * inv % MOD);
			}
		}
	cout << (F[n][n][0] + F[n][n][1]) % MOD << endl;
}

// -----------------------------------------------------------------------------

signed main() {
//	freopen("rural.in", "r", stdin);
//	freopen("rural.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(nullptr);
	Main();
	return 0;
}


詳細信息


Pretests


Final Tests

Test #1:

score: 6.25
Accepted
time: 1ms
memory: 5568kb

input:

2
..
..

output:

28

result:

ok single line: '28'

Test #2:

score: 6.25
Accepted
time: 1ms
memory: 5572kb

input:

4
..W.
..WW
WW..
...W

output:

2304

result:

ok single line: '2304'

Test #3:

score: 6.25
Accepted
time: 1ms
memory: 5636kb

input:

7
.WWWW..
W.WWWWW
W.WW.W.
WWWWWWW
WWW.WWW
WWWWWWW
WW.WWW.

output:

1088

result:

ok single line: '1088'

Test #4:

score: 6.25
Accepted
time: 1ms
memory: 5644kb

input:

10
WWW..WWWWW
WWWWWWWWWW
WWWWWWWWWW
WWWW.WWWWW
WWWWWWWW..
WWWWWWWWWW
WWWWWWWWWW
WWWW.WWW.W
WWWWWWWWW.
W.WWWW.WWW

output:

256

result:

ok single line: '256'

Test #5:

score: 6.25
Accepted
time: 0ms
memory: 8844kb

input:

200
..W...W.W..WWW....W...W..W........W..W.W...W.WW.WWW.WWW..W....WW.WW.........W..WW.WW..WW....WW...W..W.W.WW.WWW.W...W....W.WW.........W.W.WW.WWW...........W...W..W.....W..W.......W..WW.WW......W...WWW.
W..WWWW.W......W.....W......WW.W.W....W.WW.W........WW...W...WW.W.W...W...W...WW.W.WW....W..WW....

output:

73928933

result:

ok single line: '73928933'

Test #6:

score: 6.25
Accepted
time: 2ms
memory: 8732kb

input:

200
..W....W.W.W..W..W.W..WWW.WW...W...W...W.W.W.....WW....W..W..W..WW....W.....WWW..W.......WW.W..WW..W.WW.....W.W.W.W..W.WW..WW..W...W....WW...W.W...W.W.W....W............WW.W..W......W.W.......W.W.....
W.....W...............W..W.....WWWWWWW.WW....W....WW.W...W...W....W.WW.WW..W.....W.WWWW..W.W......

output:

986875102

result:

ok single line: '986875102'

Test #7:

score: 6.25
Accepted
time: 1ms
memory: 6676kb

input:

200
.W.......W.........W.W.W.W..W.....W..WW.W.W.WWW...W..W..W...W..W.W.W..W..W..W.....W..W....W.W....WWW.W..W.WW..WW.....W.........W......WWW....W.WW..........WWW.W.W..........W..W..WWW.W...WW.....WW.....
..W.W.....W..W...WW....WWWW....WW......W.WWW.WW.W.......W....WW.WW.......W.W.W...WWWW......W..W...

output:

980557628

result:

ok single line: '980557628'

Test #8:

score: 6.25
Accepted
time: 2ms
memory: 8816kb

input:

200
W.WWW.....W...WWWW...WW..W.......WW...W.W.....W..W..W........WWWW.W.WW.W...WW.WW..WW......WW...WWW.......W...WW....W..W.....W.W..WWW.W.W..W......W...W...W.W..W.WW.W...W...W.W...W..W.WW.W..W...W..W.W.W
WW.....W.W..W.W......W.W..WW...W...W..........W...W..W.W.W...W.W....WW.W.W.WW...WW.W..W...WWW.....

output:

135705039

result:

ok single line: '135705039'

Test #9:

score: 6.25
Accepted
time: 2ms
memory: 9076kb

input:

200
..W.W..W.W.WW.WW.W.W...WW...W..W...W.WW.W.W......W....W.W.WW...WW.WW.WWW.W...W.......W.W.W..WW.WWW..W..WW......WW.W...WW...WW...WWW..W....W.WW.......W..W.W.....WWWW.W....WW...W....W..W...W....WW..W..W
W......WWWW.....W..........WW..W.W.....W...W...WWW......WW.......WW...WW......W.WW.W...W...WW.W...

output:

153872030

result:

ok single line: '153872030'

Test #10:

score: 6.25
Accepted
time: 39ms
memory: 50804kb

input:

2000
W......WWWWW.W..WW......W.....WWW.......W.W.W..WW...W.....W..W..W....WWW.W.WWWW.W..W...W....W......W..WWW.WW......WW..W..W.......W.......WW..........W..WW..W..W..WWW.WW....W......W...WW.WW......W..WW......W.WW.W.W..W...W.....W.........WW.W...W...WW.WW..WWW..WW.W.WWWW....W.WW........WW.....W.W.....

output:

375172260

result:

ok single line: '375172260'

Test #11:

score: 6.25
Accepted
time: 39ms
memory: 50876kb

input:

2000
W.WW.....W..WW.................WWW..W....W.W.WWW...W.W........WW....W..W........W.W........W.......WW..WWW..W...WW..WW...WWWW..WWWW.W.......W....W...W...W.....W...WW...WWW...WW..W.WW..W....W.WW.........WWW.W..W...WW...WWW...WWW....W..W....WW....WW.W.........W...W...WWW..WW.............W...........

output:

831890193

result:

ok single line: '831890193'

Test #12:

score: 6.25
Accepted
time: 39ms
memory: 50884kb

input:

2000
.W....W.WW.W....WW..W.W....W.WW.W....WW.WW.....WW..W.W.........W.W.WWWW.WWWWWWWW.W....W.W..WW...W..W..W...W...W.W.W..W...WWW...WWW.....WW...W..W..W.W...........W.W..........WW...WWW..W..W..W..W.....W.W..W....WW.W.WW.WW...W..W.W....W.WW..WWW...WW..W...W........W..W.WWW..W......W.W..WW..WW...W......

output:

380858206

result:

ok single line: '380858206'

Test #13:

score: 6.25
Accepted
time: 38ms
memory: 51184kb

input:

2000
WW..WW..WW.WW.W...W....W...WWWW...W..W.W.W....W.W.W..W....W..W..W.W......W....WW...W..WW..W.........W.W....W..W.WW.WW......W..W.W....W..WW.WWW.WWW..WW..W.W.W.....WWW..WW..W.W...W.WW.W.W...W..........W...W..W....W...W....WW........W.W...WW..W..W...WW.WW....W.......W..WWW.W...W......WWW.WW..W..W....

output:

178610652

result:

ok single line: '178610652'

Test #14:

score: 6.25
Accepted
time: 35ms
memory: 50792kb

input:

2000
W...W..W...W.W.WW..WW....WW...W..WWW..W...W.WW.W......WW......WWW...W........WW.WWWW..W.....W.WW..W...W...WW..W...WW.W...W..WW......W.W.....W...W....W..W....W.W.W.....WW.....W.....WW...W.W.W.WW.W..W..W......W...WWW....WW...WWW..W.....W..W...WW....W.WW.W.W.W...W.W......W.....W..WWW.WW...WW..W..W...

output:

464018318

result:

ok single line: '464018318'

Test #15:

score: 6.25
Accepted
time: 37ms
memory: 50888kb

input:

2000
.WW.....W.W.......W...W.WWW.W..W..W.W.....W...WW.WW...W...WW..W.W.W...W.WWWW.W...W.W...WW.W.W..W...W.W.W...WWW..WW....W.W......WW.WWW....W..W.W.W.W.WW....WW....W..W...W..WW.....WWW.W...W.....W..WWWW.WW........W....W.....WWW...........WW......W.W..WW.W..WW..W.W..WW.WW.W.W.W....WW..W...WW.W..W.WW...

output:

751601279

result:

ok single line: '751601279'

Test #16:

score: 6.25
Accepted
time: 46ms
memory: 50880kb

input:

2000
.WW..WWWWW..W...W........WWWWW..W......W..WW.........WWWW....W.W.W.W..W.......W.WW..WW..WW..W.WW....W...W.WWW..W...W.....W.WW......W......W.WW.W..WWW.WWW....W....W.WW.............W.W.W...W.W......W....W.W.........W.WW....WW.......WW....W.W.W..W.W.W....W....WW.W.W.....W.........WW...W.....W.W......

output:

839346390

result:

ok single line: '839346390'