/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 9ms 2.984 MiB
#3 Accepted 9ms 2.75 MiB
#4 Accepted 8ms 2.602 MiB
#5 Accepted 12ms 2.918 MiB
#6 Accepted 8ms 2.602 MiB
#7 Accepted 2ms 540.0 KiB
#8 Accepted 1ms 540.0 KiB
#9 Accepted 1ms 544.0 KiB
#10 Accepted 2ms 612.0 KiB
#11 Accepted 1ms 340.0 KiB
#12 Accepted 1ms 540.0 KiB
#13 Accepted 1ms 540.0 KiB
#14 Accepted 1ms 588.0 KiB
#15 Accepted 1ms 540.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
const long long M=3e5+10,MOD=1000000000;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--){
        int n,k;
        cin>>n>>k;
        vector<int>a(n+1,0);
        string p="";
        for(int i=1;i<=n;i++){
            string s;
            cin>>s;
            p+=s;
            a[i]=(int)s.size();
            a[i]+=a[i-1];
        }
        int maximum_digit=0;
        for(int i=1;i<=n;i++){// target to find maximum digit possible
            if(i+k<=n)maximum_digit=max(maximum_digit,a[i+k]-a[i-1]);
        }
        vector<int>pos;
        for(int i=1;i<=n;i++){
            if(i+k<=n&&a[i+k]-a[i-1]==maximum_digit)pos.push_back(i);
        }
        vector<string>ans;
        for(int x:pos){
            string s="";
            int l=a[x-1];
            while(s.size()<maximum_digit)s+=p[l],l++;
            ans.push_back(s);
        }
        sort(ans.begin(),ans.end());
        cout<<ans[ans.size()-1]<<"\n";


    
    }


   
   return 0;
 
}

Information

Submit By
Type
Submission
Problem
P1083 Number concatenation
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-07 23:41:06
Judged At
2024-08-07 23:41:06
Judged By
Score
100
Total Time
12ms
Peak Memory
2.984 MiB