题目 › fcs-121

FrontierCS #121

FrontierCS 算法赛道 v1.1 · 2026-05 · L5 开放式 · C++17 · 时限 2 秒 · 0–100 连续分

查看原题跳到结果

题面

来源:FrontierCS 官方 statement.txt,与模型收到的题面相同。

DNA Matching Time Limit: 2 s Memory Limit: 512 MB A string s is called a “DNA sequence” if and only if s consists only of the characters A, C, G, T. You are given m strings s1, s2, ..., sm, each of length n, and each of them consists only of the characters A, C, G, T, ?. For a DNA sequence t of length n, we call t valid if and only if there exists an index i (1 ≤ i ≤ m) and a way to replace each ? in si by one of A,C,G,T, so that after replacement the resulting string s_i' is exactly equal to t. You need to compute the probability that a randomly chosen DNA sequence t (of length n, where each of the 4^n possible DNA sequences is equally likely) is valid. Input Format The first line contains two positive integers n, m. Then follow m lines, each line contains a string si of length n. It is guaranteed that each si only uses characters from A, C, G, T, ?. Output Format Output one real number — the probability. Make sure the number is precise enough. Sample 1 input 3 1 AC? output 0.0625 Sample 2 input 6 2 AC??A? A??A?T output 0.0302734375 ## Scoring All feasibility and interaction limits apply before scoring; invalid output receives zero. Points are averaged over test files. For the logarithmic branch, write x for the original minimizing quantity and a for its physical 60-point reference. The improvement factor is r=a/x, and the upper-band award is P=min(100,60+ln(r)). Here ln is natural: r=1 corresponds to 60 points, and on the uncapped logarithmic upper band, r=exp(P-60). Each additional point multiplies the physical improvement factor by e (divides a minimizing objective by e or multiplies a maximizing objective by e, as applicable). The lower-band, zero-objective, and completion rules below still apply. p is the output probability and p_ref is the stored reference probability. When p_ref is nonzero, E=abs(p/p_ref-1). Define the objective x=E, its physical reference a=A=0.04, and the lower-band calculation L=100*max(0,1-10*E). If p_ref=0, output p=0 receives 100 and every nonzero p receives zero; the following rule applies only when p_ref is nonzero. ```text P = 100, if x <= 1e-9 P = L, if L <= 60 and x > 1e-9 P = min(100, 60 + ln(r)), otherwise ``` Relative error at most 1e-9 is treated as zero before the lower-band test. This numerical tolerance avoids requiring the exact rounding of the stored floating-point reference. For example, the stored value 0.0052510053510665894 and the rounded output 0.005251005351 both receive 100 points. The tolerance is relative, so outputting zero for a small nonzero reference does not receive full credit. Errors above this tolerance retain the scoring curve above. The checker reports P/100.

结果

Kimi K3.1 ProKimi

max

19.9

平均得分 ↑

  • 19.9采样 1 · 部分分
  • 19.9k平均输出 token(含思考) ↓
  • 31.7输出速度 tokens/s ↑
  • 629 秒延迟 ↓

Kimi K3.1 Pro(high)Kimi high

high

28.1

平均得分 ↑

  • 28.1采样 1 · 部分分
  • 4.9k平均输出 token(含思考) ↓
  • 26.4输出速度 tokens/s ↑
  • 190 秒延迟 ↓

DeepSeek Flash V4.1-1017DeepSeek

auto(high)

0.0

平均得分 ↑

  • 0.0采样 1 · 无代码
  • 57.3k平均输出 token(含思考) ↓
  • 203.4输出速度 tokens/s ↑
  • 282 秒延迟 ↓

MiniMax M3.1 FlashMiniMax

auto(max)

0.0

平均得分 ↑

  • 0.0采样 1 · 编译错误
  • 79.3k平均输出 token(含思考) ↓
  • 85.1输出速度 tokens/s ↑
  • 932 秒延迟 ↓

↑ 越大越好,↓ 越小越好。得分 0–100,按官方时限判定,所有测试点都满分才算解出。CPU 时间 / 官方解为解出的答案在官方解最慢的 3 个测试点上的 CPU 时间之比(几何平均),只比较官方解至少需要 0.05 秒的题;复杂度按增长幂次相对官方解分类。判题与计分见 原理。

代码

Kimi K3.1 Pro · 采样 1 · 123 行
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m;
    cin >> n >> m;

    vector<string> s(m);
    for (string &x : s) cin >> x;

    const int N = 1 << m;
    vector<int> wildCount(N, 0);
    vector<unsigned char> bad(N, 0);

    auto letterId = [](char c) {
        if (c == 'A') return 0;
        if (c == 'C') return 1;
        if (c == 'G') return 2;
        return 3;
    };

    vector<array<unsigned long long, 4>> positionBits(m);

    for (int base = 0; base < n; base += 64) {
        for (auto &a : positionBits) a.fill(0);

        int len = min(64, n - base);
        for (int offset = 0; offset < len; ++offset) {
            int pos = base + offset;
            int wildMask = 0;
            unsigned long long bit = 1ULL << offset;

            for (int i = 0; i < m; ++i) {
                char c = s[i][pos];
                if (c == '?') {
                    wildMask |= 1 << i;
                } else {
                    positionBits[i][letterId(c)] |= bit;
                }
            }
            ++wildCount[wildMask];
        }

        for (int i = 0; i < m; ++i) {
            for (int j = i + 1; j < m; ++j) {
                int pairMask = (1 << i) | (1 << j);
                if (bad[pairMask]) continue;

                bool conflict = false;
                for (int a = 0; a < 4 && !conflict; ++a) {
                    for (int b = 0; b < 4; ++b) {
                        if (a != b &&
                            (positionBits[i][a] & positionBits[j][b])) {
                            conflict = true;
                            break;
                        }
                    }
                }
                if (conflict) bad[pairMask] = 1;
            }
        }
    }

    for (int b = 0; b < m; ++b) {
        int bit = 1 << b;
        for (int start = 0; start < N; start += 2 * bit) {
            for (int offset = 0; offset < bit; ++offset) {
                int low = start + offset;
                int high = low + bit;
                wildCount[low] += wildCount[high];
                bad[high] |= bad[low];
            }
        }
    }

    int maxWild = 0;
    for (int i = 0; i < m; ++i) {
        maxWild = max(maxWild, wildCount[1 << i]);
    }

    long double sum = 0.0L;
    long double compensation = 0.0L;

    auto addTerm = [&](long double value) {
        long double next = sum + value;
        if (fabsl(sum) >= fabsl(value)) {
            compensation += (sum - next) + value;
        } else {
            compensation += (value - next) + sum;
        }
        sum = next;
    };

    for (int mask = 1; mask < N; ++mask) {
        if (bad[mask]) continue;

        int difference = maxWild - wildCount[mask];
        if (difference > 20000) continue;

        long double term = ldexp(1.0L, -2 * difference);
        if (__builtin_popcount((unsigned)mask) % 2 == 0) {
            term = -term;
        }
        addTerm(term);
    }
    sum += compensation;

    int scale = n - maxWild;
    long double logProbability =
        log10(sum) - (long double)scale * log10(4.0L);

    long long exponent = (long long)floor(logProbability);
    long double mantissa =
        pow(10.0L, logProbability - (long double)exponent);

    cout << fixed << setprecision(17)
         << mantissa << 'e' << exponent << '\n';

    return 0;
}