제출 #802562

#제출 시각아이디문제언어결과실행 시간메모리
802562KN200711구경하기 (JOI13_watching)C++14
50 / 100
1084 ms31188 KiB
# include <bits/stdc++.h> # define ll long long using namespace std; int N, P, Q; vector<int> arr; int mn[2001][2001]; int edge[2][2001]; bool cek(int a) { // set edge nya dulu for(int i=0;i<N;i++) { int T = arr[i] + a - 1; edge[0][i] = upper_bound(arr.begin(), arr.end(), T) - arr.begin(); T += a; edge[1][i] = upper_bound(arr.begin(), arr.end(), T) - arr.begin(); // if(a == 4) cout<<i<<" "<<edge[0][i]<<" "<<edge[1][i]<<endl; } priority_queue< pair<int, pair<int, int> > > PQ; PQ.push(make_pair(0, make_pair(0, 0))); vector< pair<int, int> > ST; ST.clear(); while(!PQ.empty()) { int x, y, z; x = PQ.top().second.first; y = PQ.top().second.second; z = PQ.top().first; PQ.pop(); if(-z > Q) continue; if(mn[x][-y] != 1e9) continue; // if(a == 1) cout<<x<<" "<<y<<" "<<z<<endl; ST.push_back(make_pair(x, -y)); mn[x][-y] = z; if(x == N) { for(auto p : ST) mn[p.first][p.second] = 1e9; return 1; } PQ.push(make_pair(z, make_pair(edge[0][x], y-1))); PQ.push(make_pair(z-1, make_pair(edge[1][x], y))); } for(auto p : ST) mn[p.first][p.second] = 1e9; return 0; } int main() { scanf("%d %d %d", &N, &P, &Q); arr.resize(N); for(int i=0;i<N;i++) scanf("%d", &arr[i]); sort(arr.begin(), arr.end()); if(P + Q >= N) { printf("1\n"); return 0; } for(int i=0;i<=N;i++) { for(int k=0;k<=P;k++) mn[i][k] = 1e9; } // cout<<cek(4)<<endl; int l = 1, r = 1e9, ans = -1; while(l <= r) { int mid = (l + r) / 2; if(cek(mid)) { ans = mid; r = mid - 1; } else l = mid + 1; } printf("%d\n", ans); }

컴파일 시 표준 에러 (stderr) 메시지

watching.cpp: In function 'int main()':
watching.cpp:52:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |  scanf("%d %d %d", &N, &P, &Q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:54:28: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |  for(int i=0;i<N;i++) scanf("%d", &arr[i]);
      |                       ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...