結果

問題 No.59 鉄道の旅
コンテスト
ユーザー ciel
提出日時 2015-04-24 04:38:18
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
RE  
実行時間 -
コード長 382 bytes
コンパイル時間 352 ms
コンパイル使用メモリ 38,400 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-24 20:36:47
合計ジャッジ時間 2,601 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 7 RE * 5
権限があれば一括ダウンロードができます
コンパイルメッセージ
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);
      |                 ~~~~~^~~~~~~~~

ソースコード

diff #

#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==-n)v.erase(it);
		}
	}
	printf("%d\n",v.size());
}
0