結果

問題 No.874 正規表現間距離
ユーザー tnakao0123
提出日時 2019-09-05 13:02:07
言語 C++11
(gcc 13.3.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,919 bytes
コンパイル時間 1,207 ms
コンパイル使用メモリ 85,468 KB
実行使用メモリ 19,200 KB
最終ジャッジ日時 2024-06-11 07:02:58
合計ジャッジ時間 2,044 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 38
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:67:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   67 |   scanf("%s%s", sa, sb);
      |   ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #
プレゼンテーションモードにする

/* -*- coding: utf-8 -*-
*
* 874.cc: No.874 - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_N = 2000;
const int INF = 1 << 30;
/* typedef */
typedef pair<char,char> pcc;
/* global variables */
char sa[MAX_N + 4], sb[MAX_N + 4];
pcc as[MAX_N + 1], bs[MAX_N + 1];
int dp[MAX_N + 1][MAX_N + 1];
/* subroutines */
int parse(char s[], pcc v[]) {
int n = 0;
for (int i = 0; s[i]; i++) {
if (s[i] == '?') v[n - 1].second = '?';
else if (s[i] == '*') v[n - 1].second = '*';
else v[n++] = pcc(s[i], '.');
}
return n;
}
void printpcc(int n, pcc v[]) {
for (int i = 0; i < n; i++) {
putchar(v[i].first);
putchar(v[i].second);
}
putchar('\n');
}
inline void setmin(int &a, int b) { if (a > b) a = b; }
/* main */
int main() {
scanf("%s%s", sa, sb);
int an = parse(sa, as);
int bn = parse(sb, bs);
//printpcc(an, as); printpcc(bn, bs);
for (int i = 0; i <= an; i++)
fill(dp[i], dp[i] + bn + 1, INF);
dp[0][0] = 0;
for (int i = 0; i <= an; i++) {
char &ac = as[i].first, &am = as[i].second;
for (int j = 0; j <= bn; j++) {
char &bc = bs[j].first, &bm = bs[j].second;
if (i < an && j < bn) {
setmin(dp[i + 1][j + 1], dp[i][j] + ((ac != bc) ? 1 : 0));
if (am == '*' && ac == bc)
setmin(dp[i][j + 1], dp[i][j]);
if (bm == '*' && ac == bc)
setmin(dp[i + 1][j], dp[i][j]);
}
if (i < an)
setmin(dp[i + 1][j], dp[i][j] + ((am == '.') ? 1 : 0));
if (j < bn)
setmin(dp[i][j + 1], dp[i][j] + ((bm == '.') ? 1 : 0));
}
}
printf("%d\n", dp[an][bn]);
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0