QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#815932#9871. Just another Sorting Problemtamir#Compile Error//C++20964b2024-12-15 19:04:572024-12-15 19:04:57

Judging History

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

  • [2024-12-15 19:04:57]
  • 评测
  • [2024-12-15 19:04:57]
  • 提交

answer

#include<iostream>
using namespace std;

void solve() {
    int n; string st;
    cin >> n >> st;

    vector<int> a(n);
    int cnt = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
         a[i]--;
        if(a[i] != i) {
            cnt++;
        }
    }
    if(st == "Alice") {
        if(cnt <= 2) {
            cout << "Alice\n";
            return;
        }
    } else {
        int mx = 0;
        for(int i = 1; i < n; i++){
            int t = cnt;
            //(i - 1, i)
            if(a[i - 1] == i - 1)t++;
            if(a[i] == i)t++;
            if(a[i] == i - 1)t--;
            if(a[i - 1] == i)t--;
            mx = max(mx, t);
        }
        if(mx >= 3){
            cout << "Bob\n";
        } else {
            cout << "Alice\n";
        }
    }
}

int main() {
    ios::sync_with_stdio(0); cin.tie(nullptr);
    int t = 1;
    cin >> t;
    while(t--) {
        solve();
    }
}

Details

answer.code: In function ‘void solve()’:
answer.code:8:5: error: ‘vector’ was not declared in this scope
    8 |     vector<int> a(n);
      |     ^~~~~~
answer.code:2:1: note: ‘std::vector’ is defined in header ‘<vector>’; did you forget to ‘#include <vector>’?
    1 | #include<iostream>
  +++ |+#include <vector>
    2 | using namespace std;
answer.code:8:12: error: expected primary-expression before ‘int’
    8 |     vector<int> a(n);
      |            ^~~
answer.code:11:16: error: ‘a’ was not declared in this scope
   11 |         cin >> a[i];
      |                ^
answer.code:27:16: error: ‘a’ was not declared in this scope
   27 |             if(a[i - 1] == i - 1)t++;
      |                ^
answer.code:28:16: error: ‘a’ was not declared in this scope
   28 |             if(a[i] == i)t++;
      |                ^
answer.code:29:16: error: ‘a’ was not declared in this scope
   29 |             if(a[i] == i - 1)t--;
      |                ^
answer.code:30:16: error: ‘a’ was not declared in this scope
   30 |             if(a[i - 1] == i)t--;
      |                ^