UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#210906#2068. 最长公共前缀_Alexande_01394ms3216kbC++111.8kb2024-08-08 09:47:172024-08-08 12:36:20

answer

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define fir first
#define sec second
#define mkp make_pair 
#define pb push_back
#define lep( i, l, r ) for ( int i = ( l ); i <= ( r ); ++ i )
#define rep( i, r, l ) for ( int i = ( r ); i >= ( l ); -- i )

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;

char _c; bool _f; template < class type > inline void read ( type &x ) {
	_f = 0, x = 0;
	while ( _c = getchar (), !isdigit ( _c ) ) if ( _c == '-' ) _f = 1;
	while ( isdigit ( _c ) ) x = x * 10 + _c - '0', _c = getchar (); if ( _f ) { x = -x; }
}

template < class type > inline void chkmin ( type &x, type y ) { x = ( x <= y ? x : y ); }
template < class type > inline void chkmax ( type &x, type y ) { x = ( x >= y ? x : y ); }

const int N = 2005;

int n, m, q;
char s[N][N];

string help ( int x, int y, char c ) {
  string tmp = "";
  if ( c == 'H' ) {
    while ( y <= m ) {
      tmp = tmp + s[x][y];
      y ++;
    }
  }
  else if ( c == 'V' ) {
    while ( x <= n ) {
      tmp = tmp + s[x][y];
      x ++;
    }
  }
  else {
    while ( x <= n && y <= m ) {
      tmp = tmp + s[x][y];
      x ++, y ++;
    }
  }
  return tmp;
}

void Solve () {
  cin >> n >> m >> q;
  for ( int i = 1; i <= n; i ++ ) {
    for ( int j = 1; j <= n; j ++ ) {
      cin >> s[i][j];
    }
  }
  while ( q -- ) {
    int a, b, x, y;
    char c, z;
    cin >> a >> b >> c >> x >> y >> z;
    string s = help ( a, b, c ), t = help ( x, y, z );
    int pos = 0;
    while ( s[pos] == t[pos] ) {
      pos ++;
    }
    cout << pos << '\n';
  }
}

signed main () {
#ifdef judge
  freopen ( "Code.in", "r", stdin );
  freopen ( "Code.out", "w", stdout );
  freopen ( "Code.err", "w", stderr );
#endif
  Solve ();
	return 0;
}

详细

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

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1394ms
memory: 3216kb

input:

1000 2000 10000
awanannwnnaaawwnwawanwnwaaaanwnaaananwawwwwnannannawwwawwaaaaannwnwnwnnaaawaawawannn...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

wrong answer 1st words differ - expected: '0', found: '1'

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