답안 #72254

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
72254 2018-08-26T06:24:19 Z cat > /dev/null(#2231, lobo_prix, jms100300, enochjung) 오르막길 (FXCUP3_hill) C++17
100 / 100
665 ms 6156 KB
#include <cstdio>
#include <queue>
#define N 300010

using namespace std;

int n;
long long c;
int x[N], y[N];
int b[N];
bool v[N];

struct st
{
    int i;
    bool operator<(const st &hs) const
    {
        long long lv = 1LL*(y[i]-y[b[i]])*(x[hs.i]-x[b[hs.i]]);
        long long rv = 1LL*(y[hs.i]-y[b[hs.i]])*(x[i]-x[b[i]]);
        return lv==rv? i>hs.i : lv<rv;
    }
};
priority_queue<st> q;

int gcd(int a, int b)
{
    while(a%b)
    {
        int tmp = a%b;
        a = b;
        b = tmp;
    }
    return b;
}

void print(int dx, int dy)
{
    int g = gcd(dx, dy);
    dx /= g;
    dy /= g;
    printf("%d/%d", dy, dx);
}

long long abs(long long val)
{
    return val>0? val : -val;
}

long long area(int i, int j, int k)
{
    return abs(1LL*x[i]*(y[j]-y[k]) + 1LL*x[j]*(y[k]-y[i]) + 1LL*x[k]*(y[i]-y[j]));
}

int main()
{
    scanf("%d %lld", &n, &c);
    for(int i=0; i<n; ++i)
        scanf("%d", x+i);
    for(int i=0; i<n; ++i)
        scanf("%d", y+i);
    c *= 2;
    
    for(int i=1; i<n; ++i)
    {
        b[i] = i-1;
        q.push({i});
    }
    
    while(!q.empty())
    {
        int now = q.top().i;
        q.pop();
        
        if(v[now])
            continue;
        if(b[now] == 0)
        {
            print(x[now]-x[0], y[now]-y[0]);
            break;
        }
        
        long long a = area(now, b[now], b[b[now]]);
        if(a > c)
        {
            print(x[now]-x[b[now]], y[now]-y[b[now]]);
            break;
        }
        c -= a;
        v[b[now]] = true;
        b[now] = b[b[now]];
        q.push({now});
    }
    
    return 0;
}

Compilation message

hill.cpp: In function 'int main()':
hill.cpp:56:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %lld", &n, &c);
     ~~~~~^~~~~~~~~~~~~~~~~~~
hill.cpp:58:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", x+i);
         ~~~~~^~~~~~~~~~~
hill.cpp:60:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", y+i);
         ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 3 ms 484 KB Output is correct
4 Correct 3 ms 484 KB Output is correct
5 Correct 3 ms 488 KB Output is correct
6 Correct 3 ms 588 KB Output is correct
7 Correct 3 ms 588 KB Output is correct
8 Correct 4 ms 668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 248 KB Output is correct
2 Correct 2 ms 484 KB Output is correct
3 Correct 3 ms 484 KB Output is correct
4 Correct 3 ms 484 KB Output is correct
5 Correct 3 ms 488 KB Output is correct
6 Correct 3 ms 588 KB Output is correct
7 Correct 3 ms 588 KB Output is correct
8 Correct 4 ms 668 KB Output is correct
9 Correct 126 ms 6112 KB Output is correct
10 Correct 133 ms 6112 KB Output is correct
11 Correct 665 ms 6112 KB Output is correct
12 Correct 267 ms 6112 KB Output is correct
13 Correct 77 ms 6112 KB Output is correct
14 Correct 104 ms 6112 KB Output is correct
15 Correct 197 ms 6112 KB Output is correct
16 Correct 143 ms 6112 KB Output is correct
17 Correct 184 ms 6112 KB Output is correct
18 Correct 77 ms 6112 KB Output is correct
19 Correct 105 ms 6156 KB Output is correct