#include <iostream> #include <cstdio> #include <sstream> #include <string> using namespace std; int n; string str; int main() { int t; cin>>t; while(t–) { cin>>n; cin>>str; int i=0,j=1,k; while(i<n && j<n) { for(k=0;k<n;k++) { if(str[(k+i)%n]!=str[(k+j)%n]) break; } if(k==n) break; if(str[(k+i)%n]>str[(k+j)%n]) i=i+k+1; else if(str[(k+i)%n]<str[(k+j)%n]) j=j+k+1; if(i==j) j+=1; } cout<<((i>j)?j:i)<<"\n"; } return 0; }
Category: Critical
12241
Theory: We know that, From 0-9, each digit occurs once From 0-99, each digit occurs 20 times (10x in position 1 and 10x in position 2) From 0-999, each digit occurs 300 times (100x in P1, 100x in P2, 100x in P3) If the range is from 0 to a power of 10 then occurrence
12517
Theory: from 0 to 99 there are 2*10^1=20 for each 0 to 9 digits. from 0 to 999 there are 3*10^2=300 for each 0 to 9 digits. so the foemulae is for 0 to n number of 9’s n*10^(n-1) for each 0 to 9 digits. And so, for upto 445 we can find total number
1016
Theory: The key to figuring out this problem was to recognize that you needed to resolve cycles in the data – if you follow an item to the item that’s in its spot, and then the one that’s in the next one’s spot, until you reach the original item again, you’ll have a cycle of
306
#include <iostream> #include <map> #include <vector> #include <string> #include <stdio.h> /* 10 4 5 3 7 2 8 1 6 10 9 1 Hello Bob 1995 CERC 0 0 Sample Output BolHeol b C RCE */ using namespace std; int arr[202]; vector<char> c_arr[202]; char s[202]; int cycle(int pos) { int org=pos; int init=arr[pos]; int cnt=1;
12712
#include <iostream> using namespace std; int main() { int t,c=0; int MX; int L,M,N; unsigned long long sum,tmp; cin>>t; while(t–) { cin>>L>>M>>N; c++; MX=L*L; tmp=1; for(int i=M-1;i>=0;i–) { tmp=tmp*(MX-i); tmp%=10000000000007; } sum=0; for(int j=1;j<=N-M+1;j++) { sum+=tmp; sum%=10000000000007; tmp*=(MX-M+1-j); tmp%=10000000000007; } cout<<"Case "<<c<<": "; cout<<sum<<"\n"; } return 0; }
12716
#include <iostream> using namespace std; int a[30000005]; int main() { int t,n,c=0; for(int i=1;i<30000005;i++) { for(int j=i<<1;i+j<30000005;j+=i) { if(((i+j)&j)==j) a[i+j]++; } } for(int i=1;i<30000005;i++) a[i]+=a[i-1]; cin>>t; while(t–) { cin>>n; c++; cout<<"Case "<<c<<": "<<a[n]<<"\n"; } return 0; }