QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#640267#8781. Element-Wise Comparisonqianchen06WA 0ms3788kbC++141.2kb2024-10-14 10:16:122024-10-14 10:16:16

Judging History

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

  • [2024-10-14 10:16:16]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3788kb
  • [2024-10-14 10:16:12]
  • 提交

answer

#include <iostream>
#include <vector>
#include <bitset>
using namespace std;

const int MAXN = 5000;
bitset<MAXN> B[MAXN];

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> p(n);

    // 输入排列 p
    for (int i = 0; i < n; ++i)
    {
        cin >> p[i];
    }

    // 构建布尔矩阵,C[l,s] 表示 p[l] < p[l+s]
    for (int l = 0; l < n; ++l)
    {
        for (int s = 1; l + s < n; ++s)
        {
            if (p[l] < p[l + s])
            {
                B[l][s] = 1;
            }
        }
    }

    // 计数符合条件的子数组对
    int result = 0;

    for (int i = 0; i <= n - m; ++i)
    {
        for (int j = i + m; j <= n - m; ++j)
        {
            // 比较区间 [i, i+m) 和 [j, j+m) 是否逐个小于
            bool isValid = true;
            for (int k = 0; k < m; ++k)
            {
                if (p[i + k] >= p[j + k])
                {
                    isValid = false;
                    break;
                }
            }
            if (isValid)
            {
                result++;
            }
        }
    }

    cout << result << endl;
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 3
5 2 1 3 4

output:

0

result:

ok answer is '0'

Test #2:

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

input:

5 2
3 1 4 2 5

output:

2

result:

ok answer is '2'

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3788kb

input:

4 2
1 2 3 4

output:

1

result:

wrong answer expected '3', found '1'