Submission #482361

# Submission time Handle Problem Language Result Execution time Memory
482361 2021-10-24T06:48:47 Z lollipop Gift (IZhO18_nicegift) C++17
0 / 100
630 ms 77336 KB
#include<bits/stdc++.h>
#define int long long 
#define pb push_back
#define s second
#define f first
using namespace std ;
const int mod =  1000000007 ;
map < int , int > ma ; 
signed main(){
	ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int n , k ; 
    cin >> n >> k ; 
    vector < vector < int > > v ; 
    multiset < pair < int , int > > se ; 
    for( int j = 1 ; j <= n ; j ++ ){
    	int x ; cin >> x ; 
    	se.insert( { x , j } ) ; 
	}
    while( se.size() > 0 ){
    	  vector < int > ve ; 
    	  if( se.size() < k ){
    	  	  cout << -1 ; 
    	  	  return 0 ; 
		  }
    	  int k1 = k - 1 ;
		  pair < int , int > p ; 
		  p = *se.begin() ;
		  int mn = p.f ; 
		  ve.pb( mn ) ; 
		  ve.pb( p.s ) ; 
		  se.erase( se.begin() ) ;   
		  vector < pair < int , int > > z ; 
    	  while( k1 -- ){
    	  	   pair < int , int > pa ; 
    	  	   pa = *se.begin() ; 
    	  	   ve.pb( pa.s ) ; 
    	  	   se.erase( se.begin() ) ; 
    	  	   pa.f -= mn ; 
    	  	   if( pa.f != 0 ) z.pb( pa ) ; 
		  }
		  for( int j = 0 ; j < z.size() ; j ++ ) se.insert( z[ j ] ) ; 
		  //sort( ve.begin() , ve.end() ) ; 
		 // ve.pb( p.f ) ;
		  v.pb( ve ) ;  
	}
	cout << v.size() << "\n"; 
     for( int j = 0 ; j < v.size() ; j ++ ){
     	for( int i = 0; i < v[ j ].size() ; i ++ ) cout << v[ j ][ i ] << " " ; cout << '\n' ; }
	 
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:21:22: warning: comparison of integer expressions of different signedness: 'std::multiset<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   21 |        if( se.size() < k ){
      |            ~~~~~~~~~~^~~
nicegift.cpp:41:24: 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]
   41 |     for( int j = 0 ; j < z.size() ; j ++ ) se.insert( z[ j ] ) ;
      |                      ~~^~~~~~~~~~
nicegift.cpp:47:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |      for( int j = 0 ; j < v.size() ; j ++ ){
      |                       ~~^~~~~~~~~~
nicegift.cpp:48:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |       for( int i = 0; i < v[ j ].size() ; i ++ ) cout << v[ j ][ i ] << " " ; cout << '\n' ; }
      |                       ~~^~~~~~~~~~~~~~~
nicegift.cpp:48:7: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   48 |       for( int i = 0; i < v[ j ].size() ; i ++ ) cout << v[ j ][ i ] << " " ; cout << '\n' ; }
      |       ^~~
nicegift.cpp:48:79: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   48 |       for( int i = 0; i < v[ j ].size() ; i ++ ) cout << v[ j ][ i ] << " " ; cout << '\n' ; }
      |                                                                               ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB n=4
2 Incorrect 0 ms 204 KB Jury has the answer but participant has not
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB n=4
2 Incorrect 0 ms 204 KB Jury has the answer but participant has not
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB n=4
2 Incorrect 0 ms 204 KB Jury has the answer but participant has not
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 630 ms 77336 KB n=1000000
2 Correct 350 ms 59076 KB n=666666
3 Correct 198 ms 36684 KB n=400000
4 Incorrect 114 ms 22084 KB Jury has the answer but participant has not
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB n=4
2 Incorrect 0 ms 204 KB Jury has the answer but participant has not
3 Halted 0 ms 0 KB -