QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#105238#5666. Repetitive ElementsSorting#AC ✓3ms3512kbC++201.2kb2023-05-13 19:13:152023-05-13 19:13:19

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-13 19:13:19]
  • 评测
  • 测评结果:AC
  • 用时:3ms
  • 内存:3512kb
  • [2023-05-13 19:13:15]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair < int , int > pii ;
typedef vector < int > vi ;
#define fi first
#define se second
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

int n ;
string a ;

bool eq ( int i , int j , int len ) {
    for ( int k = 0 ; k < len ; ++ k ) {
        if ( a[ i + k ] != a[ j + k ] ) { return false ; }
    }
    return true ;
}

int f ( int len ) {
    for ( int i = 0 ; i + len - 1 < n ; ++ i ) {
        for ( int j = i + len ; j + len - 1 < n ; ++ j ) {
            if ( eq ( i , j , len ) == true ) { return i ; }
        }
    }
    return -1 ;
}

void solve ( ) {
    cin >> a ;
    n = a.size ( ) ;
    int l , r , mid ;
    l = 1 , r = n / 2 ;
    while ( l < r ) {
        mid = ( l + r + 1 ) / 2 ;
        int ret = f ( mid ) ;
        if ( ret == -1 ) { r = mid - 1 ; }
        else { l = mid ; }
    }
    int pos = f ( l ) ;
    for ( int i = 0 ; i < l ; ++ i ) {
        cout << a[ pos + i ] ;
    }
    cout << "\n" ;
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    int t = 1 ; cin >> t ; 
    while ( t -- ) { solve ( ) ; }
    return 0 ;
}

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 3416kb

input:

5
TATCGATCGAGTTGT
TCCGCGAGCGAGTCTCTCCATT
GTTTCATCATACGAGGCCCCATACGCGCTGG
AGATGGGATCCTTATG
GCCCTTAGGCATGGGATGTCGTTTCTTG

output:

ATCG
GCGA
CATACG
GAT
CTT

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 3ms
memory: 3512kb

input:

50
TTGACAACTTCAGGTTGGCACTCCTTCATTTGGATTTCGGAATAATAGTTTTCTGCTCTGCC
ATCCTATTCGGGGATAGGAGAGATGGGTTGCCGCTATAAAAGCATTTGAACTCCATTTCACTCCGTTGGCTAGGGGTCGCACTG
CCGTAATATAAAGACTCGGAATTCCAATAGCTGCTATTTGCGAGTATGTGACTGAAAACACACCTATAAATATTAGCTGCGTACAAGCTA
ATGGCTGCATGCAGGGTCGACTAGACACACTTTGTCT
TTGAGGATGTCGACGTGTCT...

output:

CTTCA
CATTT
TAGCTGC
TGCA
ACGTG
GCGCCGG
CTCTT
AGTAT
AGAG
ACAG
TAT
TGAC
CTTG
CGTC
TACTGG
GCCGGT
GAA
CAGTA
GCGT
GGTT
CCCT
GAG
TAGAC
GGTGC
GCAGT
TGAG
ATCAA
CCACACA
GAGTC
ATGTA
ATGGTA
TATA
TATGAA
TTCC
CATACG
TACCA
TTAG
GGAATGT
CAGG
GCT
AAG
CTGT
GGAT
TCTTC
AAAAC
ATG
GATAA
TTA
ACATAT
CAAT

result:

ok 50 lines