답안 #59246

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
59246 2018-07-21T10:15:50 Z Just_Solve_The_Problem 새 집 (APIO18_new_home) C++17
0 / 100
494 ms 7524 KB
#include <bits/stdc++.h>

using namespace std;

#define pii pair < int, int >
#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()

const int N = (int)3e5 + 7;
const int inf = (int)1e9 + 7;

int n, k, q;
int x[N], t[N], a[N], b[N];
pii ar[N];
vector < int > pos;
int cur[N];
vector < pii > query;
bool has[N];

main() {
	scanf("%d %d %d", &n, &k, &q);
	for (int i = 1; i <= n; i++) {
		scanf("%d %d %d %d", &ar[i].fr, &ar[i].sc, &a[i], &b[i]);
		has[ar[i].sc] = 1;
		pos.pb(ar[i].fr);
	}
	for (int i = 1; i <= k; i++) {
		if (!has[i]) {
			for (int j = 1; j <= q; j++) {
				puts("-1");
			}
			return 0;
		}
	}
	sort(all(pos));
	for (int i = 1; i <= q; i++) {
		int l, y;
		scanf("%d %d", &l, &y);
		int ans = inf;
		if (lower_bound(all(pos), l) != upper_bound(all(pos), l)) {
      ans = 0;
		} else {
      int pos1 = lower_bound(all(pos), l) - pos.begin();
      if (pos1 < sz(pos)) {
        ans = min(ans, abs(l - pos[pos1]));
      }
      if (pos1) {
        ans = min(ans, abs(l - pos[pos1 - 1]));
      }
		}
		assert(ans != inf);
		printf("%d\n", ans);
	}

}

Compilation message

new_home.cpp:24:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
new_home.cpp: In function 'int main()':
new_home.cpp:25:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d", &n, &k, &q);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d %d", &ar[i].fr, &ar[i].sc, &a[i], &b[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new_home.cpp:42:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &l, &y);
   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 3 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 3 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 472 ms 7524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 494 ms 7524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 3 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 3 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -