Submission #382967

# Submission time Handle Problem Language Result Execution time Memory
382967 2021-03-28T15:54:43 Z victoriad Relativnost (COCI15_relativnost) C++14
0 / 140
4000 ms 11372 KB
#include <fstream>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;
int mod=10007;
void per(vector<int>&a,vector<int>&b,int & r,vector<int>&p,int i,int c,int nec,int u){
if(u==a.size()){
    if(c>=nec){
        int j=1;
        for(int i=0;i<a.size();i++){
            j=j%mod;
            if(p[i]==1){
                j*=a[i];
                j=j%mod;
            }
            else{
                j*=b[i];
                j=j%mod;
            }
        }
        r+=j;
        r=r%mod;
        
        
    }
    
    return;
}
u++;
p[i]=0;
per(a,b,r,p,i+1,c,nec,u);
p[i]=1;
per(a,b,r,p,i+1,c+1,nec,u);
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,c,q,p,l,r;
    cin>>n>>c;
    vector<int >a(n);
     vector<int>b(n);
     for(int i=0;i<n;i++){
         cin>>a[i];
     }
     for(int i=0;i<n;i++){
         cin>>b[i];
     }
     cin>>q;
     int re;
     for(int i=0;i<q;i++){
         vector<int>pr(n,0);
         cin>>p>>l>>r;
         if(i==0){
             if(c==n){
                a[p-1]=l;
                re=1;
                for(int k=0;k<n;k++){
                    re*=a[k];
                    re=re%mod;
                }
             }
             else{
                a[p-1]=l;
                b[p-1]=r;
                re=0;
                per(a,b,re,pr,0,0,c,0); 
             }
             cout<<re%mod<<"\n";
         }
         else if(i!=0 && a[p-1]==l&& b[p-1]==r){
             cout<<re%mod<<"\n";
         }
         else if(n==c){
             re/=a[p-1];
             re*=l;
             a[p-1]=l;
             cout<<re%mod<<"\n";
         }
         else{
            a[p-1]=l;
         b[p-1]=r;
         re=0;
         per(a,b,re,pr,0,0,c,0);
        cout<<re%mod<<"\n"; 
         }
         
     }

  return 0;
}








Compilation message

relativnost.cpp: In function 'void per(std::vector<int>&, std::vector<int>&, int&, std::vector<int>&, int, int, int, int)':
relativnost.cpp:11:5: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 | if(u==a.size()){
      |    ~^~~~~~~~~~
relativnost.cpp:14:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |         for(int i=0;i<a.size();i++){
      |                     ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Execution timed out 4089 ms 492 KB Time limit exceeded
2 Execution timed out 4091 ms 364 KB Time limit exceeded
3 Execution timed out 4094 ms 364 KB Time limit exceeded
4 Execution timed out 4098 ms 6636 KB Time limit exceeded
5 Execution timed out 4100 ms 10732 KB Time limit exceeded
6 Execution timed out 4091 ms 11372 KB Time limit exceeded
7 Execution timed out 4085 ms 8044 KB Time limit exceeded
8 Execution timed out 4093 ms 11244 KB Time limit exceeded
9 Execution timed out 4098 ms 9472 KB Time limit exceeded
10 Execution timed out 4049 ms 8812 KB Time limit exceeded