QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#219543#5666. Repetitive Elementsshen0628#WA 7ms4040kbC++171.2kb2023-10-19 16:08:572023-10-19 16:08:58

Judging History

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

  • [2023-10-19 16:08:58]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:4040kb
  • [2023-10-19 16:08:57]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii; // (cnt,start_pos)
typedef long double ld;
typedef long long ll;
string s;
unordered_map<string,pii> mp;
vector<pair<string,int>> ans;
void solve(){
  mp.clear();
  ans.clear();
  cin>>s;
  int k=s.size()-1;
  for(int i=k;i>=1;i--){//100
    bool flag=false; // 
    for(int j=0;j+i<s.size();j++){//100
      string tmp=s.substr(j,i);//100
      if(mp.count(tmp)&&mp[tmp].second+i-1<j){//map -> O(log100) unordered_map->O(1)
        ans.push_back({tmp,mp[tmp].second}); // push_back(可能的ans string,出現的位置)
        flag=true; // 在長度 i 時有出現答案,繼續驗完所有長度為 i 的字串
      }else{
        mp[tmp]={1,j};
      }
    }
    if(flag) break;// 之後<i的都不是答案
  }
  sort(ans.begin(),ans.end(),[](const pair<string,int> &a,const pair<string,int> &b) -> bool{
    return a.second<b.second;
  }); // 依首次出現位置做排序 最多排序 100 個字串 O(100log100)
  cout<<ans[0].first<<"\n";
}
int main(){
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int tt=1; cin >> tt;
  while(tt--){
    solve();
  } 
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3476kb

input:

5
TATCGATCGAGTTGT
TCCGCGAGCGAGTCTCTCCATT
GTTTCATCATACGAGGCCCCATACGCGCTGG
AGATGGGATCCTTATG
GCCCTTAGGCATGGGATGTCGTTTCTTG

output:

ATCG
GCGA
CATACG
GAT
CTT

result:

ok 5 lines

Test #2:

score: -100
Wrong Answer
time: 7ms
memory: 4040kb

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
GA
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:

wrong answer 22nd lines differ - expected: 'GAG', found: 'GA'