Submission #334450

# Submission time Handle Problem Language Result Execution time Memory
334450 2020-12-09T07:30:46 Z beksultan04 Gift (IZhO18_nicegift) C++14
0 / 100
877 ms 79340 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()>1){
        pii x = *s.rbegin();
        s.erase(x);
        pii y = *s.rbegin();
        s.erase(y);
        int z = abs(x.fr-y.fr);
        if (z > 0)
            s.insert({z,y.sc});
        v.pb({{min(x.fr,y.fr),x.sc},y.sc});
    }
    if (v.empty() || !s.empty())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:60:15: 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]
   60 |     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 Incorrect 2 ms 2668 KB Taken too much stones from the heap
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB n=4
2 Incorrect 2 ms 2668 KB Taken too much stones from the heap
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB n=4
2 Incorrect 2 ms 2668 KB Taken too much stones from the heap
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 877 ms 79340 KB n=1000000
2 Incorrect 580 ms 56428 KB Expected int32, but "1500001500001" found
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2668 KB n=4
2 Incorrect 2 ms 2668 KB Taken too much stones from the heap
3 Halted 0 ms 0 KB -