Introduction to Programming Introduction to Algorithms and Data Structures Library of Data Structures Library of Graph Algorithms Library of Computational Geometry Library of Dynamic Programming Library of Number Theory
制約でなので,愚直にpriority_queueとかに突っ込むとで死ぬ.
3番目まで取っておく.
また数の連結もstringstreamを用いたらTLEした.
Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#define rep(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define inf 1<<30
#define pb push_back
#define mp make_pair
using namespace std ;
typedef long long ll ;
typedef pair < int , int > p ;
int main () {
int n ;
cin >> n ;
vector < int > v ( n );
rep ( i , n ) cin >> v [ i ];
sort ( v . begin (), v . end ());
int a = inf , b = inf , c = inf , x ;
rep ( i , n ) {
rep ( j , n ) {
if ( i == j ) continue ;
int x = v [ i ];
for ( int k = v [ j ]; k > 0 ; k /= 10 ) {
x *= 10 ;
}
x += v [ j ];
if ( x <= a ) {
c = b ;
b = a ;
a = x ;
} else if ( x <= b ) {
c = b ;
b = x ;
} else if ( x <= c ) {
c = x ;
}
}
}
cout << c << endl ;
return 0 ;
}