Submission #1092069

#TimeUsernameProblemLanguageResultExecution timeMemory
1092069vjudge1A Plus B (IOI23_aplusb)C++17
100 / 100
40 ms2632 KiB
#include<bits/stdc++.h> #include "aplusb.h" using namespace std; #define ll long long #define fi first #define se second #define pb push_back #define re exit(0); #define left id<<1 #define right id<<1|1 const int mod = 1e9+7; const int INF = 1e9; typedef vector<int> vi ; typedef pair<int,int> pii ; typedef vector<pii> vii ; void add ( int &a , int b ) { if ( a += b >= mod) a -= mod; } void sub ( int &a , int b ) { if ( a -= b <= mod ) a += mod; } template < typename T > void chkmin ( T &a , T b ) { if ( a > b ) a = b ; } template < typename T > void chkmax ( T &a , T b ) { if ( a < b ) a = b ; } void runfile() { freopen ("inp.txt","r",stdin) ; } vi smallest_sums ( int N , vi A , vi B ) { ll l = 0 , r = 2e9 , res ; while ( l <= r ) { ll mid = (l+r)/2 ; int j = N-1 ; ll total = 0 ; for ( int i = 0 ; i < N ; i ++ ) { while ( A[i] + B[j] > mid && j >= 1 ) j -- ; if ( A[i] + B[j] <= mid ) total += j+1 ; } if ( total >= N ) r = mid-1 , res = mid ; else l = mid+1 ; } vi answer ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { if ( A[i] + B[j] <= res ) answer . pb (A[i]+B[j]) ; else break ; } } sort(answer.begin(),answer.end()) ; while (answer.size() > N ) answer.pop_back() ; return answer ; }

Compilation message (stderr)

aplusb.cpp: In function 'vi smallest_sums(int, vi, vi)':
aplusb.cpp:54:26: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   54 |     while (answer.size() > N ) answer.pop_back() ;
      |            ~~~~~~~~~~~~~~^~~
aplusb.cpp: In function 'void runfile()':
aplusb.cpp:26:26: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 | void runfile() { freopen ("inp.txt","r",stdin) ; }
      |                  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~
aplusb.cpp: In function 'vi smallest_sums(int, vi, vi)':
aplusb.cpp:49:13: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   49 |             if ( A[i] + B[j] <= res ) answer . pb (A[i]+B[j]) ;
      |             ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...