Submission #1088669

# Submission time Handle Problem Language Result Execution time Memory
1088669 2024-09-14T18:34:41 Z StefanSebez Garage (IOI09_garage) C++14
100 / 100
2 ms 424 KB
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
int main(){
    int n,m;scanf("%i%i",&n,&m);
    int a[n+10];for(int i=1;i<=n;i++) scanf("%i",&a[i]);
    int b[m+10];for(int i=1;i<=m;i++) scanf("%i",&b[i]);
    int q=2*m;
    queue<int>kju;
    int res=0;
    int broj[n+10]={0};
    while(q--){
		//for(int i=1;i<=n;i++) printf("%i ",broj[i]);printf("\n");
		int j;scanf("%i",&j);
		if(j>0){
			bool bul=false;
			for(int i=1;i<=n;i++){
				if(!broj[i]){
					res+=a[i]*b[j];
					broj[i]=j;
					bul=true;
					break;
				}
			}
			if(!bul) kju.push(j);
		}
		else{
			j=-j;
			bool bul=false;
			for(int i=1;i<=n;i++){
				if(!broj[i]) bul=true;
				if(broj[i]==j){
					broj[i]=0;
				}
			}
			if(!bul && kju.size()){
				j=kju.front();kju.pop();
				for(int i=1;i<=n;i++){
					if(!broj[i]){
						res+=a[i]*b[j];
						broj[i]=j;
						bul=true;
						break;
					}
				}
			}
		}
    }
    printf("%i\n",res);
    return 0;
}

Compilation message

garage.cpp: In function 'int main()':
garage.cpp:9:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     int n,m;scanf("%i%i",&n,&m);
      |             ~~~~~^~~~~~~~~~~~~~
garage.cpp:10:44: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     int a[n+10];for(int i=1;i<=n;i++) scanf("%i",&a[i]);
      |                                       ~~~~~^~~~~~~~~~~~
garage.cpp:11:44: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     int b[m+10];for(int i=1;i<=m;i++) scanf("%i",&b[i]);
      |                                       ~~~~~^~~~~~~~~~~~
garage.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |   int j;scanf("%i",&j);
      |         ~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 424 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 416 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 2 ms 348 KB Output is correct