QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#142605#13. RouterNOI_AK_ME100 ✓370ms31280kbC++235.0kb2023-08-19 13:49:392023-08-19 13:49:41

Judging History

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

  • [2023-08-19 13:49:41]
  • 评测
  • 测评结果:100
  • 用时:370ms
  • 内存:31280kb
  • [2023-08-19 13:49:39]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;const int max_nfa=55;const int max_len=55;const int max_nfanode=65535;int vis[max_nfanode][max_len],visT;struct NFA{int S,T;vector<vector<pair<pair<char,char>,unsigned short>>>go;NFA(){go.clear();S=T=0;go.resize(1);}bool dfs(int x,char s[],int i,int l){if(x==T&&i==l)return true;if(vis[x][i]==visT)return false;vis[x][i]=visT;for(auto e:go[x])if(e.FF.FF==0&&dfs(e.SS,s,i,l))return true;for(auto e:go[x])if(e.FF.FF<=s[i]&&s[i]<=e.FF.SS&&dfs(e.SS,s,i+1,l))return true;return false;}bool match(char s[],int l){assert(go.size()<max_nfanode);visT++;return dfs(S,s,0,l);}NFA opt()const{NFA ret=(*this);ret.go[S].PB(MP(MP(0,0),T));return ret;}NFA opt_inf()const{NFA ret=(*this);ret.go[S].PB(MP(MP(0,0),T));ret.go[T].PB(MP(MP(0,0),S));return ret;}}A[max_nfa];int nfa_tot;string nfa_name[max_nfa];map<string,int>nfa_id;NFA operator|(const NFA&a,const NFA&b){NFA ret;ret.S=0;ret.T=a.T+b.T;ret.go.resize(ret.T+1);for(int i=0;i<=a.T;i++)ret.go[i]=a.go[i];ret.go[a.T].PB(MP(MP(0,0),ret.T));for(int i=0;i<=b.T;i++){int id=i==0?0:i+a.T;for(auto e:b.go[i]){ret.go[id].PB(MP(e.FF,e.SS==0?0:e.SS+a.T));}}return ret;}NFA operator+(const NFA&a,const NFA&b){NFA ret;ret.S=0;ret.T=a.T+b.T;ret.go.resize(ret.T+1);for(int i=0;i<=a.T;i++)ret.go[i]=a.go[i];for(int i=0;i<=b.T;i++){int id=i+a.T;for(auto e:b.go[i]){ret.go[id].PB(MP(e.FF,e.SS+a.T));}}return ret;}NFA make_nfa(char ls,char rs){NFA ret;ret.go.resize(2);ret.S=0;ret.T=1;ret.go[0].PB(MP(MP(ls,rs),1));return ret;}int get_bracket_value(char c){if(c=='('||c=='['||c=='{')return 1;if(c==')'||c==']'||c=='}')return-1;return 0;}bool matchable_char(char c){if(c>='0'&&c<='9')return true;if(c>='a'&&c<='z')return true;if(c>='A'&&c<='Z')return true;return false;}pair<int,int>get_seg(char s[],int l){int r0=0,r1=0;bool f=false;for(int i=0;i<l;i++){if(s[i]==',')f=true;else if(!f)r0=r0*10+s[i]-'0';else r1=r1*10+s[i]-'0';}if(s[l-1]==',')r1=-1;return MP(r0,r1);}NFA parse(char s[],int l){int cnt[max_len]={};for(int i=0;i<l;i++)cnt[i]=(i==0?0:cnt[i-1])+get_bracket_value(s[i]);for(int i=0;i<l;i++)if(cnt[i]==0&&s[i]=='|')return parse(s,i)|parse(s+i+1,l-(i+1));for(int i=l-1;i>0;i--){if(cnt[i]==0&&matchable_char(s[i]))return parse(s,i)+parse(s+i,l-i);if(cnt[i]==1&&(s[i]=='('||s[i]=='['))return parse(s,i)+parse(s+i,l-i);}if(s[l-1]=='}'){pair<int,int>seg=MP(-1,-1);NFA cur;for(int i=l-1;i>=0;i--)if(s[i]=='{'){seg=get_seg(s+i+1,l-1-(i+1));cur=parse(s,i);break;}assert(seg.FF!=-1);NFA ret;for(int i=0;i<seg.FF;i++)ret=ret+cur;if(seg.SS==-1)ret=ret+cur.opt_inf();else for(int i=seg.FF;i<seg.SS;i++)ret=ret+cur.opt();return ret;}if(s[0]=='(')return parse(s+1,l-2);if(s[0]=='['){assert(l==5);return make_nfa(s[1],s[3]);}assert(l==1&&matchable_char(s[0]));return make_nfa(s[0],s[0]);}const int max_node=200111;int node_tot;map<string,int>go[max_node];map<int,int>go_nfa[max_node];string act[max_node];int node_add_son(int p,char s[],int l){if(s[0]==':'){string name;for(int i=1;i<l;i++)name.PB(s[i]);int&id=nfa_id[name];if(id==0){id=++nfa_tot;nfa_name[id]=name;}int&ret=go_nfa[p][id];if(ret==0)ret=++node_tot;return ret;}else{string name;for(int i=0;i<l;i++)name.PB(s[i]);int&ret=go[p][name];if(ret==0)ret=++node_tot;return ret;}}void add_path(){static char s[1000111];scanf("%s",s);int l=strlen(s);int lst=1;int p=1;for(int i=1;i<=l;i++){if(s[i]=='/'||i==l){p=node_add_son(p,s+lst,i-lst);lst=i+1;}}scanf("%s",s);act[p]=string(s);assert(node_tot<max_node);}void add_nfa(){char s[55];scanf("%s",s);int id=nfa_id[string(s)];assert(id>0);scanf("%s",s);A[id]=parse(s,strlen(s));}map<string,vector<string>>para;int node_go_next(int p,char s[],int l){string cur;for(int i=0;i<l;i++)cur.PB(s[i]);if(go[p].find(cur)!=go[p].end())return go[p][cur];for(auto x:go_nfa[p])if(A[x.FF].match(s,l)){para[nfa_name[x.FF]].PB(cur);return x.SS;}return 0;}void query(){static char s[1000111];scanf("%s",s);int l=strlen(s);int lst=1;int p=1;para.clear();for(int i=1;i<=l;i++){if(s[i]=='/'||s[i]=='?'||i==l){p=node_go_next(p,s+lst,i-lst);if(!p)break;lst=i+1;if(s[i]=='?')break;}}if(!p){puts("404 Not Found");return;}for(int i=lst;i<=l;i++){if(s[i]=='&'||i==l){string s1,s2;bool f=0;for(int j=lst;j<i;j++){if(s[j]=='=')f=1;else if(!f)s1.PB(s[j]);else s2.PB(s[j]);}para[s1].PB(s2);lst=i+1;}}printf("Request matches action \"%s\" with parameters {",act[p].c_str());bool fb=true;for(auto x:para){if(fb)fb=false;else putchar(',');printf("\"%s\":",x.FF.c_str());vector<string>&v=x.SS;if(v.size()==1)printf("\"%s\"",v[0].c_str());else{printf("[");for(int i=0;i<v.size();i++){printf("\"%s\"%c",v[i].c_str(),i+1==v.size()?']':',');}}}puts("}");}void init(){nfa_id.clear();for(int i=1;i<=nfa_tot;i++)A[i]=NFA();nfa_tot=0;for(int i=1;i<=node_tot;i++){go[i].clear();go_nfa[i].clear();}node_tot=1;}void solve(){int n;scanf("%d",&n);for(int i=1;i<=n;i++)add_path();for(int i=1;i<=nfa_tot;i++)add_nfa();int q;scanf("%d",&q);for(int i=1;i<=q;i++)query();}int main(){int Tn;scanf("%d",&Tn);int tn=0;while(Tn--){printf("Case #%d:\n",++tn);init();solve();}return 0;}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 10
Accepted
time: 4ms
memory: 28736kb

input:

1
4
/user/show
userShow
/user/edit
userEdit
/user/delete
userDelete
/message/send
messageSend
8
/user/show?handle=WJMZBMR
/user/edit?handle=WJMZBMR&type=doubi
/user/show2?handle=WJMZBMR
/user/delete?handle=WJMZBMR
/message/send?from=GuyUpLion&to=WJMZBMR&content=nishishabi
/sudo/user/deleteAll?force=...

output:

Case #1:
Request matches action "userShow" with parameters {"handle":"WJMZBMR"}
Request matches action "userEdit" with parameters {"handle":"WJMZBMR","type":"doubi"}
404 Not Found
Request matches action "userDelete" with parameters {"handle":"WJMZBMR"}
Request matches action "messageSend" with param...

result:

ok 9 lines

Test #2:

score: 10
Accepted
time: 140ms
memory: 30360kb

input:

5
20000
/Oo/pt/GI/7eSZo
GaWpHfuwXZ
/Oo/pt/GI/2fD4N
PelOZXZAdJ
/Oo/pt/GI/Fneu7
GRNGPVcQUD
/Oo/pt/GI/ff1OJ
YnLFicuZwm
/Oo/pt/GI/2YjXS
xeJnUIvjZf
/Oo/pt/GI/WEbeB
dfDQvEfExS
/Oo/pt/GI/UbdVz
znwCWkROhG
/Oo/pt/GI/MVncl
SbIoWskvhP
/Oo/pt/GI/t37hx
LmJAlDmtUs
/Oo/pt/GI/bdx1b
BMMmjHOTYt
/Oo/pt/GI/VkVdo
BZqDmn...

output:

Case #1:
Request matches action "qryXhOAkdN" with parameters {}
Request matches action "WdLaIPgxLe" with parameters {"BeA":"cC7D","EtX":"27vv","kIz":"KrMG"}
404 Not Found
404 Not Found
404 Not Found
404 Not Found
Request matches action "LMgsDMAtVl" with parameters {"FvU":"blOL","LCR":"iXzR","Mlk":"Q...

result:

ok 100005 lines

Test #3:

score: 10
Accepted
time: 135ms
memory: 30344kb

input:

5
20000
/mT/kR/E7/nf7mU
DtXyJptWQE
/mT/kR/E7/HbMdw
CInmqffDmM
/mT/kR/E7/UwmxK
nhKDxbSBoH
/mT/kR/E7/QPWxn
hPnPoWNeeW
/mT/kR/E7/nO0wW
wjKYbvenJJ
/mT/kR/E7/A9FO5
lVhKuozrNs
/mT/kR/E7/sauoC
TghZLVCkbg
/mT/kR/E7/7OhtX
WvPSUjCneI
/mT/kR/E7/NaC3w
fRClfNGnPI
/mT/kR/E7/KVt5P
BAZrgwzBXb
/mT/kR/E7/5ma44
FhEBYy...

output:

Case #1:
Request matches action "NAwUKiVdkz" with parameters {"BCb":"uIAS","Bqx":"YL1q","RZT":"UT33","kDU":"edgN"}
Request matches action "RVnVUywRFD" with parameters {}
404 Not Found
404 Not Found
404 Not Found
404 Not Found
Request matches action "dUfdJhrOeU" with parameters {"TvA":"LixU","VFR":"r...

result:

ok 100005 lines

Test #4:

score: 10
Accepted
time: 4ms
memory: 28744kb

input:

3
3
/user/:id/show
userShow
/message/list
messageList
/message/:id/show
messageShow
id [0-9]{2,4}
3
/message/list
/user/123/show?avatar=true
/message/5312/show?page=1
1
/foo/:id/:bar/:bar
fun
id [0-9]{2,4}
bar [a-z]{1,3}
1
/foo/777/az/bc?bar=xyz&bar=zzz
2
/user/:handle/show
userShow
/user/:id/show
u...

output:

Case #1:
Request matches action "messageList" with parameters {}
Request matches action "userShow" with parameters {"avatar":"true","id":"123"}
Request matches action "messageShow" with parameters {"id":"5312","page":"1"}
Case #2:
Request matches action "fun" with parameters {"bar":["az","bc","xyz",...

result:

ok 11 lines

Test #5:

score: 10
Accepted
time: 4ms
memory: 28884kb

input:

2
5
/user/:userHandle/show
userShow
/user/:userHandle/edit
userEdit
/message/send
messageSend
/message/:messageId/show
messageShow
/user/:userHandle/setBirthday/:date
userSetBirthday
userHandle ([A-Z]|[a-z]){4,10}
messageId ([a-z]|[0-9]){8,8}
date (19[0-9]{2,2}|200[0-9]|201[0-4])(0[1-9]|1[0-2])
15
/...

output:

Case #1:
Request matches action "userShow" with parameters {"userHandle":"crash"}
404 Not Found
Request matches action "userEdit" with parameters {"type":"doubi","userHandle":"WJMZBMR"}
Request matches action "userShow" with parameters {"avatar":"true","userHandle":"WJMZBMR"}
Request matches action ...

result:

ok 24 lines

Test #6:

score: 10
Accepted
time: 3ms
memory: 28820kb

input:

1
9
/a/:expA
testA
/b/:expB
testB
/c/:expC
testC
/d/:expD
testD
/e/:expE
testE
/f/:expF
testF
/g/:expG
testG
/h/:expH
testH
/i/:expI
testI
expA a([b-c]{0,})(c{1,}d)
expB a([b-c]{0,})c{0,}
expC (a|b|c|d|e)f
expD a{1,}b{1,}c
expE (((((((((a)))))))))
expF a[b-d]e
expG (ab{4,5}){0,1}bc
expH (a{1,}|b){1,...

output:

Case #1:
Request matches action "testA" with parameters {"expA":"acd"}
404 Not Found
Request matches action "testA" with parameters {"expA":"accd"}
404 Not Found
Request matches action "testA" with parameters {"expA":"abbbccbbcbcd"}
Request matches action "testB" with parameters {"expB":"a"}
Request...

result:

ok 40 lines

Test #7:

score: 10
Accepted
time: 189ms
memory: 30408kb

input:

5
20000
/:d/Xa/pF/qR/AHOJi
KcioVpFutT
/:B/Xa/pF/qR/vPS8a
olfLwawkjj
/:h/Xa/pF/qR/F9pAn
DlvayDMhBr
/:X/Xa/pF/qR/dbiqh
hgWRSuyKJb
/:B/Xa/pF/qR/bYxcI
NMAhONaRqV
/:w/Xa/pF/qR/sUqgS
jnwOPhLTBc
/:e/Xa/pF/qR/jbDTg
OYXysAcgaI
/:a/Xa/pF/qR/nkDlc
MmCDeWkbOh
/:m/Xa/pF/qR/3Fu9U
IWsFasuAYF
/:r/Xa/pF/qR/GBJqj
Udl...

output:

Case #1:
404 Not Found
404 Not Found
Request matches action "XCOwpXeehZ" with parameters {"J":"JRj","Ttq":"sste","pLg":"6I7n"}
Request matches action "FwqgIOXQtx" with parameters {"AMy":"60KP","L":"LxX","QKC":"hXVY","pjN":"yRYY"}
404 Not Found
Request matches action "ORqyPOphpD" with parameters {"G"...

result:

ok 100005 lines

Test #8:

score: 10
Accepted
time: 267ms
memory: 30944kb

input:

5
20000
/:p/AG/I2/:W/qR/yR/WQp1B
OMguaUOWeL
/:X/AG/I2/:j/qR/yR/LExvw
ruPRaSFReN
/:f/AG/I2/:R/qR/yR/h69ms
mZeBvBQGPt
/:S/AG/I2/:L/qR/yR/wqMnI
mTAgDZIBZn
/:K/AG/I2/:u/qR/yR/kH2fk
liGLUxZthV
/:r/AG/I2/:N/qR/yR/AOZUz
vvywfMeRgD
/:e/AG/I2/:P/qR/yR/aR1Ub
IdxTrlllRD
/:i/AG/I2/:D/qR/yR/F70ob
bdERKpqhRA
/:c/...

output:

Case #1:
404 Not Found
Request matches action "UJzLRpXcUj" with parameters {"T":"TWw","v":"vlM"}
404 Not Found
404 Not Found
404 Not Found
404 Not Found
404 Not Found
404 Not Found
404 Not Found
Request matches action "iMRSvVsKSv" with parameters {"L":"LfF","P":"PuhY","Whi":"aZEY","kkj":"vffu","ofH"...

result:

ok 100005 lines

Test #9:

score: 10
Accepted
time: 370ms
memory: 31280kb

input:

5
20000
/:W/Qf/ZL/:S/ok/Pz/vTPCO
tTkHRaRZOl
/:y/Qf/ZL/:O/ok/Pz/GXn08
IyKwbtDosO
/:m/Qf/ZL/:b/ok/Pz/Yo5aY
MyqsYbMazS
/:y/Qf/ZL/:W/ok/Pz/ohE9i
yCdMJvQuei
/:b/Qf/ZL/:y/ok/Pz/mSLAu
SnVLmwLWHv
/:w/Qf/ZL/:S/ok/Pz/e2uK0
pKIGBMNGKW
/:B/Qf/ZL/:J/ok/Pz/6QCz6
CXMuvGooBL
/:W/Qf/ZL/:l/ok/Pz/FvMe5
mcaSoGnfmS
/:C/...

output:

Case #1:
404 Not Found
404 Not Found
Request matches action "PUECawPkdL" with parameters {"ddC":"p7aW","e":"ewA","tSn":"SpjF","y":"y","yIh":"XUcc","yac":"PXA3"}
404 Not Found
Request matches action "tWONOjhdZa" with parameters {"F":"F","qqV":"q2RY","u":"u"}
Request matches action "MDjliQiVbq" with p...

result:

ok 100005 lines

Test #10:

score: 10
Accepted
time: 363ms
memory: 31276kb

input:

5
20000
/:M/hP/QZ/:b/xN/mD/fH1G5
JHPsElQRqL
/:Q/hP/QZ/:c/xN/mD/UfLUT
wisHKFtBQg
/:O/hP/QZ/:p/xN/mD/nHH8x
opUNFZFexx
/:S/hP/QZ/:N/xN/mD/6ricK
tNIcIMuMzZ
/:x/hP/QZ/:i/xN/mD/wLNM3
qlrVWOLgqJ
/:Q/hP/QZ/:T/xN/mD/SUqgU
SREHWjveiD
/:M/hP/QZ/:p/xN/mD/LdLlM
UIctkUvzse
/:E/hP/QZ/:A/xN/mD/4IzTw
gibBlpIuOC
/:a/...

output:

Case #1:
404 Not Found
404 Not Found
404 Not Found
404 Not Found
404 Not Found
404 Not Found
404 Not Found
404 Not Found
404 Not Found
404 Not Found
404 Not Found
Request matches action "LyharhUmMM" with parameters {"D":"D","f":"f2w","gFf":"kde2","kpw":"OvUn","mQB":"4Si4"}
404 Not Found
404 Not Foun...

result:

ok 100005 lines