Submission #675954

#TimeUsernameProblemLanguageResultExecution timeMemory
675954guagua0407 Martian DNA (BOI18_dna)C++17
100 / 100
249 ms13440 KiB
/* 燒雞 燒雞 燒雞 好想進選訓 燒雞 燒雞 */ #pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define ll long long #define pii pair<int,int> #define f first #define s second #define all(x) x.begin(),x.end() #define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); void setIO(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout); } const int mxn=2e5+5; int num[mxn]; map<int,int> mp; vector<int> cntr(mxn,0); vector<bool> isenough(mxn,false); set<int> have; int n; int main() {_ //setIO("wayne"); int k,R; cin>>n>>k>>R; for(int i=1;i<=n;i++){ cin>>num[i]; } for(int i=0;i<R;i++){ int x,cnt; cin>>x>>cnt; mp[x]=cnt; have.insert(x); } int ans=n+1; int r=0; int cur=0; for(int l=1;l<=n;l++){ while(cur<R and r+1<=n){ r++; if(have.count(num[r])){ cntr[num[r]]++; if(cntr[num[r]]>=mp[num[r]]){ if(isenough[num[r]]==false){ cur++; } isenough[num[r]]=true; } } if(r==n) break; } if(cur>=R){ ans=min(ans,r-l+1); } if(have.count(num[l])==0) continue; cntr[num[l]]--; if(cntr[num[l]]<mp[num[l]]){ if(isenough[num[l]]==true){ cur--; } isenough[num[l]]=false; } } if(ans==n+1){ cout<<"impossible"; } else{ cout<<ans; } return 0; } //maybe its multiset not set

Compilation message (stderr)

dna.cpp: In function 'void setIO(std::string)':
dna.cpp:19:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dna.cpp:20:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...