Submission #334465

# Submission time Handle Problem Language Result Execution time Memory
334465 2020-12-09T07:41:36 Z beksultan04 Gift (IZhO18_nicegift) C++14
18 / 100
2000 ms 115156 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define OK puts("OK");
#define fr first
#define sc second
#define ret return
#define scan1(a) scanf("%lld",&a);
#define scan2(a,b) scanf("%lld %lld",&a, &b);
#define scan3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c);
#define all(s) s.begin(),s.end()
#define pb push_back
#define endi puts("");
const int N = 1e5+12,INF=1e9+7;
int dist[N],n;
vector <pii> g[N];

void fun(int v){
    int i,j,k;
    set <pii> s;
    s.insert({0,v});
    dist[v] = 0;
    while (!s.empty()){

        pii x = *s.begin();
        s.erase(s.begin());
        for (i=0;i<g[x.sc].size();++i){
            if (dist[g[x.sc][i].fr] > dist[x.sc]+g[x.sc][i].sc){
                s.erase({dist[g[x.sc][i].fr],g[x.sc][i].fr});
                dist[g[x.sc][i].fr] = dist[x.sc]+g[x.sc][i].sc;
                s.insert({dist[g[x.sc][i].fr],g[x.sc][i].fr});
            }
        }
    }
}

main(){
    int n,k,i,j;
    multiset<pii> s;
    vector <pair<pii,int> > v;
    scan2(n,k)
    for (i=0;i<n;++i){
        int x;
        scan1(x)
        s.insert({x,i+1});
    }
    while (s.size()>2){
        pii x = *s.rbegin();
        s.erase(x);
        pii y = *s.rbegin();
        s.erase(y);
        pii z = *s.rbegin();
        int a = y.fr-z.fr+1;
        v.pb({{a,x.sc},y.sc});
        x.fr -= a;
        y.fr -= a;
        if (x.fr > 0)s.insert(x);
        if (y.fr > 0)s.insert(y);
    }
    if (s.size() == 2){
        pii x = *s.rbegin();
        s.erase(x);
        pii y = *s.rbegin();
        s.erase(y);
        if (x.fr == y.fr){
            v.pb({{x.fr,x.sc},y.sc});
            cout <<v.size()<<"\n";
            for (i=0;i<v.size();++i){
                cout <<v[i].fr.fr<<" "<<v[i].fr.sc<<" "<<v[i].sc<<"\n";
            }
        }
        else {
            cout <<-1;
        }


    }
    else if (v.empty() || s.size() == 1)cout <<-1;
    else{
        cout <<v.size()<<"\n";
        for (i=0;i<v.size();++i){
            cout <<v[i].fr.fr<<" "<<v[i].fr.sc<<" "<<v[i].sc<<"\n";
        }
    }
}





Compilation message

nicegift.cpp: In function 'void fun(long long int)':
nicegift.cpp:28:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         for (i=0;i<g[x.sc].size();++i){
      |                  ~^~~~~~~~~~~~~~~
nicegift.cpp:20:11: warning: unused variable 'j' [-Wunused-variable]
   20 |     int i,j,k;
      |           ^
nicegift.cpp:20:13: warning: unused variable 'k' [-Wunused-variable]
   20 |     int i,j,k;
      |             ^
nicegift.cpp: At global scope:
nicegift.cpp:38:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   38 | main(){
      |      ^
nicegift.cpp: In function 'int main()':
nicegift.cpp:69:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |             for (i=0;i<v.size();++i){
      |                      ~^~~~~~~~~
nicegift.cpp:82:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |         for (i=0;i<v.size();++i){
      |                  ~^~~~~~~~~
nicegift.cpp:39:15: warning: unused variable 'j' [-Wunused-variable]
   39 |     int n,k,i,j;
      |               ^
nicegift.cpp:10:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 | #define scan2(a,b) scanf("%lld %lld",&a, &b);
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~
nicegift.cpp:42:5: note: in expansion of macro 'scan2'
   42 |     scan2(n,k)
      |     ^~~~~
nicegift.cpp:9:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 | #define scan1(a) scanf("%lld",&a);
      |                  ~~~~~^~~~~~~~~~~
nicegift.cpp:45:9: note: in expansion of macro 'scan1'
   45 |         scan1(x)
      |         ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB n=4
2 Correct 2 ms 2668 KB n=3
3 Correct 2 ms 2668 KB n=3
4 Correct 2 ms 2668 KB n=4
5 Correct 2 ms 2668 KB n=4
6 Correct 3 ms 2668 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB n=4
2 Correct 2 ms 2668 KB n=3
3 Correct 2 ms 2668 KB n=3
4 Correct 2 ms 2668 KB n=4
5 Correct 2 ms 2668 KB n=4
6 Correct 3 ms 2668 KB n=2
7 Correct 2 ms 2668 KB n=5
8 Correct 3 ms 2668 KB n=8
9 Correct 7 ms 3248 KB n=14
10 Correct 4 ms 2992 KB n=11
11 Correct 36 ms 7148 KB n=50000
12 Correct 51 ms 7652 KB n=50000
13 Correct 19 ms 3564 KB n=10
14 Correct 31 ms 4324 KB n=685
15 Correct 33 ms 4324 KB n=623
16 Correct 20 ms 3692 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB n=4
2 Correct 2 ms 2668 KB n=3
3 Correct 2 ms 2668 KB n=3
4 Correct 2 ms 2668 KB n=4
5 Correct 2 ms 2668 KB n=4
6 Correct 3 ms 2668 KB n=2
7 Correct 2 ms 2668 KB n=5
8 Correct 3 ms 2668 KB n=8
9 Correct 7 ms 3248 KB n=14
10 Correct 4 ms 2992 KB n=11
11 Correct 36 ms 7148 KB n=50000
12 Correct 51 ms 7652 KB n=50000
13 Correct 19 ms 3564 KB n=10
14 Correct 31 ms 4324 KB n=685
15 Correct 33 ms 4324 KB n=623
16 Correct 20 ms 3692 KB n=973
17 Incorrect 36 ms 4456 KB Taken too much stones from the heap
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2090 ms 115156 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB n=4
2 Correct 2 ms 2668 KB n=3
3 Correct 2 ms 2668 KB n=3
4 Correct 2 ms 2668 KB n=4
5 Correct 2 ms 2668 KB n=4
6 Correct 3 ms 2668 KB n=2
7 Correct 2 ms 2668 KB n=5
8 Correct 3 ms 2668 KB n=8
9 Correct 7 ms 3248 KB n=14
10 Correct 4 ms 2992 KB n=11
11 Correct 36 ms 7148 KB n=50000
12 Correct 51 ms 7652 KB n=50000
13 Correct 19 ms 3564 KB n=10
14 Correct 31 ms 4324 KB n=685
15 Correct 33 ms 4324 KB n=623
16 Correct 20 ms 3692 KB n=973
17 Incorrect 36 ms 4456 KB Taken too much stones from the heap
18 Halted 0 ms 0 KB -