UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#210907#2068. 最长公共前缀Larryia070ms5144kbC++111.3kb2024-08-08 09:47:362024-08-08 12:36:30

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int n, m, Q;
char g[N][N];
char p[N];
char q[N];
int extr(char t[], int x, int y, char z) {
    if (z == 'H') {
        for (int i = y; i <= m; i++) {
            t[i - y + 1] = g[x][i];
        }
        return m - y + 1;
    }
    else if (z == 'V') {
        for (int i = x; i <= n; i++) {
            t[i - x + 1] = g[i][y];
        }
        return n - x + 1;
    }
    else {
        for (int i = x; i <= n; i++) {
            int j = y + i - x;
            if (j > m) {
                return i - x + 1;
            }
            t[i - x + 1] = g[i][j];
        }
        return n - x + 1;
    }
}
int main() {
    cin >> n >> m >> Q;
    for (int i = 1; i <= n; i++) {
        scanf("%s", (g[i] + 1));
    }
    while (Q--) {
        int a, b, x, y;
        char c, z;
        scanf("%d %d %c %d %d %c", &a, &b, &c, &x, &y, &z);
        int lp = extr(p, a, b, c);
        int lq = extr(q, x, y, z);
        if (lp > lq) {
            swap(lp, lq);
            swap(p, q);
        }
        bool flag = 1;
        for (int i = 1; i <= lp; i++) {
            if (p[i] != q[i])  {
                flag = 0;
                printf("%d\n", i - 1);
                break;
            }
        }
        if (flag) printf("%d\n", lp);
    }
    return 0;
}

Details

小提示:点击横条可展开更详细的信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 11
Accepted
time: 32ms
memory: 3192kb

input:

1000 2000 10000
awanannwnnaaawwnwawanwnwaaaanwnaaananwawwwwnannannawwwawwaaaaannwnwnwnnaaawaawawannn...

output:

0
0
0
0
0
0
0
2
0
1
0
0
1
0
1
0
2
0
1
2
0
0
2
0
1
1
0
0
0
0
1
0
0
0
1
0
0
1
0
1
1
0
2
0
1
3
1
0
3
0
...

result:

ok 10000 tokens

Test #2:

score: -11
Wrong Answer
time: 38ms
memory: 5144kb

input:

2000 1000 10000
zzqzqqqqqzqqqqzqqqqzqzqzzzqqzqqqzzqzzqqqqqqqqqqqzzqzqqqzzqqzzqzqzzzqqzqqzzzzzzqzzzqq...

output:

0
3
3
1
0
2
2
2
1
0
1
0
0
0
1
0
2
0
6
1
0
1
1
0
2
1
1
1
2
4
0
1
3
2
1
0
1
2
0
0
0
1
1
0
1
1
0
4
0
3
...

result:

wrong answer 2684th words differ - expected: '2', found: '3'

Subtask #2:

score: 0
Time Limit Exceeded

Test #3:

score: 0
Time Limit Exceeded

input:

2000 2000 1000000
gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg...

output:

1146
541
203
322
618
166
345
138
520
206
1031
667
741
921
361
1110
1057
372
899
209
491
69
93
639
14...

result:


Subtask #3:

score: 0
Skipped

Subtask #4:

score: 0
Skipped