Please update the link to this and other INOI problems. Contest Page
Here's my solution, enjoy.
#include <iostream>using namespace std;int main(){int N,i,currdepth,depthmax,nestdepthloc,maxbrackseq,maxbrackseqstart,brackstart;cin>>N;char ch;currdepth=0;depthmax=0;nestdepthloc=0;brackstart=0;maxbrackseq=0;maxbrackseqstart=0;for(i=0;i<N;i++){cin>>ch;if(ch=='1'){currdepth++;if(currdepth==1){brackstart=i;}if(currdepth>depthmax){
Here's my solution in case anyone is interested.
#include <iostream>using namespace std;long partarr2(long arr[],long lowest, long highest,long arr2[]){long pivot=arr[lowest];long lpolong=lowest-1;long rpolong=highest+1;while(lpolong<=highest){do{lpolong++;}while(arr[lpolong]<pivot);do{rpolong--;}while(arr[rpolong]>pivot);if (lpolong>=rpolong){return rpolong;}swap(arr[lpolong],arr[rpolong]);swap(arr2[lpolong],arr2[rpolong]);}}void quicksort2(long arr[],long lowest, long highest, long arr2[]){
You're inputting and outputting in standard output, not into/from the file. Replace cin by fin and cout by fout. Thank you for the solution, by the way!
Yep - in Q2 L does 2000 computations, actually.
In Q3: 100*100=10000 (L) < 10*100^2+10*100 = 101000 (Q)
Less computations make an algorithm faster - thus, in Q2-Q4 L is the faster algorithm.
Almost forgot to put my output in ascending order - was getting 31% otherwise.
#include <iostream>#include <fstream>#include <algorithm>#include <vector>using namespace std;int main(){ifstream listin;listin.open("listin.txt");long int f,i,maxAm;maxAm=1;listin>>f;vector<int>IDsMax;vector<long int>amounts;amounts.resize(1001,0);int inp;for(i=1;i<=f*2;i++){listin>>inp;amounts[inp]++;
Using arrays in this problem is pretty inefficient, so I used a vector.
#include <iostream>#include <fstream>#include <vector>using namespace std;int main(){ifstream tripin;tripin.open("tripin.txt");unsigned int n,i;tripin>>n;unsigned int amount=0;long int inp;string output;vector<unsigned int> vect;for(i=1;i<=n;i++){tripin>>inp;if ((inp % 3)==0){amount++;vect.push_back(i);
In case you have difficulties with solving this problem and don't know what you forgot to include, feel free to compare your code to mine - I hope this helps!
#include <iostream>#include <fstream>using namespace std;int main(){ifstream bendin;bendin.open("bendin.txt");int x1,y1,x2,y2,x3,y3,x4,y4;bendin>>x1>>y1>>x2>>y2>>x3>>y3>>x4>>y4;bendin.close();ofstream bendout;bendout.open("bendout.txt");long int intarea=0;if((x3>=x1)&&(x3<=x2)){if((x4>=x1)&&(x4<=x2)){if((y3>=y1)&&(y3<=y2)){if((y4>=y1)&&(y4<=y2)){intarea=(x4-x3)*(y4-y3);