結果
| 問題 | No.59 鉄道の旅 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2015-04-24 04:39:26 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 438 ms / 5,000 ms | 
| コード長 | 395 bytes | 
| コンパイル時間 | 343 ms | 
| コンパイル使用メモリ | 38,912 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-12-24 20:36:55 | 
| 合計ジャッジ時間 | 1,733 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 12 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:18:18: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wformat=]
   18 |         printf("%d\n",v.size());
      |                 ~^    ~~~~~~~~
      |                  |          |
      |                  int        std::vector<int>::size_type {aka long unsigned int}
      |                 %ld
main.cpp:6:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    6 |         scanf("%d%d",&N,&K);
      |         ~~~~~^~~~~~~~~~~~~~
main.cpp:9:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |                 scanf("%d",&n);
      |                 ~~~~~^~~~~~~~~
            
            ソースコード
#include <vector>
#include <cstdio>
int main(){
	std::vector<int>v;
	int N,K;
	scanf("%d%d",&N,&K);
	for(int i=0;i<N;i++){
		int n;
		scanf("%d",&n);
		if(n>0){
			auto it=std::lower_bound(v.begin(),v.end(),n);
			if(std::distance(it,v.end())<K)v.insert(it,n);
		}else{
			auto it=std::lower_bound(v.begin(),v.end(),-n);
			if(it!=v.end()&&*it==-n)v.erase(it);
		}
	}
	printf("%d\n",v.size());
}
            
            
            
        