Submission #1066243

#TimeUsernameProblemLanguageResultExecution timeMemory
1066243UnforgettableplAbduction 2 (JOI17_abduction2)C++17
13 / 100
5094 ms7764 KiB
#pragma GCC optimize("Ofast","unroll-all-loops") #include <bits/stdc++.h> using namespace std; #define int long long int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int H,W,Q; cin >> H >> W >> Q; vector<int> A(H+1); for(int i=1;i<=H;i++)cin>>A[i]; vector<int> B(W+1); for(int i=1;i<=W;i++)cin>>B[i]; for(int i=1;i<=Q;i++) { int s,t;cin>>s>>t; int ans = 0; function<void(int,int,int,int&,int&)> dfs = [&](int x,int y,int dist,int &parx,int &pary) { if(x<1 or x>H or y<1 or y>W)return; ans=max(ans,dist); if(A[x]>B[y]) { if(x!=parx or y-1!=pary)dfs(x,y-1,dist+1,x,y); if(x!=parx or y+1!=pary)dfs(x,y+1,dist+1,x,y); } else { if(x+1!=parx or y!=pary)dfs(x+1,y,dist+1,x,y); if(x-1!=parx or y!=pary)dfs(x-1,y,dist+1,x,y); } }; dfs(s,t,0,s,t); if(A[s]>B[t]) { dfs(s-1,t,1,s,t); dfs(s+1,t,1,s,t); } else { dfs(s,t-1,1,s,t); dfs(s,t+1,1,s,t); } cout << ans << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...