Submission #443911

#TimeUsernameProblemLanguageResultExecution timeMemory
443911MahfuzAhmedGrudanje (COCI19_grudanje)C++14
Compilation error
0 ms0 KiB
/**
 *  author: mahfuzz
 *  created: 12.07.2021
**/
 
#include <bits/stdc++.h>
using namespace std;
#define trace(x) cerr << '>' << #x << ':' << x << endl;
#define all(p) p.begin(),p.end()
typedef long long ll;

int main(int argc, char* argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
	
	string s; cin >> s;
    int n = s.size();
    
    int q; cin >> q;
    vector<pii> vec;
    
    for(int i = 0; i < q; i++){
        int l, r; cin >> l >> r;
        vec.push_back({l, r});
    }
    
    int arr[n];
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    
    auto check = [&](int x){
        string temp = s;
    
        for(int k = 0; k < x; k++){
            temp[arr[k] - 1] = '*';
        }
        
        int g[26][26] = {{0}};
        
        for(int i = 0; i < 26; i++){
            char c = 'a' + i;
            
            for(int j = 0; temp[j]; j++){
                if(temp[j] == c){
                    g[i][j] = g[i][(j == 0 ? 0 : j - 1)] + 1;
                }else{
                    g[i][j] = g[i][(j == 0 ? 0 : j - 1)];
                }
            }
        }
        
        for(auto a : vec){
            int l = a.first, r = a.second;
            
            for(int i = 0; i < 26; i++){     
                if(g[i][r - 1] - g[i][l - 2] > 1)
                    return false;
            }
        }
        
        return true;
    };
    
    
    if(check(0)){
        cout << "0\n";
        return 0;
    }
    
    int l = 1, r = n;
    int ans = 0;
    while(l <= r){
        int mid = (l + r) / 2;
        
        if(check(mid)){
            ans = mid;
            r = mid - 1;
        }else{
            l = mid + 1;
        }
    }
    
    cout << ans << "\n";
    
    return 0;
}

Compilation message (stderr)

grudanje.cpp: In function 'int main(int, char**)':
grudanje.cpp:20:12: error: 'pii' was not declared in this scope
   20 |     vector<pii> vec;
      |            ^~~
grudanje.cpp:20:15: error: template argument 1 is invalid
   20 |     vector<pii> vec;
      |               ^
grudanje.cpp:20:15: error: template argument 2 is invalid
grudanje.cpp:24:13: error: request for member 'push_back' in 'vec', which is of non-class type 'int'
   24 |         vec.push_back({l, r});
      |             ^~~~~~~~~
grudanje.cpp: In lambda function:
grudanje.cpp:52:22: error: 'begin' was not declared in this scope; did you mean 'std::begin'?
   52 |         for(auto a : vec){
      |                      ^~~
      |                      std::begin
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from grudanje.cpp:6:
/usr/include/c++/10/valarray:1224:5: note: 'std::begin' declared here
 1224 |     begin(const valarray<_Tp>& __va)
      |     ^~~~~
grudanje.cpp:52:22: error: 'end' was not declared in this scope; did you mean 'std::end'?
   52 |         for(auto a : vec){
      |                      ^~~
      |                      std::end
In file included from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:95,
                 from grudanje.cpp:6:
/usr/include/c++/10/valarray:1244:5: note: 'std::end' declared here
 1244 |     end(const valarray<_Tp>& __va)
      |     ^~~
grudanje.cpp:56:25: error: 'r' was not declared in this scope
   56 |                 if(g[i][r - 1] - g[i][l - 2] > 1)
      |                         ^