QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#66134#5161. Last Guessfeeder1#RE 3ms3436kbC++142.0kb2022-12-07 00:37:162022-12-07 00:37:19

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-12-07 00:37:19]
  • 评测
  • 测评结果:RE
  • 用时:3ms
  • 内存:3436kb
  • [2022-12-07 00:37:16]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

set<ll> cmi[30], ez[30];
ll minx[30], cnt[30], curL[505];
vector<ll> aj[30];
bool maxn[30], vis[30];
bool aug(ll x) {
 if ( vis[x] )return false;
 vis[x] = true;
 for ( auto it : aj[x] ) {
  int a;
  if ( curL[it] == -1 || aug(curL[it]) ) {
   curL[it] = x;
   return true;
  }
 }
 return false;
}
int main() {
 ios::sync_with_stdio(0);
 cin.tie(0);
 int n, m, i, j, k, b, c, a;
 cin >> n >> m;
 assert(m <= 300);
 for ( i = 0; i < m; i++ )curL[i] = -1;
 string str, str2;
 for ( i = 0; i < n - 1; i++ ) {
  cin >> str >> str2;
  for ( j = 0; j < 26; j++ )cnt[j] = 0;
  for ( j = 0; j < str.size(); j++ ) {
   a = str[j] - 'a';
   if ( str2[j] == 'G' ) {
    curL[j] = a;
    cnt[a]++;
    ez[a].insert(j);
    cmi[a].insert(j);
   } else if ( str2[j] == 'Y' ) {
    cnt[a]++;
    cmi[a].insert(j);
   } else {
    cmi[a].insert(j);
    maxn[a] = true;
   }
  }
  for ( j = 0; j < 26; j++ )minx[j] = max(minx[j], cnt[j]);
 }
 for ( i = 0; i < 26; i++ ) {
  for ( j = 0; j < m; j++ ) {
   if ( cmi[i].find(j) != cmi[i].end() )continue;
   if ( curL[j] != -1 )continue;
   aj[i].push_back(j);
  }
 }
 for ( i = 0; i < 26; i++ ) {
  for ( k = 0; k < minx[i] - ez[i].size(); k++ ) {
   for ( j = 0; j < 26; j++ )vis[j] = false;
   vis[i] = true;
   for ( auto it : aj[i] ) {
    if ( curL[it] == -1 || aug(curL[it]) ) {
     curL[it] = i;
     break;
    }
   }
  }
 }
 ll cnt2 = 0;
 for ( i = 0; i < m; i++ ) {
  if ( curL[i] == -1 )cnt2++;
 }
 for ( i = 0; i < 26 && cnt2; i++ ) {
  if ( maxn[i] )continue;
  while ( cnt2 ) {
   for ( j = 0; j < 26; j++ )vis[j] = false;
   vis[i] = true;
   bool done = false;
   for ( auto it : aj[i] ) {
    if ( curL[it] == -1 || aug(curL[it]) ) {
     curL[it] = i;
     done = true;
     break;
    }
   }
   if ( !done )break;
   cnt2--;
  }
 }
 for ( i = 0; i < m; i++ ) {
  char ch = curL[i] + 'a';
  cout << ch;
 }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 3436kb

input:

4 5
reply YYGBB
refer BBBGG
puppy YYGBB

output:

upper

result:

ok 

Test #2:

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

input:

2 12
aabbccddeeff GGGYGBYYYBBB

output:

aabacaaaddeb

result:

ok 

Test #3:

score: -100
Dangerous Syscalls

input:

25 500
qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqoqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqjq...

output:


result: