답안 #1059632

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1059632 2024-08-15T06:32:15 Z KasymK Pairs (IOI07_pairs) C++17
35 / 100
4000 ms 2772 KB
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second	
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}

int main(){
    int b, n, d, m;
    scanf("%d%d%d%d", &b, &n, &d, &m);
    if(b == 1){
        vector<int> v;
        for(int i = 1; i <= n; ++i){
            int x;
            scanf("%d", &x);
            v.pb(x);
        }
        int answer = 0;
        sort(all(v));
        for(auto I = v.begin(); I != v.end(); ++I){
            auto it = upper_bound(all(v), *I-d-1);
            answer += (I-it);
        }
        printf("%d\n", answer);
    }
    else if(b == 2){
        auto get = [&](pair<int, int> A, pair<int, int> B) -> int {
            int a = A.ff, b = A.ss;
            int c = B.ff, d = B.ss;
            return (abs(a-c)+abs(b-d));
        };
        vector<pii> v;
        for(int i = 1; i <= n; ++i){
            int a, b;
            scanf("%d%d", &a, &b);
            v.pb({a, b});
        }
        int answer = 0;
        for(int i = 0; i < n; ++i)
            for(int j = i+1; j < n; ++j)
                if(get(v[i], v[j]) <= d)
                    answer++;
        printf("%d\n", answer);
    }
    else{
        auto get = [&](tuple<int, int, int> A, tuple<int, int, int> B) -> int {
            int a, b, c, x, y, z;
            tie(a, b, c) = A;
            tie(x, y, z) = B;
            return (abs(a-x)+abs(b-y)+abs(c-z));
        };
        vector<tuple<int, int, int>> v;
        for(int i = 1; i <= n; ++i){
            int a, b, c;
            scanf("%d%d%d", &a, &b, &c);
            v.pb({a, b, c});
        }
        int answer = 0;
        for(int i = 0; i < n; ++i)
            for(int j = i+1; j < n; ++j)
                if(get(v[i], v[j]) <= d)
                    answer++;
        printf("%d\n", answer);
    }
    return 0;
}

Compilation message

pairs.cpp: In function 'int main()':
pairs.cpp:15:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     scanf("%d%d%d%d", &b, &n, &d, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
pairs.cpp:20:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |             scanf("%d", &x);
      |             ~~~~~^~~~~~~~~~
pairs.cpp:40:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |             scanf("%d%d", &a, &b);
      |             ~~~~~^~~~~~~~~~~~~~~~
pairs.cpp:60:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |             scanf("%d%d%d", &a, &b, &c);
      |             ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 1240 KB Output is correct
2 Incorrect 12 ms 1240 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 1808 KB Output is correct
2 Incorrect 15 ms 1752 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 1748 KB Output is correct
2 Correct 16 ms 1752 KB Output is correct
3 Correct 17 ms 1752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 1 ms 420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4043 ms 2004 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4034 ms 2260 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4074 ms 2260 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4062 ms 2516 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4051 ms 2772 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4058 ms 2772 KB Time limit exceeded
2 Halted 0 ms 0 KB -