QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#131620 | #4676. Amalgamated Artichokes | PetroTarnavskyi# | WA | 49ms | 377672kb | C++17 | 2.4kb | 2023-07-27 19:20:05 | 2023-07-27 19:21:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FILL(a, b) memset(a, b, sizeof(a))
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
const int N = 74;
const int MAX = 17474;
const int INF = 1e9 + 47;
int dp[MAX][N][N];
int mn[4][N][N];
char c[N][N];
PII moves[N][N][4];
int dx[4] = {0, 0, -1, 1};
int dy[4] = {-1, 1, 0, 0};
bool ok(int x){
return 0 <= x && x < N;
}
void prec(){
FOR(i, 0, N){
FOR(j, 0, N){
FOR(t, 0, 4){
int ni = i, nj = j;
while(ok(ni) && ok(nj) && c[i][j] == c[ni][nj]){
ni += dx[t];
nj += dy[t];
}
if(ok(ni) && ok(nj))
moves[i][j][t] = MP(ni, nj);
else
moves[i][j][t] = MP(-1, -1);
}
}
}
}
void calc(int idx){
set<pair<int, int>> q;
FOR(i, 0, N){
FOR(j, 0, N){
dp[idx][i][j] = dp[idx - 1][i][j];
q.insert(MP(dp[idx][i][j], i * N + j));
}
}
while(SZ(q)){
auto [dist, i] = *q.begin();
q.erase(q.begin());
int x = i / N;
int y = i % N;
FOR(t, 0, 4){
if(moves[x][y][t] == MP(-1, -1))
continue;
auto [nx, ny] = moves[x][y][t];
if(dp[idx][nx][ny] > dp[idx][x][y] + 1){
q.erase(MP(dp[idx][nx][ny], nx * N + ny));
dp[idx][nx][ny] = dp[idx][x][y] + 1;
q.insert(MP(dp[idx][nx][ny], nx * N + ny));
}
}
}
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
FOR (i, 0, N) FOR (j, 0, N) c[i][j] = 'a';
int n, m;
cin >> n >> m;
FOR (i, 0, n) FOR (j, 0, m) cin >> c[i][j];
prec();
/* FOR(i, 0, n){
FOR(j, 0, m){
FOR(t, 0, 4)
cout << moves[i][j][t].F << " " << moves[i][j][t].S << "\n";
cout << "\n";
}
}*/
FOR (t, 0, MAX) FOR (i, 0, N) FOR (j, 0, N) dp[t][i][j] = INF;
dp[0][0][0] = 0;
string s;
cin >> s;
s += '*';
FOR (step, 0, SZ(s))
{
calc(step + 1);
FOR (i, 0, N)
{
FOR (j, 0, N)
{
if (c[i][j] != s[step])
dp[step + 1][i][j] = INF;
//cout << dp[step + 1][i][j] << " ";
}
// cout << endl;
}
}
int ans = INF;
FOR (i, 0, n) FOR (j, 0, m) ans = min(ans, dp[SZ(s)][i][j]);
cout << ans + SZ(s) << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 49ms
memory: 377672kb
input:
42 1 23 4 8 10
output:
1000000048
result:
wrong answer 1st numbers differ - expected: '104.8551105', found: '1000000048.0000000', error = '9536969.0480107'