# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
850434 | 2023-09-16T14:42:56 Z | alexdd | Floppy (RMI20_floppy) | C++17 | 203 ms | 13056 KB |
#include<bits/stdc++.h> #include "floppy.h" using namespace std; string cv = ""; string inc = ""; int anc[400005][20]; string get01(int x) { if(x==0) return "0"; string s; for(int i=0;i<20;i++) { if(((1<<i)&x)) s.push_back('1'); else s.push_back('0'); } while(s[s.size()-1]=='0') s.pop_back(); //cout<<"\n"<<x<<" "<<s<<" int -> string\n"; return s; } int toint(string s) { int x=0; for(int i=0;i<s.size();i++) { if(s[i]=='1') x+=(1<<i); } //cout<<"\n"<<s<<" "<<x<<" string -> int \n"; return x; } string get_bits(vector<int> v) { deque<int> dq; inc=""; cv=""; for(int i=0;i<v.size();i++) { int cnt=0; while(!dq.empty() && v[dq.back()]<v[i]) { dq.pop_back(); cnt++; } //cout<<cnt<<" "; dq.push_back(i); string s = get01(cnt); cv = cv + s; inc.push_back('1'); for(int j=1;j<s.size();j++) inc.push_back('0'); } return cv+inc; } void read_array(int subtask_id, const std::vector<int> &v) { string s1 = get_bits(v); vector<int> v2 = v; reverse(v2.begin(),v2.end()); string s2 = get_bits(v2); if((int)s1.size()<=(int)s2.size()) { save_to_floppy(s1+"0"); } else { save_to_floppy(s2+"1"); } } vector<int> solve_queries(int subtask_id, int N, const std::string &bits, const std::vector<int> &a, const std::vector<int> &b) { int poz=0, L=(int)bits.size()/2; deque<int> dq; for(int i=0;i<N;i++) { int newpoz=L; string s=""; s.push_back(bits[poz]); for(int j=poz+1;j<L;j++) { newpoz=j; if(bits[L+j]=='1') break; s.push_back(bits[j]); } int x = toint(s); //cout<<x<<" "; for(int j=0;j<x;j++) dq.pop_back(); if(!dq.empty()) anc[i][0]=dq.back(); else anc[i][0]=i; dq.push_back(i); poz = newpoz; } for(int p=1;p<20;p++) for(int i=0;i<N;i++) anc[i][p]=anc[anc[i][p-1]][p-1]; //cout<<"\n"; vector<int> ans((int)a.size()); for(int i=0;i<a.size();i++) { int newa=a[i],newb=b[i]; if(bits[bits.size()-1]=='1') { newb = N - a[i] - 1; newa = N - b[i] - 1; } int cur = newb; for(int p=19;p>=0;p--) if(anc[cur][p]>=newa) cur=anc[cur][p]; if(bits[bits.size()-1]=='1') ans[i]=N-cur-1; else ans[i]=cur; } return ans; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 812 KB | Output is correct |
2 | Correct | 1 ms | 804 KB | Output is correct |
3 | Correct | 2 ms | 812 KB | Output is correct |
4 | Correct | 1 ms | 812 KB | Output is correct |
5 | Correct | 2 ms | 804 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 4932 KB | Output is correct |
2 | Correct | 27 ms | 4824 KB | Output is correct |
3 | Correct | 24 ms | 4904 KB | Output is correct |
4 | Correct | 26 ms | 5164 KB | Output is correct |
5 | Correct | 24 ms | 4820 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Partially correct | 203 ms | 13056 KB | Partially correct |
2 | Partially correct | 183 ms | 12952 KB | Partially correct |
3 | Correct | 162 ms | 13056 KB | Output is correct |
4 | Partially correct | 157 ms | 12800 KB | Partially correct |
5 | Partially correct | 178 ms | 12936 KB | Partially correct |