Submission #26210

#TimeUsernameProblemLanguageResultExecution timeMemory
26210imsifileAbduction 2 (JOI17_abduction2)C++98
44 / 100
4003 ms15932 KiB
#include<stdio.h> #include<algorithm> #include<map> using namespace std; int H, W, Q; int ho[50505], ver[50505]; map<pair<int,int>, int> vd, hd; int verti(int, int); int hori(int, int); int verti(int h, int v){ int gap = vd[make_pair(h,v)]; if(gap) return gap; int val = ver[v]; int i, up=0, down=0; for(i=h+1; i<H; i++){ up=i-h; if(ho[i]>val)break; } if(i<H) up += hori(v, i); for(i=h-1; i>=0; i--){ down=h-i; if(ho[i]>val)break; } if(i>=0) down += hori(v, i); return vd[make_pair(h,v)] = max(up, down); } int hori(int v, int h){ int gap = hd[make_pair(h,v)]; if(gap) return gap; int val = ho[h]; int i, up=0, down=0; for(i=v+1; i<W; i++){ up=i-v; if(ver[i]>val)break; } if(i<W) up += verti(h, i); for(i=v-1; i>=0; i--){ down=v-i; if(ver[i]>val)break; } if(i>=0) down += verti(h, i); return hd[make_pair(h,v)]=max(up, down); } int main(){ scanf("%d%d%d", &H, &W, &Q); for(int i=0; i<H; i++) scanf("%d", &ho[i]); for(int i=0; i<W; i++) scanf("%d", &ver[i]); while(Q--){ int h, v; scanf("%d%d", &h, &v), h--, v--; printf("%d\n", max(verti(h, v), hori(v, h))); } return 0; }

Compilation message (stderr)

abduction2.cpp: In function 'int main()':
abduction2.cpp:50:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d%d", &H, &W, &Q);
                             ^
abduction2.cpp:51:44: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0; i<H; i++) scanf("%d", &ho[i]);
                                            ^
abduction2.cpp:52:45: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0; i<W; i++) scanf("%d", &ver[i]);
                                             ^
abduction2.cpp:55:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &h, &v), h--, v--;
                                  ^
#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...