답안 #955398

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
955398 2024-03-30T10:40:34 Z Duine Matching (CEOI11_mat) C++14
0 / 100
2000 ms 29264 KB
#include <bits/stdc++.h>

using namespace std;

int n, m, h[1000005]{}, tmp[1000005]{}, g[1000005]{}, posh[1000005]{}, posg[1000005]{};

int find_pos (int x)
{
    int l = 1, r = n, mid;
    while (l <= r)
    {
        mid =  l + ((r-l) >> 1);
        if (x == tmp[mid]) return mid;
        else if (x > tmp[mid]) l = mid+1;
        else r = mid-1;
    }
}

int main ()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
    {
        cin >> h[i];
        tmp[i] = h[i];
    }
    for (int i = 1; i <= m; ++i)
        cin >> g[i];
        
    sort (tmp+1, tmp+n+1);
    for (int i = 1; i <= n; ++i)
        posh[i] = find_pos(h[i]);
    
    for (int i = 1; i <= n; ++i) 
        tmp[i] = g[i];
    sort (tmp+1, tmp+n+1);
    for (int i = 1; i <= n; ++i)
        posg[i] = find_pos(g[i]);

    vector <int> res;
    for (int i = 1; i <= m-n+1; ++i)
    {
        bool check = true;
        for (int j = 1; j <= n; ++j)    
            if (posg[i+j-1] != posh[j])  { check = false; break; }
            
        if (check) res.push_back(i);
        
        for (int j = 1; j < n; ++j)
            if (g[i] < g[i+j]) --posg[i+j];
            
        int mn = n;
        for (int j = 1; j < n; ++j)
            if (g[i+n] < g[i+j]) { mn = min (mn, posg[i+j]); ++posg[i+j]; }
        posg[i+n] = mn;
    }
    
    cout << res.size() << '\n';
    for (int i = 0; i < res.size(); ++i)
        cout << res[i] << ' ';
    
    return 0;
}

Compilation message

mat.cpp: In function 'int main()':
mat.cpp:62:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     for (int i = 0; i < res.size(); ++i)
      |                     ~~^~~~~~~~~~~~
mat.cpp: In function 'int find_pos(int)':
mat.cpp:17:1: warning: control reaches end of non-void function [-Wreturn-type]
   17 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 8540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 8540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 130 ms 8864 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 161 ms 8848 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2008 ms 14372 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2054 ms 14428 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2009 ms 14548 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2009 ms 27008 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2009 ms 29264 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2003 ms 20808 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2050 ms 23124 KB Time limit exceeded
2 Halted 0 ms 0 KB -