Submission #572603

#TimeUsernameProblemLanguageResultExecution timeMemory
572603groshiMonochrome Points (JOI20_monochrome)C++17
100 / 100
52 ms5764 KiB
#include<iostream> #include<vector> #include<string> using namespace std; #define int long long vector<int> b,w; int n; int wyn(int ile) { int wynik=0; for(int i=0;i<b.size();i++) { int l=b[i]; int r=w[(i+ile)%n]; if(l>r) swap(l,r); int ile1=(r-l-1); int ile2=2*n-ile1-2; wynik+=min(ile1,ile2); } return wynik/2; } int32_t main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); cin>>n; string s; cin>>s; for(int i=0;i<s.length();i++) if(s[i]=='B') b.push_back(i); else w.push_back(i); int pocz=0,kon=n,sre,ostd=0; while(pocz<kon) { sre=(pocz+kon)/2; if(wyn(sre)<wyn(sre+1)) { ostd=sre+1; pocz=sre+1; } else kon=sre; } //for(int i=0;i<n;i++) //cout<<wyn(i)<<" "; cout<<wyn(ostd); return 0; }

Compilation message (stderr)

monochrome.cpp: In function 'long long int wyn(long long int)':
monochrome.cpp:11:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for(int i=0;i<b.size();i++)
      |                 ~^~~~~~~~~
monochrome.cpp: In function 'int32_t main()':
monochrome.cpp:31:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for(int i=0;i<s.length();i++)
      |                 ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...