Submission #638276

#TimeUsernameProblemLanguageResultExecution timeMemory
638276colazcyNivelle (COCI20_nivelle)C++17
110 / 110
209 ms10956 KiB
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <vector>
#define let const auto
#define rep(name,beg,end) for(auto lim_##name = end,name = beg;name <= lim_##name;name++)
#define per(name,beg,end) for(auto lim_##name = end,name = beg;name >= lim_##name;name--)
#define repn(lim) for(auto REPN_lIM = lim,REPN = 1;REPN <= REPN_lIM;REPN++)
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define trace() debug("line : %d, Function : %s\n",__LINE__,__FUNCTION__)
using ll = long long;
constexpr int maxn = 1e5 + 100,sigma = 26,inf = 0x3f3f3f3f;

char buf[maxn];
int n,val[maxn],nxt[maxn][sigma];

struct Frac{
    int fz,fm;
    bool operator < (const Frac t)const{
        return fz * t.fm < t.fz * fm; 
    }
};

Frac mi{514,114};
std::pair<int,int> ans;

int main(){
    std::scanf("%d",&n);
    std::scanf("%s",buf + 1);
    rep(i,1,n)val[i] = buf[i] - 'a';
    rep(c,0,sigma - 1)nxt[n + 1][c] = n + 1;
    per(i,n,1)
        rep(c,0,sigma - 1)
            if(val[i] == c)nxt[i][c] = i;
            else nxt[i][c] = nxt[i + 1][c];
    rep(l,1,n){
        std::vector<int> pos;
        std::vector<bool> vis(sigma);
        int r = l;
        while(r <= n){
            vis[val[r]] = 1;
            pos.push_back(r);
            
            std::pair<int,int> pir{inf,0};
            rep(c,0,25)
                if(!vis[c])
                    pir = std::min(pir,std::make_pair(nxt[r][c],c));
            r = pir.first;
        }
        pos.push_back(n + 1);
        for(size_t i = 1;i < pos.size();i++){
            let t = Frac{(int)i,pos[i] - l};
            if(t < mi){
                mi = t;
                ans = std::make_pair(l,pos[i] - 1);
            }
        }
    }
    std::printf("%d %d\n",ans.first,ans.second);
    return 0;
}

Compilation message (stderr)

nivelle.cpp: In function 'int main()':
nivelle.cpp:28:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     std::scanf("%d",&n);
      |     ~~~~~~~~~~^~~~~~~~~
nivelle.cpp:29:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     std::scanf("%s",buf + 1);
      |     ~~~~~~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...