ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1971. Graphics Settings

test 6: Runtime error (access violation), what can it be?
Posted by Abram_TA 8 Aug 2013 02:22
Here is my not accepted solution:
#include<iostream>
#include<string>
using namespace std;

double P(int power[],string names[],int a,int n,int video_power,int on_or_off[],int w,int h){
a=video_power;
for(int i=0;i<n;i++){if(on_or_off[i]==1){a/=power[i];}}
double res=a/(w*h);
return res;
}

int main()
{

int n;
cin>>n;
string * names = new string[n];
int * power = new int[n];
for (int i=0;i<n;i++){
cin>>names[i];
cin>>power[i];
}

int w,h,video_power;
cin>>w>>h>>video_power;

double results[100];
int on_or_off[100];
for(int i=0;i<n;i++){on_or_off[i]=1;}
int e=0;

int a=video_power;
for (int i=0; i<n;i++){
a/=power[i];
}
double prodyctivity=a/(w*h);
results[e]=prodyctivity;e++;

int m;
cin>>m;
for(int i=0; i<m; i++){
string change,change_name;
cin>>change;
if(change[0]!='R'){
cin>>change_name;
for(int y=0;y<n;y++){
    if(change=="On" && change_name==names[y]){
        on_or_off[y]=1;
        prodyctivity=P(power,names,a,n,video_power,on_or_off,w,h);
        results[e]=prodyctivity;e++;
        }
    else if(change=="Off" && change_name==names[y]){
        on_or_off[y]=0;
        prodyctivity=P(power,names,a,n,video_power,on_or_off,w,h);
        results[e]=prodyctivity;e++;
        }
}
}
else{
int a1,a2;
cin>>a1>>a2;
w=a1;h=a2;
prodyctivity=P(power,names,a,n,video_power,on_or_off,w,h);
results[e]=prodyctivity;e++;
}
}

for(int i=0;i<m+1;i++){
    if(results[i]<10){cout<<"Slideshow"<<endl;}
    else if(results[i]>=60){cout<<"Perfect"<<endl;}
    else{cout<<"So-so"<<endl;}
}
}

Please!
Re: test 6: Runtime error (access violation), what can it be?
Posted by Dmitry 9 Aug 2013 18:36
I dont know where your mistake is, but anyway this solution is wrong.
Check the max test case: n = 99999 and each option is 100 (100^99999). Your double precision not enough for AC.
Re: test 6: Runtime error (access violation), what can it be?
Posted by Bradut Palas 31 Oct 2016 17:27
It's 100000 results, not 100 results, hence the access violation on your tiny array