QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#152437#6617. Encoded Strings ILFCode#WA 1ms4044kbC++141.8kb2023-08-28 08:30:122023-08-28 08:30:12

Judging History

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

  • [2023-08-28 08:30:12]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4044kb
  • [2023-08-28 08:30:12]
  • 提交

answer

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <vector>

#define DEBUG(x) std::cerr << #x << " = " << x << std::endl;
#define forall(G, i_) for (int i_ = 0, __for_siz__ = (int) G.size(); i_ < __for_siz__; ++i_)
#define ALL(x) (x).begin(), (x).end()
typedef long long int lli;
using std::cin;
using std::cout;
using std::endl;

inline int read() {
    int s = 0, x = 1; char ch = getchar();
    while (!isdigit(ch)) { if (ch == '-') x = -x; ch = getchar(); }
    while (isdigit(ch)) { s = s * 10 + ch - '0'; ch = getchar(); }
    return s * x;
}

inline int readll() {
    long long int s = 0, x = 1; char ch = getchar();
    while (!isdigit(ch)) { if (ch == '-') x = -x; ch = getchar(); }
    while (isdigit(ch)) { s = s * 10ll + ch - '0'; ch = getchar(); }
    return s * x;
}

const int MAXCH = 20 + 2;
const int MAXN = 1000 + 10;

int n;
char sss[MAXN];
int calc[MAXCH];
int g[MAXCH];
std::vector<std::string> resss;

void encode(char *ss) {
    int len = strlen(ss);
    memset(g, 0, sizeof g);
    for (int i = 0; i < 21; ++i) {
        // calc G(s);
        memset(calc, 0, sizeof calc);
        for (int j = len - 1; j >= 0; --j) {
            if (ss[j] - 'a' == i) break;
            calc[ss[j] - 'a']++;
        } 
        for (int j = 0; j < 21; ++j) {
            g[i] += (calc[j] != 0);
        }
    }
    std::string res;
    for (int i = 0; i < len; ++i) res += g[ss[i] - 'a'] + 'a';
    resss.push_back(res);
}

int main() {
    scanf("%d", &n); scanf("%s", sss);
    int len = strlen(sss);
    for (int i = 0; i < len; ++i) {
        encode(sss + i);
    } std::sort(resss.begin(), resss.end());
    printf("%s\n", resss[resss.size() - 1].c_str());
    return 0;
}

详细

Test #1:

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

input:

4
aacc

output:

bbaa

result:

ok single line: 'bbaa'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3776kb

input:

3
aca

output:

ba

result:

ok single line: 'ba'

Test #3:

score: 0
Accepted
time: 1ms
memory: 4044kb

input:

1
t

output:

a

result:

ok single line: 'a'

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 3692kb

input:

12
bcabcabcbcbb

output:

cabcababaa

result:

wrong answer 1st lines differ - expected: 'cbacba', found: 'cabcababaa'