QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#777836#5420. Inscryptionhaha#Compile Error//C++141.1kb2024-11-24 10:12:362024-11-24 10:12:36

Judging History

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

  • [2024-11-24 10:12:36]
  • 评测
  • [2024-11-24 10:12:36]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

int n;

void solve() {
    scanf("%d", &n);
    // s:序列元素之和
    // c:序列元素数量
    // t:之前所有自由选择事件中,选了几次事件二
    int s = 1, c = 1, t = 0;
    bool failed = false;
    // 按顺序处理所有事件
    for (int i = 1; i <= n; i++) {
        int x; scanf("%d", &x);
        // 事件一
        if (x == 1) s++, c++;
        // 事件二
        else if (x == -1) {
            // 尝试直接执行
            if (c > 1) c--;
            // 无法直接执行,尝试反悔一次自由选择
            else if (t >= 1) t--, s++, c++;
            // 无法反悔,无解
            else failed = true;
        } else {
            // 自由选择事件,尽可能选择事件二
            if (c > 1) t++, c--;
            else s++, c++;
        }
    }
    if (failed) printf("-1\n");
    else {
        int g = gcd(s, c);
        printf("%d %d\n", s / g, c / g);
    }
}

int main() {
    int tcase; scanf("%d", &tcase);
    while (tcase--) solve();
    return 0;
}

Details

answer.code: In function ‘void solve()’:
answer.code:34:17: error: ‘gcd’ was not declared in this scope
   34 |         int g = gcd(s, c);
      |                 ^~~
answer.code:7:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
answer.code:15:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |         int x; scanf("%d", &x);
      |                ~~~~~^~~~~~~~~~
answer.code: In function ‘int main()’:
answer.code:40:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   40 |     int tcase; scanf("%d", &tcase);
      |                ~~~~~^~~~~~~~~~~~~~