QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#506603#5671. Programmable VirusUESTC_DECAYALIAC ✓1ms3880kbC++142.8kb2024-08-05 20:03:222024-08-05 20:03:22

Judging History

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

  • [2024-08-05 20:03:22]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3880kb
  • [2024-08-05 20:03:22]
  • 提交

answer

#include <bits/stdc++.h>

int k;
std::vector<int> ans;

enum {
    REG_ZERO = 0,
    REG_STATUS = 1,
    REG_NEW_STATUS = 2,
    REG_INPUT = 3,
};

int STACK_TOP = 4;

const char *v[10] = {
    "CCC",
    "ACG",
    "UGA",
    "UGC",
    "UAC",
    "GCG",
    "UCC",
    "AGG",
    "UGU",
    "CAC",
};

int p = 0;

void MOVE_P(int to) {
    while(p < to) ++p, ans.push_back(1);
    while(p > to) --p, ans.push_back(2);
}

void INC (int c) { MOVE_P(c); ans.push_back(3); }
void DEC (int c) { MOVE_P(c); ans.push_back(4); }

void WHILE(int c, std::function<void()> body) {
    MOVE_P(c);
    ans.push_back(7);
    body();
    MOVE_P(c);
    ans.push_back(8);
}

void SET(int c, int val) {
    WHILE(c, [&]() {
        INC(c);
    });
    if(val < 0) DEC(c);
    else while(val--) INC(c);
}

void ADDTO(int from, int to) {
    WHILE(from, [&]() {
        INC(to);
        DEC(from);
    });
}

int PUSH() {
    int res = STACK_TOP++;
    SET(res, 0);
    return res;
}

void POP() {
    STACK_TOP--;
}

void DEBUG() {
    ans.push_back(9);
}

void MOVE(int from, int to) {
    int temp = PUSH();
    SET(to, 0);
    WHILE(from, [&] {
        INC(to);
        INC(temp);
        DEC(from);
    });
    ADDTO(temp, from);
    POP();
}

void EQ(int lhs, int rhs, int res) {
    int t1 = PUSH(), t2 = PUSH();
    MOVE(lhs, t1);
    MOVE(rhs, t2);
    WHILE(t1, [&] {
        DEC(t1);
        DEC(t2);
    });
    SET(res, 1);
    WHILE(t2, [&] {
        SET(res, 0);
        SET(t2, 0);
    });
    POP(), POP();
}

void IFEQ(int c, int val, std::function<void()> callback) {
    int t1 = PUSH(), t2 = PUSH();
    SET(t1, val);
    EQ(c, t1, t2);
    WHILE(t2, [&] {
        callback();
        DEC(t2);
    });
    POP(), POP();
}

void WHILEEQ(int c, int val, std::function<void()> callback) {
    int t1 = PUSH(), t2 = PUSH();
    SET(t1, val);
    EQ(c, t1, t2);
    WHILE(t2, [&] {
        callback();
        SET(t1, val);
        EQ(c, t1, t2);
    });
    POP(), POP();
}

void INPUT() {
    MOVE_P(REG_INPUT);
    ans.push_back(6);
}

void EXIT(int val) {
    SET(p, val);
    ans.push_back(5);
    ans.push_back(0);
}

void WORK() {
    INPUT();
    IFEQ(REG_INPUT, -1, [&]() {
        IFEQ(REG_STATUS, 0, [&]() {
            EXIT(1);
        });
        EXIT(0);
    });
    for(int i = 0; i <= 9; ++i) IFEQ(REG_INPUT, i, [&]() {
        for(int j = 0; j < k; ++j) IFEQ(REG_STATUS, j, [&]() {
            SET(REG_NEW_STATUS, (j * 10 + i) % k);
        });
    });
    MOVE(REG_NEW_STATUS, REG_STATUS);
}

int main() {
    std::cin >> k;
    WHILEEQ(REG_ZERO, 0, WORK);
    for(auto ans: ans) std::cout << v[ans];
    std::cout << std::endl;
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3572kb

input:

1

output:

ACGACGACGACGAGGUGCUGUACGAGGUGCUGUUGAAGGUGCUGUACGACGAGGUGCUGUACGAGGUGCUGUACGAGGUGCUGUUGAUGAAGGUGCUGUUGAUGAUGAUGAUGAUGAAGGACGACGACGACGACGACGUGCACGACGUGCUGAUGAUGAUGAUGAUGAUGAUGAUACUGUACGACGACGACGACGACGACGACGAGGUGAUGAUGAUGAUGAUGAUGAUGAUGCACGACGACGACGACGACGACGACGUACUGUAGGUGCUGUUGAAGGUGCUGUUGAUGAUGAAGGACG...

result:

ok correct

Test #2:

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

input:

2

output:

ACGACGACGACGAGGUGCUGUACGAGGUGCUGUUGAAGGUGCUGUACGACGAGGUGCUGUACGAGGUGCUGUACGAGGUGCUGUUGAUGAAGGUGCUGUUGAUGAUGAUGAUGAUGAAGGACGACGACGACGACGACGUGCACGACGUGCUGAUGAUGAUGAUGAUGAUGAUGAUACUGUACGACGACGACGACGACGACGACGAGGUGAUGAUGAUGAUGAUGAUGAUGAUGCACGACGACGACGACGACGACGACGUACUGUAGGUGCUGUUGAAGGUGCUGUUGAUGAUGAAGGACG...

result:

ok correct

Test #3:

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

input:

3

output:

ACGACGACGACGAGGUGCUGUACGAGGUGCUGUUGAAGGUGCUGUACGACGAGGUGCUGUACGAGGUGCUGUACGAGGUGCUGUUGAUGAAGGUGCUGUUGAUGAUGAUGAUGAUGAAGGACGACGACGACGACGACGUGCACGACGUGCUGAUGAUGAUGAUGAUGAUGAUGAUACUGUACGACGACGACGACGACGACGACGAGGUGAUGAUGAUGAUGAUGAUGAUGAUGCACGACGACGACGACGACGACGACGUACUGUAGGUGCUGUUGAAGGUGCUGUUGAUGAUGAAGGACG...

result:

ok correct

Test #4:

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

input:

6

output:

ACGACGACGACGAGGUGCUGUACGAGGUGCUGUUGAAGGUGCUGUACGACGAGGUGCUGUACGAGGUGCUGUACGAGGUGCUGUUGAUGAAGGUGCUGUUGAUGAUGAUGAUGAUGAAGGACGACGACGACGACGACGUGCACGACGUGCUGAUGAUGAUGAUGAUGAUGAUGAUACUGUACGACGACGACGACGACGACGACGAGGUGAUGAUGAUGAUGAUGAUGAUGAUGCACGACGACGACGACGACGACGACGUACUGUAGGUGCUGUUGAAGGUGCUGUUGAUGAUGAAGGACG...

result:

ok correct

Test #5:

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

input:

1

output:

ACGACGACGACGAGGUGCUGUACGAGGUGCUGUUGAAGGUGCUGUACGACGAGGUGCUGUACGAGGUGCUGUACGAGGUGCUGUUGAUGAAGGUGCUGUUGAUGAUGAUGAUGAUGAAGGACGACGACGACGACGACGUGCACGACGUGCUGAUGAUGAUGAUGAUGAUGAUGAUACUGUACGACGACGACGACGACGACGACGAGGUGAUGAUGAUGAUGAUGAUGAUGAUGCACGACGACGACGACGACGACGACGUACUGUAGGUGCUGUUGAAGGUGCUGUUGAUGAUGAAGGACG...

result:

ok correct

Test #6:

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

input:

2

output:

ACGACGACGACGAGGUGCUGUACGAGGUGCUGUUGAAGGUGCUGUACGACGAGGUGCUGUACGAGGUGCUGUACGAGGUGCUGUUGAUGAAGGUGCUGUUGAUGAUGAUGAUGAUGAAGGACGACGACGACGACGACGUGCACGACGUGCUGAUGAUGAUGAUGAUGAUGAUGAUACUGUACGACGACGACGACGACGACGACGAGGUGAUGAUGAUGAUGAUGAUGAUGAUGCACGACGACGACGACGACGACGACGUACUGUAGGUGCUGUUGAAGGUGCUGUUGAUGAUGAAGGACG...

result:

ok correct

Test #7:

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

input:

3

output:

ACGACGACGACGAGGUGCUGUACGAGGUGCUGUUGAAGGUGCUGUACGACGAGGUGCUGUACGAGGUGCUGUACGAGGUGCUGUUGAUGAAGGUGCUGUUGAUGAUGAUGAUGAUGAAGGACGACGACGACGACGACGUGCACGACGUGCUGAUGAUGAUGAUGAUGAUGAUGAUACUGUACGACGACGACGACGACGACGACGAGGUGAUGAUGAUGAUGAUGAUGAUGAUGCACGACGACGACGACGACGACGACGUACUGUAGGUGCUGUUGAAGGUGCUGUUGAUGAUGAAGGACG...

result:

ok correct

Test #8:

score: 0
Accepted
time: 0ms
memory: 3624kb

input:

4

output:

ACGACGACGACGAGGUGCUGUACGAGGUGCUGUUGAAGGUGCUGUACGACGAGGUGCUGUACGAGGUGCUGUACGAGGUGCUGUUGAUGAAGGUGCUGUUGAUGAUGAUGAUGAUGAAGGACGACGACGACGACGACGUGCACGACGUGCUGAUGAUGAUGAUGAUGAUGAUGAUACUGUACGACGACGACGACGACGACGACGAGGUGAUGAUGAUGAUGAUGAUGAUGAUGCACGACGACGACGACGACGACGACGUACUGUAGGUGCUGUUGAAGGUGCUGUUGAUGAUGAAGGACG...

result:

ok correct

Test #9:

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

input:

5

output:

ACGACGACGACGAGGUGCUGUACGAGGUGCUGUUGAAGGUGCUGUACGACGAGGUGCUGUACGAGGUGCUGUACGAGGUGCUGUUGAUGAAGGUGCUGUUGAUGAUGAUGAUGAUGAAGGACGACGACGACGACGACGUGCACGACGUGCUGAUGAUGAUGAUGAUGAUGAUGAUACUGUACGACGACGACGACGACGACGACGAGGUGAUGAUGAUGAUGAUGAUGAUGAUGCACGACGACGACGACGACGACGACGUACUGUAGGUGCUGUUGAAGGUGCUGUUGAUGAUGAAGGACG...

result:

ok correct

Test #10:

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

input:

6

output:

ACGACGACGACGAGGUGCUGUACGAGGUGCUGUUGAAGGUGCUGUACGACGAGGUGCUGUACGAGGUGCUGUACGAGGUGCUGUUGAUGAAGGUGCUGUUGAUGAUGAUGAUGAUGAAGGACGACGACGACGACGACGUGCACGACGUGCUGAUGAUGAUGAUGAUGAUGAUGAUACUGUACGACGACGACGACGACGACGACGAGGUGAUGAUGAUGAUGAUGAUGAUGAUGCACGACGACGACGACGACGACGACGUACUGUAGGUGCUGUUGAAGGUGCUGUUGAUGAUGAAGGACG...

result:

ok correct