QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#462455#6600. Whispers of the Old GodsJCY_AC ✓352ms414604kbC++143.6kb2024-07-03 19:43:592024-07-03 19:44:00

Judging History

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

  • [2024-07-03 19:44:00]
  • 评测
  • 测评结果:AC
  • 用时:352ms
  • 内存:414604kb
  • [2024-07-03 19:43:59]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using i128 = __int128;
using u128 = unsigned __int128;
template <typename T>
void chkmax(T &x, const T &y) {
  x = max(x, y);
}
template <typename T>
void chkmin(T &x, const T &y) {
  x = min(x, y);
}
constexpr int MAXLEN = 5010, MAXTOT = 1e4 + 10, INF = 0x3f3f3f3f;
int tpn, tpo, tot, dis[MAXTOT][MAXTOT];
bitset<MAXTOT> vis[MAXTOT];
char stko[MAXLEN];
pair<int, int> stkn[MAXLEN];
vector<pair<int, char>> g[MAXTOT];
deque<pair<int, int>> qu;
pair<int, int> new_node(const string &expr) {
  int x = ++tot, y = ++tot;
  for (auto c : expr) g[x].emplace_back(y, c);
  return {x, y};
}
pair<int, int> repeat(const pair<int, int> &u) {
  int x = ++tot, y = ++tot;
  g[x].emplace_back(u.first, '\0');
  g[u.second].emplace_back(y, '\0');
  g[u.second].emplace_back(u.first, '\0');
  return {x, y};
}
pair<int, int> concat(const pair<int, int> &u, const pair<int, int> &v) {
  g[u.second].emplace_back(v.first, '\0');
  return {u.first, v.second};
}
pair<int, int> alter(const pair<int, int> &u, const pair<int, int> &v) {
  int x = ++tot, y = ++tot;
  g[x].emplace_back(u.first, '\0');
  g[x].emplace_back(v.first, '\0');
  g[u.second].emplace_back(y, '\0');
  g[v.second].emplace_back(y, '\0');
  return {x, y};
}
void push(char op) {
  if (op == '+') {
    stkn[tpn] = repeat(stkn[tpn]);
  } else if (op == '*') {
    stkn[tpn - 1] = concat(stkn[tpn - 1], stkn[tpn]);
    --tpn;
  } else {
    assert(op == '|');
    stkn[tpn - 1] = alter(stkn[tpn - 1], stkn[tpn]);
    --tpn;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string expr, tar;
  cin >> expr >> tar;
  for (int i = 0; i < (int)expr.size(); ++i) {
    if (i && (expr[i] == '(' || isdigit(expr[i]) || expr[i] == '[') && (expr[i - 1] != '|' && expr[i - 1] != '(')) {
      while (tpo && stko[tpo] != '(' && stko[tpo] != '|') push(stko[tpo--]);
      stko[++tpo] = '*';
    }
    if (isdigit(expr[i])) {
      stkn[++tpn] = new_node(string{expr[i]});
    } else if (expr[i] == '[') {
      int j = expr.find(']', i);
      stkn[++tpn] = new_node(expr.substr(i + 1, j - i - 1));
      i = j;
    } else if (expr[i] == '(') {
      stko[++tpo] = '(';
    } else if (expr[i] == ')') {
      while (stko[tpo] != '(') push(stko[tpo--]);
      --tpo;
    } else if (expr[i] == '+') {
      while (tpo && stko[tpo] == '+') push(stko[tpo--]); 
      stko[++tpo] = '+';
    } else {
      assert(expr[i] == '|');
      while (tpo && stko[tpo] != '(') push(stko[tpo--]);
      stko[++tpo] = '|';
    }
  }
  while (tpo) push(stko[tpo--]);
  assert(tpn == 1);
  int s, t;
  tie(s, t) = stkn[1];
  memset(dis, 0x3f, sizeof(dis));
  dis[s][0] = 0;
  qu.emplace_back(s, 0);
  while (!qu.empty()) {
    int x, y;
    tie(x, y) = qu.front();
    qu.pop_front();
    if (vis[x][y]) continue;
    if (x == t && y == (int)tar.size()) break;
    vis[x][y] = true;
    auto upd = [&](int nx, int ny, int d) {
      if (dis[x][y] + d < dis[nx][ny]) {
        dis[nx][ny] = dis[x][y] + d;
        if (d) {
          qu.emplace_back(nx, ny);
        } else {
          qu.emplace_front(nx, ny);
        }
      }
    };
    for (auto &i : g[x]) {
      upd(i.first, y, (bool)i.second);
      if (y != (int)tar.size()) upd(i.first, y + 1, tar[y] != i.second);
    }
    if (y != (int)tar.size()) upd(x, y + 1, 1);
  }
  cout << dis[t][tar.size()] << "\n";
  return 0;
}
/*
g++ whisper.cpp -o whisper -std=c++14 -O2 -Wall -Wextra -Wshadow -g -fsanitize=address,undefined
*/

详细

Test #1:

score: 100
Accepted
time: 12ms
memory: 397600kb

input:

(5|6+)[12]3+
4334

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 3ms
memory: 395948kb

input:

[12](3+|4+)+
2345

output:

1

result:

ok 1 number(s): "1"

Test #3:

score: 0
Accepted
time: 12ms
memory: 396756kb

input:

(234|25)+
2442342523535

output:

3

result:

ok 1 number(s): "3"

Test #4:

score: 0
Accepted
time: 7ms
memory: 396040kb

input:

(1+)|(2+)
1112212

output:

3

result:

ok 1 number(s): "3"

Test #5:

score: 0
Accepted
time: 0ms
memory: 397284kb

input:

123
12

output:

1

result:

ok 1 number(s): "1"

Test #6:

score: 0
Accepted
time: 8ms
memory: 397368kb

input:

12
123

output:

1

result:

ok 1 number(s): "1"

Test #7:

score: 0
Accepted
time: 12ms
memory: 396368kb

input:

123
23

output:

1

result:

ok 1 number(s): "1"

Test #8:

score: 0
Accepted
time: 20ms
memory: 397168kb

input:

23
123

output:

1

result:

ok 1 number(s): "1"

Test #9:

score: 0
Accepted
time: 16ms
memory: 397532kb

input:

1
2

output:

1

result:

ok 1 number(s): "1"

Test #10:

score: 0
Accepted
time: 0ms
memory: 395984kb

input:

111
11

output:

1

result:

ok 1 number(s): "1"

Test #11:

score: 0
Accepted
time: 19ms
memory: 395764kb

input:

11
111

output:

1

result:

ok 1 number(s): "1"

Test #12:

score: 0
Accepted
time: 3ms
memory: 396132kb

input:

1+
2

output:

1

result:

ok 1 number(s): "1"

Test #13:

score: 0
Accepted
time: 15ms
memory: 397060kb

input:

1+2
2

output:

1

result:

ok 1 number(s): "1"

Test #14:

score: 0
Accepted
time: 15ms
memory: 397344kb

input:

[13][23][32]
233

output:

1

result:

ok 1 number(s): "1"

Test #15:

score: 0
Accepted
time: 11ms
memory: 395528kb

input:

00
0

output:

1

result:

ok 1 number(s): "1"

Test #16:

score: 0
Accepted
time: 20ms
memory: 396188kb

input:

0
00

output:

1

result:

ok 1 number(s): "1"

Test #17:

score: 0
Accepted
time: 11ms
memory: 397564kb

input:

0
0

output:

0

result:

ok 1 number(s): "0"

Test #18:

score: 0
Accepted
time: 16ms
memory: 401124kb

input:

(1|2)+1(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|2)(1|...

output:

1

result:

ok 1 number(s): "1"

Test #19:

score: 0
Accepted
time: 72ms
memory: 403700kb

input:

(0484|(8|(9|(198)))|(178)2126[7187645308865171]|99774(6(88(1687)+)4(8663))++((249))(3938)(7124)(314))(6|((779)))((86|04)(4375)(39|670((466))|(2701)(44|5|(4718)|9((890))+4))(8(9|(568)|[3116948995686](6382|9|7462748906210490|(490|0(349)85|(0(121))|2)+3(67|(003))++|8|640648)+((313)((072)7)0064(66(362))...

output:

149

result:

ok 1 number(s): "149"

Test #20:

score: 0
Accepted
time: 352ms
memory: 414604kb

input:

(046)965|61|((104|([2]))(((893))70|5(378))6277|41|752|012012|[6343803328803802907084854430832486850155279098472524604776748522071416414949516644524528](989(6212|216)|(9998)|80(88|((705))+5)|(89|875|2))(((553))|37|12)55(2769)(60803508|3(388|5((490)))|496|7((6(345)|2)(1030)((877|3)+[90])+67|1)(2501)[6...

output:

16

result:

ok 1 number(s): "16"

Test #21:

score: 0
Accepted
time: 36ms
memory: 401200kb

input:

(((370)7)(440)5733((175)6473|67)39((6|6227)|(9(404)0|(019(695))8[707]9)6|08|((185))|05)|(0(228)63))(([3492]+96|(5945)(007|((827))|30)((537)(4257)7|(623))6((416))(681)(686)[2501590252260068029443263942911323419]2|(582)9|843542814312326180245925650453239502011)(816257|(6(((((((303))))))))|59)+(3898)+(...

output:

27

result:

ok 1 number(s): "27"

Test #22:

score: 0
Accepted
time: 11ms
memory: 402084kb

input:

5407312253793023866322970242189685986027204962629554(1275)((1|510)+|448(823)(((696)6(437)|01+++))+(0(249)))+(469++26|255|((6967|990[3]16)0010)++(170)(719)371)|((79|97)((2(973|3)26)88)[164]|((500))5|((317)9(980607+)89((70|4760))|(329(4(350)((((476))))|3069689238030377)+1|275|54|(([4813]+4))7|5)(((([9...

output:

23

result:

ok 1 number(s): "23"

Test #23:

score: 0
Accepted
time: 277ms
memory: 404708kb

input:

(3(6|409222|117688(57|[9]7)(272|7((345)84723|(((((471))))5)|03|4)040(46((((728))))|43|43)|7[1])|69|00((310)|00)|(05897|89)36)(7|(425))((0(863)))(9|9(2078))((164)232587021598+(183))|[3](1(703)|689490303509515)53(6447)|(039)5((881)7|164[202977])(80737[08467302]|(277)|2002186+++)9|9)|(31((045)88((047)8...

output:

637

result:

ok 1 number(s): "637"

Test #24:

score: 0
Accepted
time: 172ms
memory: 406824kb

input:

((400)3)|((716))(758|[44]+++59233(0(368))|76)(((6(993)14)|9094([1]|2))[0712173]([71]66(057|((9|((442))83)82|21214(27((358)|8)|72|0(929|6(652)0)+++((326))+))+1(26|(889)|5)[34511])(923|9042)+|78(2|724)47|(7446)(245)049412385271)((6|0(177))3)((637)41(7|034)3|08|(3(((955))))|6(55|1|(42(0206)))|3((013)))...

output:

97

result:

ok 1 number(s): "97"

Test #25:

score: 0
Accepted
time: 39ms
memory: 401380kb

input:

(269606|967(527)(8|25|9|635|((333|9|94)+)830)++|(135)+(5|(075)9|(5+++))(0|76|634)|5(310)+07|3|9[07]+87)((5(452))(435)4(799)|(4|212|((120))28|50782)+((268))92(5|01052)(68(3((270)))(8|55(0(([2])))|(5((056))6|8)2)+(08552)|7|((72|38)|458)(5|[8]34905)++|(27|9500|941712)+|(7+++)3943818629764524(2(90|765)8...

output:

32

result:

ok 1 number(s): "32"

Test #26:

score: 0
Accepted
time: 148ms
memory: 407568kb

input:

209(7650|5)+|(3|871855|(79|3(5500294(2585)32(936|0))64|(913)666(46[01])|54(77|15)++96([2])|15)((240)|(217)|71(3989|37)(((3994)))+(3|6003)6(8212728676+028|380|73(5648)2(212))|07238941198++(482)35(08|97))|44|9((((5131))6)+324038)3(61(02|90|4((2372))+|(1|(827)(7284|(040)))+4208)(4(824))4|7508|40(008)(0...

output:

31

result:

ok 1 number(s): "31"

Test #27:

score: 0
Accepted
time: 160ms
memory: 404288kb

input:

((14|((6272)67)012|013|((3246))8)(1|671)(4064|72)4816+++96)(7(8(339))+7((255)|16|6777)+[3205986669731]((([0]))|0)(83|631)(16|52045((5|8290)))|(6410|97|024(612)(395)((((189)))1|162)((439)8))+((5|(3(168))7(55|318|9)(3513)(971)|073|(07065)|20[564020294116]+[0]8)((598))(3143)|69322979++92231075092872171...

output:

310

result:

ok 1 number(s): "310"

Test #28:

score: 0
Accepted
time: 96ms
memory: 405076kb

input:

[77854229801533667435968460630510773]21((014|899)76|75|87(917)|77(9((3996))388)4)+11((7(40(840))5+++)(8|408)+7|(913|1(20|52))|([3]|3|[27](1679(((337))85441)++1(1|5132)|23)((124)5)|((7(((564)))0786|6(((993))))++25|3831)(9((397)))(0288)|7282[410385472])8((290)+|7161))+|44|5(8450)(822|9)+82|((9(776))|[...

output:

36

result:

ok 1 number(s): "36"