답안 #269960

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
269960 2020-08-17T11:33:49 Z MKopchev Bulldozer (JOI17_bulldozer) C++14
25 / 100
2000 ms 97716 KB
#include<bits/stdc++.h>
using namespace std;

const int nmax=2e3+42;

struct info
{
    long long x,y,gain;
};

int n;

info inp[nmax];

vector< pair<long long,long long> > seen,other;

bool cmp(pair<long long,long long> a,pair<long long,long long> b)
{
    return a.first*b.second<a.second*b.first;
}

void extend()
{
    for(int i=1;i<seen.size();i++)
    {
        long long up=seen[i].first+seen[i-1].first;
        long long down=seen[i].second+seen[i-1].second;

        long long g=__gcd(up,down);

        up=up/g;
        down=down/g;

        other.push_back({up,down});
    }

    for(auto k:other)seen.push_back(k);

    seen.push_back({seen.back().first+1,seen.back().second});
    seen.insert(seen.begin(),{seen[0].first-1,seen[0].second});
}

pair<long long,long long> cur;

bool eq(info u,info v)
{
    return (u.x-v.x)*cur.second==cur.first*(u.y-v.y);
}
bool cmp_2(info u,info v)
{
    return (u.x-v.x)*cur.second<cur.first*(u.y-v.y);
}
long long solve(pair<long long,long long> a)
{
    cur=a;

    sort(inp+1,inp+n+1,cmp_2);

    long long ret=0,cur_best=0,sum_now=0;

    for(int i=1;i<=n;i++)
    {
        sum_now+=inp[i].gain;

        if(eq(inp[i],inp[i+1])==0||i==n)
        {
            cur_best=max(cur_best+sum_now,sum_now);
            sum_now=0;
        }

        ret=max(ret,cur_best);
    }
    return ret;
}
int main()
{
    scanf("%i",&n);
    for(int i=1;i<=n;i++)
        scanf("%lld%lld%lld",&inp[i].x,&inp[i].y,&inp[i].gain);

    seen.push_back({0,1});

    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
        {
            long long up=inp[i].x-inp[j].x;
            long long down=inp[i].y-inp[j].y;

            if(down)
            {
                long long g=__gcd(abs(up),abs(down));

                up=up/g;
                down=down/g;

                if(down<0)down=-down,up=-up;

                seen.push_back({up,down});
            }
        }

    sort(seen.begin(),seen.end(),cmp);
    unique(seen.begin(),seen.end());

    extend();

    long long outp=0;

    for(auto k:seen)
        outp=max(outp,solve(k));

    printf("%lld\n",outp);
    return 0;
}

Compilation message

bulldozer.cpp: In function 'void extend()':
bulldozer.cpp:24:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(int i=1;i<seen.size();i++)
      |                 ~^~~~~~~~~~~~
bulldozer.cpp: In function 'int main()':
bulldozer.cpp:77:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   77 |     scanf("%i",&n);
      |     ~~~~~^~~~~~~~~
bulldozer.cpp:79:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   79 |         scanf("%lld%lld%lld",&inp[i].x,&inp[i].y,&inp[i].gain);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 360 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 768 KB Output is correct
2 Correct 49 ms 768 KB Output is correct
3 Correct 45 ms 768 KB Output is correct
4 Correct 56 ms 768 KB Output is correct
5 Correct 46 ms 768 KB Output is correct
6 Correct 52 ms 800 KB Output is correct
7 Correct 51 ms 768 KB Output is correct
8 Correct 56 ms 768 KB Output is correct
9 Correct 56 ms 768 KB Output is correct
10 Correct 59 ms 768 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 45 ms 768 KB Output is correct
22 Correct 47 ms 768 KB Output is correct
23 Correct 45 ms 768 KB Output is correct
24 Correct 45 ms 768 KB Output is correct
25 Correct 47 ms 768 KB Output is correct
26 Correct 53 ms 896 KB Output is correct
27 Correct 44 ms 768 KB Output is correct
28 Correct 43 ms 768 KB Output is correct
29 Correct 44 ms 768 KB Output is correct
30 Correct 45 ms 768 KB Output is correct
31 Correct 54 ms 768 KB Output is correct
32 Correct 44 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 768 KB Output is correct
2 Correct 49 ms 768 KB Output is correct
3 Correct 45 ms 768 KB Output is correct
4 Correct 56 ms 768 KB Output is correct
5 Correct 46 ms 768 KB Output is correct
6 Correct 52 ms 800 KB Output is correct
7 Correct 51 ms 768 KB Output is correct
8 Correct 56 ms 768 KB Output is correct
9 Correct 56 ms 768 KB Output is correct
10 Correct 59 ms 768 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 45 ms 768 KB Output is correct
22 Correct 47 ms 768 KB Output is correct
23 Correct 45 ms 768 KB Output is correct
24 Correct 45 ms 768 KB Output is correct
25 Correct 47 ms 768 KB Output is correct
26 Correct 53 ms 896 KB Output is correct
27 Correct 44 ms 768 KB Output is correct
28 Correct 43 ms 768 KB Output is correct
29 Correct 44 ms 768 KB Output is correct
30 Correct 45 ms 768 KB Output is correct
31 Correct 54 ms 768 KB Output is correct
32 Correct 44 ms 768 KB Output is correct
33 Execution timed out 2059 ms 97716 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 58 ms 768 KB Output is correct
2 Correct 49 ms 768 KB Output is correct
3 Correct 45 ms 768 KB Output is correct
4 Correct 56 ms 768 KB Output is correct
5 Correct 46 ms 768 KB Output is correct
6 Correct 52 ms 800 KB Output is correct
7 Correct 51 ms 768 KB Output is correct
8 Correct 56 ms 768 KB Output is correct
9 Correct 56 ms 768 KB Output is correct
10 Correct 59 ms 768 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 45 ms 768 KB Output is correct
22 Correct 47 ms 768 KB Output is correct
23 Correct 45 ms 768 KB Output is correct
24 Correct 45 ms 768 KB Output is correct
25 Correct 47 ms 768 KB Output is correct
26 Correct 53 ms 896 KB Output is correct
27 Correct 44 ms 768 KB Output is correct
28 Correct 43 ms 768 KB Output is correct
29 Correct 44 ms 768 KB Output is correct
30 Correct 45 ms 768 KB Output is correct
31 Correct 54 ms 768 KB Output is correct
32 Correct 44 ms 768 KB Output is correct
33 Execution timed out 2059 ms 97716 KB Time limit exceeded
34 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 360 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 372 KB Output is correct
16 Correct 58 ms 768 KB Output is correct
17 Correct 49 ms 768 KB Output is correct
18 Correct 45 ms 768 KB Output is correct
19 Correct 56 ms 768 KB Output is correct
20 Correct 46 ms 768 KB Output is correct
21 Correct 52 ms 800 KB Output is correct
22 Correct 51 ms 768 KB Output is correct
23 Correct 56 ms 768 KB Output is correct
24 Correct 56 ms 768 KB Output is correct
25 Correct 59 ms 768 KB Output is correct
26 Correct 1 ms 256 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 256 KB Output is correct
29 Correct 1 ms 256 KB Output is correct
30 Correct 1 ms 256 KB Output is correct
31 Correct 1 ms 256 KB Output is correct
32 Correct 1 ms 256 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 256 KB Output is correct
35 Correct 1 ms 256 KB Output is correct
36 Correct 45 ms 768 KB Output is correct
37 Correct 47 ms 768 KB Output is correct
38 Correct 45 ms 768 KB Output is correct
39 Correct 45 ms 768 KB Output is correct
40 Correct 47 ms 768 KB Output is correct
41 Correct 53 ms 896 KB Output is correct
42 Correct 44 ms 768 KB Output is correct
43 Correct 43 ms 768 KB Output is correct
44 Correct 44 ms 768 KB Output is correct
45 Correct 45 ms 768 KB Output is correct
46 Correct 54 ms 768 KB Output is correct
47 Correct 44 ms 768 KB Output is correct
48 Execution timed out 2059 ms 97716 KB Time limit exceeded
49 Halted 0 ms 0 KB -