QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#541623#1995. Sprinklers 2: Return of the AlfalfaDimash0 0ms0kbC++172.6kb2024-08-31 20:13:562024-08-31 20:13:57

Judging History

你现在查看的是最新测评结果

  • [2024-08-31 20:13:57]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2024-08-31 20:13:56]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
    
typedef long long ll;
const int  N = 2e3 + 12, MOD = (int)1e9 + 7;

ll binpow(ll a, ll b) {
    ll ret = 1,k = a;
    while(b) {
        if(b & 1) {
            ret *= k;
            ret %= MOD;
        }
        k *= k;
        k %= MOD;
        b >>= 1;
    }
    return ret;
}
int n, a[N][N], s[N][N], st[N * N], col = 0, dp[N][N], pref[N][N];
int res = 0;
void add(int &a, int b) {
    a += b;
    if(a >= MOD) a -= MOD;
}
void test() {
    cin >> n;
    st[0] = 1;
    for(int i = 1; i <= n * n; i++) {
        st[i] = (st[i - 1] + st[i - 1]) % MOD;
    }
    int div2 = binpow(2, MOD - 2);
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            char x;
            cin >> x;
            a[i][j] = (x == '.');
            col += a[i][j];
        }
    }
    dp[0][0] = st[col];
    for(int i = 1; i <= n; i++) {
        pref[0][i] = st[col];
        if(i == 1 || a[1][i - 1]) {
            s[0][i] = pref[0][i];
        }
    }
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= n; j++) {
            // for(int i1 = i - 1; i1 >= 0; i1--) {
            //     if(j == 1 || a[i1 + 1][j - 1]) {
            //         for(int j1 = j - 1; j1 >= 0; j1--) {
            //             int _ = div2;
            //             if(j != 1) {
            //                 _ = (_ *1ll* div2)%MOD;
            //             }
            //             add(dp[i][j], dp[i1][j1] * 1ll * _ % MOD);
            //         }
            //     }
            // }
            s[i][j] = s[i - 1][j];
            pref[i][j] = pref[i][j - 1];
            if(a[i][j]) {
                int _ = div2;
                if(j != 1) {
                    _ = (_ *1ll* div2)%MOD;
                }
                add(dp[i][j],s[i - 1][j] * 1ll * _ % MOD);
            }
            if(j == 1 || a[i + 1][j - 1]) {
                add(s[i][j], pref[i][j - 1]);
            }
            add(pref[i][j],dp[i][j]);
            int cf = 1;
            if(i == n || a[i + 1][n]) {
                if(i != n) {
                    cf = div2;
                }
                add(res,dp[i][j] * 1ll * cf % MOD);
            }
        }
    }
    if(a[1][n]) {
        add(res, st[col - 1]);
    }
    cout << res << '\n';
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    freopen("sprinklers2.in","r",stdin);
    freopen("sprinklers2.out","w",stdout); 

    int t = 1; 
    // cin >> t;
    while(t--) 
        test();

    return 0;
}   

詳細信息


Pretests


Final Tests

Test #1:

score: 0
Dangerous Syscalls

input:

2
..
..

output:


result:


Test #2:

score: 0
Dangerous Syscalls

input:

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

output:


result:


Test #3:

score: 0
Dangerous Syscalls

input:

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

output:


result:


Test #4:

score: 0
Dangerous Syscalls

input:

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

output:


result:


Test #5:

score: 0
Dangerous Syscalls

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:


result:


Test #6:

score: 0
Dangerous Syscalls

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:


result:


Test #7:

score: 0
Dangerous Syscalls

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:


result:


Test #8:

score: 0
Dangerous Syscalls

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:


result:


Test #9:

score: 0
Dangerous Syscalls

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:


result:


Test #10:

score: 0
Dangerous Syscalls

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:


result:


Test #11:

score: 0
Dangerous Syscalls

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:


result:


Test #12:

score: 0
Dangerous Syscalls

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:


result:


Test #13:

score: 0
Dangerous Syscalls

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:


result:


Test #14:

score: 0
Dangerous Syscalls

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:


result:


Test #15:

score: 0
Dangerous Syscalls

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:


result:


Test #16:

score: 0
Dangerous Syscalls

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:


result: