結果
| 問題 |
No.859 路線A、路線B、路線C
|
| コンテスト | |
| ユーザー |
tarattata1
|
| 提出日時 | 2019-08-09 22:02:37 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 1,000 ms |
| コード長 | 1,572 bytes |
| コンパイル時間 | 584 ms |
| コンパイル使用メモリ | 69,072 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-19 12:05:10 |
| 合計ジャッジ時間 | 1,268 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
コンパイルメッセージ
main.cpp: In function ‘int main(int, char**)’:
main.cpp:45:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
45 | scanf("%d%d%d", &x, &y, &z);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:49:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
49 | scanf("%s %d", str0, &p0);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
main.cpp:50:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
50 | scanf("%s %d", str1, &p1);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996)
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;
int x,y,z;
void calc( char* str0, int p0, ll& dist0, ll& dist1 )
{
if(str0[0]=='A') {
dist0+=p0;
dist1+=(x-p0);
}
else if(str0[0]=='B') {
dist0+=p0;
dist1+=(y-p0);
}
else {
dist0+=p0;
dist1+=(z-p0);
}
return;
}
int main(int argc, char* argv[])
{
scanf("%d%d%d", &x, &y, &z);
char str0[5]={0}, str1[5]={0};
int p0, p1;
scanf("%s %d", str0, &p0);
scanf("%s %d", str1, &p1);
int cnt[3]={0};
cnt[str0[0]-'A']++;
cnt[str1[0]-'A']++;
ll dist=LINF;
if(str0[0]==str1[0]) {
dist = abs(p0-p1);
}
{
ll dist00=0, dist01=0, dist10=0, dist11=0;
calc(str0, p0, dist00, dist01);
calc(str1, p1, dist10, dist11);
dist=MIN(dist, dist00+dist10-1);
dist=MIN(dist, dist01+dist11+1);
int k;
for(k=0; k<3; k++) {
ll L=(k==0? x: (k==1? y: z));
dist=MIN(dist, dist00+dist11+L);
dist=MIN(dist, dist10+dist01+L);
}
printf("%lld\n", dist);
}
return 0;
}
tarattata1