/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 332.0 KiB
#2 Accepted 772ms 672.0 KiB
#3 Accepted 759ms 684.0 KiB
#4 Accepted 750ms 684.0 KiB
#5 Accepted 755ms 680.0 KiB
#6 Accepted 774ms 764.0 KiB
#7 Accepted 881ms 676.0 KiB
#8 Accepted 13ms 588.0 KiB
#9 Accepted 2ms 568.0 KiB
#10 Accepted 653ms 684.0 KiB
#11 Accepted 2ms 324.0 KiB
#12 Accepted 96ms 596.0 KiB
#13 Accepted 1260ms 664.0 KiB
#14 Accepted 573ms 612.0 KiB
#15 Accepted 591ms 676.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;

// Function to return the maximum of two numeric strings
string max_num(const string& a, const string& b){
    if(a.length() > b.length()) return a;
    if(a.length() < b.length()) return b;
    return (a > b) ? a : b;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int T;
    cin >> T;
    while(T--){
        int N, K;
        cin >> N >> K;
        vector<string> s(N);
        for(int i=0; i<N; i++) cin >> s[i];
        
        // Initialize max_number as the first element
        string max_number = s[0];
        for(int i=1; i<N; i++) {
            max_number = max_num(max_number, s[i]);
        }
        
        // Determine the maximum number by considering all possible concatenations
        int max_m = min(K+1, N); // Maximum group size
        for(int m=2; m<=max_m; m++){
            for(int i=0; i + m <= N; i++){
                // Concatenate elements from index i to i+m-1
                string concat = "";
                for(int j=i; j<i+m; j++) concat += s[j];
                
                // Update max_number if the concatenated string is larger
                max_number = max_num(max_number, concat);
            }
        }
        
        cout << max_number << "\n";
    }
}

Information

Submit By
Type
Submission
Problem
P1083 Number concatenation
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-04 16:05:08
Judged At
2024-11-11 02:42:40
Judged By
Score
100
Total Time
1260ms
Peak Memory
764.0 KiB